FFMPEG is a multitool for media and metadata. It is handy for video, or extracting audio from video, or whatever other permutation of these ingredients you wish.


Documentation is not so much abstruse, as requiring knowledge of the minor implementation details video formats which is one of the most boring domains of human endeavour imaginable, and something that only patent trolls and sometimes engineers are paid enough to care about. Thankfully we have copy-pasta.

There is a wiki page for each major supported format, e.g. AAC audio and H.264 video.

There is a dummies’ guide.


FFMPEG is conservative in its default install under homebrew, skipping anything that might conceivably infringe upon any patent in any jurisdiction, or anything that sounds like too much effort; you might want something more expansive, like:

brew install ffmpeg \
    --with-fdk-aac \
    --with-libsoxr \
    --with-libvorbis \

or even

brew install ffmpeg --with-all

Extract audio

If you wish to salvage pure audio for your sampling (up to you to ensure this is legal in your jurisdiction) by getting rid of the video track:

ffmpeg -i mangled_file.m4a -acodec copy -vn plain_audio_file.m4a

Replace a video soundtrack

Stackoverflow advises on replacing a video soundtrack:

ffmpeg -i v.mp4 -i a.wav -c:v copy -map 0:v:0 -map 1:a:0 -shortest new.mp4

Turning outdated camera video into web-friendly video

Using these I have stitched together a workflow for, e.g. converting annoying camera video into something more compact and modern:

You could go for -c:v libx265 for an even fancier codev.

$ for i in 2 3 4 5 6 7 8 9 10 11 12 13; do
> ffmpeg -i filename_$i.avi \
    -c:v libx264 -preset slower -crf 22 \
    -c:a libfdk_aac -vbr 5 \
> done

Convert GIF to movie

Google advises on converting animated GIFs to movies:

ffmpeg -i input.gif -b:v 0 -crf 25 output.mp4

The evil martians version is lengthier:

ffmpeg -i input.gif -map_metadata -1 -c:a libfdk_aac -c:v libx264 -cfr 24 -preset veryslow -profile:v mail -px_fmt yuv420p -movflags +faststart -vf "scale=trunc(iw/2)*2:trunc(ih/2)*2" image.h264.mp4

Convert photos to a movie

Stitch photos to video for making animated GIFs:

ffmpeg -framerate 5 -start_number 1234 -i IMG_%04d.JPG \
    -c:v libx264 -pix_fmt yuv420p -vf scale=1920:-2:flags=lanczos \
    -crf 20 -preset slow -c:a copy ../something.m4v

Compressing gigantic smartphone videos into a lower-fi web upload

Depend what you want, but here is a start that meets my needs based on a few different hints I found online

for i in *.MOV;
  do ffmpeg -i "$i" \
    -c:v libx265 \
    -preset slow -crf 23 \
    -filter:v scale=720:-1 \
    -af "highpass=f=150, equalizer=f=50:width_type=h:width=100:g=-15" \
    -c:a aac -strict experimental -b:a 192k "${i%.MOV}-ENCODED.MOV";

I’m also fond of this one because it does not preserve much metadata from your phone video; This is good. Those web people don’t need to know everything about your smartphone.


Keunwoo Choi shows how to make an animated scrolling spectrogram.

Normalizing is easiest with wrapper script ffmpeg-normalize.

Advanced class: ffmpeg includes a programmatic control from ZeroMQ, so you can dynamically control filters while, e.g. playing video. There are controversies about implementation.

Warning! Experimental comments system! If is does not work for you, let me know via the contact form.

No comments yet!

GitHub-flavored Markdown & a sane subset of HTML is supported.