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
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 to some extremely basic usecases.
UPDATE: now there is a good manual by itsfoss
.
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 that woulf be liable for patent royalties, so this is more general:
brew install ffmpeg \
--with-fdk-aac \
--with-libsoxr \
--with-libvorbis \
--with-openh264
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
Trim
ffmpeg -i long_movie.mp4 -ss 36:33 -to 57:36 -c:v copy -c:a copy excerpt.mp4
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 codec.
$ 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 \
filename_$i.mp4;
> done
Animated GIF conversion
See Animated GIFs.
Convert photos to a movie
Stitch photos to video
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";
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.
Incoming
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 its implementation.
No comments yet. Why not leave one?