Key takeaways
- Two-pass encoding encodes a video twice. Pass 1 analyses scene complexity, and pass 2 uses that analysis to spend a fixed bitrate budget where it matters most.
- Use it when you must hit a target file size or average bitrate with the best possible quality. Use CRF (constant rate factor) when consistent quality matters more than file size.
- It takes longer than single-pass encoding and needs the whole file, so it does not suit live streaming.
- FFmpeg runs two-pass encoding with the -pass 1 and -pass 2 options.
What Is Two-Pass Encoding?
Two-pass encoding is a video encoding method that processes the source twice. The first pass analyses how complex each scene is and writes a statistics log. The second pass reads that log and distributes a fixed bitrate budget, giving more bits to complex scenes and fewer to simple ones.
During the first pass, the encoder analyzes the video and records information about the amount of data needed to encode each frame. This data is then used during the second pass to optimize the encoding process, that is, to determine the appropriate bitrate for each frame while minimizing quality loss.
How Does Two-Pass Encoding Work?
- Set a target. Choose an average bitrate, or choose a file size and convert it to a bitrate by dividing the target size by the duration.
- Run pass 1. The encoder analyses the video and writes a stats file. The video output of this pass is discarded.
- Run pass 2. The encoder uses the stats file to allocate bits across the timeline and writes the final video.
- Verify. Check the output size and quality, for example with VMAF or a visual review of high-motion scenes.
In the first pass, the encoder scans through the entire video, gathering statistics about its complexity and content. This pass does not produce the final output but creates a log file that captures characteristics such as scene changes, motion, and color information.
During the second pass, this pre-gathered data is used to allocate bits to preserve quality where it matters most while conserving data space in less complex scenes. This allows for better distribution of the available bitrate over the entire video, ensuring that complex scenes get the attention they need, while simpler ones do not use up more data than necessary.
Why Is Two-Pass Encoding Important?
Two-pass encoding is essential for optimizing the size and quality of video files. Video encoding often involves using a constant bitrate throughout the encoding process. However, this can result in poor quality output due to higher compression for high complexity areas and, conversely, less compression for lower complexity areas. The two-pass technique helps apply the best possible bitrate to each frame, optimizing compression efficiency and reducing file size while preserving video quality.
Two-pass vs CRF vs CBR: which rate control mode should you use?
| Mode | What it controls | Passes | File size | Best for |
|---|---|---|---|---|
| Two-pass (average bitrate) | Average bitrate across the file | 2 | Predictable | Hitting a size or bandwidth target with the best quality |
| CRF (constant quality) | Visual quality | 1 | Varies with content | Web video where quality matters more than size |
| CBR (constant bitrate) | Bitrate at every moment | 1 | Predictable | Live streams and fixed-capacity links |
What does a two-pass command look like in FFmpeg?
The example targets 2,500 kbps H.264 video with 128 kbps AAC audio. On Windows, replace /dev/null with NUL.
ffmpeg -y -i input.mp4 -c:v libx264 -b:v 2500k -pass 1 -an -f null /dev/null
ffmpeg -i input.mp4 -c:v libx264 -b:v 2500k -pass 2 -c:a aac -b:a 128k output.mp4
Which encoders support two-pass encoding?
| Encoder | Codec | Two-pass support | Note |
|---|---|---|---|
| x264 | H.264 / AVC | Yes, -pass 1 and -pass 2 | The most widely compatible output |
| x265 | HEVC / H.265 | Yes | Lower bitrate for the same quality, narrower device support |
| libvpx-vp9 | VP9 | Yes, and recommended for quality | Google recommends two-pass for VP9 VOD |
| libaom-av1 | AV1 | Yes | Slowest to encode, best compression |
| Hardware encoders (NVENC, QuickVideo, VideoToolbox) | Various | Limited or none | Speed-first, so rate control options are reduced |
Benefits of two-pass encoding
Adopting two-pass encoding in your video processing workflow can significantly uplift the final output’s quality while efficiently using your encoding resources.
- Optimized video quality. By analyzing the video in the first pass, this method allows for a more informed bitrate distribution during the second pass, ensuring that visually complex scenes retain higher quality.
- Efficient bitrate usage. It prevents wastage of data on simpler scenes, conserving bandwidth and storage while maintaining overall visual fidelity.
- Adaptability. Two-pass encoding can be tailored to fit different bandwidth and storage scenarios, offering flexibility to content distributors across various platforms.
- Accurate targets. It hits a target bitrate or file size far more accurately than a single-pass average bitrate encode.
- Viewer satisfaction. The end result is a smoother streaming experience, with less buffering and higher quality visuals.
Drawbacks of two-pass encoding
- Time consumption. Since the process scans the video twice, it inherently takes longer, potentially slowing down workflows.
- Resource intensity. It requires more computational power than single-pass encoding, which matters when dealing with large volumes or limited processing capacity.
- Complexity in live streaming. It needs the complete source file, so live video cannot use it.
- Potential overhead. The first pass generates additional data that needs to be managed, which can introduce complexity and temporary storage needs.
- Redundant when quality is the only goal. If you only need consistent quality, CRF achieves it in one pass without a bitrate target.
Is Two-Pass Encoding Worth It?
Deciding whether two-pass encoding is the right choice for your project hinges on several factors, primarily revolving around your priorities regarding quality, resource availability, and time constraints. At its core, two-pass encoding is designed to elevate video quality without disproportionately increasing file size or consuming additional bandwidth. This makes it particularly appealing for content where every pixel counts, such as feature films or high-quality online video content.
However, it’s also crucial to weigh these advantages against the practical considerations of your project. The increased encoding time and the higher computational demands mean that two-pass encoding might not fit all workflows—especially those needing rapid turnaround times or operating under limited computing resources. Live streaming, for example, presents unique challenges that may not align well with the two-step process of two-pass encoding.
Ultimately, the decision boils down to balancing desired output quality and available resources. If achieving the highest quality video is a priority and the project budget allows for the extra encoding time and computational expense, then two-pass encoding is undoubtedly worth considering. On the other hand, exploring efficient single-pass solutions or alternative encoding strategies might be the way to go for projects with tighter time frames or limited processing capabilities.
How does two-pass encoding help adaptive streaming?
Apple’s HLS authoring specification requires that, for video on demand, the average segment bit rate stays within 10% of the declared AVERAGE-BANDWIDTH value, and says the peak bit rate should be no more than 200% of the average. Two-pass encoding with a bitrate cap makes both limits easier to meet for each rung of a bitrate ladder.
Is two-pass encoding worth it?
Deciding whether two-pass encoding is the right choice hinges on your priorities regarding quality, resource availability, and time. At its core, two-pass encoding is designed to elevate video quality without disproportionately increasing file size or consuming additional bandwidth. This makes it particularly appealing for content where every pixel counts, such as feature films or high-quality online video.
The increased encoding time and higher computational demands mean it might not fit all workflows, especially those needing rapid turnaround or operating under limited computing resources. Live streaming presents unique challenges that do not align with a two-step process. Ultimately, the decision balances desired output quality against available resources. If the highest quality video is a priority and the project allows for the extra encoding time two-pass encoding is worth considering. For tighter time frames or limited processing capability, efficient single-pass solutions may be the better route.
When should you skip two-pass encoding?
- Live or low-latency streams, because the full file does not exist yet.
- Quality-first workflows where CRF is simpler.
- Short clips where file size accuracy does not matter.
- Some hardware encoders that do not offer a two-pass mode.
Common mistakes with two-pass encoding
- Changing encoder settings between passes. The stats file from pass 1 only matches the settings that produced it. Alter the preset or resolution and the allocation is wrong.
- Leaving the pass 1 log behind. Stale .log files from an earlier encode get reused silently and produce odd bitrate distribution.
- Encoding audio in pass 1. It is discarded, so -an in the first pass saves time for nothing lost.
- Using two-pass with no bitrate target. Without a target there is nothing to allocate, and CRF is the right tool.
- Setting a target below what the content needs. Two passes distribute a budget well, but they cannot invent bits that were never allowed.
Do you need to run two-pass encoding yourself in Cloudinary?
No. When you upload a video to Cloudinary you do not manage encoder passes. Add q_auto and f_auto to a delivery URL so Cloudinary chooses quality and format for each request, and use sp_auto to deliver adaptive HLS or DASH streams. See the Cloudinary video optimization documentation for current guidelines.
https://res.cloudinary.com/<cloud_name>/video/upload/q_auto/f_auto/<public_id>
The encoded renditions are then served over multi-CDN delivery, so viewers reach a nearby edge, and protected content can be restricted with signed URLs carrying an expiry and with token-based access. Assets are encrypted with AES-256 at rest and TLS in transit.
Frequently asked questions
Is two-pass encoding better than CRF?
Neither wins in every case. Two-pass gives a predictable file size and average bitrate. CRF gives consistent visual quality in one pass. FFmpeg’s H.264 guide describes two-pass as the method for targeting a specific output file size.
Is two-pass encoding worth it?
It is worth it when you must meet a size or bandwidth target and want the best quality inside it. It is not worth it for live video or when CRF already meets your quality goal.
Can you use two-pass encoding for live streaming?
No. Two-pass encoding analyses the complete file before the final encode, and a live stream has no complete file. Live workflows use single-pass modes such as CBR or constrained VBR.
Which encoders support two-pass encoding?
In FFmpeg, x264, x265, libvpx-vp9 and libaom-av1 all offer two-pass modes. Option names differ by encoder, and most hardware encoders offer limited rate control.
How much longer does two-pass encoding take?
It takes longer than a single pass, and the added time depends on the encoder preset, resolution and video length. Test on a short sample before encoding a full library.
