# Jump method is getting stuck

**URL:** <https://discourse.processing.org/t/jump-method-is-getting-stuck/11995>\
**Category:** Libraries\
**Created:** [June 11, 2019, 7:53pm UTC](https://discourse.processing.org/t/jump-method-is-getting-stuck/11995 "2019-06-11T19:53:23Z")\
**Posts on this page:** 3\
**Page:** 1

<div class="post-metadata">

**Author:** ![MCPepsh](https://avatars.discourse-cdn.com/v4/letter/m/74df32/32.png) [@MCPepsh](https://discourse.processing.org/u/MCPepsh)\
**Post date:** [June 11, 2019, 7:53pm UTC](https://discourse.processing.org/t/jump-method-is-getting-stuck/11995/1 "2019-06-11T19:53:23Z")

</div>

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](https://github.com/processing/processing-video/issues/113))

I just changed very little:

```auto
/**
 * 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

---

<div class="post-metadata">

**Author:** ![jeremydouglass](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/jeremydouglass/32/20_2.png) [@jeremydouglass](https://discourse.processing.org/u/jeremydouglass)\
**Post date:** [June 14, 2019, 5:09pm UTC](https://discourse.processing.org/t/jump-method-is-getting-stuck/11995/2 "2019-06-14T17:09:08Z")

</div>

Possibly related:

> [@Program stops running at some point](https://discourse.processing.org/t/program-stops-running-at-some-point/11985):
>
> I have a program that searches for all the frames in a 864.000 frame video to spot the different ones and save them for me. But for some reason, the program stops running at around 10% of the progress. The video is the following(I downloaded it): [https://www.youtube.com/watch?v=7ly6hgzwsLU&t=30606s](https://www.youtube.com/watch?v=7ly6hgzwsLU&t=30606s) My code is the following: import processing.video.\*; Movie video; void setup() { video = new Movie(this, "24h.mp4"); System.out.println("Video loaded!"); System.out.println("Analysing fra…

---

<div class="post-metadata">

**Author:** ![JackRyan404](https://avatars.discourse-cdn.com/v4/letter/j/76d3ee/32.png) [@JackRyan404](https://discourse.processing.org/u/JackRyan404)\
**Post date:** [March 18, 2020, 12:41pm UTC](https://discourse.processing.org/t/jump-method-is-getting-stuck/11995/3 "2020-03-18T12:41:39Z")

</div>

I think the process you are doing is correct. I might be a bug which is not letting due to which you are getting stuck.
