An Automation for my Code (Video)

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)

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

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);
    }
  }
}
1 Like

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 also (further down) https://www.processing.org/tutorials/video/

What you need

  // 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

1 Like

Thank you very much for replying !

I followed your instructions and altered the code to the following

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 ?

1 Like

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

1 Like