When downloading OpenCV sources, no matter whether it is for Windows or for Linux, the sources directory contains only the Windows already-compiled shared library 3rdparty/ffmpeg/opencv_ffmpeg.dll
, that is essential for the VideoCapture
module to work on the Python portings for OpenCV.
In Linux, as this file is not provided, you'd expect it to be automatically built when you build OpenCV, especially when in CMakeCache.txt
, you can spot the line WITH_FFMPEG:BOOL=ON
.
It is of course not built... Any idea?
Found a great workaround - sharing with everybody.
Instead of using OpenCV's VideoCapture
, I use the library scikit-video
.
First, installing it (make sure to install a late enough version):
pip install sk-video
Then, reading videos in the following way:
import skvideo.io
cap = skvideo.io.vreader(input_video_filepath)
metadata = skvideo.io.ffprobe(input_video_filepath)
framerate = metadata['video']['@r_frame_rate']
for frame in cap:
# Do whatever you want...
# "cap" is a generator, the for loop will simply end when there are no more frames
# "frame" is a NumPy array, just like in OpenCV's VideoCapture
Further docs and examples are available here: http://www.scikit-video.org/stable/io.html