Configure hevc_nvenc Rate Control and Quality in FFmpeg

This article provides a straightforward guide on how to configure the rate control and quality options for the NVIDIA NVENC HEVC (hevc_nvenc) hardware encoder in FFmpeg. You will learn how to select and configure different rate control modes—such as Constant QP, VBR, and CBR—and how to utilize quality-enhancing settings like presets, lookahead, and adaptive quantization to optimize your video encodes.

Rate Control Modes

Rate control determines how the encoder allocates data (bitrate) across the video frames. The hevc_nvenc encoder supports several rate control modes using the -rc option, combined with target bitrate (-b:v) and quality parameters.

1. Constant QP (CQP)

Constant QP defines a fixed quantization parameter for all frames, ensuring consistent image quality at the expense of unpredictable file sizes. It is ideal for local archiving where disk space is not a primary concern.

ffmpeg -i input.mp4 -c:v hevc_nvenc -rc constqp -qp 23 output.mp4

2. Variable Bitrate (VBR)

VBR allows the bitrate to fluctuate based on the complexity of the scene. It is suitable for streaming and general encoding.

ffmpeg -i input.mp4 -c:v hevc_nvenc -rc vbr -b:v 5M -maxrate 8M -bufsize 10M output.mp4

3. Constrained Quality (CQ / Target Quality VBR)

This mode acts like a VBR mode but prioritizes a specific quality level (defined by the CQ parameter) while respecting a maximum bitrate limit if specified.

ffmpeg -i input.mp4 -c:v hevc_nvenc -rc vbr -cq 22 -b:v 0 output.mp4

4. Constant Bitrate (CBR)

CBR maintains a strict, constant bitrate throughout the entire video. This is essential for live streaming environments with fixed bandwidth constraints.

ffmpeg -i input.mp4 -c:v hevc_nvenc -rc cbr -b:v 4M -maxrate 4M -bufsize 8M output.mp4

Quality and Performance Tuning Options

Beyond rate control, several settings directly impact the compression efficiency and visual quality of the output video.

Presets and Tuning

NVIDIA’s newer SDKs use a preset system ranging from p1 (fastest/lowest quality) to p7 (slowest/highest quality).

ffmpeg -i input.mp4 -c:v hevc_nvenc -preset p6 -tune hq output.mp4

Lookahead and Adaptive Quantization

These features analyze adjacent frames and frame regions to distribute bits more efficiently to areas where human eyes notice quality degradation the most.

ffmpeg -i input.mp4 -c:v hevc_nvenc -rc vbr -b:v 6M -preset p6 -rc-lookahead 20 -spatial-aq 1 -temporal-aq 1 output.mp4