wiki:Hardware/AMF

1 Introduction

The Advanced Media Framework (AMF) SDK provides developers with easy access to AMD GPUs for multimedia processing.

AMF is effectively supported by FFmpeg to significantly speed up video encoding, decoding, and transcoding via AMD GPUs.

The following user guide shows how to use the FFmpeg command line to efficiently use the AMD hardware acceleration for video decoding, encoding, and transcoding.

2 Hardware Decode

AMF supports hardware decoding via DirectX in FFmpeg. Currently AMF supports DX9 and DX11 in FFmpeg.

Hardware decoding via DX9

ffmpeg -hwaccel dxva2 -i input.mkv output.yuv

Note: Currently AMD hardware doesn’t support AV1 elementary stream decoding via DX9. So, this command line is not applicable for AV1 bitstream as input.

Hardware decoding via DX11

ffmpeg -hwaccel d3d11va -i input.mkv output.yuv

In the above command line, “input.mkv” is only an example. The AMD hardware accelerated decoder supports most widely used containers and video elementary stream types. The following table lists detailed information about the widely used containers and video elementary streams which the AMD hardware accelerated decoder supports.

Table 1: Containers and video elementary streams supported by the AMD hardware accelerated decoder

Format Filename Extension H.264/AVC H.265/HEVC AV1
Matroska .mkv Y Y Y
MPEG-4 Part 14 (MP4) .mp4 Y Y Y
Audio Video Interleave (AVI) .avi Y N Y
Material Exchange Format (MXF) .mxf Y n/a n/a
MPEG transport stream (TS) .ts Y Y N
3GPP (3GP) .3gp Y n/a n/a
Flash Video (FLV) .flv Y n/a n/a
WebM .webm n/a n/a Y
Advanced Systems Format (ASF) .asf .wmv Y Y Y
QuickTime File Format (QTFF) .mov Y Y n/a
  • 'Y': Hardware accelerated decoder supports this input
  • 'N': Hardware accelerated decoder doesn’t support this input
  • 'n/a': This input is not applicable in specification

3 Hardware Encode

Currently AMF encoder supports H.264/AVC, H.265/HEVC, AV1 encoder. FFmpeg uses _amf as the postfix for the AMF encoder names. The command lines shown below may use h264_amf, and should be replaced by hevc_amf for H.265/HEVC encoder and av1_amf for AV1 encoder.

ffmpeg -s 1920x1080 -pix_fmt yuv420p -i input.yuv -c:v h264_amf output.mp4

ffmpeg -s 1920x1080 -pix_fmt yuv420p -i input.yuv -c:v hevc_amf output.mp4

ffmpeg -s 1920x1080 -pix_fmt yuv420p -i input.yuv -c:v av1_amf output.mp4

In the above command line, “output.mp4” is only an example. The AMD hardware accelerated encoder supports most widely used container and video elementary stream types. The following table lists the detail information about the widely used containers and video elementary streams which the AMD hardware accelerated encoder supports.

Table 2: Containers and video elementary streams supported by the AMD hardware accelerated encoder

Format Filename Extension H.264/AVC H.265/HEVC AV1
Matroska .mkv Y Y Y
MPEG-4 Part 14 (MP4) .mp4 Y Y Y
Audio Video Interleave (AVI) .avi Y Y Y
Material Exchange Format (MXF) .mxf Y n/a n/a
MPEG transport stream (TS) .ts Y Y Y
3GPP (3GP) .3gp Y n/a n/a
Flash Video (FLV) .flv Y n/a n/a
WebM .webm n/a n/a Y
Advanced Systems Format (ASF) .asf .wmv Y Y Y
QuickTime File Format (QTFF) .mov Y Y n/a
  • 'Y': Hardware accelerated encoder supports this output
  • 'n/a': This output is not applicable in specification

4 Transcode

There are two possible methods for transcoding: hardware decoding and hardware encoding, or software decoding and hardware encoding.

4.1 Hardware Decode and Hardware Encode

Use DX9 hardware decoder

ffmpeg -hwaccel dxva2 -hwaccel_output_format dxva2_vld -i input.mkv -c:v av1_amf output.mp4

Note: Currently AMD hardware doesn’t support AV1 elementary stream decoding via DX9. So, this command line is not applicable for AV1 bitstream as input.

Use DX11 hardware decoder

ffmpeg -hwaccel d3d11va -hwaccel_output_format d3d11 -i input.mkv -c:v hevc_amf output.mp4

The parameter hwaccel_output_format will specify the raw data (YUV) format after decoding.

To avoid raw data copy between GPU memory and system memory, use -hwaccel_output_format dxva2_vld when using DX9 and use -hwaccel_output_format d3d11 when using DX11. This will improve transcoding speed greatly. This is the best setting we recommend for transcoding.

When using AV1 as the source elementary stream type, with hardware acceleration, additional support for hardware surfaces is required in the transcoding case. This is achieved by adding the extra_hw_frames parameter.

ffmpeg -hwaccel dxva2 -hwaccel_output_format dxva2_vld -extra_hw_frames 10 -i input_av1_source.mkv -c:v av1_amf output.mp4
ffmpeg -hwaccel d3d11va -hwaccel_output_format d3d11 -extra_hw_frames 10 -i input_av1_source.mkv -c:v hevc_amf output.mp4

4.2 Software Decode and Hardware Encode

Use the CPU to decode the input bitstream, and the GPU to encode the output stream.

ffmpeg -i input.mkv -c:v av1_amf output.mp4

The default software decoder corresponding to the elementary video stream will be used as the decoder.

4.3 Transcode with Scaling

Scaling is a very common operation in transcoding. It is done through video filter in FFmpeg.

1. Hardware decode and hardware encode with scaling

ffmpeg -hwaccel dxva2 -i input.mkv  -vf scale=1280x720 -c:v h264_amf output.mp4

ffmpeg -hwaccel d3d11va -i input.mkv  -vf scale=1280x720 -c:v h264_amf output.mp4

If filter parameters are used in transcoding, users can’t set hwaccel_output_format parameters. In fact, the filter processing is finished in the CPU in the above example.

Note: Currently AMD hardware doesn’t support AV1 elementary stream decoding via DX9. So, this command line with parameter “-hwaccel dxva2” is not applicable for AV1 bitstream as input.

2. Software decode and hardware encode with scaling

In the following command line, both decoding and scaling are done via the CPU, and encoding is done via the GPU.

ffmpeg -i input.mkv -vf scale=1280x720 -c:v h264_amf output.mp4

5. Benchmark Testing and Profiling

When the encoder and decoder work on a specific device, their performances are determined by several factors, such as CPU performance, GPU performance, memory performance, and disk read/write speed. The following command lines are used for benchmark testing. By avoiding writing raw data to the disk, users can test the performance of encoders and decoders more accurately.

To run the decoding benchmark, use the following command:

ffmpeg -hwaccel dxva2 -hwaccel_output_format dxva2_vld -i input.mkv -f null - -benchmark

ffmpeg -hwaccel d3d11va -hwaccel_output_format d3d11 -i input.mkv -f null - -benchmark

To run the encoding benchmark, use the following command:

ffmpeg -s 1920x1080 -pix_fmt yuv420p -i input.yuv -c:v av1_amf output.mp4 -benchmark

To run the transcoding benchmark, use the following command:

ffmpeg -hwaccel d3d11va -hwaccel_output_format d3d11 -i input.mkv -c:v hevc_amf output.mp4 -benchmark
Last modified 8 months ago Last modified on Apr 1, 2024, 1:49:14 PM
Note: See TracWiki for help on using the wiki.