ffmpeg Commands

Here is a collection of useful ffmpeg commands for converting image stacks to mp4s.

The basic command should look like this:

ffmpeg -i frame_%5d.png -vcodec libx264 -pix_fmt yuv420p out.mp4

Where -i frame_%5d.png specifies the file pattern for the image stack. In this case the files have a 5 digit integer padded with zeros (i.e frame_00000.png, frame_00001.png, frame_00002.png, …).

The -vcodec libx264 specifies the use of the H264 codec, and the -pix_fmt yuv420p specifies the pixel format.

Finally, out.mp4 specifies the output file name and mp4 container.

Other common flags that can be used to modify the resulting video are:



-r 60

set the frame rate, in this case to 60 frames per second

-vf “transpose=1”

where the transpose parameter can be:

  • 0 = 90 Counter-clockwise and Vertical Flip (default)

  • 1 = 90 Clockwise

  • 2 = 90 Counter-clockwise

  • 3 = 90 Clockwise and Vertical Flip

-crf 25

quality for constant quality mode, higher the number the smaller lower quality video.

putting it all together:

ffmpeg -r 20 -i frame_%5d.png -vf "transpose=1" -vcodec libx264 -pix_fmt yuv420p -crf 20 out.mp4