无法打开“.mp4”使用OpenCV 2.4.3的视频文件,Windows 7中的Python 2.7 [英] Cannot open ".mp4" video files using OpenCV 2.4.3, Python 2.7 in Windows 7 machine

查看:543
本文介绍了无法打开“.mp4”使用OpenCV 2.4.3的视频文件,Windows 7中的Python 2.7的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述

我正在开展一个涉及阅读mp4视频文件的项目。
我遇到的问题是在Windows 7机器中使用Python 2.7(32位),OpenCV 2.4.3(cv2.pyd)。

I am currently working on a project that involves reading mp4 video files. The problem I encountered is that it using Python 2.7 (32 bit), OpenCV 2.4.3 (cv2.pyd) in a Windows 7 machine.

代码片段如下:

try:
        video = cv2.VideoCapture("video.mp4")
except:
        print "Could not open video file"
        raise
print video.grab()

video.grab()总是返回false:表示没有读取文件 video .mp4
但是当我们尝试这样做:

"video.grab()" always returns false: meaning it doesn't read the file "video.mp4" But when we try this:

try:
        video = cv2.VideoCapture("video.avi")
except:
        print "Could not open video file"
        raise
print video.grab()

video.grab()返回true:能够阅读 .avi 文件。

"video.grab()" returns true: meaning it is able to read ".avi" files.

另一个是我们在Linux和Mac上尝试过同样的片段,它似乎工作正常,这意味着它能够读取mp4文件和avi文件。

Another is we have tried this same snippet on Linux and Mac and it seems to work fine, meaning it is able to read both mp4 files and avi files.

此问题类似于这个问题这个问题的。两者仍然没有一个清晰可行的答案。

This problem is similar to this problem and this problem. Both still don't have a clear and workable answer.

我将不胜感激任何帮助或解决方法,除了使用Linux或Mac进行编程,因为我需要这样工作在所有三个系统上。

I would appreciate any help or workaround aside from just using Linux or Mac for programming this as I need this to work on all three systems.

推荐答案

以前我已经有同样的问题,解决了这一步:

I have had the same issue before, solved by this step:

检查您的OpenCV python版本

Check your OpenCV python version

>>> from cv2 import __version__
>>> __version__
'2.4.0'

然后复制您的 opencv_ffmpeg。 dll C:\Python27\ ,并将其重命名为与OpenCV Python版本相关。在我的情况下,我不得不将其重命名为 opencv_ffmpeg240.dll

Then Copy your opencv_ffmpeg.dll to C:\Python27\ and rename it to relevant your OpenCV Python Version. In my case I had to rename it to opencv_ffmpeg240.dll.

更新:在Windows上,您可以在OpenCV安装的构建文件夹中找到opencv_ffmpeg DLL。例如: C:\dev\opencv\build\x86\vc12\bin

Update: On Windows, you can find the opencv_ffmpeg DLL inside of the build folder of your OpenCV installation. For example: C:\dev\opencv\build\x86\vc12\bin

然后,只需将 opencv_ffmpeg< version> .dll 文件复制并粘贴到Python安装的根文件夹中。

Then, just copy and paste the opencv_ffmpeg<version>.dll file into the root folder of your Python installation.

这篇关于无法打开“.mp4”使用OpenCV 2.4.3的视频文件,Windows 7中的Python 2.7的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆