capture->set(CAP_PROP_POS_FRAMES,f) is very slow in mjpg AVI files using VideoCapture

asked 2019-04-18 13:49:38 -0500

B4silio gravatar image

updated 2019-04-18 13:53:28 -0500

Hi everyone,

I'm using VideoCapture to open large AVI files encoded in MJPG (from 4 up to 30Gb). Opening and reading the files & frames works well, but if I try to seek to the end of the video, it takes ages to set the position and read the new frame. I'm using:

capture->set(cv::CAP_PROP_POS_FRAMES, newFrame);

Setting the position to a frame that is close to the current position of the grabber does not take much time, and "playing" (grabbing frames sequentially without resetting the frame position) goes perfectly smoothly. As MJPG is an i-frame only codec, there shouldn't be any need to decode tons of frames prior to grabbing the new frame. Moreover, reading the videos using VLC does not have the issue.

EDIT: The issue is present on Linux (Ubuntu) and Mac, OpenCV versions 3.4 and 4.1

Is it simply a bug that might be solved in the future or are there things I can do now to solve this issue? Are there any alternatives to VideoCapture now that the old C API is no longer supported?

Any help is appreciated!

p.s. the MJPG support for large files has always been very sketchy on VideoCapture, and it is only very recently that it has become able to properly read the correct frame count in videos above 8-10Gb, so I can understand if it's still a bit finnicky.

edit retag flag offensive close merge delete