How I can use ffmpeg to read a video through OpenCV? This my code:
cap = cv2.VideoCapture("input2.mp4")
ret = cap.read()
print ret
The result is (False, None)
.
I set up OpenCV through Anaconda.
How I can use ffmpeg to read a video through OpenCV? This my code:
cap = cv2.VideoCapture("input2.mp4")
ret = cap.read()
print ret
The result is (False, None)
.
I set up OpenCV through Anaconda.
I got the error while read a h264 mp4 sometimes. The ffmpeg has more codec than cv2 that may solve the reading problem. You can use this pkg, which is similar to cv2 in API.
#!pip install ffmpegcv
import ffmpegcv
vfile_in = 'A.mp4'
vfile_out = 'A_h264.mp4'
vidin = ffmpegcv.VideoCapture(vfile_in)
w, h = vidin.width, vidin.height
vidout = ffmpegcv.VideoWriter(vfile_out, 'h264_nvenc', vidin.fps, (w, h))
for frame in vidin:
vidout.write(frame)
vidin.release()
vidout.release()
What OS are you using? OpenCV is not compiled with FFMPEG which is the video codec library for Linux and OSX as described here . So you have to build OpenCV with FFMPEG manually. This will guide you with the building process. But the building process can be tricky with issues as the building environments differ from each other. I recommend using a docker container for running the code like this.