VideoCapture Does Not Work in Anaconda

20,310

Solution 1

ffmpeg is not present in default conda channel.

You need to download opencv from conda-forge channel which contains latest and additional packages and dependencies for video processing. Try the following:

conda install -c conda-forge ffmpeg
conda install -c conda-forge opencv

Here -c tells which channel to use. In our case we need 'conda-forge'.

Solution 2

The solution is to compile ffmpeg with opencv. For opencv3, refer to https://github.com/menpo/conda-opencv3

For opencv2, refer to http://dhaneshr.net/2016/06/03/installing-opencv-2-4-x-with-ffmpeg-python-on-anaconda/

Solution 3

I ran into the same problem. VideoCapture doesn't work with Conda's default version of OpenCV because ffmpeg is not enabled. In order for VideoCapture to work, you have to enable ffmpeg in the Cmake GUI and compile. You can also install my version of OpenCV which has ffmpeg enabled:

conda install -c https://conda.binstar.org/jaimeivancervantes opencv

Solution 4

Use conda-recipes to install ffmpeg.

git clone https://github.com/conda/conda-recipes.git

cd conda-recipes

conda build x264

conda build ffmpeg

See also here.

Share:
20,310
user3892614
Author by

user3892614

Updated on July 09, 2022

Comments

  • user3892614
    user3892614 almost 2 years

    I am using ubuntu 14.04, and have anaconda python installed. I used conda install opencv and conda install cv2 to install opencv. However I am unable to use the VideoCapture at all (I need to process videos frames by frames). I need to use anaconda for the rest of the project.

    Here is my code:

    import cv2
    import os
    capture = cv2.VideoCapture('/home/Downloads/data/zfH2XdRcH14.mp4')
    while not capture.isOpened():
        print 'noob'
    while True:
        ret, frame = capture.read()
        cv2.imwrite('~/Downloads/data/pic.png',frame)
        cv2.imshow('Video', frame)
        count += 1
        print count
    

    The code keeps printing noob. I have checked the location multiple times and it is correct. I have no clue what the issue is and I have been stuck on this for hours.