When I render this code, it gives me 2 second video. but it have to give 6 secs

import processing.video.*;
import com.hamoid.*;

VideoExport videoExport;
int cellSize = 20;
int cols, rows;
PShape asuda[] = new PShape[5];

Movie movie;

void setup() {
  size(1920, 1080);
  cols = width / cellSize;
  rows = height / cellSize;
  movie = new Movie(this, "asuda-d_1.mp4");
  asuda[0] = loadShape("a-1-01.svg");
  asuda[1] = loadShape("a-1-02.svg");
  asuda[2] = loadShape("a-1-03.svg");
  asuda[3] = loadShape("a-1-04.svg");
  asuda[4] = loadShape("a-1-05.svg");
  videoExport = new VideoExport(this);

void draw() {
  if (movie.available()) {    
    for (int i = cols-1; i >= 0; i--) {
      for (int j = rows-1; j >= 0; j--) {
        int x = i * cellSize;
        int y = j * cellSize;
        int loc = (movie.width + x - 1) + y*movie.width;
        color c = movie.pixels[loc];
        float sz = (brightness(c) / 255.0) * cellSize;
        PShape t = asuda[3]; 
        shape(t, x + cellSize/2, y + cellSize/2, sz, sz);   
void keyPressed() {
  if (key == 'q') {

Frame rate tasks processing to draw 60 frames per second. If calculation and activities are light it usually succeeds. If you set frameRate to 20 you’re video should be three times longer.

I did eveything. This code reads movie file and makes video according to the brightness of the video.
I give it a 6 second video, but it gives me a 2 second video. It gives less pictures when I try to render it.
What can i do ?

Hi! To get a video that has exactly the same number of frames as another video I would first convert the source video to images. You can use ffmpeg for that. Something like:

ffmpeg -r 1 -i file.mp4 -r 1 frame%04d.jpg

Then I would change the processing program to not load a video, but load the frames one by one instead. And every time you load a frame you process it and output a frame for the new video.

I should include an example like this with the Video Export library some day…


ffmpeg -r 1 -i file.mp4 -r 1 frame%04d.jpg

how to use this ?

It’s a command to type in a terminal. Are you familiar with using the terminal?

Once you open the terminal you first have to go into the folder where the mp4 file is found by using the cd command (change directory). Once you’re in that folder you can run that command, assuming that the ffmpeg program is in thepath. When a program is said to be in the path it means that it is located in one of the folders where the system looks for commands when you try to run them. If you type ffmpeg, hit enter and it tells you the command is not found then it’s not in the path. There are solutions for that.

-r 1 is used twice to make sure you export every single frame from the video.
file.mp4 is the name of your input movie.
frame%04d.jpg is used to ask ffmpeg to create images like frame0001.jpg, frame0002.jpg, etc (04d means 4 digits).

If you and the terminal are not good friends there are other programs you can use to split a movie into frames, but I can’t recommend any.

Okay, thank u so much. It helped :slight_smile: