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

**URL:** <https://discourse.processing.org/t/when-i-render-this-code-it-gives-me-2-second-video-but-it-have-to-give-6-secs/21773>\
**Category:** Libraries\
**Created:** [June 11, 2020, 2:55pm UTC](https://discourse.processing.org/t/when-i-render-this-code-it-gives-me-2-second-video-but-it-have-to-give-6-secs/21773 "2020-06-11T14:55:23Z")\
**Posts on this page:** 9\
**Page:** 1

<div class="post-metadata">

**Author:** ![yhlaskerimov](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/yhlaskerimov/32/9725_2.png) [@yhlaskerimov](https://discourse.processing.org/u/yhlaskerimov)\
**Post date:** [June 11, 2020, 2:55pm UTC](https://discourse.processing.org/t/when-i-render-this-code-it-gives-me-2-second-video-but-it-have-to-give-6-secs/21773/1 "2020-06-11T14:55:23Z")

</div>

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

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

Movie movie;

void setup() {
  frameRate(60);
  size(1920, 1080);
  cols = width / cellSize;
  rows = height / cellSize;
  movie = new Movie(this, "asuda-d_1.mp4");
  movie.loop();
  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);
  //videoExport.startMovie();
  //shapeMode(CENTER);
}

void draw() {
  
  if (movie.available()) {    
    movie.read();  
    movie.loadPixels();
    
    background(255);
    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);   
      }
    }
  }
  //videoExport.saveFrame();
}
void keyPressed() {
  if (key == 'q') {
    videoExport.endMovie();
    exit();
  }
}

```

---

<div class="post-metadata">

**Author:** ![SomeOne](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/someone/32/8639_2.png) [@SomeOne](https://discourse.processing.org/u/SomeOne)\
**Post date:** [June 14, 2020, 10:12am UTC](https://discourse.processing.org/t/when-i-render-this-code-it-gives-me-2-second-video-but-it-have-to-give-6-secs/21773/2 "2020-06-14T10:12:10Z")

</div>

> [@yhlaskerimov](#):
>
> `frameRate(60);`

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.

---

<div class="post-metadata">

**Author:** ![yhlaskerimov](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/yhlaskerimov/32/9725_2.png) [@yhlaskerimov](https://discourse.processing.org/u/yhlaskerimov)\
**Post date:** [June 16, 2020, 7:20am UTC](https://discourse.processing.org/t/when-i-render-this-code-it-gives-me-2-second-video-but-it-have-to-give-6-secs/21773/3 "2020-06-16T07:20:57Z")

</div>

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 ?

---

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [June 16, 2020, 1:57pm UTC](https://discourse.processing.org/t/when-i-render-this-code-it-gives-me-2-second-video-but-it-have-to-give-6-secs/21773/4 "2020-06-16T13:57:57Z")

</div>

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…

---

<div class="post-metadata">

**Author:** ![yhlaskerimov](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/yhlaskerimov/32/9725_2.png) [@yhlaskerimov](https://discourse.processing.org/u/yhlaskerimov)\
**Post date:** [June 18, 2020, 9:08am UTC](https://discourse.processing.org/t/when-i-render-this-code-it-gives-me-2-second-video-but-it-have-to-give-6-secs/21773/5 "2020-06-18T09:08:29Z")

</div>

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

how to use this ?

---

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [June 18, 2020, 1:54pm UTC](https://discourse.processing.org/t/when-i-render-this-code-it-gives-me-2-second-video-but-it-have-to-give-6-secs/21773/6 "2020-06-18T13:54:06Z")

</div>

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 the`path`. 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.

---

<div class="post-metadata">

**Author:** ![yhlaskerimov](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/yhlaskerimov/32/9725_2.png) [@yhlaskerimov](https://discourse.processing.org/u/yhlaskerimov)\
**Post date:** [June 19, 2020, 10:50am UTC](https://discourse.processing.org/t/when-i-render-this-code-it-gives-me-2-second-video-but-it-have-to-give-6-secs/21773/7 "2020-06-19T10:50:28Z")

</div>

Okay, thank u so much. It helped 🙂

---

<div class="post-metadata">

**Author:** ![hamoid](https://yyz2.discourse-cdn.com/flex036/user_avatar/discourse.processing.org/hamoid/32/58_2.png) [@hamoid](https://discourse.processing.org/u/hamoid)\
**Post date:** [April 3, 2025, 9:38pm UTC](https://discourse.processing.org/t/when-i-render-this-code-it-gives-me-2-second-video-but-it-have-to-give-6-secs/21773/9 "2025-04-03T21:38:11Z")

</div>

How does it fail in Windows?

---

<div class="post-metadata">

**Author:** ![LangdonS](https://avatars.discourse-cdn.com/v4/letter/l/ebca7d/32.png) [@LangdonS](https://discourse.processing.org/u/LangdonS)\
**Post date:** [April 4, 2025, 3:19pm UTC](https://discourse.processing.org/t/when-i-render-this-code-it-gives-me-2-second-video-but-it-have-to-give-6-secs/21773/10 "2025-04-04T15:19:00Z")

</div>

nvm

I assumed FFMPEG was like Linux/Mac only, but it isn’t.
