FFmpeg 101: A Beginner’s Guide to the Command Line
Wed Apr 10 2024
Understand inputs/outputs, streams, codecs vs containers, and safe defaults to get productive with FFmpeg.
FFmpeg is a powerful, open‑source toolkit for working with audio and video. You can convert formats, trim clips, add subtitles, and much more — all from the command line. This guide teaches the mental model you need to read and write FFmpeg commands confidently.
Install FFmpeg
Follow the official documentation for your platform:
- macOS: Homebrew (
brew install ffmpeg) or download from the website - Windows: download binaries; add
ffmpeg.exeandffprobe.exeto PATH - Linux: your distro’s package manager (e.g.
apt install ffmpeg)
See: https://ffmpeg.org/download.html
Anatomy of a Command
An FFmpeg command reads: global options → inputs → per‑stream options → output file(s).
General pattern:
ffmpeg [global opts] -i input.ext [stream opts] output.ext
- Inputs start with
-i. Input‑specific options must appear before their-i. - Per‑stream options like
-c:vor-b:acome after the input and before the output file.
Streams and Mapping
Files contain streams: video (v), audio (a), and subtitles (s). FFmpeg auto‑maps typical streams. For advanced cases, use -map to pick exactly what goes where, e.g. -map 0:v:0 -map 0:a:1.
Safe Defaults for Common Tasks
# Show basic media info via ffmpeg (quick peek) ffmpeg -i input.mp4 # Transcode to H.264/AAC MP4 (good defaults) ffmpeg -i input.mp4 -c:v libx264 -preset medium -crf 23 -c:a aac -b:a 128k -movflags +faststart output.mp4 # Remux (no re-encode): MP4 → MKV ffmpeg -i input.mp4 -c copy output.mkv # Extract audio as MP3 ffmpeg -i input.mp4 -vn -c:a libmp3lame -q:a 2 output.mp3 # Grab a thumbnail at 10s ffmpeg -ss 00:00:10 -i input.mp4 -frames:v 1 -q:v 2 thumb.jpg
Pitfalls
- Option order matters (input options before
-i, output options after). - Overwriting files: add
-yto auto‑overwrite or omit to be prompted. - Quote filenames with spaces:
"My File.mp4".
That’s it! With the model of inputs → options → outputs, you can read most FFmpeg commands at a glance.