OpenCV 2.4 VideoCapture not working on Windows

PythonWindowsOpencv

Python Problem Overview


I'm using Python bindings to OpenCV 2.4 installed with following instructions.

My problem is similar to this one, but I need Windows machine solution.

Problem: when I try to use

cap = cv2.VideoCapture(0)
print cap.grab()

it works fine, but the following code

cap = cv2.VideoCapture(filename)
print cap.grab()

always return False.

Path to the file is correct, absolute and has no spaces.

I tried on two machines with Windows XP and Windows 7 with similar results. On Linux (Ubuntu) it works fine for me.

Python Solutions


Solution 1 - Python

Add C:\OpenCV\3rdparty\ffmpeg\ to the Windows PATH environment variable or copy opencv_ffmpeg.dll from that directory to C:\Python27\ or to a directory that is in the PATH. Alternatively, use the OpenCV binaries from http://www.lfd.uci.edu/~gohlke/pythonlibs/#opencv.

Renaming the opencv_ffmpeg.dll file may also be necessary.

For OpenCV version X.Y.Z
opencv_ffmpeg.dll ==> opencv_ffmpegXYZ.dll

For 64-bit OpenCV version X.Y.Z
opencv_ffmpeg.dll ==> opencv_ffmpegXYZ_64.dll

Solution 2 - Python

Copying opencv_ffmpeg.dll wasn't enough for me - I had to rename it to opencv_ffmpeg246.dll, when I used OpenCV 2.4.6 with Python 2.7.5

Solution 3 - Python

I first tried copying, then changing the Path environment of windows.. it didn't work until i changed the name to opencv_ffmpeg245.dll for my openCV version 2.4.5 and python 2.7. (notice **245.dll is from opencv version 2.4.5)

Solution 4 - Python

For 64 bit versions, rename opencv_ffmpeg_64.dll to opencv_ffmpeg249_64.dll Change 249 to your opencv version.

Solution 5 - Python

For OpenCV 3.0.0 on 64 bit environment copy opencv_ffmpeg_64.dll and rename it to opencv_ffmpeg300_64.dll.

Also add this path to your PATH environment variable to get it work with OpenCV under Java.

Solution 6 - Python

Update: This is still true for OpenCV 2.4.9, copy all the files, and rename the dll opencv_ffmpeg249.dll

Solution 7 - Python

I had the same issue with python 2.7 and opencv 2.4.10. I copied the opencv_ffmpeg2410_64.dll file from C:\Applications\opencv\build\x64\vc10\bin into the python path (mine is at C:\Users\mohammad\Anaconda) and it was solved!

Solution 8 - Python

At first I use windows8.1 32bit and opencv 2.4.10.
I faced same problem to use file test1.wmv which was made by Logicool C270.
I tried to use other file test2.mov which was made by Digital Camera ( Canon SX160 ). So I can play test2.mov to append path C:\opencv\build\x86\vc12\bin.
But I cannot Play test1.wmv.
So I try to change format test1.wmv to test1a.mp4 by using VLC ( to Video for youtube HD) .
Then I can play test1a.mp4.
I tried test1.wmv on Ubuntu 14.04 LTS , then I can play it easy.
It may occur some difference on default ffmpeg binary between windows8.1 and Ubuntu 14.04 LTS.

Solution 9 - Python

For anaconda environment copy opencv_ffmpeg249_64.dll from C:\Python27
rename its version according to your opencv correct version and past it to C:\Users\KHALID\Anaconda2\Library\bin

Attributions

All content for this solution is sourced from the original question on Stackoverflow.

The content on this page is licensed under the Attribution-ShareAlike 4.0 International (CC BY-SA 4.0) license.

Content TypeOriginal AuthorOriginal Content on Stackoverflow
QuestionBihaqoView Question on Stackoverflow
Solution 1 - PythoncgohlkeView Answer on Stackoverflow
Solution 2 - PythonememView Answer on Stackoverflow
Solution 3 - PythonSanDView Answer on Stackoverflow
Solution 4 - Pythonuser3738775View Answer on Stackoverflow
Solution 5 - PythonmasewoView Answer on Stackoverflow
Solution 6 - Pythonbw4szView Answer on Stackoverflow
Solution 7 - Pythonuser1947921View Answer on Stackoverflow
Solution 8 - PythonuserView Answer on Stackoverflow
Solution 9 - PythonKhalid Bin HudaView Answer on Stackoverflow