Program stops running at some point

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):

My code is the following:


Movie video;

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

void draw() {}

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

Why does it stop running?

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

1 Like

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

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

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

Or does it also hang on that new last frame?

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.

Oops, my fault, I meant to write

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.