I have a while loop that decodes a video file by retrieving each frame, so something like this:
while (get_frame(codec_ctx, format_ctx, video_stream, frame) != 0) {
...
}
Now, once a frame is retrieved, it needs to be drawn onto the screen at a certain point in the future (according to the frame’s timestamp.) How could this be implemented? Is there some means by which I can set a callback to be executed at a specific time?
You can push a (frame, time) pair onto a queue, then have a separate thread execute the following algorithm:
where
popwaits for an item to be pushed onto the queue if it is empty.