Categories
Video

Create video slideshows with ImageMagick and FFmpeg in minutes

I’ve been using a Pixelbook, a Chromebook from Google, for the past two and a half years.

Chromebooks are not known as great for photo and video editing, but I have found it’s an excellent platform for my needs. It does nearly all of the photo and video editing I need to do — and usually quicker.

The trick is to enable Linux on your Chromebook and use some very well-known command-line tools: youtube-dl, FFmpeg, ImageMagick, and MediaInfo.

Here is how I created a video slideshow in just a few minutes using ImageMagick and FFmpeg.

I had a series of photos taken with my Fujifilm X20 point-and-shoot camera of our dogs. Winston and Charley.

They were 4000 x 3000 pixels, a 4:3 aspect ratio. I wanted to create a video of those photos in a 16:9 aspect ratio (the aspect ratio of your HD TV) with as little “black frame” as possible and add background music.

Charley photo in a 4:3 aspect ratio

Here is what I did.

I put all the photos in a folder under Linux on the Pixelbook and then I ran this ImageMagick script on the files in the folder:

for i in *JPG;do convert "$i" 
-gravity center -crop 16:9
+repage 16x9-"$i";done

This converted all the “.JPG” files to 4000×2250, or a 16:9 aspect ratio with the center as the most important part to keep in the crop. Yes, I could have resized them as well to 1920×1080, but in this case, FFmpeg handles that.

Also, it’s Linux, case matters for JPG vs jpg.

Then I deleted the 4:3 aspect ratio versions, leaving only the new 16:9 aspect ratio ones so I could run this FFmpeg command to combine the photos as a video.

ffmpeg -framerate 1/5 -pattern_type glob -i '.JPG' 
-vf "scale=iwmin(1920/iw\,1080/ih):ihmin(1920/iw\,1080/ih),
pad=1920:1080:(1920-iwmin(1920/iw\,1080/ih))/2:(1080-ih*min(1920/iw\,1080/ih))/2,
fps=8,format=yuv420p" -crf 20 output-video-name.mp4

This command says to create a video showing each photo for 5 seconds (-framerate 1/5). The order of the photos wasn’t important.

Disclosure: I found the above script somewhere on the internet, but I don’t remember where. You might want to change the output framerate to 25 or 30 … change fps=8 to fps=25 or 30 … but fps=8 worked for me and all that happens in the photos are duplicated to get the frames per second.

There also are other ways to combine a series of photos, particularly ones with sequentially numbered filenames.

I downloaded some royalty-free music from YouTube and ran another FFmpeg command. (These two steps probably could be combined.)

ffmpeg -i video-name.mp4 -i background-music.mp3 
-c copy -map 0:v:0 -map 1:a:0 -shortest
video-name-with-music.mp4

Here is the result:

If you have vertical photos, they might come in sideways. I was able to fix that with ImageMagick using this command:

mogrify -auto-orient image-name.JPG

You might not want to change the aspect of vertical photos to 16:9. Run a few test files to see what you like.

There are tons of resources out there, but one of the best for FFmpeg is on Reddit. Some of the users in that subreddit are truly FFmpeg power users (which I am not).

If you wanted to take it further, it would be possible to add a watermark or “bug” to the video and to have narration as well as background audio — and a long list of other command-line options, enhancements, and tweaks.

Also, MediaInfo will also give you detailed information on a video/audio/image file.

The command is really simple:

mediainfo filename

There are versions of these command-line tools for Windows and the MacOS, but it seems the Linux versions are more actively updated. Also, you can run a Linux terminal on a Windows 10 PC now.

If your slideshows are pretty standardized, this is a very fast way to create them.

Suggestions or comments? Hit me up on Twitter at @jacklail

Note: If you copy any of the code snippets above, remove any returns.