This library interfaces with ffmpeg and makes it easy to export video files out of Processing.
import com.hamoid.*;
VideoExport videoExport;
void setup() {
size(600, 600);
videoExport = new VideoExport(this, "basic.mp4");
}
void draw() {
background(#224488);
rect(frameCount * frameCount % width, 0, 40, height);
videoExport.saveFrame();
}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:
- GNU/Linux systems: use your favorite package manager.
- Windows: get a static 32bit or 64bit binary
- Mac: get a static 64bit binary
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. This may happen once per sketch.
Add videoExport.forgetFfmpegPath() to your setup(), run your program once, then remove that line. This will trigger the library asking for the location of ffmpeg again, so you can point to the new location of ffmpeg.
mp4 files contain essential metadata at the end of the file. The video export library saves this metadata when shutting down your sketch, inside the dispose() method. In theory, Processing calls dispose() automatically when stopping the sketch. Unfortunately dispose() is not always called.
There's at least 3 ways to stop your program: pressing ESC, pressing STOP on the IDE, and closing the sketch window. Try those three ways to find out what works for you (until this bug is resolved in Processing). You can also try calling videoExport.dispose() manually (for instance when pressing a key to stop exporting video frames).
- v0.1.3 - 24.07.2016
- Add webcam saving example.
- Add getFfmpegPath() public method (requested by @ffd8).
- Replace PGraphics with PImage, enables webcam/movie saving (requested by @transfluxus).
- v0.1.1 - 15.06.2016
- Use .waitFor() to reduce chances of video corruption.
- ...
- v0.0.1 - 25.01.2015