Freeze the movie for a few seconds

edited April 2017 in Questions about Code

I want make a video of a running sketch using saveFrame. I want the video to freeze for a few seconds under certain circumstances, so one has time to see what's happening. I tried using saveFrame several times with a for-loop:

 if (x < 10){
    saveFrame("video/video_####.png");
 }else{
    for(int i = 0; i < 90; i++){
       saveFrame("video/video_####.png");
    }
 }

I don't know why but it only saves one file in the else statement, so the videos doesn't freeze. Do you have a suggestion for how to freeze the movie for a few seconds?

Tagged:

Answers

  • Answer ✓

    hmmm if you are using this in draw, you are going to be saving the same frame 90 times.

    Consider posting a run ning version of your approach. You can also explore the Video Export library. You can install it directly from the Processing IDE using the library manager. Then you can explore the examples the library comnes with.

    Kf

  • edited April 2017 Answer ✓

    @KmHg -- To explain why this is happening: "####" gets filled in with the current value of frameCount.

    You can then see what happens in this demo sketch -- the same file is repeatedly overwritten:

    void draw(){
      for(int i=0; i<4; i++){
        println("SAVE: video/video_" + frameCount + ".png");
      }
      if(frameCount>60){ exit(); }
    }
    

    SAVE: video/video_1.png
    SAVE: video/video_1.png
    SAVE: video/video_1.png
    SAVE: video/video_2.png
    SAVE: video/video_2.png
    SAVE: video/video_2.png
    SAVE: video/video_2.png
    SAVE: video/video_3.png

    The easiest way to freeze is to actually add the pause to your sketch -- then saveFrame will proceed as normal. However, if you want the sketch to run without freezing and only the output to freeze, then simply change your saveFrame filenames -- for example, give them a separate suffix.

    /**
     * PauseSaveFrame
     * 2017-04-20 Jeremy Douglass Processing 3.2.3 
     * sketch runs for 10 seconds (10fps)
     * output pauses for 1 sec at 2, 4, 6, 8, 10 (15 secs total output at 10fps)
     * forum.processing.org/two/discussion/22104/freeze-the-movie-for-a-few-seconds
    **/
    void setup() {
      textAlign(CENTER, CENTER);
      frameRate(10);
    }
    void draw() {
      background(192);
      text(frameCount, width/2, height/2);
      if (frameCount%20==0) {
        for (int i=0; i<10; i++) {
          saveFrame("video/video_####_" + i + ".png");
        }
      } else {
        saveFrame("video/video_####_" + "0" + ".png");
      }
      if (frameCount>=100) {
        exit();
      }
    }
    

    That outputs files like this:

    video_0018_0.png
    video_0019_0.png
    video_0020_0.png
    *** pause in output ***
    video_0020_1.png
    video_0020_2.png
    video_0020_3.png
    video_0020_4.png
    video_0020_5.png
    video_0020_6.png
    video_0020_7.png
    video_0020_8.png
    video_0020_9.png
    *** resume ***
    video_0021_0.png
    video_0022_0.png

  • @jeremydouglass That's a great solution. Thank you.

Sign In or Register to comment.