Hello!
I'm using the VideoExport library in conjunction with the processing.video library to try to display and capture a webcam video while running Processing. The video displays beautifully in a section of the window in Processing. The issue I'm having is that I want to store the video at 10fps, and Processing's frame rate shifts around a bit as the program runs. If I grab every frame after the draw function I get a video that drifts out of time as the frame rate shifts slightly over time. For my application, having the video well synchronized is important, so I need it to match the system clock. So, I tried the following code to address this problem.
After creating the VideoExport instance I set the frame rate to 10 per second and set the filename, then start the movie: videoExport.setFrameRate(OutputFrameRate); videoExport.setMovieFileName("NewMovie.mp4"); videoExport.startMovie();
Then in the draw() function, I use the code below to read a frame from the web cam, but then only export the frame if it's been 100ms since the last frame was written.
if (cam.available() == true) {
cam.read();
}
image(cam, x, y-navHeight,640,480);
if(WebCamActive){
CurrentMilliseconds = millis();
if (CurrentFrame == 0){ //This is the first frame to be recorded
videoExport.saveFrame();
CurrentFrame = 1;
} else {
if (CurrentMilliseconds > BaseFrameTime + (MillisecondsBetweenFrames*CurrentFrame)) {
println(CurrentMilliseconds);
videoExport.saveFrame();
CurrentFrame = CurrentFrame+1;
}
}
}
Looking at the output in the console, the export code is being executed every 100ms.
When I look at the video on the screen in processing, it looks great. When I look at the recorded video, it's synced up correctly with the time (I added a text overlay with a timestamp to make sure), but the video keeps freezing and restarting, like the export function is sometimes sending out the same frame multiple times, and then it jumps ahead to the correct frame.
I don't understand why if the video is being displayed correctly on screen, the saveFrame function is not grabbing the frame that's currently being displayed when it's called. Any ideas? I feel like this is VERY close to what I need. Just need that one last piece.
Thanks! Dan