I was unable to read video frames in OpenCV (python and c++) after using ffmpeg.
Specifically, I had the following problems:
1) unable to open the video file using VideoCapture
.
2) able to open the video file using VideoCapture
, but reading zero frames and/or receiving frames of size 0x0 pixels.
I am pasting my solution below, hoping this will help others.
These problems were encountered on Mac OS X Sierra 10.12.5, ffmpeg 3.2.4, Python 2.7.13, g++ 4.2.1
1) OpenCV cannot read as many video formats as ffmpeg. Therefore, it is often possible to play videos in VLC, but not to open them in OpenCV's
VideoCapture
. Hence, conversion with a tool such asffmpeg
is often required (see next point). One format that worked for me is h.264.2) OpenCV seemed to require YUV420, whereas
ffmpeg
used YUV444 by default. Therefore, the following command solved my problems:ffmpeg -i input.avi -c:v libx264 -vf format=yuv420p output.mp4