windows使用python opencv 录视频打不开_无法打开“.mp4”使用OpenCV 2.4.3的视频文件,Windows 7中的Python 2.7...

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:\dev\opencv\build\x86\vc12\bin

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

  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值