Brendan Dawes
The Art of Form and Code

Creating Thumbnails of Videos with FFmpeg and Automator

Just a quick one, but wanted to make a note of this very handy FFmpeg script.

For a project I'm currently working on I wanted to quickly create thumbnail images from a couple of hundred videos. I wandered if FFmpeg could do it and of course the answer was yes, after finding this great blog post from Josephine Loo.

I created a new Automator Quick Action for Files and Folders and added a Runs Shell Script action with pass into set to Arguments. I then added this code into the shell script field:

cd "$@:h"
for f in "$@"
do
name=$(echo $f | cut -f 1 -d '.')
/usr/local/bin/ffmpeg -y -i "$f" -vf "thumbnail,scale=640:-1,crop=200:200" -frames:v 1 "$name.png"
done
how it looks in Automator

The first line changes the directory to the one containing the files that are selected. After grabbing the filename and putting it into a variable called $name, it then works through each file and performs the FFmpeg command, creating thumbnails, scaled to 640 pixels wide but cropped square – which is what I wanted for my purposes.

After saving the Automator action I could then select the video files, and choose my Quick Action. Instant thumbnails!