Precise video playback control

Hello,

I’m looking for a way to attach a post-processing to each frame of a video, and to do this as fast as the disk can deliver the fames (going to next frame as soon as the previous one is done).

I have made quite unsuccessful attempts with “player.nextFrame()”, rising the CPU usage up to 600%…

The most elegant version is to pause the video before making the post-processing, then un-pause it:

player.update();
player.setPaused(true);
player.update();
if (player.getCurrentFrame() != last_frame) {
    ... // post-processing
    ofPixels hiResPixels;
    saved_frame.readToPixels(hiResPixels);
    ofSaveImage(hiResPixels, ss.str());
}
player.setPaused(false);

This implies that I have to wait for the next frame to arrive, even the process is faster than the video frame rate.
The other issue is the lack of precision: I missed several frames, due to the value returned by getCurrentFrame()…

Is there a way to attach a callback to the video player, independent of the main loop?
I’m on linux…

Thanks in advance!

can you not use

player.update();
if(player.isFrameNew()){
      // do some stuff
    }

i’ve not checked but would guess it will be faster,

The player methodology isn’t the thing to be looking into so much as the video codec - I think there is an addon being made for using HAP (GPU-accelerated video made by Vidvox / VDMX). There’s also the DXV codec by Resolume, and Photo JPEG, which is the fastest non 3rd party codec and will work out of the box with ofVideoPlayer, ofxOMXPlayer etc

I did what you are looking for some time ago.
I think that the following is what you need.
ofApp.h (612 Bytes)
ofApp.cpp (3.0 KB)
best