How to Use AMD AMF for H.264 Encoding in FFmpeg

This guide provides a straightforward walkthrough on leveraging AMD's Advanced Media Framework (AMF) to achieve hardware-accelerated H.264 video encoding in FFmpeg. You will learn the prerequisites needed for AMF, how to verify your FFmpeg build supports it, the fundamental command structure, and the most effective parameters for controlling video quality and bitrate.

Prerequisites

To use AMD AMF encoding in FFmpeg, you need:

  1. A compatible AMD GPU (Radeon HD 7000 series or newer).
  2. Up-to-date AMD graphics drivers installed on your system.
  3. An FFmpeg build compiled with AMF support (--enable-amf). Pre-built binaries from sources like Gyan.dev (Windows) typically include AMF support by default.

Verify AMF Support in FFmpeg

Before encoding, verify that your FFmpeg installation includes the AMD H.264 encoder. Run the following command in your terminal or command prompt:

ffmpeg -encoders | findstr amf

(On Linux/macOS, replace findstr with grep)

Look for h264_amf in the output. If it appears, your installation is ready.

Basic Encoding Command

The basic syntax replaces the default software encoder (libx264) with h264_amf:

ffmpeg -i input.mp4 -c:v h264_amf -c:a copy output.mp4

Essential AMF Configuration Parameters

To control performance and output quality, customize the following key parameters:

  • -quality: Sets the encoding preset. Options include:
    • speed: Fast encoding, lower compression efficiency.
    • balanced: Default trade-off between performance and quality.
    • quality: Highest visual fidelity, slightly slower encoding.
  • -rc: Sets the rate control method.
    • cbr: Constant Bitrate.
    • vbr_peak: Variable Bitrate with peak constraint.
    • cqp: Constant Quantization Parameter (fixed quality mode).
  • -b:v: Sets the target video bitrate (e.g., 5M for 5 Mbps).
  • -profile:v: Specifies the H.264 profile (baseline, main, high).
  • -usage: Sets the encoder usage scenario (transcoding, lowlatency, ultralowlatency, webcam).

Common Usage Examples

1. Constant Bitrate (CBR) for Streaming

Best for scenarios requiring predictable bandwidth, such as live broadcasting.

ffmpeg -i input.mp4 -c:v h264_amf -usage transcoding -quality quality -rc cbr -b:v 6M -c:a aac output.mp4

2. Variable Bitrate (VBR) for General Transcoding

Best for balancing file size and quality during standard file conversion.

ffmpeg -i input.mp4 -c:v h264_amf -quality quality -rc vbr_peak -b:v 5M -maxrate 8M -c:a copy output.mp4

3. Constant Quality (CQP)

Best for archival purposes where target visual quality matters more than final file size. Lower values result in higher quality (typical range is 18–28).

ffmpeg -i input.mp4 -c:v h264_amf -rc cqp -qp_i 20 -qp_p 22 -c:a copy output.mp4