2

I am trying to use OpenCV2 with my Conda environment for Python 2.7.

My installation was basically the same as what was described in this question.

I retrieved OpenCV like so:

conda install --channel https://conda.anaconda.org/menpo opencv3

I can import the library cv2 and print the version, which is 3.1.0. So far so good. I can even load an image and display it:

import cv2

img = cv2.imread('desertfloor.jpg')
cv2.imshow('foo',img)
cv2.waitKey(0)
cv2.destroyAllWindows()

This works just fine. But when I go to load a video in the same directory:

vid = cv2.VideoCapture('bbb.avi') # Big Buck Bunny
returnval,frame = vid.read()
print returnval

The returned value is False, which tells me that the frame wasn't returned correctly. When I check vid.isOpened(), it is False as well. Since it doesn't return an error, it's really hard to tell what's going on. I've heard that ffmpeg can cause some issues if it's not installed properly (whatever that means), but I can't tell if that's what's going on here.

Can anyone tell me why the video isn't opening properly?

Community
  • 1
  • 1
Noise in the street
  • 589
  • 1
  • 6
  • 20
  • `avi` is just a wrapper, if the encoded video requires a codec that is unsupported then it won't load is my guess, if the file definitely exists and you can open using normal python `open` command then it's likely that this is the issue – EdChum Mar 23 '16 at 14:25
  • Thanks for the advice. How can I tell what codecs are supported? I can play the video on my system using Windows Media Player, which I believe means that the codec is installed on the system (since it doesn't have codecs baked in like VLC does). Is there a known, working video somewhere that someone could point me to that I can use to test? I've tried several that I have, to no avail. – Noise in the street Mar 23 '16 at 14:41
  • it will depend on your environment but you may need to update ffmpeg, this may be of use: http://stackoverflow.com/questions/20133988/opencv-codecs-under-windows – EdChum Mar 23 '16 at 14:44
  • That's great information, thanks... I'm trying to update ffmpeg and I have the most recent 'shared' version of it that has the DLLs. I can't find the spot to put them in my Python 2.7 environment though. How do I go about manually updating the ffmpeg DLLs? – Noise in the street Mar 23 '16 at 15:02
  • Sorry I'm not sure you may need to google this for yourself as I personally don't use opencv for reading video files, rather I manipulate individual video frames – EdChum Mar 23 '16 at 15:03
  • facing the same issue myself. One workaround that people seem to have use to certain success is mentioned here: http://stackoverflow.com/a/22806767/1403840 (basically copy opencv dlls ) However, being a conda installation, cant find them. – Manuel G Jun 07 '16 at 05:05
  • use the **official** OpenCV package, which is on PyPI. don't use packages on conda. – Christoph Rackwitz Sep 07 '22 at 10:03

1 Answers1

0

The error is most probably due to the reason of missing codecs. The VideoCapture simply displays False, in case of missing codecs rather than displaying actual error.

If using pre-built binaries, for Python in Windows. The third-party ffmpeg are not available as it should be built from source. For the same reason, I have provided the link of pre-built binaries, built and wrapped with OpenCV-compatible API.


https://drive.google.com/drive/folders/0Bzxd9GL63enNMEpPV0lWRng1VW8?resourcekey=0-DuyKvzQXU0oUmezm9iO01A


The binaries are built for opencv-3.0.0, rename it with respect to OpenCV version.

For 32-bit architecture, OpenCV version X.Y.Z -> opencv_ffmpegXYZ.dll
For 64-bit architecture, OpenCV version X.Y.Z -> opencv_ffmpegXYZ_64.dll

copy this renamed file, in c:\Python27\, or wherever python is installed (different in case, if using any open source distribution of the Python, like Anaconda). After this VideoCapture should work fine.

Hope this helps !!

Shubham Singh
  • 73
  • 1
  • 6