-
Notifications
You must be signed in to change notification settings - Fork 151
FFmpeg and AMF HW Acceleration
The information presented in this document is for informational purposes only and may contain technical inaccuracies, omissions, and typographical errors. The information contained herein is subject to change and may be rendered inaccurate for many reasons, including but not limited to product and roadmap changes, component and motherboard version changes, new model and/or product releases, product differences between differing manufacturers, software changes, BIOS flashes, firmware upgrades, or the like. Any computer system has risks of security vulnerabilities that cannot be completely prevented or mitigated. AMD assumes no obligation to update or otherwise correct or revise this information. However, AMD reserves the right to revise this information and to make changes from time to time to the content hereof without obligation of AMD to notify any person of such revisions or changes. THIS INFORMATION IS PROVIDED ‘AS IS.” AMD MAKES NO REPRESENTATIONS OR WARRANTIES WITH RESPECT TO THE CONTENTS HEREOF AND ASSUMES NO RESPONSIBILITY FOR ANY INACCURACIES, ERRORS, OR OMISSIONS THAT MAY APPEAR IN THIS INFORMATION. AMD SPECIFICALLY DISCLAIMS ANY IMPLIED WARRANTIES OF NON-INFRINGEMENT, MERCHANTABILITY, OR FITNESS FOR ANY PARTICULAR PURPOSE. IN NO EVENT WILL AMD BE LIABLE TO ANY PERSON FOR ANY RELIANCE, DIRECT, INDIRECT, SPECIAL, OR OTHER CONSEQUENTIAL DAMAGES ARISING FROM THE USE OF ANY INFORMATION CONTAINED HEREIN, EVEN IF AMD IS EXPRESSLY ADVISED OF THE POSSIBILITY OF SUCH DAMAGES.
AMD, the AMD Arrow logo, and combinations thereof are trademarks of Advanced Micro Devices, Inc. Other product names used in this publication are for identification purposes only and may be trademarks of their respective companies.
© 2023 Advanced Micro Devices, Inc. All rights reserved.
© 2023 Advanced Micro Devices, Inc. All rights reserved
Notice Regarding Standards. AMD does not provide a license or sublicense to any Intellectual Property Rights relating to any standards, including but not limited to any audio and/or video codec technologies such as MPEG-2, MPEG-4; AVC/H.264; HEVC/H.265; AV1; AAC decode/FFMPEG; AAC encode/FFMPEG; VC-1; and MP3 (collectively, the “Media Technologies”). For clarity, you will pay any royalties due for such third party technologies, which may include the Media Technologies that are owed as a result of AMD providing the Software to you.
Copyright (c) 2023 Advanced Micro Devices, Inc. All rights reserved.
Permission is hereby granted, free of charge, to any person obtaining a copy of this software and associated documentation files (the "Software"), to deal in the Software without restriction, including without limitation the rights to use, copy, modify, merge, publish, distribute, sublicense, and/or sell copies of the Software, and to permit persons to whom the Software is furnished to do so, subject to the following conditions:
The above copyright notice and this permission notice shall be included in all copies or substantial portions of the Software.
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
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.
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
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
There are two possible methods for transcoding: hardware decoding and hardware encoding, or software decoding and hardware encoding.
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
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.
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
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