- FFmpeg Compilation Guide
- All platforms
- Linux
- macOS
- Windows
- Other Platforms
- Performance Tips
- Ffmpeg compile on windows
- Setting the environment
- Build
- Problem solving
- Debug Builds
- Compiling FFmpeg with external libraries
- libx264
- libopenh264
- MinGW/FFmpeg installation guide
- Contents
- Introduction
- Installing Requirements
- MinGW
- Option 1: MinGW-w64
- Option 2: MinGW «mainline»
- Option 1: MSYS
- Option 2: MSYS2
- MinGW Installation Style
- libx264
- lib.exe
- DirectShow
- OpenAL
- pkg-config
- Configuring FFmpeg
- Windows Compilation Tips
- More Resources
FFmpeg Compilation Guide
This page contains a list of resources which describe the necessary steps required for compiling FFmpeg from scratch or with the help of build scripts and/or package managers.
All platforms
Read the Generic compilation guide, regardless of your platform. It provides generic compilation and installation instructions, including the use of configure .
- CompilationGuide/vcpkg – vcpkg also aims to be portable accross all platforms. For windows it uses MinGW/MSYS compilation toolchain.
Linux
Alternative ways to obtain/compile ffmpeg under Linux:
macOS
Windows
- CompilationGuide/MinGW – MinGW Compilation Guide for compiling FFmpeg with Windows/MinGW/MSYS.
- CompilationGuide/CrossCompilingForWindows – Cross compiling for Windows is sometimes easier than using MSYS+MinGW.
- CompilationGuide/WinRT – Compiling FFmpeg for Windows Apps (Windows 10 and Windows 8.1)
- CompilationGuide/MSVC – Compiling FFmpeg using MSYS+MSVC, see also:
- Instructions on the reference web page
- Roxlu’s guide
Using external scripts or tools:
- Media Autobuild Suite – Automatically build FFmpeg under Windows
- Linuxbrew, which can be used with Windows Subsystem for Linux (WSL)
- Chocolatey – a package manager for Windows with an FFmpeg package
Other Platforms
Performance Tips
There are numerous avenues to extract maximum performance out of FFmpeg when it is built from source. The following list describes some of them:
- If using GCC/Clang , consider adding -march=native to —extra-cflags to make slightly better use of your hardware. Alternatively, for a more general solution, examine the —arch and —cpu options. Gains are variable, and usually quite small. However, this is usually even more safe than the above, and is thus listed here.
- Depending on your use case, —enable-hardcoded-tables may be a useful option. It results in an increase of approximately 15% in the size of libavcodec , the main library impacted by this change. It enables savings in table generation time, done once at codec initialization, since by hardcoding the tables, they do not need to be computed at runtime. However, the savings are often negligible (
100k cycles is a typical number) especially when amortized over the entire encoding/decoding operation. By default, this is not enabled. Improvements are being made to the runtime initialization, and so over time, this option will have an impact on fewer and fewer codecs.
- Other options may be found by examining ./configure —help .
Ffmpeg compile on windows
FFmpeg can be built on Windows with Visual Studio. The official guide is quite clear, but a little bit out-of-date.
FFmpeg can be built with MSVC 2012 or earlier using a C99-to-C89 conversion utility and wrapper, or with MSVC 2013 or later natively.
You will need the following prerequisites:
First, you need to unzip and copy the prerequisites into a folder, for example, c:\c99 .
Then, you need to add the folder c:\c99 into your PATH environment variable.
Rename the yasm executable you will use to yasm.exe .
Finally, create an INCLUDE environment variable, and point it to c:\c99 ; this is the location where the compiler will find inttypes.h .
Note: If it complains of MSVCR100.dll not found when running yasm, install the Microsoft 2010 VC redistributable.
Setting the environment
In order to build a program with the VisualStudio tools, you need to setup a proper environment in order to make sure that the configure and build system will be able to find the tools.
In particular, the build system will use the cl compiler and the link linker bundled with the employed version of VisualStudio. In order to setup the enviroment it is so necessary to set the PATH , LIB , and INCLUDE variables to appropriate values.
This can be done by launching a cmd.exe native shell from the VisualStudio GUI. This can be done for example adding a tool from the Tools menu: Tools -> External tools. -> Add
To build 64bit you need to run this command to enable the 64bit compiler and linker:
Installed in the Visual Studio VC directory (for example: C:\Program Files (x86)\Microsoft Visual Studio 12.0\VC ). Depending on the system the argument might be x86_amd64 or similar.
Finally, to set up a proper MSYS environment, you need to run msys.bat (or the equivalent mingw32_shell.bat ) from the command prompt.
Now, make sure that the cl and link program are not override by other programs with the same name from MSYS/MinGW (in particular, note that MinGW provides a program named link ). In order to do so, you can set the MSYS path so that the VisualStudio tools are used instead, for example with the command:
or when building for 64bit
or removing or renaming the link binary provided by MSYS.
Next, make sure any other headers and libs you want to use, such as zlib, are located in a location that the compiler can see. Do so by modifying the LIB and INCLUDE environment variables to include the Windows-style paths to these directories. Alternatively, you can try and use the —extra-cflags / —extra-ldflags configure options.
Build
Finally, run: For MSVC:
For 64 bit builds specify target and architecture:
or the following:
—enable-shared will generate the dynamic linked lib (dlls)
Note: You might see an error saying cl can’t generate executable; this is because you installed the link.exe from MSYS. It conflicts with the link.exe of Visual Studio. This can also indicate that you are mixing 64bit and 32bit versions of cl.exe and link.exe .
You can try which link.exe to verify if it is the case. If you see /bin/link.exe , then you can simply rm /bin/link.exe . For more info see #3203 Windows MSVC configure failed.
The right link.exe should come from this location:
or in the case of 64bit builds
Problem solving
You might see three problems when building ffmpeg :
A solution is posted at MSYS pr not found. Basically, pr.exe is removed from MSYS. You need to download it and copy pr.exe to the msys/bin folder.
- The compiler might complain about redefinition issues of stdint.h , because both msinttypes and Visual Studio have stdint.h . I removed stdint.h from c:\c99 to let the compiler uses the one provided by Visual Studio.
In the end of configuration, you might also see pkg-config not found issue. That won’t affect compilation, you can ignore it. It is said that installing pkg-config to MSYS is kinda tiresome.
- common.mak:140: *** missing separator. Stop.
This can happen if you try to build from a cloned git repository and have git configured to replace line endings in your local working copy. Be sure that you have the git option core.autocrlf set to false when cloning the git repo.
To make sure that MSVC finds the zlib files, add the include and lib path from the Visual Studio Command Line prior to launching MSYS2:
Debug Builds
How to build debug version?
Compiling FFmpeg with external libraries
In order to build FFmpeg with support to external libraries, you need to make sure that the libraries and headers are placed in a location specified by the INCLUDE and LIB directories referenced by the VC compiler and linker. In case multiple libraries are used, you could use a common prefix to install all the libraries, so that you have to specify a single location.
Also, you may need to compile the libraries themselves with VC in order to make it possible to link them when building the FFmpeg DLLs.
The following subsections document how you can build some of the external libraries employed by FFmpeg using VC. Note that the setup step is the same for all the libraries (so it can be done just once, then you can build several libraries using the same MSYS terminal session).
libx264
The following example command will configure libx264:
The NO_PREFIX flag may be necessary to make linkable libraries.
libopenh264
libopenh264 provides no configuration system, so the build parameters have to be specified either by editing the Makefile, or by setting the parameters on the commandline. The following command will build the openh264 library with VC:
MinGW/FFmpeg installation guide
Contents
Introduction
In order to compile FFmpeg on Windows, you need to install the MinGW environment and a few tools which are strictly required. The following sections give some indications for installing some of the required components.
Tip: The Media Autobuild Suite can automatically build FFmpeg under Windows with several external dependencies. You can still follow this guide if you want to manually compile FFmpeg.
Note that the only strict requirement for compiling a plain vanilla version of FFmpeg (no external libraries) is MinGW (compilation environment) and Git required for downloading and updating the source code.
Also note that sometimes it is easier to cross compile, see the Cross Compiling guide, which also may contain some hints/clues for compiling the various dependencies you’d need using MinGW, too.
Some Windows-specific compilation information can be found in the official documentation.
Installing Requirements
MinGW
You have two options for a compiler:
Both offer working gcc s for Windows. The first tends to be slightly more up to date than the latter, and offers more library compatibility, like DirectShow headers, so preferably use MinGW-w64.
The MinGW package provides gcc and headers.
Option 1: MinGW-w64
This project does not have downloadable compilers by default; you’ll probably want the «mingw-builds» project, which provides pre-built compilers.
To use MinGW-w64, install Msys using the MinGW setup, as above, but only check the «msys for developers option». Then install a MinGW-w64 compiler. Here is an example.
Then configure your PATH appropriately, for instance mine looks like this:
In this case, the MINGW_PATH would be:
To access DirectShow input devices you have to use MinGW-w64 as the compiler (or cross compiler), as straight MinGW headers don’t have this functionality.
To install libraries you’d either use
The latter if you wanted to install something to your MINGW_PATH itself.
Option 2: MinGW «mainline»
Go to http://www.mingw.org and look for the «Download» page.
The recommended way to install MinGW/MSys is through the automated installer, mingw-get-setup.exe .
This will download most of the basic core packages. It will usually install in C:\MinGW but you can define the installation path when configuring. Note down this path (that we will call as «MinGW path» or MINGW_PATH later in this guide).
Once you install MinGW you should see in the Windows menu the «MinGW» entry with the option «MinGW shell». Click on it and it will launch a terminal with a bash shell. This is supposed to be a GNU/Unix environment, and you’re supposed to know a bit of UNIX commands for getting through it. Alternatively, or in case the MinGW entry is missing, you need to manually launch the MINGW_PATH/msys/1.0/msys.bat file.
MinGW adopts a mounting mechanism to make Windows directories appear like native UNIX-like paths. Check the output of the mount command, and familiarize yourself with the mapping mechanism. In the rest of the guide, when not explicitly specified, we’ll use the UNIX mapped paths.
Note that by default the user home will be placed in MINGW_PATH/msys/1.0/home/USER , and that will be your working directory of the msys shell.
Finally, you need to edit the system environment PATH variable, adding the MINGW_PATH/bin directory. This will allow both the system and the msys shell to find programs provided by MinGW. This can be done for example with:
Msys provides shell utilities like make and bash . Choose either MSys or MSYS2.
Option 1: MSYS
Then run its console. You will be able to then run configure (assuming you’ve installed a gcc to your PATH already).
Option 2: MSYS2
Then run the mingw32_shell.bat or mingw64_shell.bat command in the MSYS2 installation home. Be careful not to run the MSYS2 Shell as this will result in FFmpeg’s configure saying building an MSYS binary is not recommended and exiting.
Now install requisite packages:
Alternatively, you can also install GCC from MSYS2 system itself, and not need any of the MinGW-w64 instructions above:
MSYS2 comes with a package management system called pacman adopted from Arch Linux, and allows to easily install binary packages from the commandline. To compile FFmpeg, you need to install the mingw-w64 GCC environment (either in the i686 or x86_x64 flavor). Use one of the commands:
This installs «gcc.exe» commands that are actually built for MSYS2 but are the windows gcc compilers. Configure and make as normal.
If you use MSYS2 many packages can be easily installed by using pacman (for example pacman -S pkg-config ).
Unfortunately the gcc.exe it provides seems to create binary’s that require files like «libgcc_s_dw2-1.dll» and «libwinpthread-1.dll» (etc.?) to accompany your executable, so can cause some difficulty there. You can remove some files to remove dependencies on things like «libbzip2.dll» see https://ffmpeg.zeranoe.com/forum/viewtopic.php?f=5&t=3688 and possibly avoid the libgcc.dll requirement by using «-static» at linking time.
MinGW Installation Style
It is a good norm to keep the locally installed packages separated from the MinGW/MSys packages. For this reason we recommend to use /usr/local for locally installed files. That means that packages will be configured with —prefix=/usr/local . For removing the local packages it will be sufficient to erase the /usr/local directory.
This should also avoid conflicts with MinGW/MSys.
Git is the source code control system used by FFmpeg, and you need it for downloading and updating the source code.
The official Git project site is here. The recommended installation way is through the Git for Windows project.
The autoinstaller will create a separate Msys environment for Git. In order to be able to let your MinGW and msysgit coexist on the same system you need some tuning in the Windows environment. Indeed the msysgit installer will modify some of the environment values set by the MinGW install, and you may need to manually restore them.
In particular, you need to:
- Fix the HOME variable, so that it will point to $MINGW_PATH/msys/1.0/home/$USER
- Edit the path, so that the git bin and cmd paths are located after the corresponding MinGW bin directory.
YASM is a non-strict requirement; it allows for optimized compilation so it is recommended to install it. The easiest way to install it for Windows is by simply downloading the binary provided.
You’ll have to choose between the versions provided (e.g. 32 vs 64 bit), download and install it in /usr/local/bin or in /bin .
Since the name of the binary is usually suffixed with the program version (e.g. it is named yasm-1.1.0-win32.exe ), you need to create a copy named yasm , so it can be invoked by using simply yasm .
Alternatively you may install the source version and compile it.
In case the system is complaining about a missing MSVCR100.dll file when trying to run yasm, you may need to install the Microsoft Visual C++ 2010 SP1 Redistributable Package from Microsoft.
SDL is required for ffplay and the SDL output device. You need the 1.2 version.
Once installed in the MINGW_PATH , the FFmpeg configure should be able to auto-detect it.
Note that SDL flags, as issued by sdl-config/pkg-config, contain the -mwindows flag which will prevent applications to log on console. As a workaround you’ll need to remove that flag, e.g. by editing the sdl-config script or the SDL pkg-config file in lib.
libx264
libx264 can be compiled and installed in the MinGW+MSys environment.
If you want libx264.dll files (instead of static) you should use the —enable-shared configure option.
The only way I was able to figure out how to get this to work was to add —extra-ldflags=L../libx264_unpacked_dir —extra-cflags=-I../libx264_unpacked_dir to my ffmpeg configure line, after successfully building libx264.
lib.exe
lib.exe is required for creating .dll.a import stub libraries, so that you can link to the DLLs from MSVC (Microsoft Visual Studio compiler, bundled with it), if you are planning on creating a DLL style FFmpeg build and need/want to do that.
lib.exe is a Microsoft tool used for creating DLL files. It is bundled together with Visual Studio. Microsoft Visual Studio Express download is available for free. Once installed you’ll need to add the directory where lib.exe is located to the system path.
dlltool.exe (which is part of binutils) may be used instead of lib.exe . The downside in this case is that the import libraries break if you use the linker optimization option in MSVC (which is enabled by default).
DirectShow
DirectShow SDK is required for DirectShow capture, supported through the dshow input device. DirectShow support is enabled only through mingw-64 compilation.
For more detailed information related to DirectShow check the dshow section in the FFmpeg manual.
OpenAL
Required for acquiring from the audio device using the OpenAL framework.
Download and install the SDK (the file named like «OpenAL11CoreSDK.zip»), then configure with —enable-openal (you may need to add —extra-cflags and —extra-ldflags for specifying where OpenAL libraries and headers are placed). Note that you may also need to move all the headers in the include dir to a separate «AL» directory, which is where FFmpeg will look for the OpenAL headers.
pkg-config
pkg-config is a program used by many software libraries (FFmpeg included) for determining the compilation flags to use. It is not installed by default by MinGW, so you need to manually install it.
There is also a related MinGW FAQ:
pkg-config can be found at one of these addresses:
At this point you need to install the following packages:
- GLib (Binaries)
- gettext-runtime (Binaries)
- pkg-config (Binaries)
gettext-runtime contains the intl.dll (GNU Internationalization Library) which is required by pkg-config.
Configuring FFmpeg
To configure a basic build you just need to run ./configure in the FFmpeg source directory.
Once you installed all the necessary packages (MinGW is the only strict requirement for building FFmpeg, git is required to update your FFmpeg source), you need to open a MinGW shell, change directory to where you checked out the FFmpeg sources, and configure and make FFmpeg the usual way.
Note that under MinGW, configuring can be painfully slow.
Windows Compilation Tips
- You may want to use Dependency Walker for troubleshooting dependency issues. depends.exe is similar in purpose to ldd .
- Working with a Windows native terminal can be painful, especially if you have a non-US/EN keyboard and you have no means to type special characters like ‘
‘. AutoHotKey is a nice FLOSS project which allows to compose shortcuts and do other nifty things.
More Resources
You can find many resources dedicated to FFmpeg in Windows in:
At this address you can find a MinGW environment used for MPlayer, as well as FFmpeg builds:
The following project has a script for cross compiling lots of FFmpeg dependencies, and may contain hints as to how to get them working with mingw: