3

I am trying open *.mp4 file with opencv. I am trying with following code but I am unable to do this. How can solve this issue?

import cv2
cap = cv2.VideoCapture("test.mp4")
# cap = cv2.VideoCapture("test.avi") # it's also not working
cap.isOpened() # Output: False
  • N.B:

    • OS : ubuntu 16.04
    • OpenCv version: 3.3.0
Md. Rezwanul Haque
  • 2,802
  • 5
  • 26
  • 41

4 Answers4

2

I don't know if this post up-to-date. However, I had the same problem on Ubuntu 18.4 and had installed the opencv via conda:

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

And it turned out that menpo is not supported anymore. After installing from conda-forge, the problem disappeared:

conda install -c conda-forge opencv

You can surely check if the mpeg support is there:

python -c "import cv2; print(cv2.getBuildInformation())" | grep -i ffmpeg

it should return "YES"

2

install this package, it enable ffmpeg in opencv:

pip install opencv-contrib-python 
1

Install this package

pip install VideoCapture

import cv2
cap = cv2.VideoCapture("test.mp4")
# cap = cv2.VideoCapture("test.avi")
cap.isOpened() 

cap.release()
0

try updating opencv. also, this might help: Cannot open ".mp4" video files using OpenCV 2.4.3, Python 2.7 in Windows 7 machine