FFmpeg - Encode VP9
VP9 is Google’s open, royalty‑free video codec designed to deliver high compression efficiency and excellent visual quality at lower bitrates. When encoding VP9 with FFmpeg’s libvpx-vp9 encoder, two-pass encoding is generally recommended. Some of VP9’s quality‑enhancing features are only available in multi-pass mode, and two-pass encoding allows the encoder to make better bitrate allocation decisions across the entire file.
Why Two-Pass Encoding?
Two-pass encoding provides FFmpeg with full knowledge of the input before performing the final encode. This enables:
- Better quality at a target size
- Access to quality-enhancing algorithms
- More predictable output quality
Constant Quality Mode (CRF)
Unlike constant bitrate encoding, CRF mode prioritises visual quality. To invoke CRF mode in VP9:
- Set -b:v 0
- Select a CRF value (lower = higher quality)
Typical CRF ranges:
| CRF | Quality Level | Typical Use |
|---|---|---|
| 15–25 | High quality | Archival, production masters |
| 28–32 | Good quality | General-purpose encoding, streaming |
| 33–40 | Low bitrate | Mobile, constrained bandwidth |
Two-Pass VP9 Encoding (CRF + Bitrate 0)
Linux / macOS
ffmpeg -i input.file -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 1 -an -f null /dev/null && ffmpeg -i input.file -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 2 -c:a libopus output.webm
Windows
ffmpeg -i input.file -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 1 -an ^
-f null NUL ^
&& ffmpeg -i input.file -c:v libvpx-vp9 -b:v 0 -crf 30 -pass 2 ^
-c:a libopus output.webm
Audio Encoding
Recommended:
-c:a libopus -b:a 96k
Recommended Additional Options
| Option | Meaning |
|---|---|
| -row-mt 1 | Enables row-based multi-threading |
| -tile-columns 2 | Enables parallel decode paths |
| -tile-rows 1 | Further decode parallelism |
| -g 240 | GOP size |
Encoding Time vs Quality
VP9 is CPU-intensive. Raising -speed can reduce encoding time:
- -speed 1 — best quality
- -speed 2 — faster
- -speed 3 — acceptable for many workflows
Troubleshooting
Low CPU Usage
Check:
-row-mt 1 -threads N
Output File Is Very Large
Increase CRF:
-crf 32
Audio Missing After First Pass
Expected. Audio is encoded only in pass 2.