VideoCapture.retrieve(Mat, driver specific flag) -> driver specific flag as milliseconds possible?

Hello,
due to different frequencies I try to grab every frame by its position in milliseconds.

Right now I use the methods set and read to do this.
At first I set the position in the videocapture instance like this:

cap.set(CAP_PROP_POS_MSEC, time_in_ms);

after that I grab the “next” frame with read and store it in Mat_at_time_in_ms:

cap.read(Mat_at_time_in_ms);

This works fine but is just very slow.

Therefore I am looking for another possibilty. (I do not want to use set().

I was looking and found the method retrieve(). In the documentation I found that you can pass a driver specific flag (other than the frame index) to the function.

I was wondering wether I could use this function and pass a time in milliseconds to retrieve (instead of an index).
I couldnt find a helpful post on this problem yet. Maybe you can help.
Thanks in advance.

1 Like

you’re on the wrong path here, there is no such flag implemented, also you would have to call grab() before a retrieve(), and the combination of it is exactly, what read() does.

then, think about it, what makes “random access” (no matter if by millis or index) so expensive ?
to get your frame, most codecs have to rewind to some keyframe, and successively decode up to the desired position

1 Like

thanks for your quick help