FFmpeg supports over 100 video codecs and dozens of audio codecs[reference:0]. But only a fraction of those are worth a deeper dive. This guide covers the ones you'll actually use — from the universal compatibility of H.264 to the bleeding‑edge compression of AV1.
Before we dive in, a quick note on how FFmpeg names codecs:
- Encoders are specified with
-c:v(video) or-c:a(audio). - List all available codecs:
ffmpeg -codecs - List all encoders:
ffmpeg -encoders - List all decoders:
ffmpeg -decoders[reference:1]
Key takeaways
- H.264 (libx264) – the universal standard. Best for compatibility.
- H.265 / HEVC (libx265) – ~50% better compression than H.264. Great for 4K.
- VP9 (libvpx-vp9) – royalty‑free, web‑friendly. Comparable to H.265.
- AV1 (libaom-av1 / libsvtav1) – the future. ~30% better than VP9, ~50% better than H.264[reference:2].
- AAC (aac) – the default audio codec. High quality at low bitrates.
- Hardware encoders (QSV, NVENC, VAAPI) – fast but lower quality per bit.
Video codecs
H.264 / AVC – libx264
H.264 is the most widely used video codec in the world. It's supported by every browser, every phone, every smart TV, and every video platform. If you need maximum compatibility, this is your codec.
FFmpeg uses the libx264 encoder. It's an external library, so your FFmpeg build needs --enable-libx264[reference:3].
Basic H.264 encode
ffmpeg -i input.mov -c:v libx264 -preset medium -crf 23 -c:a aac output.mp4
libx264 options
-preset– speed vs. compression. Values:ultrafast,superfast,veryfast,faster,fast,medium(default),slow,slower,veryslow,placebo. Slower = better compression.-crf– Constant Rate Factor. Quality scale from 0 (lossless) to 51 (worst). Default is 23. 18–28 is the practical range. Lower = better quality.-tune– optimise for specific content:film,animation,grain,stillimage,fastdecode,zerolatency.-profile:v– H.264 profile:baseline,main,high(default),high10, etc.
For advanced tuning, use -x264-params with a colon‑separated list of key=value pairs[reference:4]:
ffmpeg -i input.mov -c:v libx264 -x264-params "keyint=250:min-keyint=25:bframes=3" output.mp4
H.265 / HEVC – libx265
H.265 (High Efficiency Video Coding) delivers roughly 50% better compression than H.264 at the same visual quality[reference:5]. That means half the file size for the same quality, or better quality at the same file size. It's the go‑to codec for 4K, 8K, and HDR content.
FFmpeg uses the libx265 encoder. Enable with --enable-libx265 at build time[reference:6].
Basic H.265 encode
ffmpeg -i input.mov -c:v libx265 -preset medium -crf 24 -c:a aac output.mp4
libx265 options
-preset– same speed/quality trade‑off as x264:ultrafastthroughveryslow.-crf– Constant Rate Factor. Default is 24. Range 0–51. For H.265, CRF 24 is roughly equivalent to H.264 CRF 23.-tune–psnr,ssim,grain,zerolatency,fastdecode.-x265-params– pass raw x265 options[reference:7].
ffmpeg -i input.mov -c:v libx265 -x265-params "crf=26:psy-rd=1" output.mp4
VP9 – libvpx-vp9
VP9 is Google's royalty‑free, open‑source codec. It's the standard for WebM and is widely supported in browsers (Chrome, Firefox, Edge)[reference:8]. In terms of compression, VP9 is roughly comparable to H.265, but it's completely free to use with no licensing fees.
FFmpeg uses the libvpx-vp9 encoder. Enable with --enable-libvpx.
Basic VP9 encode
ffmpeg -i input.mov -c:v libvpx-vp9 -crf 30 -b:v 0 -c:a libopus output.webm
VP9 options
-crf– Constant Rate Factor. 0–63, where lower is better. 30 is a good starting point.-b:v 0– disables target bitrate, enabling CRF mode.-row-mt 1– enables row‑based multi‑threading (much faster).-speed– 0–5 (0 = slowest/best, 5 = fastest/worst).
ffmpeg -i input.mov -c:v libvpx-vp9 -crf 30 -b:v 0 -speed 2 -row-mt 1 -c:a libopus output.webm
AV1 – libaom-av1 / libsvtav1
AV1 is the next‑generation, royalty‑free codec from the Alliance for Open Media. It typically delivers ~30% better compression than VP9 and ~50% better than H.264[reference:9]. It's the future of web video — already supported in Chrome, Firefox, and Edge.
FFmpeg offers two main AV1 encoders:
- libaom-av1 – the reference encoder. Slow but highest quality.
- libsvtav1 – the Scalable Video Technology encoder from Intel. Much faster, with good quality. Recommended for most use cases.
Basic AV1 encode (libsvtav1)
ffmpeg -i input.mov -c:v libsvtav1 -crf 30 -preset 8 -g 240 -c:a libopus output.mkv
AV1 options
-crf– 0–63. 30 is a good starting point.-preset– for libsvtav1: 0–13 (0 = slowest/best, 13 = fastest). 8 is a good balance.-g– GOP size (keyframe interval). 240 is typical for 24/30fps content.
Lossless & near‑lossless video codecs
Sometimes you need pixel‑perfect quality — for archiving, intermediate masters, or when you'll be doing further processing.
- FFV1 – FFmpeg's own lossless intra‑only video codec[reference:10]. Efficient and well‑supported. Use
-c:v ffv1. - Ut Video – lossless codec family.
utvideo. - H.264 lossless – set
-crf 0with libx264. - H.265 lossless – set
-crf 0with libx265. - ProRes – Apple's intermediate codec.
-c:v prores -profile:v 0(proxy) through 3 (4444). - DNxHD / DNxHR – Avid's intermediate codecs.
-c:v dnxhd.
# FFV1 lossless ffmpeg -i input.mov -c:v ffv1 -level 3 -coder 1 -context 1 output.mkv # ProRes 422 HQ ffmpeg -i input.mov -c:v prores -profile:v 3 -vendor apl0 output.mov # H.264 lossless ffmpeg -i input.mov -c:v libx264 -crf 0 -preset slower output.mp4
Audio codecs
AAC – aac
AAC (Advanced Audio Coding) is the default audio codec for MP4 and the most widely used audio format in video. FFmpeg's native aac encoder is now the recommended choice — its quality is on par with or better than libfdk_aac at 128 kbps[reference:11].
Basic AAC encode
ffmpeg -i input.mov -c:a aac -b:a 128k output.mp4
AAC options
-b:a– target bitrate. 128k is the sweet spot. 96k for web, 192k+ for high quality[reference:12].-q:a– VBR quality. 0–9 (higher = better). Use instead of-b:afor variable bitrate[reference:13].-cutoff– low‑pass filter cutoff frequency. Default is dynamically adjusted[reference:14].-aac_coder– coding method:twoloop(default, best quality),anmr(experimental),fast(fastest)[reference:15].
MP3 – libmp3lame
MP3 is still the most compatible audio format. Use it when you need maximum playback compatibility — old devices, MP3 players, etc. FFmpeg uses the libmp3lame encoder[reference:16].
ffmpeg -i input.mov -c:a libmp3lame -b:a 192k output.mp3
Opus – libopus
Opus is the most modern and efficient audio codec. It's royalty‑free, open, and delivers superior quality at low bitrates. It's the standard for WebM and is widely supported in browsers.
ffmpeg -i input.mov -c:a libopus -b:a 96k output.webm
Lossless audio codecs
- FLAC –
-c:a flac. Free Lossless Audio Codec. Great for archiving. - ALAC –
-c:a alac. Apple Lossless. Good for Apple ecosystem. - WAV / PCM –
-c:a pcm_s16le. Uncompressed, huge files.
Hardware‑accelerated encoders
If you have a modern GPU, you can offload encoding to hardware. This is much faster than software encoding, but quality per bit is usually lower. Use hardware encoding for live streaming, quick previews, or when speed is more important than file size.
| Hardware | H.264 encoder | H.265 encoder | Notes |
|---|---|---|---|
| Intel QSV | h264_qsv | hevc_qsv | Built into Intel GPUs |
| NVIDIA NVENC | h264_nvenc | hevc_nvenc | NVIDIA GPUs |
| AMD AMF | h264_amf | hevc_amf | AMD GPUs |
| VAAPI (Linux) | h264_vaapi | hevc_vaapi | Generic Linux GPU acceleration |
| Apple VideoToolbox | h264_videotoolbox | hevc_videotoolbox | macOS / iOS |
# NVIDIA NVENC H.264 ffmpeg -i input.mov -c:v h264_nvenc -preset p4 -tune hq -cq 23 -c:a aac output.mp4 # Intel QSV H.265 ffmpeg -i input.mov -c:v hevc_qsv -global_quality 24 -c:a aac output.mp4
Codec comparison table
| Codec | FFmpeg encoder | Compression | Speed | Royalty‑free | Best for |
|---|---|---|---|---|---|
| H.264 | libx264 | Good | Fast | No | Universal compatibility |
| H.265 / HEVC | libx265 | Excellent (~50% better than H.264) | Slow | No | 4K, HDR, streaming |
| VP9 | libvpx-vp9 | Excellent | Slow | Yes | Web (WebM) |
| AV1 | libsvtav1 | Best (~50% better than H.264) | Very slow | Yes | Future‑proof web video |
| FFV1 | ffv1 | Lossless | Medium | Yes | Archiving, masters |
| ProRes | prores | Near‑lossless | Fast | Yes | Editing, post‑production |
How to choose the right codec
- For maximum compatibility – H.264 (libx264) + AAC. This plays everywhere.
- For smallest file size at high quality – H.265 (libx265) or AV1 (libsvtav1). AV1 is better but slower.
- For web delivery – H.264 for MP4 fallback, VP9 or AV1 in WebM for modern browsers[reference:17].
- For editing / post‑production – ProRes, DNxHD, or FFV1.
- For live streaming – hardware encoder (NVENC, QSV) for low latency.
- For archiving – FFV1 (video) + FLAC (audio).
Want to combine codec choices with other operations? Check out our guides on compression, format conversion, and filter complex effects.
Ready to put this into practice? FFmpegLab gives you a visual timeline where you can pick your codec, set quality presets, and generate the exact command — all entirely offline.