Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

jump method is getting stuck #113

Open
MCPepsh opened this issue Jun 11, 2019 · 0 comments

Comments

Projects
None yet
1 participant
@MCPepsh
Copy link

commented Jun 11, 2019

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 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);
}

@shiffman

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.