How to Use AMD AMF for HEVC Encoding in FFmpeg

This article provides a straightforward guide on how to leverage AMD’s Advanced Media Framework (AMF) for hardware-accelerated HEVC (H.265) video encoding using FFmpeg. You will learn how to verify your system compatibility, run basic encoding commands, and fine-tune encoding parameters such as bitrate, rate control, and quality presets to achieve optimal performance on AMD Radeon graphics cards.

Prerequisites and Verification

To use AMD AMF hardware acceleration, you must have a compatible AMD graphics card (Radeon HD 7000 series or newer) with the latest AMD drivers installed. Additionally, your FFmpeg build must be compiled with AMF support.

To verify if your FFmpeg installation supports the AMD AMF HEVC encoder, run the following command in your terminal:

ffmpeg -encoders | grep amf

Look for hevc_amf (or h265_amf) in the output list. If it is present, your FFmpeg build is ready for AMD hardware-accelerated HEVC encoding.

Basic HEVC AMF Encoding Command

The simplest way to encode a video to HEVC using AMD AMF is to specify the hevc_amf video encoder. Run the following command:

ffmpeg -i input.mp4 -c:v hevc_amf output.mp4

This command takes input.mp4, decodes it, and encodes the video stream using the AMD AMF HEVC encoder with default settings, while copying or re-encoding the audio depending on your default FFmpeg configuration.

Adjusting Quality and Bitrate

To control the file size and visual quality of your output, you can customize the bitrate and rate control modes.

Constant Bitrate (CBR)

For streaming or scenarios requiring a strict bandwidth limit, use Constant Bitrate by setting the rate control mode to cbr and specifying a target bitrate:

ffmpeg -i input.mp4 -c:v hevc_amf -rc cbr -b:v 5M output.mp4

Variable Bitrate (VBR)

For general storage and playback, Peak Constrained Variable Bitrate is recommended to balance quality and file size:

ffmpeg -i input.mp4 -c:v hevc_amf -rc vbr_latency -b:v 5M -maxrate:v 8M output.mp4

Constant Quantization Parameter (CQP)

For maximum quality control without targeting a specific file size, use CQP mode. Lower values yield higher quality and larger file sizes:

ffmpeg -i input.mp4 -c:v hevc_amf -rc cqp -qp_i 22 -qp_p 22 output.mp4

Tuning Performance and Quality Presets

AMD AMF offers a -quality parameter to balance encoding speed against visual compression efficiency. The available presets are: * speed: Prioritizes fast encoding throughput. * balanced: The default option, offering a mix of speed and quality. * quality: Prioritizes visual fidelity at the expense of encoding speed.

Example of encoding a high-quality HEVC file using the quality preset:

ffmpeg -i input.mp4 -c:v hevc_amf -quality quality -rc vbr_latency -b:v 6M output.mp4