简体   繁体   English

Anaconda 和 Opencv 不打开 mp4

[英]Anaconda and Opencv does not open mp4

im trying to read an mp4 file in my python script with Opencv3 (which is installed in conda env) on ubuntu.我试图在 ubuntu 上使用 Opencv3(安装在conda env 中)读取我的 python 脚本中的 mp4 文件。 But get following message :但得到以下消息:

Unable to stop the stream: Inappropriate ioctl for device

I found that Opencv does not support mp4 out of the box.我发现 Opencv 不支持开箱即用的 mp4。 Is it possible to install extra libs on my machine to make video work without rebuilding Opencv?是否可以在我的机器上安装额外的库来使视频工作而无需重建 Opencv? Some configuration maybe?可能是一些配置?

Here comes the code :代码如下:

def workOnVideoFile(path) : 
    print('Reading the video from ' + path )
    cap = cv2.VideoCapture(path)

    print('Is video opened?  ' + str(cap.isOpened()) )
    while(cap.isOpened()):

        ret, frame = cap.read()
        print('Frame has been read ' + str(ret))
        workOnFrame(frame)
        if cv2.waitKey(1) & 0xFF == ord('q'):
            break

    print('Releasing the video' + str(cap))
    cap.release()


#img = cv2.imread('car.jpg')



if __name__ == "__main__":
    if (os.path.isfile(videoFile)) :
        workOnVideoFile(videoFile)
    else : 
        print('File ' + videoFile + ' is not found')


cv2.destroyAllWindows()

I think its probably ubuntu which is not supporting MP4 out of the box - this is because MP4 has some patent issues.我认为它可能是 ubuntu 不支持开箱即用的 MP4 - 这是因为 MP4 有一些专利问题。

The usual approach is to add support for MP4 in a standard way to an Ubuntu install like this:通常的方法是以标准方式为 Ubuntu 安装添加对 MP4 的支持,如下所示:

sudo apt-get install ubuntu-restricted-extras sudo apt-get install ubuntu-restricted-extras

This name maybe looks a little odd but its more or less standard practice - see the help article here to reassure you:这个名字可能看起来有点奇怪,但它或多或少是标准做法 - 请参阅此处的帮助文章向您保证:

Many people who want to just play back video simply install VideoLan which takes care of all this, so they don't have to do the step above.许多只想播放视频的人只需安装 VideoLan 即可完成所有这些工作,因此他们不必执行上述步骤。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM