python cv2.Videocapture() does not work, cap.isOpened() returns false

You need the ffmpeg codec to be able to read the video.


try

pip install opencv-contrib-python

It worked for me


I was getting the same error while using opencv in anaconda3 virtual environment. I checked the buildinformation for current opencv version and ffmpeg was marked "no".

To resolve this

  1. I uninstalled opencv from my conda environment (conda uninstall opencv)
  2. Installed latest ffmpeg using conda-forge channel (conda install -c conda-forge ffmpeg)

    Name Version Build Channel

    ffmpeg 4.0.2 ha6a6e2b_0 conda-forge

  3. Then installed opencv again using conda-forge channel (conda install -c conda-forge opencv)

    Name Version Build Channel

opencv 3.4.1 py36_blas_openblash829a850_201 [blas_openblas] conda-forge

Restart the python console after doing this and import cv2.