Video library: grab specific frame of a movie

Hi,

I have been trying to write code to grab a specific frame from a movie file using the Movie object and the “jump” method, but I am unable to jump to a specific point in the movie unless the movie is playing. The only way I’m able to do this right now is to start playing, jump to the frame, and immediately stop playing, which gives me a few frames past the desired frame, and not a consistent number of frames. This is the hack I’ve come up with for now, but even so, it makes a set number of attempts, and doesn’t guarantee the right frame every time.

import processing.video.*;
Movie myMovie;
float desiredframe;

void setup() {
  size(800, 800);
  frameRate(30);
  myMovie = new Movie(this, "eyes.mov");
  myMovie.loop();
  myMovie.pause();
  desiredframe = 0;
}

void draw() {
  if (myMovie.available()) {
    myMovie.read();
    image(myMovie, 0, 0);
  }
}

void mousePressed() {
  if (mouseX > 2*width/3) desiredframe+=1;
  if (mouseX < width/3) desiredframe-=1;
  float desiredjump = desiredframe/30.0;
  float error = 0;
  int attempts = 0;
  while ((error <= 5.0 || error >= 6.0) && attempts < 10){
    // THIS RANGE IS TYPICAL FOR NOW BUT IF
    // IT'S NOT COMMON ENOUGH IT WILL HANG!!
    myMovie.play();
    myMovie.jump(desiredjump);      
    myMovie.pause();
    error = myMovie.time()*30 - desiredframe;
    attempts++;
  }
  println(attempts, error);
}

Is there a better and more reliable way to do this? I want to work on each frame of the movie, in order, without skipping or repeating frames. Thank you!

did you start from the original frame example?
because that works here fine.
PDE / Examples / Libraries / Video / Movie / Frames

I just looked at that example, and it does the same thing mine does; it plays, then jumps, then pauses. It doesn’t necessarily go to the exact frame, because of the unpredictable lag between mov.jump() and mov.pause(), even if they’re consecutive commands.

1 Like