Librav1e AV1 Encoder Rate Control Modes
This article provides an overview of the specific rate control methods supported by the librav1e AV1 video encoder. It explains how each mode manages video quality and file size, detailing Constant Quantizer (CQ), Target Bitrate, and multi-pass encoding configurations so you can select the optimal rate control strategy for your video compression pipeline.
Librav1e is a modern, fast AV1 encoder written in Rust. To balance output quality, file size, and encoding speed, it offers two primary native rate control methods, which can be deployed in either single-pass or multi-pass configurations.
1. Constant Quantizer (CQ) / Constant Quality
The Constant Quantizer mode is the default and most efficient one-pass encoding method in librav1e. Instead of targeting a specific file size or bitrate, it maintains a consistent level of visual quality throughout the video.
- How it works: You set a fixed quantizer value. The encoder applies this value to determine how much detail to discard. Frame sizes will vary wildly depending on the complexity of the scene (e.g., high-motion action scenes will use more data, while static scenes will use very little).
- Parameters: Controlled using the
--quantizer(or-q) flag. The scale ranges from0to255, where lower values yield higher quality (and larger files) and higher values yield lower quality (and smaller files). - Best use case: Video archiving, offline encoding, and any scenario where consistent visual quality is preferred over strict file size limitations.
2. Target Bitrate (Variable Bitrate / VBR)
When you have strict storage limitations or bandwidth constraints, the Target Bitrate mode forces librav1e to aim for a specific average bitrate.
- How it works: The encoder dynamically adjusts the quantization parameter (QP) on a frame-by-frame basis to keep the average bitrate close to your specified target.
- Parameters: Controlled using the
--bitrate(or-b) flag, specified in kilobits per second (kbps). - Best use case: Video streaming, video conferencing, or creating files that must fit within exact storage limits.
3. One-Pass vs. Two-Pass Encoding
Both rate control methods can be optimized depending on how many passes the encoder makes over the video file:
- One-Pass Encoding: The encoder analyzes and compresses the video in a single run. This is fast and ideal for real-time applications, but it offers less precision for the Target Bitrate mode because the encoder cannot predict future scene complexity.
- Two-Pass Encoding: In the first pass, librav1e
analyzes the video to map out scene complexity and writes this data to a
stats file (using the
--pass 1and--statsflags). In the second pass (--pass 2), it uses this data to allocate bitrate highly efficiently—saving bits on static scenes and distributing them to complex, high-motion scenes. This is highly recommended when using Target Bitrate to achieve the best possible quality-to-size ratio.