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

4

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.

Irremeable answered 12/12, 2012 at 6:54 Comment(1)
I'm dealing with this currently. Have an elegant solution now?Waive
M
15

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<version>.dll file into the root folder of your Python installation.

Maniple answered 2/4, 2014 at 9:17 Comment(2)
Thank you! I originally started with python 3 until I noticed some of the blogs I was following ref'd to the 2.7. This simple thing did the trick.Carney
Not working for me. My Python installation is here: c:\Users__name__\AppData\Local\Programs\Python\Python37-32\Sanderlin
S
1

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.

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".

Selfeffacing answered 24/5, 2015 at 15:51 Comment(0)
H
0

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.

Heartbeat answered 15/12, 2012 at 23:46 Comment(2)
I don't know if the system doesn't support mp4. When I am using opencv +python in my Mac and my Linux, I can read mp4s with ease. As of codecs, I can watch mp4s using any other software. As of libav, it comes with the package of opencv and also downloaded a new libav for Windows from the FFmpeg website... I just don't know if I installed it right... Do you know how to install the libav and other libraries for opencv+python to use?Irremeable
Will it be safe to say that my system does support mp4 if I can open the same video file and it plays inside the stock player (I run Windows 10)?Teodora
F
0

I had the same problem with my .mpg video file. Couldn't open it in openCV.

I copied the openCv_ffmpeg330.dll from the C:\OpenCV\build\bin folder into the c:\python27 folder.

That worked!.

Fructification answered 24/10, 2017 at 12:33 Comment(0)

© 2022 - 2024 — McMap. All rights reserved.