# Program stops running at some point

**URL:** <https://discourse.processing.org/t/program-stops-running-at-some-point/11985>\
**Category:** Coding Questions\
**Created:** [June 11, 2019, 5:10am UTC](https://discourse.processing.org/t/program-stops-running-at-some-point/11985 "2019-06-11T05:10:37Z")\
**Posts on this page:** 6\
**Page:** 1

<div class="post-metadata">

**Author:** ![Hjtunfgb](https://avatars.discourse-cdn.com/v4/letter/h/50afbb/32.png) [@Hjtunfgb](https://discourse.processing.org/u/Hjtunfgb)\
**Post date:** [June 11, 2019, 5:10am UTC](https://discourse.processing.org/t/program-stops-running-at-some-point/11985/1 "2019-06-11T05:10:37Z")

</div>

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:

```auto
import processing.video.*;

Movie video;

void setup() {
  video = new Movie(this, "24h.mp4");
  System.out.println("Video loaded!");
  
  System.out.println("Analysing frames...");
  
  video.play();
  for (int i = 0; i < 864000; i++) {
    video.jump(i);
    if (video.available()) {
      video.read();
      PImage p = createImage(16, 9, RGB);
      p.copy(video, 0,0, video.width,video.height, 0,0, video.width,video.height);
      if (!check(p)) p.save("frame" + i + ".jpg");
      if (i != 0 && i%864 == 0) System.out.println((float)i/8640 + "% complete...");
    }
  }
  System.out.println("Done!");
}

void draw() {}

boolean check(PImage a) {
  a.loadPixels();
  for (int i = 0; i < a.pixels.length; i++) {
    if (brightness(a.pixels[i]) > 2) return false;
  }
  return true;
}

```

Why does it stop running?

---

<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 13, 2019, 8:12pm UTC](https://discourse.processing.org/t/program-stops-running-at-some-point/11985/2 "2019-06-13T20:12:02Z")

</div>

When you say it “stops running” do you mean it crashes? Is there an error message? Does it freeze?

---

<div class="post-metadata">

**Author:** ![Hjtunfgb](https://avatars.discourse-cdn.com/v4/letter/h/50afbb/32.png) [@Hjtunfgb](https://discourse.processing.org/u/Hjtunfgb)\
**Post date:** [June 13, 2019, 8:29pm UTC](https://discourse.processing.org/t/program-stops-running-at-some-point/11985/3 "2019-06-13T20:29:58Z")

</div>

It just freezes at the frame 86399 (9,99%), and just stops there

---

<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 13, 2019, 11:33pm UTC](https://discourse.processing.org/t/program-stops-running-at-some-point/11985/4 "2019-06-13T23:33:59Z")

</div>

Does it work if you stop short of the last frame?

```auto
for (int i = 863990; i < 863999; i++) {

```

Or does it also hang on that new last frame?

---

<div class="post-metadata">

**Author:** ![Hjtunfgb](https://avatars.discourse-cdn.com/v4/letter/h/50afbb/32.png) [@Hjtunfgb](https://discourse.processing.org/u/Hjtunfgb)\
**Post date:** [June 17, 2019, 9:56pm UTC](https://discourse.processing.org/t/program-stops-running-at-some-point/11985/5 "2019-06-17T21:56:33Z")

</div>

Hey, sorry for the long time to answer, school is busy these weeks. It just runs frame 863990 and says it’s finished without analysing the other 9 frames. Changing the number to 863999 didn’t change anything. Starting on 863900 also makes it look only the first frame. I changed the limit to 10 times it (8640000) to see if it worked too, but nothing changed. It still stopped on 86399.

---

<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 17, 2019, 10:10pm UTC](https://discourse.processing.org/t/program-stops-running-at-some-point/11985/6 "2019-06-17T22:10:17Z")

</div>

Oops, my fault, I meant to write

```auto
for (int i = 86390; i < 86399; i++) {

```

That is, just process the frames _before_ the frame that freezes. Perhaps that one frame is damaged somehow? Or perhaps the frame count isn’t correct, and there are no frames beyond that point.
