FFmpeg h264_amf Rate Control and Quality Settings
This guide explains how to configure rate control and quality options
for the h264_amf encoder in FFmpeg. The
h264_amf encoder utilizes AMD’s Advanced Media Framework
(AMF) to leverage hardware-accelerated H.264 video encoding on AMD
Radeon graphics cards. Below, you will find the essential parameters,
rate control modes, and command-line examples needed to optimize your
encoding workflow for quality, speed, or file size.
Rate Control Modes
(-rc)
The rate control mode determines how the encoder allocates bitrate
across the video. You can set the rate control mode using the
-rc parameter. The most common modes for
h264_amf include:
cqp(Constant QP): Best for archiving and high-quality local recording. It maintains a constant quantization parameter, ensuring consistent image quality at the expense of unpredictable file sizes.cbr(Constant Bitrate): Best for live streaming. It enforces a strict, constant output bitrate.vbr_peak(Variable Bitrate with Peak): Best for general video distribution. It aims for a target average bitrate but allows spikes up to a defined peak bitrate for complex scenes.vbr_latency(Low Latency VBR): Optimized for real-time communication and low-latency streaming.
Configuring Quality and Bitrate Options
Depending on your chosen rate control mode, you will need to adjust different parameters to control the output quality.
1. Constant Quality (CQP Mode)
To use Constant QP, set -rc to cqp and
define the QP (Quantization Parameter) values for I-frames and P-frames.
QP values range from 0 to 51, where lower values mean higher quality and
larger file sizes (a value of 18–23 is generally recommended for
visually lossless quality).
-qp_i: Sets the QP for I-frames.-qp_p: Sets the QP for P-frames.
Example command:
ffmpeg -i input.mp4 -c:v h264_amf -rc cqp -qp_i 22 -qp_p 22 output.mp42. Constant Bitrate (CBR Mode)
To use CBR, set -rc to cbr and specify your
target bitrate using the -b:v flag.
-b:v: Target bitrate (e.g.,5Mfor 5 Mbps).
Example command:
ffmpeg -i input.mp4 -c:v h264_amf -rc cbr -b:v 5M output.mp43. Variable Bitrate (VBR Peak Mode)
To use VBR with a peak limit, set -rc to
vbr_peak. You must define both the target average bitrate
(-b:v) and the maximum allowed peak bitrate
(-maxrate).
-b:v: Target average bitrate.-maxrate: Maximum peak bitrate.
Example command:
ffmpeg -i input.mp4 -c:v h264_amf -rc vbr_peak -b:v 4M -maxrate 8M output.mp4Performance and
Quality Presets (-quality)
The -quality option allows you to balance encoding speed
against compression efficiency. AMD AMF supports three primary quality
presets:
speed(0): Prioritizes fast encoding speed; suitable for low-end hardware or high-framerate capture.balanced(1): Balances speed and compression quality (default).quality(2): Prioritizes visual quality and compression efficiency; recommended for general encoding.
Example command using the quality preset:
ffmpeg -i input.mp4 -c:v h264_amf -rc vbr_peak -b:v 5M -maxrate 10M -quality quality output.mp4Profile and Level Settings
To ensure compatibility with specific playback devices, you can set the H.264 profile and level:
-profile:v: Set tobaseline,main, orhigh.-level: Set the H.264 level (e.g.,4.1,5.1).
Example command:
ffmpeg -i input.mp4 -c:v h264_amf -profile:v high -level 4.1 output.mp4