import cv2
import numpy as np
cap = cv2.VideoCapture('traffic.avi')
retval, frame = cap.read()
print retval
================ RESTART: J:\Python For DIP\traffic_video.py ================
False
>>>
The Value of retval is always False, which means the video is not read by the command. It must be True to read frames. I don't know what to do. However when I use my default webcam it turns to be True. I tried many videos and the same problem appears. Note: I have installed the ffmpeg correctly.
Note: This is not the full code, in this step I am only validating cap.read() either True or False
Finding the root directory of Python can be a little tricky. I am using an Enthought distribution and, at first, pasted the
opencv_ffmpeg
file into the wrong Python directory.WRONG:
RIGHT:
Long story short, make sure you find the right Python directory.
This method is guaranteed 100%
first of all check your version of OpenCV, say for instance 2.4.11. you can check it by typing the following commands in your Python Shell:
Then go to
C:\opencv\build\x86\vc12\bin
and copyopencv_ffmpeg2411.dll
. Finally go to root directory of Python ex:C:\Python27
and pasteopencv_ffmpeg2411.dll
in itAfter that create a new Python file and copy this code and paste it loading your own video
you will have an output video for example like this: Result