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

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

问题描述

我目前正在从事一个涉及阅读 mp4 视频文件的项目.我遇到的问题是它在 Windows 7 机器上使用 Python 2.7(32 位)、OpenCV 2.4.3 (cv2.pyd).

代码片段如下:

尝试:视频 = cv2.VideoCapture("video.mp4")除了:打印无法打开视频文件"增加打印 video.grab()

"video.grab()" 总是返回 false:意味着它不读取文件 "video.mp4"但是当我们尝试这样做时:

尝试:video = cv2.VideoCapture("video.avi")除了:打印无法打开视频文件"增加打印 video.grab()

"video.grab()" 返回 true:意味着它能够读取 ".avi" 文件.

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

这个问题类似于这个问题这个问题.双方都没有明确可行的答案.

除了仅使用 Linux 或 Mac 进行编程之外,我将不胜感激,因为我需要它在所有三个系统上工作.

解决方案

我之前也遇到过同样的问题,通过这一步解决了:

检查您的 OpenCV python 版本

<预><代码>>>>从 cv2 导入 __version__>>>__版本__'2.4.0'

然后将您的 opencv_ffmpeg.dll 复制到 C:Python27 并将其重命名为相关的 OpenCV Python 版本.就我而言,我不得不将其重命名为 opencv_ffmpeg240.dll.

更新:在 Windows 上,您可以在 OpenCV 安装的构建文件夹中找到 opencv_ffmpeg DLL.例如:C:devopencvuildx86vc12in

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

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.

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:

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.

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.

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:

Check your OpenCV python version

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

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.

Update: On Windows, you can find the opencv_ffmpeg DLL inside of the build folder of your OpenCV installation. For example: C:devopencvuildx86vc12in

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

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

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