Skip to content
Go back

Creating Image Slideshows with Voiceovers using FFMPEG

· Updated:
By SumGuy 6 min read
Creating Image Slideshows with Voiceovers using FFMPEG

FFMPEG

In the world of multimedia processing, FFMPEG stands as a powerful and versatile tool for handling audio and video files. FFMPEG, short for Fast Forward Moving Pictures Experts Group, is a command-line-based utility that enables users to manipulate media files with ease. This article aims to provide a comprehensive guide on installing FFMPEG on Ubuntu and utilizing a specific code snippet to create stunning image slideshows accompanied by audio tracks.

Installing FFMPEG

Before diving into the utilization of FFMPEG, it’s important to have the tool installed on your Ubuntu system. Follow these steps to install FFMPEG:

Once the installation process completes, you will have FFMPEG up and running on your Ubuntu system, ready to unleash its capabilities. Now that you have FFMPEG installed, let’s explore how to utilize it to create captivating image slideshows accompanied by audio tracks.

Examples

First example: I have an image file called mountain.jpg and a mp3 file called awesome_song.mp3. I want to make one mp4 file from these files called mountainsongs.mp4:

ffmpeg -loop 1 -i "mountain.jpg" -i "awesome_song.mp3" -r 1 -c:v libx264 -pix_fmt yuv420p -preset veryslow -crf 12 -tune stillimage -c:a copy -shortest mountainsongs.mp4

In the second example, I have a folder with 10 images all named various things ending in extension png. I also have 10 audio tracks named after each image (you can have any audio including tracks you recorded or downloaded). e.g. 1.png 2.png 3.png along with 1.mp3 2.mp3 3.mp3

for i in *.PNG; do ffmpeg -loop 1 -i "${i%.*}.PNG" -i "${i%.*}.mp3" -r 1 -c:v libx264 -pix_fmt yuv420p -preset veryslow -crf 12 -tune stillimage -c:a copy -shortest "${i%.*}.mp4"; done

Piece-by-piece explanation:

By running this code snippet, FFMPEG will process each PNG image file and its associated MP3 audio file, creating MP4 video files as output. The resulting videos will feature a still image slideshow with synchronized audio tracks.

Conclusion on FFMPEG

FFMPEG is a powerful multimedia tool that can be harnessed to manipulate audio and video files from the command line. This article guides you through the installation process of FFMPEG on Ubuntu and provided an explanation of the provided code snippet, which enables you to create captivating image slideshows accompanied by audio tracks. By leveraging FFMPEG’s extensive options and parameters, you can customize your output videos to suit your specific needs. With FFMPEG in your toolkit, you have the means to unleash your creativity and enhance your multimedia projects.

Stitching the Clips Together into One Video

So you’ve got ten 1.mp4, 2.mp4, 3.mp4 files sitting there — now what? If you want a single deliverable instead of a folder of individual clips, you’ll need to concatenate them. FFmpeg has a concat demuxer for exactly this, and it’s way cleaner than piping everything through a filter graph.

First, build a text file listing every clip in order:

Terminal window
for i in $(ls -v *.mp4); do echo "file '$i'"; done > filelist.txt

The -v flag on ls gives you natural sort order (so 2.mp4 comes before 10.mp4 instead of after 19.mp4 — the classic gotcha that bites everyone at least once). Now concatenate:

Terminal window
ffmpeg -f concat -safe 0 -i filelist.txt -c copy final_slideshow.mp4

-c copy means no re-encoding — FFmpeg just splices the streams, so it’s nearly instant regardless of how many clips you have. The -safe 0 flag is required when your filelist contains relative paths; without it, FFmpeg will refuse to open the files and throw a cryptic “unsafe file name” error.

One real gotcha worth knowing: all clips must share the same codec, resolution, and audio sample rate for stream-copy concat to work cleanly. If you batch-encoded everything with the same FFmpeg command above, you’re fine. But if you mixed in a clip from a different source — different resolution, different sample rate — you’ll get desync or outright errors. Fix it by re-encoding the odd-one-out to match before adding it to the list:

Terminal window
ffmpeg -loop 1 -i "oddone.PNG" -i "oddone.mp3" \
-r 1 -c:v libx264 -pix_fmt yuv420p \
-preset veryslow -crf 12 -tune stillimage \
-ar 44100 -c:a aac -shortest oddone.mp4

The -ar 44100 forces a consistent audio sample rate. Once everything matches, re-run the concat and you’re done.


Share this post on:

Send a Webmention

Written about this post on your own site? Send a webmention and it'll show up above once verified.


Previous Post
Docker Compose Environment Variable Precedence
Next Post
CUDA vs ROCm vs CPU: Running AI on Whatever GPU You've Got

Discussion

Powered by Garrul . Sign in with GitHub or Google, or post anonymously.

Related Posts