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.
Why create a video slideshow from images?
There are several reasons why you might want to create a video slideshow from images:
- Photography portfolios: Showcase your best photographs in a dynamic format.
- Event recaps: Create memorable videos from event photos for weddings, conferences, or parties.
- Educational content: Combine images with voiceovers for informative presentations.
- Marketing materials: Develop engaging product showcases or company timelines.
- Personal memories: Turn family photos into shareable video memories.
- Real estate listings: Create virtual tours from property images.
- 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.
Basic 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:
ffmpeg -f image2 \
-framerate 1/5 \
-i image%d.jpg \
-c:v libx264 -pix_fmt yuv420p output.mp4Breakdown 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.
After you have created your slideshow video you may be interested in the Mux Video API for video encoding, storage and delivery.
Learn more about Mux VideoCrossfading between multiple images:
This command adds a crossfade affect between each image:
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.mp4This 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).
Adding background music
To add background music to your slideshow:
ffmpeg -f image2 -framerate 1/5 -i image%d.jpg \
-i music.mp3 \
-vsync vfr -pix_fmt yuv420p \
-shortest \
output.mp4Similar 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.
Mux tips 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).
Video slideshow creation FAQs
What image format works best for video slideshows?
JPEG works well for photographic content and provides good quality with manageable file sizes. PNG is ideal if you need transparency or have graphics with sharp edges. Use the highest resolution source images available—FFmpeg will scale them down if needed, but can't add detail that isn't there. Ensure all images have the same dimensions or aspect ratio to avoid black bars or distortion in the final video.
How do I control how long each image displays?
Use the -framerate parameter to set display duration. The value 1/5 means each image displays for 5 seconds (1 frame every 5 seconds). For 3-second displays, use -framerate 1/3. For half-second displays, use -framerate 2 (2 frames per second). This input framerate combined with your output framerate (typically 24-30fps) determines timing while FFmpeg duplicates frames as needed.
Can I use images with different aspect ratios in one slideshow?
Yes, but you'll need to handle them with scaling and padding filters to avoid distortion. Use the scale and pad filters to fit all images into a consistent canvas size, adding letterboxing or pillarboxing as needed. Alternatively, use the crop filter to extract matching portions from each image. The cleanest approach is preprocessing images to consistent dimensions before creating the slideshow.
Why is my slideshow file size so large?
Large file sizes typically result from high bitrates or inefficient encoding. Reduce bitrate with -b:v 2M (for 2 Mbps) or use CRF mode with -crf 23 for quality-based encoding. Since slideshows contain static images, they compress efficiently—unusually large files suggest encoding issues. Also ensure you're using -pix_fmt yuv420p for compatibility and compression efficiency.
How do I add transitions beyond crossfade?
FFmpeg supports various transitions through the xfade filter, including fade, wipeleft, wiperight, slidedown, and more. Replace the fade filter in the crossfade example with xfade=transition=wipeleft:duration=1:offset=4 to create a wipe transition. Each transition type has different visual effects. Experiment with duration and offset values to control transition timing and smoothness.
Can I add text overlays or captions to slideshow images?
Yes, use the drawtext filter to add text overlays. For example: -vf "drawtext=text='Vacation 2024':fontsize=48:fontcolor=white:x=(w-text_w)/2:y=50" centers white text at the top. You can add timestamps, captions, or watermarks. For more complex text layouts or multiple text elements per image, consider preprocessing images with text overlaid before creating the slideshow.
What framerate should I use for the output video?
Use 24fps or 30fps for most platforms—these are standard video framerates that ensure broad compatibility. The output framerate doesn't need to match your input framerate (which controls display duration). FFmpeg automatically duplicates frames as needed. For example, with input framerate 1/5 and output 30fps, FFmpeg creates 150 identical frames per image (5 seconds × 30fps).
How do I handle audio that's longer or shorter than my images?
Use -shortest to end the video when the shortest stream (images or audio) finishes. If audio is shorter, add the -stream_loop -1 flag before the audio input to loop it until images end. If you want to extend or trim audio to exactly match image duration, calculate total image time, then use -t to trim audio: -t 25 for 25 seconds total. Alternatively, fade audio out at the end using audio filters.