I want to process a video frame by frame, but the jump(float where) method is either just taking ages or stuck in some kind of infinite loop or something like that. I used the Frames.pde example and just tweaked it a little for my needs.
Another problem is that mov.frameRate is -1 most of the time. I think both problems are caused by the fact that the movie just started playing very short before, but I might be wrong.
Am I doing something wrong or is this a bug?
(I also posted this to GitHub)
I just changed very little:
/**
* Frames
* by Andres Colubri.
*
* Moves through the video one frame at the time by using the
* arrow keys. It estimates the frame counts using the framerate
* of the movie file, so it might not be exact in some cases.
*/
import processing.video.*;
Movie mov;
int newFrame = 0;
float framerate = 30;
void setup() {
size(1920, 1080);
background(0);
// Load and set the video to play. Setting the video
// in play mode is needed so at least one frame is read
// and we can get duration, size and other information from
// the video stream.
mov = new Movie(this, "video.mp4");
// Pausing the video at the first frame.
setFrame(0);
}
void movieEvent(Movie m) {
m.read();
}
void draw() {
background(255);
image(mov, 0, 0, width, height);
saveFrame("frames/frame" + nf(getFrame(), 3) + ".png");
fill(127);
text(getFrame() + " / " + (getLength() - 1), 10, 30);
newFrame++;
setFrame(newFrame);
}
int getFrame() {
return ceil(mov.time() * 30) - 1;
}
void setFrame(int n) {
mov.play();
// The duration of a single frame:
float frameDuration = 1.0 / framerate;
// We move to the middle of the frame by adding 0.5:
float where = (n + 0.5) * frameDuration;
// Taking into account border effects:
float diff = mov.duration() - where;
if (diff < 0) {
where += diff - 0.25 * frameDuration;
}
// The Program runs until here
mov.jump(where);
// But never executes the following code
mov.pause();
}
int getLength() {
return int(mov.duration() * framerate);
}