@niklasM wrote:
Hi, I want to have two playbacks of the same video file where the only difference is the current playback position. One should play the latest frame, the other on should lag behind (e.g. 60 frames). Currently, I am using a .mov as a source, but later I would like to use the webcam.
I read through the OF documentation but couldn’t identify a suitable function so I came up with the following solution:
Use the ofVideoPlayer, apply .getPixels() on the current frame to create an ofImage and then push this image in a vector. Later draw the images stored in the vector.
class ofApp : public ofBaseApp{ ofVideoPlayer srcVid; vector<ofImage> frameBuffer; int playbackOffSet = 0; } void ofApp::setup(){ srcVid.load("movies/fingers.mov"); srcVid.setLoopState(OF_LOOP_NORMAL); srcVid.play(); } void ofApp::update(){ srcVid.update(); } void ofApp::draw(){ // saving the current frame to a vector ofPixels pixTemp = srcVid.getPixels(); ofImage imgTemp(pixTemp); frameBuffer.push_back(imgTemp); // limit the number of saved frames if(frameBuffer.size() > 60) frameBuffer.erase(frameBuffer.begin()); // define the playback offset if(frameBuffer.size() < 60) playbackOffSet = 1; else playbackOffSet = CLAMP(ofMap(mouseX, 0, ofGetWidth(), 0, 59), 1, 59); // draw the video from the player, and the images out of the vector srcVid.draw(0,0); frameBuffer[frameBuffer.size()-playbackOffSet].draw(srcVid.getWidth(), 0, srcVid.getWidth(), srcVid.getHeight()); }
The solution works but is very heavy on memory. I was wondering if there is a smarter way to do that and would appreciate any input.
Thanks a lot!
Posts: 1
Participants: 1