FFMPEG
November 11, 2019 — December 23, 2019
FFMPEG is a multitool for media and metadata. It is handy for video, extracting audio from video, or whatever other permutation of these ingredients we might wish.
1 Documentation
Documentation is sensible but requires knowledge of the minor implementation details of 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 and chatgpt. I fully expect that in the future no one will use this software except via chatbots.
There is a wiki page for each major supported format, e.g. AAC audio and H.264 video.
There is a dummies’ guide to some extremely basic use cases.
UPDATE: now there is a less esoteric manual by itsfoss
.
2 Installing
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; I generally do not care about that because I am unlikely to be building anything using ffmpeg
that would be liable for patent royalties such as a turkey commercial product. As such, I prefer a more capable build:
or even
3 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:
4 Trim
5 Replace a video soundtrack
Stackoverflow advises on replacing a video soundtrack:
6 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 codec.
7 Animated GIF conversion
See Animated GIFs.
8 Convert photos to a movie
Stitch photos to video
9 Compressing gigantic smartphone videos into a lower-fi web upload
Depends on 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";
done
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.
10 Incoming
Keunwoo Choi shows how to make an animated scrolling spectrogram.
Normalising 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 its implementation.