Transcode Video with FFmpeg hevc_amf Encoder
This article provides a straightforward guide on how to transcode
video files using the AMD Advanced Media Framework (AMF) HEVC encoder
(hevc_amf) in FFmpeg. You will learn the basic command
syntax, hardware requirements, and key configuration parameters to
leverage your AMD graphics card for high-speed hardware-accelerated
video encoding.
Prerequisites
To use AMD’s hardware encoder in FFmpeg, you need: * An AMD Radeon graphics card that supports HEVC (H.265) hardware encoding. * Up-to-date AMD graphics drivers installed on your system. * A version of FFmpeg compiled with AMF support (enabled by default in most modern official builds for Windows and Linux).
To verify if your FFmpeg installation supports the encoder, run the following command in your terminal:
ffmpeg -encoders | findstr amf(On Linux/macOS, replace findstr with
grep). You should see hevc_amf listed in
the output.
Basic Transcoding Command
The simplest way to transcode a video using the AMD HEVC hardware
encoder is to specify hevc_amf as the video codec.
ffmpeg -i input.mp4 -c:v hevc_amf -c:a copy output.mp4In this command: * -i input.mp4 specifies the source
video file. * -c:v hevc_amf tells FFmpeg to encode the
video stream using AMD’s HEVC encoder. * -c:a copy copies
the audio stream directly from the source without re-encoding it, saving
CPU power and time.
Advanced Configuration and Quality Tuning
To get the best balance between file size and video quality, you can customize the encoding parameters.
Controlling Bitrate and Rate Control Mode
AMF supports several rate control modes via the -rc
flag. The most common modes are Constant QP (cqp), Constant
Bitrate (cbr), and Variable Bitrate
(vbr_latency or vbr_peak).
Constant Quality (CQP) Mode: CQP is recommended for archival purposes where quality is the priority. Lower values produce higher quality and larger files.
ffmpeg -i input.mp4 -c:v hevc_amf -rc cqp -qp_i 22 -qp_p 22 output.mp4-qp_isets the QP value for I-frames.-qp_psets the QP value for P-frames. A value between 18 and 28 is generally optimal.
Variable Bitrate (VBR) Mode: VBR is ideal for streaming or target file sizes.
ffmpeg -i input.mp4 -c:v hevc_amf -rc vbr_latency -b:v 5M -maxrate 8M output.mp4-b:v 5Msets the target average video bitrate to 5 Mbps.-maxrate 8Mcaps the maximum bitrate spike at 8 Mbps.
Adjusting the Quality Preset
You can instruct the encoder to prioritize either encoding speed or
visual quality using the -quality parameter. *
speed: Maximizes transcoding speed (ideal for live
streaming). * balanced: The default setting balancing
speed and quality. * quality: Prioritizes visual
fidelity at the cost of processing speed.
ffmpeg -i input.mp4 -c:v hevc_amf -quality quality output.mp4By combining these parameters, you can efficiently offload the heavy lifting of video transcoding to your AMD GPU, achieving rapid render times with minimal CPU usage.