Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Welcome To Ask or Share your Answers For Others

Categories

0 votes
1.3k views
in Technique[技术] by (71.8m points)

Cannot open ".mp4" video files using OpenCV 2.4.3, Python 2.7 in Windows 7 machine

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.

See Question&Answers more detail:os

与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
Welcome To Ask or Share your Answers For Others

1 Reply

0 votes
by (71.8m points)

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.


与恶龙缠斗过久,自身亦成为恶龙;凝视深渊过久,深渊将回以凝视…
OGeek|极客中国-欢迎来到极客的世界,一个免费开放的程序员编程交流平台!开放,进步,分享!让技术改变生活,让极客改变未来! Welcome to OGeek Q&A Community for programmer and developer-Open, Learning and Share
Click Here to Ask a Question

...