Changes between Version 39 and Version 40 of CompilationGuide/MinGW


Ignore:
Timestamp:
Nov 1, 2017, 3:51:16 PM (3 weeks ago)
Author:
slhck
Comment:

clean up messy guide, add prominent link to autobuild suite as this might work better for everyone (this guide seems outdated/incomplete?)

Legend:

Unmodified
Added
Removed
Modified
  • CompilationGuide/MinGW

    v39 v40  
    11= MinGW/FFmpeg installation guide = 
    22 
     3[[PageOutline(2, Contents)]] 
     4 
     5== Introduction == 
     6 
    37In order to compile FFmpeg on Windows, you need to install the MinGW 
    4 environment and a few tools which are strictly required. 
    5  
    6 The following sections give some indications for installing some of the required components. 
    7 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. 
    8  
    9 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. 
    10  
    11 Some Windows-specific compilation information can be found in the official documentation at: 
    12  
    13 http://ffmpeg.org/platform.html#Windows 
    14  
    15 == MinGW/MSys == 
    16  
    17 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. 
    18  
    19 === mingw-w64 === 
    20  
    21 MinGW-w64 (arguably like MinGW but with better header files) can be found at: 
    22  
    23 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). 
    24  
    25 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 
    26  
    27 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 
    28  
    29 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. 
    30  
    31 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  
    32  
    33 The latter if you wanted to install something to your MINGW_PATH itself... 
    34  
     8environment and a few tools which are strictly required. The following sections give some indications for installing some of the required components. 
     9 
     10{{{ 
     11#!div style="border: 1px solid #c7e5c7; margin: 1em; background-color: #ddffdd;" 
     12'''Tip:''' The [https://github.com/jb-alvarado/media-autobuild_suite 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. 
     13}}} 
     14 
     15Note 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. 
     16 
     17Also note that sometimes it is easier to cross compile, see [[CrossCompilingForWindows|the Cross Compiling guide]], which also may contain some hints/clues for compiling the various dependencies you'd need using MinGW, too. 
     18 
     19Some Windows-specific compilation information can be found in the [http://ffmpeg.org/platform.html#Windows official documentation]. 
     20 
     21== Installing Requirements == 
    3522 
    3623=== MinGW === 
    3724 
    38 Go to: 
    39  
    40 http://www.mingw.org 
    41  
    42 and look for the "Download" page. 
     25You have two options for a compiler: 
     26 
     271. MinGW-w64 
     282. MinGW "mainline" 
     29 
     30Both 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.  
     31 
     32The MinGW package provides `gcc` and headers. 
     33 
     34==== Option 1: MinGW-w64 ==== 
     35 
     36MinGW-w64 can be [http://mingw-w64.sourceforge.net found on SourceForge]. 
     37 
     38This project does not have downloadable compilers by default; you'll probably want the [http://mingw-w64.org/doku.php/download "mingw-builds" project], which provides pre-built compilers. 
     39 
     40To use MinGW-w64, install Msys using the MinGW setup, as above, but only check the "msys for developers option".  Then [http://ingar.satgnu.net/devenv/mingw32/base.html install a MinGW-w64 compiler]. [http://www.helyar.net/2014/compile-ffmpeg-64-bit-on-windows-with-msysmingw-w64 Here] is an example. 
     41 
     42Then configure your PATH appropriately, for instance mine looks like this: 
     43 
     44{{{ 
     45c:\installs\mingw-w64\i686-4.9.2-posix-dwarf-rt_v3-rev0\mingw32\bin;c:\MinGW\msys\1.0\bin; ... 
     46}}} 
     47 
     48In this case, the `MINGW_PATH` would be: 
     49 
     50{{{ 
     51C:\installs\mingw-w64\i686-4.9.2-posix-dwarf-rt_v3-rev0\mingw32 
     52}}} 
     53 
     54To 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. 
     55 
     56To install libraries you'd either use 
     57 
     58{{{ 
     59./configure --prefix=/usr/local 
     60}}} 
     61 
     62or 
     63 
     64{{{ 
     65./configure --prefix=/c/installs/mingw-w64/i686-4.9.2-posix-dwarf-rt_v3-rev0/mingw32/i686-w64-mingw32  
     66}}} 
     67 
     68The latter if you wanted to install something to your `MINGW_PATH` itself. 
     69 
     70==== Option 2: MinGW "mainline" ==== 
     71 
     72Go to http://www.mingw.org and look for the "Download" page. 
    4373 
    4474The recommended way to install MinGW/MSys is through the automated 
    45 installer, mingw-get-setup.exe. 
     75installer, `mingw-get-setup.exe`. 
    4676 
    4777This will download most of the basic core packages. It will usually 
    48 install in C:\MinGW but you can define the installation path when 
    49 configuring, note down this path (that we will call as "MinGW path" or 
    50 $MINGW_PATH later in this guide). 
     78install in `C:\MinGW` but you can define the installation path when 
     79configuring. Note down this path (that we will call as "MinGW path" or 
     80`MINGW_PATH` later in this guide). 
    5181 
    5282Once you install MinGW you should see in the Windows menu the "MinGW" 
    53 entry with the option "MinGW shell". Click on it and it will launch a terminal with a bash shell. This is 
    54 supposed to be a GNU/Unix environment, and you're supposed to know a 
    55 bit of UNIX commands for getting through it. Alternatively, or in case the MinGW entry is missing, you need to manually 
    56 launch the MINGW_PATH/msys/1.0/msys.bat file. 
    57  
    58 MinGW adopts a mounting mechanism to make Windows directories appear like 
    59 native UNIX-like paths. Check the output of the mount command, and 
     83entry 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. 
     84 
     85MinGW adopts a mounting mechanism to make Windows directories appear like native UNIX-like paths. Check the output of the mount command, and 
    6086familiarize yourself with the mapping mechanism. In the rest of the 
    6187guide, when not explicitly specified, we'll use the UNIX mapped 
    6288paths. 
    6389 
    64 Note that by default the user home will be placed in MINGW_PATH/msys/1.0/home/USER, 
    65 and that will be your working directory of the msys shell. 
    66  
    67 Finally, you need to edit the system environment {{{Path}}} variable, adding the MINGW_PATH/bin directory. This will allow both the system 
    68 and the msys shell to find programs provided by MinGW. This can be done for example with:  
     90Note 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. 
     91 
     92Finally, you need to edit the system environment {{{PATH}}} variable, adding the MINGW_PATH/bin directory. This will allow both the system 
     93and the msys shell to find programs provided by MinGW. This can be done for example with: 
     94 
    6995{{{ 
    7096Control Panel -> System -> Advanced -> Edit Environment Variables    
    7197}}} 
    7298 
    73 === MSYS === 
    74  
    75 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). 
    76  
    77 === MSYS2 === 
    78  
    79 MSYS2, install it, 
    80  
    81 https://msys2.github.io/ 
    82  
    83  
    84 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. 
     99=== MSys === 
     100 
     101Msys provides shell utilities like `make` and `bash`. Choose either MSys or MSYS2. 
     102 
     103==== Option 1: MSYS ==== 
     104 
     105Just install MSys from http://www.mingw.org/wiki/msys. 
     106 
     107Then run its console. You will be able to then run `configure` (assuming you've installed a `gcc` to your `PATH` already). 
     108 
     109==== Option 2: MSYS2 ==== 
     110 
     111Install MSYS2 from https://msys2.github.io/. 
     112 
     113Then 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. 
    85114 
    86115Now install requisite packages: 
     
    92121}}} 
    93122 
    94 Alternatively, you can also install GCC from MSYS2 system itself, and not need any of the mingw-w64 instructions above: 
     123Alternatively, you can also install GCC from MSYS2 system itself, and not need any of the MinGW-w64 instructions above: 
    95124 
    96125MSYS2 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: 
     126 
    97127{{{ 
    98128pacman -S mingw-w64-x86_64-gcc 
     
    106136Unfortunately 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. 
    107137 
    108 === MinGW installation style === 
     138=== MinGW Installation Style === 
    109139 
    110140It is a good norm to keep the locally installed packages 
    111 separated from the MinGW/MSys packages. For this reason we recommend to use 
    112 /usr/local for locally installed files. That means that packages will 
    113 be configured with --prefix=/usr/local, for removing the local 
    114 packages it will be sufficient to erase the /usr/local directory. 
     141separated 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 
     142packages it will be sufficient to erase the `/usr/local` directory. 
    115143 
    116144This should also avoid conflicts with MinGW/MSys. 
    117145 
    118 == Git == 
     146=== Git === 
    119147 
    120148Git is the source code control system used by FFmpeg, and you need it 
    121149for downloading and updating the source code. 
    122150 
    123 The official Git project site is: 
    124  
    125 http://git-scm.com/ 
    126  
    127 The recommended installation way is through the msysgit project: 
    128  
    129 http://msysgit.github.io/ 
     151The official Git project site [http://git-scm.com/ is here]. The recommended installation way is through the [https://git-for-windows.github.io/ Git for Windows] project. 
    130152 
    131153The autoinstaller will create a separate Msys environment for Git.  In 
     
    136158 
    137159In particular, you need to: 
    138 * fix the HOME variable, so that it will point to 
    139   $MINGW_PATH/msys/1.0/home/$USER 
    140  
    141 * edit the path, so that the git bin and cmd paths are located '''after''' 
    142   the corresponding MinGW bin directory. 
    143  
    144  
    145 == yasm == 
    146  
    147 yasm is a non-strict requirement, it allows for optimized compilation 
    148 so it is recommended to install it. 
    149 The easiest way to install it for Windows is by simply downloading the 
    150 binary provided in: 
    151  
    152 http://www.tortall.net/projects/yasm/wiki/Download 
     160 
     161* Fix the HOME variable, so that it will point to `$MINGW_PATH/msys/1.0/home/$USER` 
     162 
     163* Edit the path, so that the git bin and cmd paths are located '''after''' the corresponding MinGW bin directory. 
     164 
     165=== YASM === 
     166 
     167YASM is a non-strict requirement; it allows for optimized compilation 
     168so it is recommended to install it. The easiest way to install it for Windows is by simply downloading the 
     169[http://www.tortall.net/projects/yasm/wiki/Download binary provided]. 
    153170 
    154171You'll have to choose between the versions provided (e.g. 32 vs 64 
    155 bits), download and install it in /usr/local/bin or in /bin. 
     172bit), download and install it in `/usr/local/bin` or in `/bin`. 
    156173 
    157174Since the name of the binary is usually suffixed with the program 
    158 version (e.g. it is named "yasm-1.1.0-win32.exe"), you need to create 
    159 a copy named "yasm", so it can be invoked by using simply "yasm". 
     175version (e.g. it is named `yasm-1.1.0-win32.exe`), you need to create 
     176a copy named `yasm`, so it can be invoked by using simply `yasm`. 
    160177 
    161178Alternatively you may install the source version and compile it. 
     
    164181Microsoft Visual C++ 2010 SP1 Redistributable Package from Microsoft. 
    165182 
    166  
    167 == SDL == 
    168  
    169 SDL is required for ffplay and the SDL output device, the project 
    170 website can be looked at: 
    171  
    172 http://www.libsdl.org/ 
    173  
    174 You need the 1.2 version: 
    175  
    176 http://www.libsdl.org/download-1.2.php 
    177  
    178 Once installed in the MINGW_PATH, the FFmpeg configure should be able to auto-detect it. 
     183=== SDL === 
     184 
     185SDL is required for ffplay and the SDL output device. You need the [http://www.libsdl.org/download-1.2.php 1.2 version]. 
     186 
     187Once installed in the `MINGW_PATH`, the FFmpeg `configure` should be able to auto-detect it. 
    179188 
    180189Note that SDL flags, as issued by sdl-config/pkg-config, contain the 
    181 -mwindows flag which will prevent applications to log on console. As a 
    182 workaround you'll need to remove that flag, e.g. by editing the 
     190`-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 
    183191sdl-config script or the SDL pkg-config file in lib. 
    184192 
    185 The bug has been reported here: 
    186  
    187 http://bugzilla.libsdl.org/show_bug.cgi?id=1237 
    188  
    189 == libx264 == 
    190  
    191 libx264 can be compiled and installed in the MinGW+msys environment. 
    192  
    193 Latest version can be found at this address: 
    194  
    195 http://www.videolan.org/developers/x264.html 
    196  
    197 if you want libx264.dll files (instead of static) you should use the {{{--enable-shared}}} configure option. 
     193The bug has been reported here: http://bugzilla.libsdl.org/show_bug.cgi?id=1237 
     194 
     195=== libx264 === 
     196 
     197[http://www.videolan.org/developers/x264.html libx264] can be compiled and installed in the MinGW+MSys environment. 
     198 
     199If you want libx264.dll files (instead of static) you should use the {{{--enable-shared}}} configure option. 
    198200 
    199201The 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. 
    200202 
    201 == lib.exe == 
    202  
    203 lib.exe is required for creating .dll.a import stub libraries, so that 
    204 you can link to the DLLs from MSVC (Microsoft Visual Studio compiler, 
    205 bundled with it), if you are planning on creating a DLL style FFmpeg build and need/want to do that. 
    206  
    207 lib.exe is a Microsoft tool used for creating DLL files. It is bundled 
    208 together with Visual Studio. Microsoft Visual Studio Express download 
    209 is available for free. Once installed you'll need to add the directory 
    210 where lib.exe is located to the system Path. 
    211  
    212 dlltool.exe (which is part of binutils) may be used instead of 
    213 lib.exe. The downside in this case is that the import libraries break 
     203=== lib.exe === 
     204 
     205`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. 
     206 
     207`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. 
     208 
     209`dlltool.exe` (which is part of binutils) may be used instead of 
     210`lib.exe`. The downside in this case is that the import libraries break 
    214211if you use the linker optimization option in MSVC (which is enabled by 
    215212default). 
    216213 
    217  
    218 == !DirectShow == 
     214=== !DirectShow === 
    219215 
    220216!DirectShow SDK is required for !DirectShow capture, supported through 
     
    223219For more detailed information related to !DirectShow check the dshow section in the FFmpeg manual. 
    224220 
    225 == OpenAL == 
    226  
    227 Required for acquiring from the audio device using the recently new 
    228 OpenAL framework: 
    229  
    230 http://connect.creativelabs.com/openal 
     221=== OpenAL === 
     222 
     223Required for acquiring from the audio device using the 
     224[http://connect.creativelabs.com/openal OpenAL framework]. 
    231225 
    232226Download and install the SDK (the file named like 
    233 "OpenAL11CoreSDK.zip"), then configure with --enable-openal (you may 
    234 need to add --extra-cflags and --extra-ldflags for specifying where 
     227"OpenAL11CoreSDK.zip"), then configure with `--enable-openal` (you may 
     228need to add `--extra-cflags` and `--extra-ldflags` for specifying where 
    235229OpenAL libraries and headers are placed). Note that you may also need 
    236230to move all the headers in the include dir to a separate "AL" 
    237231directory, which is where FFmpeg will look for the OpenAL headers. 
    238232 
    239  
    240 == pkg-config == 
     233=== pkg-config === 
    241234 
    242235pkg-config is a program used by many software libraries (FFmpeg 
     
    248241 
    249242pkg-config can be found at one of these addresses: 
     243 
    250244* http://www.gtk.org/download/win32.php 
    251245* http://www.gtk.org/download/win64.php 
     
    260254Library) which is required by pkg-config. 
    261255 
    262  
    263 == FFmpeg == 
    264  
    265 To configure a basic build you just need to run configure in the 
     256== Configuring FFmpeg == 
     257 
     258To configure a basic build you just need to run `./configure` in the 
    266259FFmpeg source directory. 
    267260 
    268 Once you installed all the necessary packages (MinGW is the only strict requirement for building FFmpeg, git is required to update your FFmpeg source), 
    269 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. 
    270  
    271 NOTE: configure is sometimes painfully slow in MinGW. 
    272  
     261Once 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. 
     262 
     263Note that under MinGW, configuring can be painfully slow. 
    273264 
    274265== Windows Compilation Tips == 
    275266 
    276 * You may want to use dependency walker for troubleshooting dependency issues: 
    277  
    278   http://www.dependencywalker.com/ 
    279  
    280   depends.exe is similar in purpose to ldd. 
     267* You may want to use [http://www.dependencywalker.com/ Dependency Walker] for troubleshooting dependency issues. `depends.exe` is similar in purpose to `ldd`. 
    281268 
    282269* Working with a Windows native terminal can be painful, especially if 
    283270  you have a non-US/EN keyboard and you have no means to type special 
    284   characters like '~'. 
    285  
    286   autohotkey is a nice FLOSS project which allows to compose shortcuts 
    287   and do other nifty things: 
    288  
    289   http://www.autohotkey.com/ 
    290  
    291 == More resources == 
     271  characters like '~'. [http://www.autohotkey.com/ AutoHotKey] is a nice FLOSS project which allows to compose shortcuts and do other nifty things. 
     272 
     273== More Resources == 
    292274 
    293275You can find many resources dedicated to FFmpeg in Windows in: 
     276 
    294277* http://ffmpeg.zeranoe.com/  
    295  
    296 * http://wiki.ivonet.nl/display/howto/HowTo+build+MPLayer+with+Mingw is a useful wiki 
     278* http://wiki.ivonet.nl/display/howto/HowTo+build+MPLayer+with+Mingw 
    297279 
    298280At this address you can find a MinGW environment used for MPlayer, as well as FFmpeg builds: 
     281 
    299282* http://oss.netfarm.it/mplayer-win32.php 
    300283* http://sourceforge.net/projects/mplayer-win32/files/MinGW/MinGW%20BE%20gcc%204.2.5/MinGW-full-gcc-4.2.5-Dec-2010.7z/download 
    301284 
    302 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:  
     285The 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: 
     286 
    303287* https://github.com/rdp/ffmpeg-windows-build-helpers 
    304288* https://github.com/jb-alvarado/media-autobuild_suite