Two-Pass Encoding in FFmpeg
Pick the target size, turn it into a bitrate, then run two passes. Example: a 10-minute video that must fit in 100 MB: 100 × 8,000 ÷ 600 s ≈ 1,333 kbps in total; minus 128 kbps of audio leaves about 1,200 kbps for video.
ffmpeg -y -i input.mkv -c:v libx264 -preset medium -b:v 1200k -pass 1 -an -f null /dev/null— pass 1 (analysis only). On Windows, writeNULinstead of/dev/null.ffmpeg -i input.mkv -c:v libx264 -preset medium -b:v 1200k -pass 2 -c:a aac -b:a 128k output.mp4— pass 2 (the real encode).
Both passes must use the same video settings. FFmpeg writes the analysis to ffmpeg2pass-0.log in the current folder; pass 2 reads it, and you can delete it afterwards.
The Fundamental Difference
CRF and two-pass encoding solve the same problem — balancing quality against file size — but from opposite directions:
- CRF (Constant Rate Factor): "I want this quality level. Give me whatever file size is needed to achieve it." You control quality; file size is the variable.
- Two-pass: "I want this file size (target bitrate). Give me the best quality that fits." You control file size; quality is the variable.
| Feature | CRF | Two-Pass |
|---|---|---|
| You control | Quality level (CRF number) | Target bitrate / file size |
| Variable | File size | Quality |
| Passes | 1 (single pass) | 2 (analyze + encode) |
| Speed | 1x (baseline) | ~2x slower |
| File size prediction | Unpredictable | Predictable |
| Quality consistency | Constant quality per frame | Optimal bit distribution |
How CRF Works
CRF encoding is a single-pass process. The encoder processes each frame and asks: "How many bits do I need to achieve this quality level for this specific frame?"
- High-complexity frames (explosions, fast motion) receive more bits
- Low-complexity frames (static shots, title cards) receive fewer bits
- The quality stays constant; the bitrate fluctuates
The result is a variable bitrate (VBR) file where every frame gets exactly the bits it needs — no waste on simple scenes, no starvation on complex ones. This is why CRF produces the optimal quality-to-size ratio for offline encoding.
How Two-Pass Works
Two-pass encoding processes the video twice:
- Pass 1 (Analysis): The encoder scans the entire video without producing output. It builds a frame-by-frame complexity map — which scenes are simple, which are complex, where scene changes occur.
- Pass 2 (Encoding): Using the analysis from pass 1, the encoder distributes the target bitrate optimally across all frames. Complex scenes get more of the bitrate budget; simple scenes get less.
The result: a file that precisely hits the target bitrate while distributing quality as evenly as possible across all scenes.
Quality Comparison
At sensible settings, CRF and two-pass produce nearly identical quality. The differences are subtle:
- CRF advantage: Every frame gets exactly the bits it needs. No frame is ever starved. CRF may produce slightly better average quality because it's not constrained by a bitrate budget.
- Two-pass advantage: Better bit distribution for extreme content (long videos with wildly varying complexity). The analysis pass helps the encoder prepare for upcoming complex scenes.
In practice, the quality difference between CRF and a well-targeted two-pass encode is negligible for most content. You would need frame-by-frame VMAF analysis to detect differences.
Speed Comparison
The speed difference is straightforward:
- CRF: 1x encoding time (single pass through the video)
- Two-pass: ~1.7–2x encoding time (first pass is fast since it doesn't produce output, but still takes time)
For a 10-minute 1080p video on a modern CPU:
- CRF medium: about 10 minutes at ~30 fps encoding speed (18,000 frames ÷ 30 fps = 600 s)
- Two-pass medium: about 17–20 minutes, since the first pass runs faster than the second. A faster preset shortens both passes; our FFmpeg presets guide to speed vs file size shows the trade-off.
When to Use CRF
CRF is the better choice for almost all common scenarios:
- File conversion: MKV to MP4, MOV to MP4, any format conversion where you want the best quality
- Personal archival: Storing your video library at consistent quality
- Web upload: YouTube, social media, and most platforms accept variable bitrate files
- Sharing: When file size doesn't need to be exact, CRF gives optimal quality
- Batch processing: One setting (CRF 23) works well for all content types
This is why our converter uses CRF — it produces the best quality without requiring users to calculate target bitrates.
When to Use Two-Pass
Two-pass encoding is the better choice when file size must be predictable:
- DVD/Blu-ray authoring: Content must fit on a specific disc capacity
- Bandwidth-constrained streaming: Adaptive bitrate streaming (HLS/DASH) requires precise bitrate targets for each quality level
- File size limits: Platforms with strict upload limits (Discord 10 MB without Nitro, email 25 MB) where you need to guarantee the output fits
- Professional broadcast: Broadcast pipelines often require CBR or precise VBR targets
The Best of Both: Capped CRF
There is a hybrid approach called capped CRF (constrained quality) that combines the advantages of both methods:
ffmpeg -i input.mkv -c:v libx264 -crf 23 -maxrate 4000k -bufsize 8000k -c:a aac output.mp4
This tells the encoder: "Target CRF 23 quality, but stay at or under about 4 Mbps (averaged over the 8,000-kbit buffer, about 2 seconds)." In practice:
- Simple scenes: encoded at CRF 23 quality (well below 4 Mbps)
- Complex scenes: encoded at CRF 23 quality unless it would exceed 4 Mbps, in which case quality is slightly reduced to stay within the cap
Capped CRF is ideal for streaming applications where you need bandwidth predictability without sacrificing CRF's quality-first approach.
VBR 1-Pass vs 2-Pass in Premiere Pro, Media Encoder and HandBrake
- Premiere Pro and Adobe Media Encoder: in the H.264 export settings, Bitrate Encoding offers CBR, VBR 1 pass and VBR 2 pass. VBR 2 pass takes longer and usually distributes bits better at the same target.
- HandBrake: on the Video tab, switch from Constant Quality to Avg Bitrate, then turn on two-pass (labelled 2-Pass or Multi-Pass Encoding, depending on the version).
- Rule of thumb: at generous bitrates 1-pass and 2-pass look the same; the second pass pays off when the bitrate is tight for the content.