Build
Build
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
pacman -S cmake
- C:\msys64\home\aiusubov\.local\share
- /usr/local/share/
- /usr/share/
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
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.3.1\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:
# Configure your compiler to gcc/g++
sudo update-alternatives --config g++
# Select x86_64-linux-gnu-g++
sudo update-alternatives --config gcc
# Select x86_64-linux-gnu-gcc
export CMAKE_CXX_COMPILER=/usr/bin/g++
export CMAKE_C_COMPILER=/usr/bin/gcc
export CC=/usr/bin/gcc
export CXX=/usr/bin/g++
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
#AI notes: Install arm64 cross-compiler:
sudo apt-get install gcc-aarch64-linux-gnu g++-aarch64-linux-gnu
# Configure your compiler to aarch64-linux-gnu-gcc/aarch64-linux-gnu-g++
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/x86_64-linux-gnu-gcc
100
sudo update-alternatives --install /usr/bin/gcc gcc /usr/bin/aarch64-linux-gnu-gcc
50
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/x86_64-linux-gnu-g++
100
sudo update-alternatives --install /usr/bin/g++ g++ /usr/bin/aarch64-linux-gnu-g++
50
sudo update-alternatives --config g++
# Select aarch64-linux-gnu-g++
sudo update-alternatives --config gcc
# Select aarch64-linux-gnu-gcc
export CMAKE_CXX_COMPILER=/usr/bin/aarch64-linux-gnu-g++
export CMAKE_C_COMPILER=/usr/bin/aarch64-linux-gnu-gcc
export CC=/usr/bin/aarch64-linux-gnu-gcc
export CXX=/usr/bin/aarch64-linux-gnu-g++
2. make
Compile openssl
---------------
1. Grab the OpenSSL sources. (https://www.openssl.org/)
OpenSSL 3.3.0
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
#AI notes:
# $ cd C:\openssl-openssl-3.3.0\openssl-openssl-3.3.0
# for x64:
$ perl Configure VC-WIN64A --prefix=C:\openssl\x64 no-shared -static zlib --with-
zlib-include=C:/drivers/drivers/amf/Thirdparty/ffmpeg/ffmpeg/ffmpeg-7.0/zlib/x64 --
with-zlib-lib=C:/drivers/drivers/amf/Thirdparty/ffmpeg/ffmpeg/ffmpeg-7.0/zlib/x64/
zlib.lib
# for x86
$ perl Configure VC-WIN32 --prefix=C:\openssl\x86 no-shared -static zlib --with-
zlib-include=C:/drivers/drivers/amf/Thirdparty/ffmpeg/ffmpeg/ffmpeg-7.0/zlib/x86 --
with-zlib-lib=C:/drivers/drivers/amf/Thirdparty/ffmpeg/ffmpeg/ffmpeg-7.0/zlib/x86/
zlib.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
#AI notes:
# Error: 'rc' is not recognized as an internal or external command, operable
program or batch file. NMAKE : fatal error U1077: '"rc' : return code '0x1'
# Solution:
# for x64:
# $ set path=%PATH%;C:\Program Files (x86)\Windows Kits\10\bin\x64
# for x86:
# $ set path=%PATH%;C:\Program Files (x86)\Windows Kits\10\bin\x86
# or restart windows after changing from x64 to x86
# Error: fatal error LNK1112: module machine type 'x64' conflicts with target
machine type 'x86'
# Solution: Compiler doesn't suit to your build. Change your compiler on VC
manually:
# Restart your VC.
# $ cd C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\
Auxiliary\Build
# for x64:
# $ vcvarsall.bat amd64
# for x86:
# $ vcvarsall.bat x86
Compile libaom
---------------
2. Windows
a. Run 32/64 bit VC env variable command prompt (depending on configuration
required)
b. mkdir aom_build near the aom folder to hold generated config files and cd
into it
c. Generate Visual studio sln
# To build with Visual Studio 2019 for the 32-bit x86 target:
Move to cd C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\
Auxiliary\Build and run (vcvarsall.bat x86)
cd to Folder near aom (cd C:/)
mkdir aom-build
cd aom-build
$ cmake path/to/aom -G "Visual Studio 16 2019" -A Win32
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" -
DAOM_TARGET_CPU=x86_x64 -DENABLE_SHARED=off -DENABLE_NASM=on ../aom -
DCMAKE_INSTALL_LIBDIR=/path to release/ && \
$ make -j`nproc`
$ make install | tee install.log
$ Move aom.lib under path/to/aom_build_x64/lib
#AI notes:
#VC also create aom.pc file. It is in aom_build folder, i didn't need to build it
by msys.
#VC builds all *.exe and *.lib files inside aom_build/Release folder.
# $ cd C:/aom_build/Release
# $ mkdir bin
# $ mkdir include
# $ mkdir lib
# $ cd lib
# $ mkdir pkgconfig
# Move all lib inside Release folder to lib folder
# Move all exe files inside Release folder to bin folder
# Move all headers from C:/aom to C:/aom_build/Release/include
# Move aom.pc from C:/aom_build to C:/aom_build/Release/lib/pkgconfig
# Open aom.pc and change "prefix=" to correct path:
# prefix=/c/aom_build/Release
# If you move zlib build to another folder or rename the path, then also change
"prefix=" in aom.pc to correct.
#
# I also builded in with msys, but this build doesn't work for me with FFMPEG:
# $ cmake -G"Unix Makefiles" -DCMAKE_INSTALL_PREFIX=/c/aom-build/release -
DENABLE_SHARED=off -DAOM_TARGET_CPU=x86_64 -DENABLE_NASM=on ../aom -
DCMAKE_INSTALL_LIBDIR=release
64 bit:
$ git clone --depth 1 https://aomedia.googlesource.com/aom
$ mkdir aom_build
#AI notes:
#For lnx64 set compiler prefer:
# $ export CMAKE_CXX_COMPILER=g++-x64
# $ export CMAKE_C_COMPILER=gcc-x64
# $ 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
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 C:\msys64\msys2_shell.cmd -mingw64
3. cd /c/drivers/drivers/amf/Thirdparty/ffmpegy/ffmpeg/ffmpeg-7.0
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
you should find the following code (32 & 64bit): (for openssl)
------------------------------------------------
For Windows:
#AI notes:
#Prefer to open CMD as administrator, due to openSSL also create files in "Program
Files (x86)" folder:
# $ cd C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\
Auxiliary\Build
# $ vcvarsall.bat amd64
#
# I had to add also those path to VC, or my build fail:
# $ set include=%include%;C:\Program Files (x86)\Windows Kits\10\Include\
10.0.19041.0\ucrt
# $ set include=%include%;C:\Program Files (x86)\Windows Kits\10\Include\
10.0.19041.0\um
# $ set include=%include%;C:\Program Files (x86)\Windows Kits\10\Include\
10.0.19041.0\shared
# $ set lib=%lib%;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\
ucrt\x64
# $ set lib=%lib%;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\
um\x64
# $ set lib=%lib%;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\
shared\x64
# $ set path=%PATH%;C:\Program Files\NASM
# This line depends on your Windows Kit and MSVC compiler version: "...\
10.0.19041.0\..."
2. Navigate to cd C:\msys64
3. Add path to zlib
set include=%include%;C:\drivers\drivers\amf\Thirdparty\ffmpeg\ffmpeg\ffmpeg-
7.0\zlib\x64
set lib=%lib%;C:\drivers\drivers\amf\Thirdparty\ffmpeg\ffmpeg\ffmpeg-7.0\zlib\
x64
4. Add path to openssl lib
set include=%include%;C:\drivers\drivers\amf\Thirdparty\ffmpeg\ffmpeg\ffmpeg-
7.0\openssl\x64\include
set lib=%lib%;C:\drivers\drivers\amf\Thirdparty\ffmpeg\ffmpeg\ffmpeg-7.0\
openssl\x64\lib
set path=%path%;C:\drivers\drivers\amf\Thirdparty\ffmpeg\ffmpeg\ffmpeg-7.0\
openssl\x64\include
5. Add path to libaom
set include=%include%;C:\drivers\drivers\amf\Thirdparty\ffmpeg\ffmpeg\ffmpeg-
7.0\aom\x64\include
set lib=%lib%;C:\drivers\drivers\amf\Thirdparty\ffmpeg\ffmpeg\ffmpeg-7.0\aom\
x64\lib
set path=%path%;C:\drivers\drivers\amf\Thirdparty\ffmpeg\ffmpeg\ffmpeg-7.0\
aom\x64\include
6. Run C:\msys64\msys2_shell.cmd -mingw64 -use-full-path
7. Navigate to cd /c/drivers/drivers/amf/Thirdparty/ffmpeg/ffmpeg/ffmpeg-7.0
8. export PKG_CONFIG_PATH=path/to/aom_build_x64/lib/pkgconfig
#Example: export
PKG_CONFIG_PATH=/c/drivers/drivers/amf/Thirdparty/ffmpeg/ffmpeg/ffmpeg-7.0/aom/
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.
#AI notes:
# Error: LINK : fatal error LNK1104: cannot open file 'LIBCMT.lib'
# Error: LINK : fatal error LNK1104: cannot open file 'OLDNAMES.lib'
# Solution: Make sure that your Windows Kit version is the same as MSVC compiler
version.
# If it's different, then add it to environment variable path or set manually in
VC (i used version 10.0.19041.0):
# $ set include=%include%;C:\Program Files (x86)\Windows Kits\10\Include\
10.0.19041.0\ucrt
# $ set include=%include%;C:\Program Files (x86)\Windows Kits\10\Include\
10.0.19041.0\um
# $ set include=%include%;C:\Program Files (x86)\Windows Kits\10\Include\
10.0.19041.0\shared
# $ set lib=%lib%;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\ucrt\
x86
# $ set lib=%lib%;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\um\x86
# $ set lib=%lib%;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\shared\
x86
#
# Error: LINK : error LNK2001: unresolved external symbol mainCRTStartup
# Error: aom_integer.h(15): fatal error C1083: Cannot open include file:
'stddef.h': No such file or directory
# Error: Out of tree builds are impossible with config.h in source dir.
# Solution: seems that your aom builded with wrong Runtime Library (default /MD)
- you need to return back to aom.
# Open AOM.sln with VisualStudio, change build to Release x64 or Release x32
(depends on your build), and change Runtime Library on each project (including in
folders) to /MT:
# Open Properties of each project file -> C/C++ -> Code Generation -> Runtime
Library
#AI notes: Pprefer to open CMD as administrator, due to openSSL also create files
in "Program Files (x86)" folder:
# $ cd C:\Program Files (x86)\Microsoft Visual Studio\2019\Community\VC\
Auxiliary\Build
# $ vcvarsall.bat x86
#
# I had to add also those path to VC, or my build fail:
# $ set include=%include%;C:\Program Files (x86)\Windows Kits\10\Include\
10.0.19041.0\ucrt
# $ set include=%include%;C:\Program Files (x86)\Windows Kits\10\Include\
10.0.19041.0\um
# $ set include=%include%;C:\Program Files (x86)\Windows Kits\10\Include\
10.0.19041.0\shared
# $ set lib=%lib%;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\
ucrt\x86
# $ set lib=%lib%;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\
um\x86
# $ set lib=%lib%;C:\Program Files (x86)\Windows Kits\10\Lib\10.0.19041.0\
shared\x86
# $ set path=%PATH%;C:\Program Files\NASM
# This line depends on your Windows Kit and MSVC compiler version: "...\
10.0.19041.0\..."
2. Navigate to C:\msys64
3. Add path to zlib
set include=C:\drivers\drivers\amf\Thirdparty\ffmpeg\ffmpeg\ffmpeg-7.0\zlib\
x86; %include%
set lib=C:\drivers\drivers\amf\Thirdparty\ffmpeg\ffmpeg\ffmpeg-7.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
#AI notes:
#this add in zlib.h lead build to fail (couldn't find zlib)
#Solution: builded without this add in zlib.h
#
#No necessary (openSSL):
#AI notes:
#ERROR: zlib requested but not found
# Skip 4th point in VC 32 build. Do not add #undef ZEXPORT.
#AI notes:
#if you get error: /bin/bash^M: bad interpreter: No such file or directory
# Then need to bring script in Linux format:
# $ sudo apt-get install dos2unix
# $ dos2unix ffmpeg-build-linux
#AI notes:
#if you get error: /bin/bash^M: bad interpreter: No such file or directory
# Then need to bring script in Linux format:
# $ sudo apt-get install dos2unix
# $ dos2unix ffmpeg-build-linux
# Error: libavutil/aarch64/bswap.h:42: Error: no such instruction: `rev %ax,%ax'
# Try to add to ffmpeg-build-linux file to 125 line: --enable-cross-compile --
cross-prefix=aarch64-linux-gnu- --target-os=linux
# If still fail, i resolve it by removing AOM from build:
# delete "--enable-libaom" from "ffmpeg-build-linux" file.
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 :)