Creating Image Slideshows with Voiceovers using 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 Picture Expert 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:

  • Update the package lists
    • apt update
  • Install FFmpeg
    • apt 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.


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:

  1. for i in *.PNG; do This initiates a loop that iterates through all PNG files in the current directory.
  2. 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"; This is the FFMPEG command that performs the actual processing. Let’s break down the various options and parameters used:
    • -loop 1: Specifies that the input image should be looped infinitely.
    • -i "${i%.*}.PNG": Defines the input image file. The ${i%.*} part of the code extracts the file name without the extension, allowing the script to dynamically process each image file in the loop.
    • -i "${i%.*}.mp3": Specifies the input audio file associated with the corresponding image.
    • -r 1: Sets the output video frame rate to 1 frame per second. Adjust this value as per your preference.
    • -c:v libx264 -pix_fmt yuv420p -preset veryslow -crf 12 -tune stillimage: These options control the video encoding settings, ensuring high-quality output. The libx264 codec is used with the yuv420p pixel format, and the veryslow preset with a Constant Rate Factor (CRF) of 12 and tuning stillimage are employed to optimize for still image content.
    • -c:a copy: This option instructs FFMPEG to copy the audio stream without re-encoding it, preserving the original audio quality.
    • -shortest: Automatically sets the output video duration to the shortest input file’s duration, ensuring synchronization between the image slideshow and audio track.
    • "${i%.*}.mp4": Specifies the output video file name. Similar to the input image file, the ${i%.*} part extracts the file name without the extension, allowing the script to generate a corresponding output video file for each input image.
  3. done this just ends the loop from step 1.

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.

Similar Posts

Leave a Reply

Your email address will not be published. Required fields are marked *