Create slide show from pictures - part 1

After you upload your pictures from your digital camera to your Linux computer, you want to view them without having to manually open each one. This post explains how to create a slide show from a set of picture files using ffmpeg, a command-line tool. My next post turns to Imagination, a GUI-based tool, to achieve the same goal.

To create a video from still images,


$ ffmpeg -r 1/3 -i image-%03d.png -vcodec copy out.mp4

Notes:

  • Order matters

    In general, options are applied to the next specified file on the command line. For instance, the -r (aka, frame rate) option applies to the PNG files, not the MP4 file. The order of specifying options is important for ffmpeg.

  • -r

    This is the frame rate specified in frames per second. The default is 25 which is too fast for human consumption. For a quick view of a large number of pictures, I prefer 3 seconds per frame, or 1/3 frame per second, hence -r 1/3.

  • -i

    The input picture files must be sequentially numbered, starting with the number 1. The image-%03d.png pattern matches files image-001.png, image-002.png, etc.

    The input files must share the same size (e.g., 1280 x 720 pixels) and format (e.g., PNG).

  • -vcodec copy

    The video input stream will be copied as is to the output file. Without this parameter, I found that the last picture file is omitted from the output video.

A slide show can be quite bland without background music. You can enhance the slide show by adding an audio stream from a sound file using the following command:


$ ffmpeg -r 1/3 -i image-%03d.png -i music.mp3 -vcodec copy -strict experimental out.mp4

Notes:

  • -i

    The video file (PNG) and the audio file (MP3) are specified.

  • -strict experimental

    This option is required because the default AAC audio encoder is experimental in ffmpeg.

Ideally, the duration of both the video and audio input files is the same. Otherwise, you may be staring at the video with no background music, or listening to the music while the video is stuck at the last frame. The simplest solution is to add the -shortest option.

The -shortest option guarantees that the length of the output video does not exceed that of the shortest input stream, audio or video. Therefore, when the video stops, so does the audio, and vice versa.


$ ffmpeg -r 1/3 -i image-%03d.png -i music.mp3 -vcodec copy -strict experimental -shortest out.mp4

If your audio is longer than the video, you can enable video looping by specifying -loop 1. The net effect is that the video will restart at the beginning if it finishes before the audio does.


$ ffmpeg -loop 1 -r 1/3 -i image-%03d.png -i music.mp3 -vcodec copy -shortest -strict experimental out.mp4

Note that -loop applies to video looping only. The audio track is not looped if it finishes before the video.

Using ffmpeg, you can create a basic, no-thrill slide show from your still pictures. If you want to add animation effect while transitioning from 1 slide to the next, please see my next post on the Imagination GUI tool.

If you are interested in what else you can do with ffmpeg, please read my earlier post on Capturing video snapshots.