Convert a bunch of images into a video, batch job

Alec Jacobson

October 26, 2012

weblog/

I was sure I posted this some time before, but just in case, here it is again. My programs can easily dump jpgs, pngs, or tga image files at every frame. Sometimes it suffices to convert these to an animated GIF using imagemagick. But if there are many images and they're all hi-res then really you need a proper video codec to get a reasonably small file. I use this ffmpeg command:

ffmpeg -f image2 -r 30 -i myimages-%04d.tga -r 30 -vcodec libx264 -pix_fmt yuv420p -q:vscale 0 output.mp4

or using GLOB for a lexicographical, alphabetical file list:

ffmpeg -f image2 -r 30 -pattern_type glob -i 'my-images-*.png' -r 30 -vcodec libx264 -pix_fmt yuv420p -q:vscale 0 output.mp4

Update : The -pix_fmt yuv420p` is important for getting the output video to play in quicktime.