Creating Video With Processing and FFMPEG

Max/MSP users: look familiar?

For the past week I have been wrangling with getting ffmpeg (the open-source, command line video utility) to run in a Processing sketch and preserve the hard edges of graphical and/or intentionally pixelly video. It now works!

Details are listed in the code itself, but it is most important to note that the codec is likely the most important factor in getting good quality.   The “png” codec is great, but will create rather large files; mjpeg (MotionJPEG) also works well for graphics and hard edges (pixellated images, etc); H.264 is all-around good for photgraphic images.

The sketch below runs ffmpeg’s commands within Processing (as covered before) and exports a video from a series of still files.  Processing’s built-in video library seems ok, but offers little in the way of control as compared to ffmpeg.  Questions or suggestions are welcomed – feel free to use but please give credit!

While I really don’t know why, the previous sketch seems to break with a Java IOException error.  It appears that ffmpeg can’t be found, but the solution is simple: specify the path to your ffmpeg install.  For example:

    /usr/local/bin/ffmpeg etc...

The “-c:v” option to specify the codec is also updated to “-vcodec” and “-acodec”

[ download the updated sketch here ]



2 Replies to “Creating Video With Processing and FFMPEG”

  1. Hi there, fantastic post!

    One question, I have been working with some of your code but I keep coming up against the JavaIO exception error you mention, except I am not sure how to get past it – I am working on Windows 7 and have saved my ffmpeg download in C:\ffmpeg, but whenever I try to update your String ffmpegInstall = “/usr/local/bin/”; command with “C:\ffmpeg” or something like it, I keep getting this error:

    Creating temporary directory for still images…
    Error, sorry! Cannot run program “mkdir” (in directory “C:\Users\Alison\AppData\Local\Temp\untitled5492383391214224779sketches\sketch_141024e”): CreateProcess error=2, The system cannot find the file specified

    Also one other thing, I was also initially getting an error about a class/type called InputStreamReader not being found, but I was able to add in an import*; line in which fixed this.

  2. Hmm, seems to be a few different problems:

    1. I can’t tell from your description if this is the case, but you have to actually install ffmpeg, if can’t just be in put in a folder.
    2. Did you test ffmpeg after installing? Just type “ffmpeg” into the command line. On my Mac, I can type which ffmpeg to see where it’s installed.
    3. Your error message is for a different command, mkdir, and that it’s trying to find that command in your sketch folder.
    4. Since you’re on Windows, it’s possible this will have to be run a different way. I’d suggest a post to Stack Overflow on running command-line programs within Java on Windows.

Leave a Reply

Your email address will not be published. Required fields are marked *