Configure HEVC AMF Rate Control and Quality in FFmpeg
This article provides a practical guide on how to configure the rate
control and quality settings for the AMD Advanced Media Framework (AMF)
HEVC encoder (hevc_amf) in FFmpeg. You will learn about the
available rate control modes, quality presets, and specific command-line
arguments required to optimize your hardware-accelerated video encodes
for streaming, archiving, or recording.
Rate Control Modes in hevc_amf
Rate control determines how the encoder allocates bitrate across the
video frames. The hevc_amf encoder supports several rate
control modes via the -rc parameter.
1. Constant QP (CQP)
Constant QP mode encodes every frame using a fixed quantization parameter. This mode prioritizes image quality over file size and is ideal for local recording and archiving. Lower QP values result in higher quality and larger file sizes.
Command Example:
ffmpeg -i input.mp4 -c:v hevc_amf -rc cqp -qp_i 22 -qp_p 22 output.mp4Key Parameters:
-qp_i: Sets the QP for I-frames (keyframes).-qp_p: Sets the QP for P-frames.
2. Constant Bitrate (CBR)
CBR maintains a strict, consistent bitrate throughout the video. This is best suited for live streaming environments where bandwidth is limited and predictable data flow is required.
Command Example:
ffmpeg -i input.mp4 -c:v hevc_amf -rc cbr -b:v 5M output.mp4Key Parameters:
-b:v: Sets the target video bitrate (e.g.,5Mfor 5 Mbps).
3. Variable Bitrate (VBR Peak)
VBR adjusts the bitrate depending on the complexity of the scene, while ensuring the bitrate does not exceed a specified peak limit. This is highly efficient for general video playback and local storage.
Command Example:
ffmpeg -i input.mp4 -c:v hevc_amf -rc vbr_peak -b:v 5M -maxrate 8M output.mp4Key Parameters:
-b:v: Target average bitrate.-maxrate: The maximum peak bitrate allowed for complex scenes.
Quality Presets and Optimization
To balance encoding speed and output quality, hevc_amf
offers a direct quality preset option alongside other tuning
parameters.
The -quality Parameter
You can set the overall encoding quality preference using the
-quality option. This adjusts internal encoder settings to
favor either execution speed or compression efficiency.
speed: Prioritizes fast encoding and low latency; ideal for live streaming or older hardware.balanced: The default setting, providing a compromise between speed and compression quality.quality: Prioritizes visual fidelity and compression efficiency; ideal for archiving.
ffmpeg -i input.mp4 -c:v hevc_amf -quality quality output.mp4Additional Quality Adjustments
For further optimization, you can combine rate control and quality presets with the following parameters:
- GOP Size (
-g): Sets the keyframe interval. For streaming, a GOP size equal to double the framerate (e.g.,-g 120for a 60 fps video) is recommended. - Profile (
-profile:v): Sets the HEVC profile. Usemainfor standard 8-bit video, ormain10for 10-bit HDR content (if supported by your AMD GPU).
Comprehensive High-Quality Example
This command uses VBR with the highest quality preset, a defined keyframe interval, and a 10-bit color profile:
ffmpeg -i input.mp4 -c:v hevc_amf -rc vbr_peak -b:v 6M -maxrate 10M -quality quality -profile:v main10 -g 120 output.mp4