hamoid / video_export_processing

Processing library that interfaces with ffmpeg to export video files
http://funprogramming.org/VideoExport-for-Processing/
GNU General Public License v2.0
116 stars 19 forks source link
creative-coding processing

Notes:

1. I'm looking for someone to maintain this library. Get in contact if you are using it and would like to continue its development. I can help by answering any questions you may have.

2. There's a newer rewrite of the library using Kotlin and Gradle. Download it from https://github.com/hamoid/video_export_processing/tree/kotlinGradle

Video Export for Processing

This library interfaces with FFmpeg and makes it easy to export video files out of Processing.

Example

import com.hamoid.*;

VideoExport videoExport;

void setup() {
  size(600, 600);
  videoExport = new VideoExport(this, "hello.mp4");
  videoExport.startMovie();
}
void draw() {
  background(#224488);
  rect(frameCount * frameCount % width, 0, 40, height);
  videoExport.saveFrame();
}
void keyPressed() {
  if (key == 'q') {
    videoExport.endMovie();
    exit();
  }
}

FFmpeg

You need to download and install FFmpeg on your system before you can use this library. Note that you might already have it installed! You can find out by typing ffmpeg or ffmpeg.exe in the terminal. If the program is not found:

For more details and download links, check the official FFmpeg website: http://ffmpeg.org

When you start a Processing sketch that uses this library you may be asked to indicate the location of your FFmpeg executable.

Frequent issues and questions

What if I change the location of FFmpeg?

The library should notice and ask you for its location again. The location information is saved in a json file which you can find in the library location. If you delete this json file the library will ask you for the location of FFmpeg and create the file again with the updated information.

Sometimes the resulting mp4 video files are not working. Why?

mp4 files contain essential metadata at the end of the file. The video export library saves this metadata when you call the endMovie() method. If you don't call it, the movie may be incomplete. The endMovie() method was added in version 0.1.5.

I see an FFmpeg error related to "crf". Why?

This happens if your copy of FFmpeg does not include the h264 encoder. Not all FFmpeg binaries are equal, some include more features than others. Try downloading a different or more recent binary. Let me know if that doesn't work.

Odd widths and heights not allowed

The exported video is compressed using the h264 codec. This codec does not allow odd image sizes like 111 x 113. Some computer screens actually have odd sizes like 1920 x 1059. If you use fullScreen() with such a screen, exporting will fail with an error like height not divisible by 2 (1920x1059). This will be fixed in future versions by auto correcting the requested size to an even number and notifying the user.

How can I tweak the FFmpeg command the library runs?

The first time the library runs it will produce a settings.json file, which will be placed in the library folder. This file can be carefully edited to adjust the FFmpeg parameters used during the video creation. Why would you do this? FFmpeg accepts hundreds of parametrs to define which codec to use, how the codec should behave, etc. FFmpeg also includes hundreds of audio and video filters that can be used and configured. It would not make sense for me to create hundreds of methods in the video export library to let you access all those features. If you are and advanced user, you can tweak those settings yourself by editing settings.json to change the codec settings or apply special effects to the resulting video files. See this example.

NoSuchMethodError when calling endMovie()

There seems to be a conflict between the Video Export library and the Video library. Both use different versions of the JNA library. See this discussion: https://github.com/hamoid/video_export_processing/issues/38

change log

Download

http://funprogramming.org/VideoExport-for-Processing/