Version 11 (modified by slhck, 6 years ago) (diff)

alternative fps option for specifying rate, see ticket #3164

Frame rates

This will create a video slideshow (using the encoder libx264) from series of numerically sequential PNG images named img001.png, img002.png, img003.png, etc. Important: All images in a series need to be of the same size and format.

You can specify two frame rates:

  • The rate according to which the images are read, by setting -r before -i. The default for reading input is -r 25 which will be set if no -r is specified.
  • The output frame rate for the video stream, by setting -r after -i, or using the fps filter. If you want the input and output frame rates to be the same, then just declare an input -r and the output will inherit the same value.

By using a separate -r (frames per second) for the input and output you can control the duration at which each input is displayed and tell ffmpeg the frame rate you want for the output file. If the input -r is lower than the output, -r ffmpeg will duplicate frames to reach your desired output frame rate. If the input -r is higher than the output -r ffmpeg will drop frames to reach your desired output frame rate.

In this example each image will have a duration of 5 seconds (the inverse of 1/5 frames per second). The video stream will have a frame rate of 30 fps, by duplicating the frames accordingly:

ffmpeg -r 1/5 -i img%03d.png -c:v libx264 -r 30 -pix_fmt yuv420p out.mp4

If your video does not show the frames correctly, setting the fps filter instead of the output framerate should work:

ffmpeg -r 1/5 -i img%03d.png -c:v libx264 -vf fps=25 -pix_fmt yuv420p out.mp4

Color space conversion and chroma sub-sampling

By default when using libx264, and depending on your input, ffmpeg will attempt to avoid color subsampling. Technically this is preferred, but unfortunately almost all video players and many online video services only support YUV 4:2:0. PNG uses the RGB color space, so when using PNG images as your input you must add -pix_fmt yuv420p or -vf format=yuv420p if you want maximum compatibility. You can omit this if you are using JPG images as inputs.

Using a glob pattern

ffmpeg also supports bash-style globbing (* represents any number of any characters). This is useful if your images are sequential but not necessarily in a numerically sequential order as in the previous examples.

ffmpeg -r 1 -pattern_type glob -i '*.jpg' -c:v libx264 out.mp4

For PNG images:

ffmpeg -r 1 -pattern_type glob -i '*.png' -c:v libx264 -pix_fmt yuv420p out.mp4

Using a single image as an input

If you want to create a video out of just one image, this will do (output video duration is set to 30 seconds with -t 30):

ffmpeg -loop 1 -i img.png -c:v libx264 -t 30 -pix_fmt yuv420p out.mp4

Adding audio

If you want to add audio (e.g. audio.wav) to one "poster" image, you need -shortest to tell it to stop after the audio stream is finished. We use the internal AAC encoder, but you can use any other AAC encoder as well:

ffmpeg -loop 1 -i img.jpg -i audio.wav -c:v libx264 -c:a aac -strict experimental -b:a 192k -shortest out.mp4

See also