Location via proxy:   [ UP ]  
[Report a bug]   [Manage cookies]                
0% found this document useful (0 votes)
0 views

Build

This document provides a comprehensive guide on building FFMPEG for AMF on Windows and Linux, detailing the required tools, dependencies, and step-by-step commands for installation and compilation. It covers the setup of the build environment, compilation of necessary libraries like zlib, OpenSSL, and libaom, and includes troubleshooting tips for common errors. The guide emphasizes the importance of configuring paths and environment variables correctly to ensure successful builds.

Uploaded by

helpdeskpid
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
0% found this document useful (0 votes)
0 views

Build

This document provides a comprehensive guide on building FFMPEG for AMF on Windows and Linux, detailing the required tools, dependencies, and step-by-step commands for installation and compilation. It covers the setup of the build environment, compilation of necessary libraries like zlib, OpenSSL, and libaom, and includes troubleshooting tips for common errors. The guide emphasizes the importance of configuring paths and environment variables correctly to ensure successful builds.

Uploaded by

helpdeskpid
Copyright
© © All Rights Reserved
Available Formats
Download as TXT, PDF, TXT or read online on Scribd
You are on page 1/ 7

Welcome to how to build FFMPEG for AMF!!

Buckel up its going to be a long ride :)

Build environment for Win10 64bit: (Note type out commands it didnt like it when i
copied them, annoying i know but just for the first pacman things then copy away)
1. Download msys2-x86_64-xxx.exe from http://www.msys2.org/
2. intall msys2 to default path C:\msys64\
3. Run MSYS2
4. execute pacman -Syu (confirm with "y" on prompt)
5, when prompted terminate shell and re-run MSYS2
6. Execute pacman -Su (confirm with "y" on prompt)
7. Run (confirm with "y" on prompts)
pacman -S make
pacman -S diffutils
pacman -S yasm
pacman -S mingw-w64-x86_64-gcc
pacman -S mingw-w64-i686-gcc
pacman -S mingw-w64-x86_64-gtk3
pacman -S mingw-w64-i686-gtk3

8. Download http://ftp.gnome.org/pub/gnome/binaries/win64/dependencies/pkg-
config_0.23-2_win64.zip
9. Unzip and copy pkg-config.exe to E:\msys64\mingw64\bin
10. Download http://ftp.gnome.org/pub/gnome/binaries/win32/dependencies/pkg-
config_0.26-1_win32.zip
11. Unzip and copy pkg-config.exe to E:\msys64\mingw32\bin

12. Copy to intl.dll in two folders:


cd C:\msys64\\mingw32\bin
copy libintl-8.dll intl.dll
cd C:\msys64\\mingw64\bin
copy libintl-8.dll intl.dll

(All you do is rename these files and change .a -> .a-org)


13. in E:\msys64\mingw64\lib rename libpthread.dll.a libwinpthread.dll.a - change
extension to a-org,
14. In E:\msys64\mingw64\lib rename libbz2.dll.a libz.dll.a libiconv.dll.a
liblzma.dll.a optionally libSDL.dll.a - change extension to a-org,
15. in E:\msys64\mingw32\lib rename libpthread.dll.a libwinpthread.dll.a - change
extension to a-org,
16. In E:\msys64\mingw32\lib rename libbz2.dll.a libz.dll.a libiconv.dll.a
liblzma.dll.a optionally libSDL.dll.a - change extension to a-org,

Compile zlib for EXR support


----------------------------
Grab the zlib sources version (http://zlib.net/)

Windows:
1. Edit win32/Makefile.msc so that it uses -MT instead of -MD, since this is how
FFmpeg is built as well.
2. Edit zconf.h and remove its inclusion of unistd.h. This gets erroneously
included when building FFmpeg.
3. Run nmake -f win32/Makefile.msc.
Alternatively, under \zlib-1.2.11\contrib\vstudio\vc14 there is a VisualStudio
project for building zlib.
I would suggest using VisualStudio as it's easier to change the settings.
For x86, compile the ReleaseWithoutAsm - the asm code seems to be causing a
crash in the openSSL unit tests
For x64, Release version (which includes asm), passed the openSSL unit tests
4. (Only for VS) Once you build the projects will build zlibstat.lib you will need
to rename this to zlib.lib or ffmpeg will not link properly
5. Move zlib.lib, zconf.h, and zlib.h to somewhere MSVC can see.

Linux:
64 bit:
1. ./configure --static --64
2. make
(to check x86/x64 for compiled library version in Linux: "objdump -f libz.a | grep
^architecture")
ARM64 Linux:
1. ./configure --static
2. make

Compile openssl
---------------
1. Grab the OpenSSL sources. (https://www.openssl.org/)

OpenSSL 3.0.5

2. Read INSTALL and NOTES.WIN (or NOTES.UNIX)

3. Windows:
a. Download and install Perl.
- Perl. We recommend ActiveState Perl, available from
https://www.activestate.com/ActivePerl. Another viable alternative
appears to be Strawberry Perl, http://strawberryperl.com.
You also need the perl module Text::Template, available on CPAN.
Please read NOTES.PERL for more information.
Note: I recommend Strawberry perl which contains all necessary librarie

b. Download and install NASM.


- Netwide Assembler, a.k.a. NASM, available from https://www.nasm.us,
is required. Note that NASM is the only supported assembler. Even
though Microsoft provided assembler is NOT supported, contemporary
64-bit version is exercised through continuous integration of
VC-WIN64A-masm target.

c. Run 64 bit VS env variable command prompt

d. Add NASM to the path


set path=%PATH%;X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-5.1.0\openssl\nasm-
2.14.02

perl Configure VC-WIN64A


--prefix=X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-5.1.0\openssl\x64
// where to copy the files when "nmake install" runs
no-shared // don't use
dlls
-static // generate
static library
zlib // use zlib
--with-zlib-include=X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-5.1.0\zlib\x64
// path to zlib include
--with-zlib-lib=X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-5.1.0\zlib\x64\zlib.lib
// full path\name to zlib static lib

Note: while Configure is running, it pops up a window suggesting that nmake is not
in the path, and offering to download dmake. Ignore this message! If you are
running a VS2015/VS2017 command window, as suggested above, nmake is certainly in
your path.
notepad makefile
replace CNF_CFLAGS=/Gs0 /GF /Gy
with CNF_CFLAGS=/Gs0 /GF /Gy /MT /MP
/MT to eliminate the linking to runtime DLLs (like VCRUNTIME140.dll)
/MP for multi-processor compilation - though I haven't seen any build
performance difference than without it

after makefile changes:


$ nmake // build the files
$ nmake test // validate the build
$ nmake install // copy required files to specified
output directory

Compile libaom
---------------

1. Grab the AOM sources from git. (https://aomedia.googlesource.com/aom/)


The website already has most instructions

git clone --depth 1 https://aomedia.googlesource.com/aom

2. Windows
a. Run 32/64 bit VC env variable command prompt (depending on configuration
required)
b. mkdir aom_build to hold generated config files and cd into it
c. Generate Visual studio sln

# To build with Visual Studio 2019 for the x64 target:


$ cmake path/to/aom -G "Visual Studio 16 2019"
$ cmake --build .

# To build with Visual Studio 2019 for the 32-bit x86 target:
$ cmake path/to/aom -G "Visual Studio 16 2019" -A Win32

d. open aom_build\AOM.sln with VS


Check build dependencies of project "aom"
Change all depended projects (including aom) Properies -> C/C++ -> Code
Generation -> Runtime Library - > change it to Multi-threaded (/MT)
Build project "aom"

Note: VS may hang while building the release "aom" (I had it while building win32).
You can build the dependency projects before "aom"

Move aom.lib, and all header files under path/to/aom/aom (eg, aom_codec.h)to
somewhere MSVC can see.
However to generate pkg-config file aom.pc, will still need to cmake with msys2
$ cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="path/to/aom_build_x64" -
DENABLE_SHARED=off -DENABLE_NASM=on ../aom && \
$ make && \
$ make install
$ Move aom.lib under path/to/aom_build_x64/lib

3. Linux or ARM64 Linux


https://trac.ffmpeg.org/wiki/CompilationGuide/Ubuntu Most of pre requirements can
be found in Get the Dependencies section
However, -DBUILD_SHARED_LIBS is not enough for static lib build.
To avoid error "can not be used when making a shared object; recompile with
-fPIC/usr/bin/ld: final link failed: bad value" Please use the following cmake cmd
The flag -march=znver2 is optional for performance, you can adject with your GPU

64 bit:
$ git clone --depth 1 https://aomedia.googlesource.com/aom
$ mkdir aom_build
$ cmake -G "Unix Makefiles" -DCMAKE_INSTALL_PREFIX="/path/to/aom_build_lnx64"
-DBUILD_SHARED_LIBS=0 -DCMAKE_BUILD_TYPE=Release -DCMAKE_CXX_FLAGS="-flto -O3 -
march=znver2" -DCMAKE_C_FLAGS="-flto -O3 -march=znver2" -DCMAKE_C_FLAGS_INIT="-
flto=8 -static" -DENABLE_NASM=on path/to/aom
$ make
$ make install

ARM64: I had to switch -march=znver2 to -march=native

CONGRATS!! After all that blood sweat and tears you now have what you actually new
to build FFMPEG. Buckel up kidos this is where the fun begins

Getting source code: (you need to update the version of ffmpeg in the
get_sourcecode script)
1. In this directory:
2. Run E:\msys64\msys2_shell.cmd -mingw64
3. cd /e/dev/ffmpeg
4. run ./get_sourcecode

Note: Msys2 compiled binraies will create dependencies on many dll libraries, you
will have to build static openssl and libaom lib by yourself
Build 64
1. Run E:\msys64\msys2_shell.cmd -mingw64
2. cd /e/dev/ffmpeg
3. ./ffmpeg-build-win release 64

Build 32
1. Run E:\msys64\msys2_shell.cmd -mingw32
2. cd /e/dev/ffmpeg
3. ./ffmpeg-build-win release 32

Build with VC++


---------------
1. Navigate to cd e:/dev/ffmpeg/ffmpeg-5.1.0
2. Edit the "configure" file, due to openSSL and zlib
NOTE: this change is not needed for mingw builds (Windows)

you should find the following code (32 & 64bit): (for openssl)
------------------------------------------------

enabled openssl && { check_pkg_config openssl openssl openssl/ssl.h


OPENSSL_init_ssl ||
check_pkg_config openssl openssl openssl/ssl.h
SSL_library_init ||
check_lib openssl openssl/ssl.h
SSL_library_init -lssl -lcrypto ||
check_lib openssl openssl/ssl.h
SSL_library_init -lssl32 -leay32 ||
check_lib openssl openssl/ssl.h
SSL_library_init -lssl -lcrypto -lws2_32 -lgdi32 ||
die "ERROR: openssl not found"; }
replace it with the code below:

For Windows:

enabled openssl && { check_pkg_config openssl openssl openssl/ssl.h


OPENSSL_init_ssl ||
check_pkg_config openssl openssl openssl/ssl.h
SSL_library_init ||
check_lib openssl openssl/ssl.h
OPENSSL_init_ssl -llibssl -llibcrypto -lzlib -lws2_32 -lgdi32 -luser32 -ladvapi32 -
lcrypt32 ||
check_lib openssl openssl/ssl.h
SSL_library_init -lssl -lcrypto ||
check_lib openssl openssl/ssl.h
SSL_library_init -lssl32 -leay32 ||
check_lib openssl openssl/ssl.h
SSL_library_init -lssl -lcrypto -lws2_32 -lgdi32 ||
die "ERROR: openssl not found"; }

which basically adds:


check_lib openssl openssl/ssl.h
OPENSSL_init_ssl -llibssl -llibcrypto -lzlib -lws2_32 -lgdi32 -luser32 -ladvapi32 -
lcrypt32 ||
to enable the check for the openssl staic library to succeed

Build 64 with VC++


------------------
1. Run 64 bit VC env variable command prompt
2. Navigate to E:\msys64
3. Add path to zlib
set include=X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-5.1.0\zlib\x64; %include%
set lib=X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-5.1.0\zlib\x64; %lib%
4. Add path to openssl lib
set include=%include%;X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-5.1.0\openssl\x64\
include
set lib=%lib%;X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-5.1.0\openssl\x64\lib
set path=%path%;X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-5.1.0\openssl\x64\
include
5. Add path to libaom
set include=%include%;X:\path\to\aom_build_x64\include
set lib=%lib%;X:\path\to\aom_build_x64\lib (Note: copy aom.lib under lib
folder)
set path=%path%;X:\path\to\aom_build_x64\include
6. Run E:\msys64\msys2_shell.cmd -mingw64 -use-full-path
7. Navigate to cd /e/dev/ffmpeg
8. export PKG_CONFIG_PATH=path/to/aom_build_x64/lib/pkgconfig
9. Run ./ffmpeg-build-win release 64 msvc

Notes: If you get this error: cl.exe is unable to create an executable file. If
cl.exe is a cross-compiler, use the --enable-cross-compile option. Only do this if
you know what cross compiling means. C compiler test failed.
First thing to check is where the cl.exe and link.exe are. Run "which cl.exe"
and "which cl.exe" and make sure its pointing to MSVC if its pointing to msys
either rm the file or rename it.
If that doesnt work look in the log file I had the error in "mslink" with the
error "LINK : fatal error LNK1104: cannot open file 'kernel32.lib'" If this is the
case its having trouble finding your Windows SDK. In the mslink file change
"$LINK_EXE_PATH" $@
For:
"$LINK_EXE_PATH" $@ -verbose -LIBPATH:"C:\Program Files (x86)\Windows Kits\
10\Lib\10.0.22621.0\um\x64" -LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\
10.0.22621.0\ucrt\x64" -LIBPATH:"C:\Program Files (x86)\Windows Kits\10\Lib\
10.0.22621.0\ucrt_enclave\x64"
Replace the paths with a link to your sdk and make sure you have links to um,
ucrt, and ucrt_enclave. When you compile x32 you will need to change the path to
the x32 folders. Note you done need -verbose this just gives you more info

If you get "ERROR: aom >= 1.0.0 not found using pkg-config" when you 100%
followed the steps its because even though you are giving it the path to the aom.pc
file it still doesnt want to work. First thing run pkg-config --libs "aom >= 1.0.0"
and if it finds the
package in the correct directory you are having the same problem as me. Go
into the aom.pc file and make sure that the top of the file the element "prefix" is
an abs path to the directory that has the lib/include/bin for the correct build
type.

Build 32 with VC++


------------------
1. Run 32 bit VC env variable command prompt
2. Navigate to E:\msys64
3. Add path to zlib
set include=X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-5.1.0\zlib\x86; %include%
set lib=X:\dvtP4\AMF\Thirdparty\ffmpeg\ffmpeg-5.1.0\zlib\x86; %lib%
4. For 32 bit add the following code in zlib.h: (for zlib)
#undef ZEXPORT
#define ZEXPORT __stdcall
so ffmpeg will link properly with zlib
5. Add path to libaom
set include=%include%;X:\path\to\aom_build_win32\include
set lib=%lib%;X:\path\to\aom_build_win32\lib (Note: copy aom.lib under lib
folder)
set path=%path%;X:\path\to\aom_build_win32\include
6. Run E:\msys64\msys2_shell.cmd -mingw32 -use-full-path
7. Navigate to cd /e/dev/ffmpeg
8. export PKG_CONFIG_PATH=path/to/aom_build_win32/lib/pkgconfig
9. Run ./ffmpeg-build-win release 32 msvc

Build 64 with gcc under Linux


-----------------------------
1. add path to zlib by modifying the ffmpeg-build-linux
extracflags='--extra-cflags=-I/home/rhuts/Desktop/ffmpeg/zlib-1.2.11/bin/
lib64,-I/home/rhuts/Desktop/ffmpeg/aom/aom_build_lnx64/include'
extralinkflags='--extra-ldflags=-Wl,-rpath=$ORIGIN,-L/home/rhuts/Desktop/
ffmpeg/zlib-1.2.11/bin/lib64,-L/home/rhuts/Desktop/ffmpeg/aom/aom_build_lnx64/lib'
export PKG_CONFIG_PATH="/home/amd/newFFMPEG/aom_build/lib/pkgconfig"
2. Run ./ffmpeg-build-linux release 64 linux
3. Run patchelf to set binaries runpath to current working directory
NOTE: ffmpeg doesn't set runpath to current directly correctly with flag -
rpath=$ORIGIN, we still need to use other tools to achieve this. I recommend
patchelf. Please do this for all the generated binaries.
eg. sudo patchelf --set-rpath '$ORIGIN' libswscale.so.5
(to check the binary's runpath, objdump -p libswscale.so.5 | grep RUN)
Build ARM64 with gcc under Linux
-----------------------------
It's same as what we have on x64
1. add path to zlib and openssl by modifying the ffmpeg-build-linux
extracflags='--extra-cflags=-I/home/rhuts/Desktop/ffmpeg/zlib-1.2.11/bin/
lib64,-I/home/rhuts/Desktop/ffmpeg/aom/aom_build_lnx64/include'
extralinkflags='--extra-ldflags=-Wl,-rpath=$ORIGIN,-L/home/rhuts/Desktop/
ffmpeg/zlib-1.2.11/bin/lib64,-L/home/rhuts/Desktop/ffmpeg/aom/aom_build_lnx64/lib'
export PKG_CONFIG_PATH="/home/amd/newFFMPEG/aom_build/lib/pkgconfig"
2. Run ./ffmpeg-build-linux release arm64 linux
3. Run patchelf to set binaries runpath to current working directory
eg. sudo patchelf --set-rpath '$ORIGIN' libswscale.so.5

CONGRATS you have now built FFMPEG on the 4 diff machines! That was a brutal
process but I hope that these notes made it a little better. Pls add your own notes
so that the next person who was to build it will have slightly less issues

Now lets intagrate this new code! Let me tell you it will be just as much fun :)

You might also like