# An Automation for my Code (Video)

**URL:** <https://discourse.processing.org/t/an-automation-for-my-code-video/20041>\
**Category:** Libraries\
**Created:** [April 22, 2020, 5:41pm UTC](https://discourse.processing.org/t/an-automation-for-my-code-video/20041 "2020-04-22T17:41:41Z")\
**Posts on this page:** 4\
**Page:** 1

<div class="post-metadata">

**Author:** ![arazym](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@arazym](https://discourse.processing.org/u/arazym)\
**Post date:** [April 22, 2020, 5:41pm UTC](https://discourse.processing.org/t/an-automation-for-my-code-video/20041/1 "2020-04-22T17:41:41Z")

</div>

I basically want to run a video through this Code. (See below)  
The idea is, to extract all the frames, run each through the script and render them back together to a Video file. So far so good.

My Video is 60sec long @ 25 Fps , I end up with 1500 frames. I Want the rendered video to rotate 360° over its duration ( 60sec)  
Therefore each Frame has to rotate 0.24°

Since I don’t want to alter the Code each Frame by hand, I need an automation, that loads a Frame, (Image) runs it trough the code, saves it to the output folder, loads a new Frame, rotates it with added 0.24° in comparison to the last frame, saves it… and again and again.

I am very new to Processing and struggling a lot, trying to implement such wished automation in my code, ended in destroying the complete structure of my code…

Luckily I saved a Copy of my “blank” Code ( original found at [http://formandcode.com/code-examples/transform-landscape](http://formandcode.com/code-examples/transform-landscape))

Could someone please help me, to structure the wished automation ? 🙂

```auto
import processing.opengl.*;

PImage img;
int[][] values;
float angle;

void setup() {
  size(1920, 1080, OPENGL);
  noFill();
  
  values = new int[width][height];

  
  img = loadImage(".jpg");
  img.loadPixels();
  for (int i = 0; i < img.height; i++) {
    for (int j = 0; j < img.width; j++) {
      color pixel = img.pixels[i*img.width + j];
      values[j][i] = int(brightness(pixel));
    }
  }
}

void draw() {
  
  background(0); // Set black background
  translate(width/2, height/2, 0); // Move to the center
  scale(1); // Scale to 400%
  
  
  // Update the angle
  angle += 0.001;
  rotateY(angle);  
  
  // Display the image mass
  for (int i = 0; i < img.height; i += 2) {
    for (int j = 0; j < img.width; j += 2) {
      stroke(values[j][i], 153);
      float x1 = j-img.width/1.75;
      float y1 = i-img.height/1.75;
      float z1 = -values[j][i]/1.75;
      float x2 = j-img.width/1.75;
      float y2 = i-img.height/1.75;
      float z2 = -values[j][i]/3.5-5.25;
      line(x1, y1, z1, x2, y2, z2);
    }
  }
}

```

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 22, 2020, 7:34pm UTC](https://discourse.processing.org/t/an-automation-for-my-code-video/20041/2 "2020-04-22T19:34:01Z")

</div>

Hello!

Welcome to the processing forum!

Great to have you with us!

You are working in 3D. Is this intentionally? Because when you rotate a photo on a desk, 2D is enough. Or are we talking about a 3D rotation?

You don’t load a movie. Please

- see [https://www.processing.org/reference/libraries/video/movieEvent\_.html](https://www.processing.org/reference/libraries/video/movieEvent_.html)
- which belongs to a library [https://www.processing.org/reference/libraries/video/index.html](https://www.processing.org/reference/libraries/video/index.html)

See also (further down) [https://www.processing.org/tutorials/video/](https://www.processing.org/tutorials/video/)

**What you need**

```auto
  // Update the angle
  angle += 0.001;
  translate(width/2, height/2, 0); // Move to the center
  rotateY(angle);  
  image(movie, 0, 0); /// see tutorial 
  saveFrame(............. /// see reference

```

Warm regards,

Chrisir

---

<div class="post-metadata">

**Author:** ![arazym](https://avatars.discourse-cdn.com/v4/letter/a/b2d939/32.png) [@arazym](https://discourse.processing.org/u/arazym)\
**Post date:** [April 22, 2020, 8:07pm UTC](https://discourse.processing.org/t/an-automation-for-my-code-video/20041/3 "2020-04-22T20:07:55Z")

</div>

Thank you very much for replying !

I followed your instructions and altered the code to the following

```auto
import processing.opengl.*;
import processing.video.*;
Movie myMovie;
PImage img;
int[][] values;
float angle;

void setup() {
  size(1920, 1080, OPENGL);
  myMovie = new Movie(this, "A Labattoir_Sub_02.3gp");
  myMovie.loop();
  noFill();
  
  values = new int[width][height];

  // Extract the brightness of each pixel in the image
  // and store in the "values" array

  img.loadPixels();
  for (int i = 0; i < img.height; i++) {
    for (int j = 0; j < img.width; j++) {
      color pixel = img.pixels[i*img.width + j];
      values[j][i] = int(brightness(pixel));
    }
  }
}

void draw() {
  
  background(0); // Set black background
  translate(width/2, height/2, 0); // Move to the center
  scale(1); // Scale to 400%
  
  
  // Update the angle
  angle += 0.001;
  rotateY(angle);  
  image(movie, 0, 0);
  
  // Display the image mass
  for (int i = 0; i < img.height; i += 2) {
    for (int j = 0; j < img.width; j += 2) {
      stroke(values[j][i], 153);
      float x1 = j-img.width/1.75;
      float y1 = i-img.height/1.75;
      float z1 = -values[j][i]/1.75;
      float x2 = j-img.width/1.75;
      float y2 = i-img.height/1.75;
      float z2 = -values[j][i]/3.5-5.25;
      line(x1, y1, z1, x2, y2, z2);
    }
  }
}

```

But now I am getting the Error message : movie cannot be resolved to a variable, what am I missing ?

---

<div class="post-metadata">

**Author:** ![Chrisir](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/chrisir/32/45_2.png) [@Chrisir](https://discourse.processing.org/u/Chrisir)\
**Post date:** [April 22, 2020, 8:25pm UTC](https://discourse.processing.org/t/an-automation-for-my-code-video/20041/4 "2020-04-22T20:25:02Z")

</div>

> [@arazym](#):
>
> image(movie, 0, 0);

looks suspicious

In the tutorial I mentioned above section Recorded video, step 5 and the full Sketches after it.

In your code it’s `myMovie`, not movie
