无法在 Windows 7 机器中使用 OpenCV 2.4.3、Python 2.7 打开“.mp4”视频文件
声明:本页面是StackOverFlow热门问题的中英对照翻译,遵循CC BY-SA 4.0协议,如果您需要使用它,必须同样遵循CC BY-SA许可,注明原文地址和作者信息,同时你必须将它归于原作者(不是我):StackOverFlow
原文地址: http://stackoverflow.com/questions/13834399/
Warning: these are provided under cc-by-sa 4.0 license. You are free to use/share it, But you must attribute it to the original authors (not me):
StackOverFlow
Cannot open ".mp4" video files using OpenCV 2.4.3, Python 2.7 in Windows 7 machine
提问by TJ Monserrat
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.
我目前正在从事一个涉及阅读 mp4 视频文件的项目。我遇到的问题是它在 Windows 7 机器上使用 Python 2.7(32 位)、OpenCV 2.4.3(cv2.pyd)。
The code snippet is as follows:
代码片段如下:
try:
video = cv2.VideoCapture("video.mp4")
except:
print "Could not open video file"
raise
print video.grab()
"video.grab()" always returns false: meaning it doesn't read the file "video.mp4"
But when we try this:
" video.grab()" 总是返回 false: 意味着它不读取文件 " video.mp4" 但是当我们尝试这样做时:
try:
video = cv2.VideoCapture("video.avi")
except:
print "Could not open video file"
raise
print video.grab()
"video.grab()" returns true: meaning it is able to read ".avi" files.
" video.grab()" 返回 true:意味着它能够读取 " .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.
另一个是我们在 Linux 和 Mac 上尝试了相同的片段,它似乎工作正常,这意味着它能够读取 mp4 文件和 avi 文件。
This problem is similar to this problemand this problem. Both still don't have a clear and workable answer.
这个问题类似于这个问题和这个问题。两者仍然没有明确和可行的答案。
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.
除了仅使用 Linux 或 Mac 进行编程之外,我将不胜感激,因为我需要它在所有三个系统上工作。
回答by av501
Your mp4 may be having codecs for which your system does not have support (or opencv does not have support) while your avi codecs may be supported. Also if opencv is using libav for decoding you should install that.
您的 mp4 可能具有您的系统不支持(或 opencv 不支持)的编解码器,而您的 avi 编解码器可能受支持。此外,如果 opencv 使用 libav 进行解码,您应该安装它。
回答by Yuda Prawira
I have had the same issue before, solved by this step:
我以前也遇到过同样的问题,通过这一步解决了:
Check your OpenCV python version
检查您的 OpenCV python 版本
>>> from cv2 import __version__
>>> __version__
'2.4.0'
Then Copy your opencv_ffmpeg.dllto C:\Python27\and rename it to relevant your OpenCV Python Version. In my case I had to rename it to opencv_ffmpeg240.dll.
然后将您复制opencv_ffmpeg.dll到C:\Python27\并将其重命名为相关的 OpenCV Python 版本。就我而言,我不得不将其重命名为opencv_ffmpeg240.dll.
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
更新:在 Windows 上,您可以在 OpenCV 安装的构建文件夹中找到 opencv_ffmpeg DLL。例如:C:\dev\opencv\build\x86\vc12\bin
Then, just copy and paste the opencv_ffmpeg<version>.dllfile into the root folder of your Python installation.
然后,只需将该opencv_ffmpeg<version>.dll文件复制并粘贴到 Python 安装的根文件夹中即可。
回答by Hexadecimal
I ran into this issue using OpenCV version 2.4.11 and Python 2.7 under a Windows 7 operating system. I wasn't able to open and manipulate mp4 files, but was able to open avi files.
我在 Windows 7 操作系统下使用 OpenCV 版本 2.4.11 和 Python 2.7 遇到了这个问题。我无法打开和操作 mp4 文件,但能够打开 avi 文件。
The solution in my case was to copy the opencv_ffmpeg2411.dll file from the build folder of my OpenCV installation, and paste it into the root folder of my Python installation. So, in my case, the DLL file is in "C:\dev\opencv\build\x86\vc12\bin", and I copied it to "C:\Program Files(x86)\Python2.7".
我的解决方案是从我的 OpenCV 安装的 build 文件夹中复制 opencv_ffmpeg2411.dll 文件,并将其粘贴到我的 Python 安装的根文件夹中。因此,就我而言,DLL 文件位于“C:\dev\opencv\build\x86\vc12\bin”中,我将其复制到“C:\Program Files(x86)\Python2.7”。
回答by Suresh Doraiswamy
I had the same problem with my .mpgvideo file. Couldn't open it in openCV.
我的.mpg视频文件也有同样的问题。无法打开它openCV。
I copied the openCv_ffmpeg330.dllfrom the C:\OpenCV\build\bin folder into the c:\python27folder.
我openCv_ffmpeg330.dll从C:\OpenCV\build\bin folder into the c:\python27文件夹中复制了。
That worked!.
那行得通!

