Skip to content

Build FFmpeg with AMF Support

Huts, Roman edited this page Sep 12, 2023 · 2 revisions

Advanced Micro Devices

Build FFmpeg with AMF Support

Usage Guide


Disclaimer

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.


Copyright Notice

© 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.

MIT license

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.


Table of Contents

  1. Introduction
  2. Build FFmpeg with AMF Support for Linux
  3. Build FFmpeg with AMF Support for Windows

1 Introduction

FFmpeg uses the AMD Advanced Media Framework (AMF) library for accelerated H.264, HEVC, and AV1 encoding on AMD GPUs.

The executables released by the FFmpeg officially support AMD AMF by default. You can go directly to the official FFmpeg website https://ffmpeg.org/download.html to download these executables.

In some cases, users like to build FFmpeg with AMF. In the following part we will give methods on how users can build FFmpeg. General instructions on how to build FFmpeg can be found at https://trac.ffmpeg.org/wiki/CompilationGuide/Generic.

To enable AMF support, you need to download the AMF framework header files(version 1.4.29+) from https://github.com/GPUOpen-LibrariesAndSDKs/AMF.git and use the --enable-amf configuration when building FFmpeg.

2 Build FFmpeg with AMF for Linux

We will use Ubuntu to show how to build FFmpeg on the Linux operating system.

  1. Create an “AMF” directory in the system include path /usr/local/include

  2. Download AMD AMF from https://github.com/GPUOpen-LibrariesAndSDKs/AMF.git . Copy the contents of AMF/amf/public/include/ to the above “AMF” directory.

  3. Install supporting packages

    sudo apt-get install install yasm
    
    sudo apt-get install pkg-config
    
    sudo apt-get install gcc
    
    sudo apt-get install make
    
    sudo apt-get install diffutils
    
    sudo apt-get install git
  4. Clone the FFmpeg source code

    git clone https://github.com/FFmpeg/FFmpeg.git ffmpeg
  5. Configure

    cd ffmpeg
    
    ./configure --enable-amf
  6. Make

    make -j
  7. The binary files are built in the ffmpeg folder

3 Build FFmpeg with AMF for Windows

To compile FFmpeg under Windows operating system, we use two typical compilers.

3.1 Using the MinGW Compiler

  1. Install MSYS2 from http://msys2.github.io . Suppose installed at C:\msys64

  2. Run C:\msys64\mingw64.exe, which will launch the “MSYS2 MinGW x64 Prompt”

  3. In the MSYS2 MinGW x64 Prompt, install all supporting packages

    pacman -S make pkgconf diffutils mingw-w64-x86_64-nasm mingw-w64-x86_64-gcc mingw-w64-x86_64-SDL2 mingw-w64-x86_64-gdb mingw-w64-x86_64-dlfcn git
    
  4. Inside your Windows Environment variables, add “C:\msys64\mingw64\bin” to the “Path” of “User variables for username”, here “username” should be replaced by the actual user of current Windows OS

  5. Create an “AMF” directory in the MSYS2 system include path "C:\msys64\usr\local\include\amd".

  6. Download AMD AMF from https://github.com/GPUOpen-LibrariesAndSDKs/AMF.git . Copy the contents of AMF/amf/public/include/ to the above “AMF” directory

  7. Clone the FFmpeg source code

    git clone https://github.com/FFmpeg/FFmpeg.git ffmpeg
    
  8. Configure

    cd ffmpeg
    
    ./configure --enable-amf --extra-cflags=-I/usr/local/include/amd
    
  9. Make

    make -j
    
  10. The binary files are built in the ffmpeg folder

3.2 Using the MSVC Compiler

  1. Install Microsoft Visual Studio 2022 from https://visualstudio.microsoft.com/vs/

  2. Install MSYS2 from http://msys2.github.io. Suppose installed at C:\msys64

  3. Run C:\msys64\mingw64.exe, which will launch “MSYS2 MinGW x64 Prompt”

  4. In the MSYS2 MinGW x64 Prompt, install all supporting packages

    pacman -S make pkgconf diffutils nasm git
    
  5. Inside your Windows Environment variables, add “C:\msys64\mingw64\bin” to the “Path” of “User variables for username”, here “username” should be replaced by the actual user of current Windows

  6. Create an “AMF” folder in the directory in the MSYS2 system include path "C:\msys64\usr\local\include".

  7. Download AMD AMF from https://github.com/GPUOpen-LibrariesAndSDKs/AMF.git . Copy the contents of AMF/amf/public/include/ to the above “AMF” directory.

  8. In the Windows “Start” menu, from “Visual Studio 2022” run “x64 Native Tools Command Prompt for VS 2022”

  9. In the “x64 Native Tools Command Prompt for VS 2022” prompt,

    C:\Program Files\Microsoft Visual Studio\2022\Community>cd c:\msys64
    
    C:\msys64>msys2_shell.cmd -mingw64 -use-full-path
    

    This will launch a MinGW x64 Prompt.

  10. In the MinGW x64 Prompt, clone the ffmpeg source code

    git clone https://github.com/FFmpeg/FFmpeg.git ffmpeg
    
  11. Configure

    cd ffmpeg
    
    ./configure --extra-cflags=-I/usr/local/include --toolchain=msvc --enable-amf
    
  12. Make

    make -j
    
  13. The binary files are built in the ffmpeg folder.