Brendan Dawes
Analogue + Digital

Handy FFMpeg Automator Scripts

This is a follow up to the post detailing how to quickly convert sequential images into a movie using ffmpeg.

Since writing that I've added a few more things to my ffmpeg arsenal: joining several movies into one movie and quickly adding an audio track to a movie, just as a rough test or something similar. Yet now, rather than use the command line, I have Automator scripts setup so I can just control-click on a folder and have it do its magic. Here's the scripts I find very handy.

Install ffmpeg

The first thing to do is to install ffmpeg. This is easiest using Homebrew, a Mac package manager. If you don't have Homebrew first open up a terminal and paste this in the terminal window then press return

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Homebrew will then install. Next we can install FFmpeg using Homebrew. Again paste or type the following into the terminal and press return.

brew install FFmpeg

All being well FFmpeg should now be installed.

Creating the Automator Scripts

On your Mac, when you fire up Automator, choose the Quick Action option when you're asked what type of script to make. Everything below is done using a Run Shell Script action acting on a Folder in the Finder.

Concatenate MOVs into One MPeg

Often when I'm recording a screen cast I'll do it in several chunks in case I make a mistake somewhere but not ruin the whole recording. To then turn these movies into one mpeg, I use this Automator script:

cd "$@"
for f in ./*.mov; do echo "file '$f'" >> filelist.txt; done
/usr/local/bin/ffmpeg -f concat -safe 0 -i filelist.txt -c copy output.mp4

This is setup in Automator like so:

Concat Automator window

This will make a file listing all the .movs in the folder and then use that to pass into ffmpeg, using its concat method to concatenate all the movies into into one mpeg. All you need to be aware of is making sure you number the files in the order you want them to be chained together.

Quickly Dub Audio Onto a Movie

Another one that can come in handy and saves firing up Quicktime or sime other video software. It's raw and dirty but sometimes that's all you need:

cd "$@"
/usr/local/bin/ffmpeg -i *.mp4 -i *.aiff -c:v libx264  output.mp4
audio

For this one to work, you put an mp4 and an aiff into a folder and then choose the action created from the above script. It will then create a new movie called output.mp4 with sound dubbed over the top of the original movie.

Create an Mpeg from Sequential Images

This is the one I use all the time, taking a sequence of png images and creating an mp4.

cd "$@"
/usr/local/bin/ffmpeg -r 24 -f image2 -pattern_type glob -i '*?png' -vcodec libx264 -crf 20 -pix_fmt yuv420p output.mp4
mpeg creator

Gotchas

One thing to be aware of — most of the above will probably fail if you have spaces in the file names.