# ArrayIndexOutOfBoundsException error, using movie

**URL:** <https://discourse.processing.org/t/arrayindexoutofboundsexception-error-using-movie/33682>\
**Category:** Coding Questions\
**Created:** [November 23, 2021, 1:21am UTC](https://discourse.processing.org/t/arrayindexoutofboundsexception-error-using-movie/33682 "2021-11-23T01:21:17Z")\
**Posts on this page:** 1\
**Page:** 1

<div class="post-metadata">

**Author:** ![mysterzomb](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/mysterzomb/32/15075_2.png) [@mysterzomb](https://discourse.processing.org/u/mysterzomb)\
**Post date:** [November 23, 2021, 1:21am UTC](https://discourse.processing.org/t/arrayindexoutofboundsexception-error-using-movie/33682/1 "2021-11-23T01:21:17Z")

</div>

Hello! I am trying to make this Daniel Shiffman’s code : [MotionPixels | Learning Processing 2nd Edition](http://learningprocessing.com/examples/chp16/example-16-13-MotionPixels)  
not with the Capture datatype, but with the Movie so that it reads a video file instead of a device on my computer. The code is meant to capture the motion of a video.

The problem is that this error appears : ArrayIndexOutOfBoundsException: 0  
The problem is the loc i think.  
can anyone help ? thank you 🙂

code :

```auto
import processing.video.*;

boolean start = false;

Movie video;
PImage prevFrame;
float threshold = 50;

void setup() {
  size(1280, 720);

  video = new Movie(this, "macron.mp4");
  video.play();
  prevFrame = createImage(video.width, video.height, RGB);
}

void movieEvent(Movie video) {
  prevFrame.copy(video, 0, 0, video.width, video.height, 0, 0, video.width, video.height);
  prevFrame.updatePixels();
  video.read();
}

void draw() {

  image(video, 0, 0);
  
  if (start) {
    loadPixels();
    video.loadPixels();
    prevFrame.loadPixels();
    for (int x = 0; x < video.width; x ++ ) {
      for (int y = 0; y < video.height; y ++ ) {
        int loc = x + y*video.width;            
        color current = video.pixels[loc];      
        color previous = prevFrame.pixels[loc]; //where the problem is
        float r1 = red(current); 
        float g1 = green(current); 
        float b1 = blue(current);
        float r2 = red(previous); 
        float g2 = green(previous); 
        float b2 = blue(previous);
        float diff = dist(r1, g1, b1, r2, g2, b2);
        if (diff > threshold) { 
          pixels[loc] = color(0);
        } else {
          pixels[loc] = color(255);
        }
      }
    }
  }
  updatePixels();
}

void keyPressed() {
  if (start == false) {
    start = true;
  } else {
    start = false;
  }
}

```
