ffmpeg: Image Slideshow with Audio and Title Overlay

I often need to put audio interviews on YouTube, which requires they be movie files. Making slideshows in Adobe Premiere can take a long time to create and export. This ffmpeg process is quick to set up, and even quicker to export. You end up with a .mp4 format video slideshow with a transparent PNG title overlay  in a 16:9 aspect ratio (960×540 pixels) set to the audio of your choice. There’s no fancy transitions or anything, but the time it saves is tremendous.

I am using OS X El Capitan with ffmpeg version 3.0.

First we’ll start with a folder that contains your audio (as a single file – to concate multiple audio files, see trac.ffmpeg.org) and your images (jpgs and pngs of any size, we’ll convert them shortly).

If you want a title overlay, use the drawing program of your choice (or an online png creator) to make a transparent png that will overlay your whole slideshow. Make it 960×540 pixels, and place your text in an area where it won’t interfere with your images too much. We’ll name it MyTitle.png and put it in the folder with the rest of our images.

Next thing we’ll do is make a python script which will take all of our images and fit them into a 960×450 pixel frame with black padding. We’ll retain our images aspect ratio so they aren’t distorted. I am used the script here at www.bogotobogo.com as a starting point, and improved it to add black padding and maintain aspect ratio with answers from this stackoverflow.com post. The script will also convert all of our image names to “img-XXX.jpg” and convert them to jpgs.

**Notice that there is a configuration variable called “title_image”. You’ll want to make sure that matches the name of your title overlay or else it too will be transformed and become part of the slideshow.**

Place this script in the folder with your images.

Next, we make our bash script that contains our ffmpeg command.

What’s going on here?

First is just ffmpeg setup:
-y : Overwrite any existing file

Next, we deal with our image slideshow:
-loop 1 : loop the images
-framerate 1/3 : the “framerate” of the images. This gives us about 3s per image but you can adjust it. Smaller the number the longer the images will show.
-i img-%03d.jpg : tells ffmpeg which files to use (get anything named img-XXX.jpg)

Then our overlay:
-i MyTitle.png : set the title overlay filename
-filter_complex “0:0” : set the overlay filter. Since we used a title that filled our whole screen, we can just position it at (0,0) coordinates. If you want to be able to scale or more specifically position your overlay, the ffmpeg docs for overlay and this stackoverflow post are good places to start.

Then, our audio:
-i “Track01.mp3” : indicates which audio file to use (change this to your audio name)
-c:a copy : tells ffmpeg not to change the audio format. Just use it as is.

Finally, our output:
-shortest : tells ffmpeg to stop our slideshow when the audio is finished.
-aspect 16:9 : sets our aspect ratio for the final product.
-r 5 : gives the framerate for the output. I chose 5fps because it is quicker to export.
“FinalSlideshow.mp4” : the name of our output. Simply change the extension to change the output type.

That’s it. You should now have a folder with:

      • slideshow images
      • title overlay
      • audio track
      • resize.py script
      • make_show.sh script


Just run your python script python resize.py and take a look at your images. You should see a similar conversion to this:





Next, run your make_show.sh script sh make_show.sh

You should see a flurry of ffmpeg activity, and after a while (a slideshow lasting an hour took about 8 mins to do) your FinalSlideshow.mp4 movie should be inside your folder along with everything else.

Here’s what I came up with for a slideshow with some transitions (fade to black). It’s based on this StackExchange post for the transitions, and this one for the concatenating.

Basically what we are doing is making a short slideshow of a few slides as one short video, then concatenating it together a bunch of times. Then we go and add the audio track to that. A little clunky, but we do get some nice transitions!

Sources for this project:

Leave a Reply

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