12

I'm creating a 3D visualisation in Processing. I'm anticipating that each frame will take longer to draw than is acceptable for displaying the animation as a program, so I'd like to export it as a video.

Is this possible? What's the best way of going about it?

alnorth29
  • 3,525
  • 2
  • 34
  • 50
  • Professor Shiffman described the in-built method here, a mix of saveFrame() and the IDE-integrated tool for movie-making from sketches execution https://www.youtube.com/watch?v=G2hI9XL6oyk – WildWilyWilly Jul 15 '21 at 22:06

5 Answers5

11

If you are not using Processing 2.0 you can use MovieMaker library to export the sketch as a video (in processing 2.0 MovieMaker will be converted in a tool, but it doesn't work yet).

Other option is to use the saveFrame() method in your draw () function

Here you can find an example of how to use MovieMaker

and here the docs of the saveFrame() method

Sr.Richie
  • 5,680
  • 5
  • 38
  • 62
  • 3
    `saveFrame()` is definitely the way to go. You can pile those frames into Quicktime Pro < 7.6 if you have it, which has a nice Open Image Sequence feature and then Export to a quicktime, or you can try ffmpeg to stitch them together. http://ffmpeg.org/ – ericsoco Sep 25 '12 at 03:57
  • I had the same issue one month ago and I used the saveFrame() + Quicktime technique too – Sr.Richie Sep 25 '12 at 11:23
  • Yup, this worked well for me. `saveFrame()` combined with ffmpeg. – alnorth29 Sep 25 '12 at 11:40
  • when using `saveFrame()` I am not getting all the frames, the result lags a lot. Anyone know what can I do? – JordanBelf Jan 10 '14 at 05:31
  • 1
    @JordanBelf when using saveFrame() it's normal to have a low framerate (depending on the size of your sketch, but sometimes it can reach 1 fps or lower) but you should have all the frames exported – Sr.Richie Jan 10 '14 at 09:59
  • saveFrame() should not be used with millis() as a time function... instead do a fixed frame jump to avoid the lag. Writing to the hard drive takes longer than displaying to the screen. – Torrien Aug 16 '17 at 15:08
  • I always use saveFrame() and delay(), just to make sure the animation is smooth – Caio Vertematti Jan 20 '18 at 04:19
  • The first link, regarding MovieMaker, is broken. – Paul Wintz Mar 13 '21 at 20:36
7

The Video Export for Processing library allows direct mp4 export from Processing. It requires you to install ffmpeg on your system though.

aBe
  • 422
  • 3
  • 9
1

The GSVideo library here helps with this in Processing 2.0. Has a class "GSMovieMaker" with objects much like described above.

Community
  • 1
  • 1
  • It should be noted that GSVideo depends on gstreamer, which is common on many modern Linux distros but not on Windows or OS X. – David Foerster Jan 20 '15 at 00:00
1

After a week of research I have written myself very simple code using ffmprg binaries:

if(frameCount<628){
    saveFrame("temp/anim_#####.png");
  }else if(frameCount == 628){
    println("Saving file!");
    processBuilder = new ProcessBuilder("G:/.../ffmpg/bin/ffmpeg.exe", "-r", "60", "-i",
        "C:/.../temp/anim_%05d.png", "-c:v", "libx264",
        "-r", "30", "-pix_fmt", "yuv420p", "C:/.../test.mp4");
    try {
      process = processBuilder.start();
    } catch (Exception e) {
      e.printStackTrace();
    }
  }

Of course you need to adjust paths to files and ffmpeg binaries (https://www.ffmpeg.org/download.html). It sjould be Processing version independent, as it uses only saveFrame and calls external binaries to generate video. Enjoy ;)

Piotrva
  • 11
  • 1
0

Dear can use the Program made by Randel Shofer, you just have to modified 8,10 lines of code to use it with in your program ( and if you have more time you can do it without modifying the source code).

Program(Jar.) Link: http://www.randelshofer.ch/cubetwister/files/QuickTimeDemo2.jar

Description: http://www.randelshofer.ch/blog/2010/10/writing-quicktime-movies-in-pure-java/

MrGreen
  • 147
  • 1
  • 9