Skip to content

Create a video slideshow with images using FFmpeg

Creating a video slideshow from a collection of images is an effective way to present visual content. Whether you're showcasing photography or putting together a business presentation, FFmpeg can be used to transform your still images into dynamic video slideshows. This guide will walk you through various methods of creating video slideshows using FFmpeg.

LinkWhy create a video slideshow from images?

There are several reasons why you might want to create a video slideshow from images:

  1. Photography portfolios: Showcase your best photographs in a dynamic format.
  2. Event recaps: Create memorable videos from event photos for weddings, conferences, or parties.
  3. Educational content: Combine images with voiceovers for informative presentations.
  4. Marketing materials: Develop engaging product showcases or company timelines.
  5. Personal memories: Turn family photos into shareable video memories.
  6. Real estate listings: Create virtual tours from property images.
  7. Social media content: Produce eye-catching video content for platforms like Instagram or Facebook.

Let's explore how to use FFmpeg to create video slideshows in various scenarios.

LinkBasic video slideshow creation

This is the simplest way to create a video slideshow using FFmpeg's image2 input format. First, create some images in the format of image1.jpg, incrementing the the number for each subsequent image.

Then, use the following FFmpeg command:

bash
ffmpeg -f image2 \ -framerate 1/5 \ -i image%d.jpg \ -c:v libx264 -pix_fmt yuv420p output.mp4

Breakdown of the command:

  • -f image2: Specifies the input format as image2, which expects image files as input
  • -framerate 1/5: This sets the input framerate to 1/5, meaning each image will be displayed for 5 seconds in the resulting video. You can adjust this value to change how long each image is shown.
  • -i image%d.jpg: This specifies the input file pattern. The %d is a placeholder for a number. ffmpeg will look for files named image1.jpg, image2.jpg, image3.jpg, and so on, in numerical order.
  • -c:v libx264: This sets the video codec to H.264
  • -pix_fmt yuv420p: Sets pixel format for compatibility
  • output.mp4: Name of the output file

This command will create a video where each image is displayed for 5 seconds.

LinkCrossfading between multiple images:

This command adds a crossfade affect between each image:

bash
ffmpeg \ -loop 1 -t 5 -i image1.jpg \ -loop 1 -t 5 -i image2.jpg \ -loop 1 -t 5 -i image3.jpg \ -filter_complex \ "[1]format=yuva444p,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+4/TB[f0]; \ [2]format=yuva444p,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+8/TB[f1]; \ [0][f0]overlay[bg1];[bg1][f1]overlay,format=yuv420p[v]" -map "[v]" output.mp4

This command is more complex as it utilizes filters to achieve the crossfade. Here's a quick breakdown of what is happening:

  • -loop 1 -t 5 -i image1.jpg repeats image 1 for 5 seconds, and similarly for the other images.
  • [1]format=yuva444p,fade=d=1:t=in:alpha=1,setpts=PTS-STARTPTS+4/TB[f0]: Sets a format for the second image to one that supports transparency (yuva444p). Applies a 1-second fade-in effect and adjusts the timing so that image 2 starts 4 seconds into the video. We adjust the 3rd image similarly afterwards.
  • The rest of the command orders the images on top of each other correctly ([0][f0]overlay[bg1];[bg1][f1]overlay) and sets up the output format (yuv420p).

LinkAdding background music

To add background music to your slideshow:

bash
ffmpeg -f image2 -framerate 1/5 -i image%d.jpg \ -i music.mp3 \ -vsync vfr -pix_fmt yuv420p \ -shortest \ output.mp4

Similar to our first basic slideshow command but we added an input for the audio stream and specified that it should trim the output video to the shortest track length using the -shortest flag. If the audio is longer than the images, this will trim the audio track back to where the images end.

LinkTips for creating effective video slideshows

  • Choose high-quality images: The output quality depends on your source images.
  • Consider image aspect ratios: Use images with the same aspect ratio as your intended output, otherwise you will have to adjust the FFmpeg commands to crop the final output.
  • Optimize for platforms: Consider the requirements of your target platform when changing the output video settings, like bitrate and size (1080p, 4K, etc).

No credit card required to start using Mux.