The 'just works' codec
H.264 (a.k.a. AVC) ships in every browser, every phone, every TV, every editor, every cloud transcoder, every set-top box made in the last 15 years. When you don't know what to use, use H.264. libx264 is its open-source CPU encoder and is widely considered the gold standard for software encoding quality.
The three knobs
- -crf — quality target. 18 ≈ visually transparent, 23 = default, 28 = web-acceptable but soft. Don't go above 28 unless you're targeting low-bandwidth.
- -preset — speed/efficiency tradeoff. Slower presets = smaller files at the same quality. Names:
ultrafast, superfast, veryfast, faster, fast, medium, slow, slower, veryslow, placebo. slow is the sweet spot for one-off jobs. - -tune — content-aware optimization:
film,animation,grain,stillimage,fastdecode,zerolatency. Use sparingly — defaults are usually fine.
Profiles and levels
For maximum compatibility (Apple TV, smart TVs, old Android phones), set -profile:v high -level 4.0. For 4K, you need at least -level 5.1. The encoder picks reasonable defaults; you only override when a target device chokes.