wiki:

CompilationGuide

/

MinGW

MinGW/FFmpeg installation guide

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. Note that the only strict requirements 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 CrossCompilingForWindows, 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 at:

http://ffmpeg.org/platform.html#Windows

MinGW/MSys

You basically have two options for a compiler: mingw "mainline" or mingw-w64. Both offer working gcc's for windows. The latter tends to be slightly more up to date than the former, and offers more library compatibility, like DirectShow headers, so preferably use mingw-w64. The instructions here are basically for mingw "mainline", but the two are interchangeable. Basically, you will install one "MinGW" package (MinGW or mingw-w64) and one ("MSys" or "Msys2"), MinGW provides gcc and headers and change, Msys provides shell utilities like make and bash.

mingw-w64

MinGW-w64 (arguably like MinGW but with better header files) can be found at:

http://mingw-w64.sourceforge.net (note this project does not have downloadable compilers by default, you'll probably want the "mingw-builds" project, which provide pre-built compilers, see list of options here: http://stackoverflow.com/a/20502212/32453 and here http://mingw-w64.org/doku.php/download).

To use mingw-w64, basically install Msys using the MinGW setup, as above, but only check the "msys for developers option". Then install a mingw-w64 compiler (see http://ingar.satgnu.net/devenv/mingw32/base.html). Here is an example: http://www.helyar.net/2014/compile-ffmpeg-64-bit-on-windows-with-msysmingw-w64

Then configure your PATH appropriately, for instance mine looks like this: c:\installs\mingw-w64\i686-4.9.2-posix-dwarf-rt_v3-rev0\mingw32\bin;c:\MinGW\msys\1.0\bin... being the beginning of the PATH. In this case, the MINGW_PATH would be C:\installs\mingw-w64\i686-4.9.2-posix-dwarf-rt_v3-rev0\mingw32

Also note that to access directshow input devices you have to use the mingw-w64 as the compiler (or cross compiler), as straight MinGW headers don't have this functionality apparently.

And to install libraries you'd either use ./configure --prefix=/usr/local or--prefix=/c/installs/mingw-w64/i686-4.9.2-posix-dwarf-rt_v3-rev0/mingw32/i686-w64-mingw32

The latter if you wanted to install something to your MINGW_PATH itself...

MinGW

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:

Control Panel -> System -> Advanced -> Edit Environment Variables   

MSYS

Just install it then run its console, you will be able to then run configure (assuming you've installed a gcc to you PATH already).

MSYS2

MSYS2, install it,

https://msys2.github.io/

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:

pacman -S make
pacman -S diffutils
pacman -S yasm

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:

pacman -S mingw-w64-x86_64-gcc
pacman -S mingw-w64-i686-gcc

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

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:

http://git-scm.com/

The recommended installation way is through the msysgit project:

http://msysgit.github.io/

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

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 in:

http://www.tortall.net/projects/yasm/wiki/Download

You'll have to choose between the versions provided (e.g. 32 vs 64 bits), 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

SDL is required for ffplay and the SDL output device, the project website can be looked at:

http://www.libsdl.org/

You need the 1.2 version:

http://www.libsdl.org/download-1.2.php

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.

The bug has been reported here:

http://bugzilla.libsdl.org/show_bug.cgi?id=1237

libx264

libx264 can be compiled and installed in the MinGW+msys environment.

Latest version can be found at this address:

http://www.videolan.org/developers/x264.html

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 recently new OpenAL framework:

http://connect.creativelabs.com/openal

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.

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: configure is sometimes painfully slow in MinGW.

Windows Compilation Tips

  • You may want to use dependency walker for troubleshooting dependency issues:

http://www.dependencywalker.com/

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:

http://www.autohotkey.com/

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:

Last modified 8 months ago Last modified on Dec 30, 2016, 5:24:23 PM