Compile ffmpeg 64 bit on Windows with MSYS/MinGW-w64

Set up the MSYS environment

Download MSYS from MinGW-builds. Extract it to a path with no spaces, to which you have write permissions. For example, D:\msys. This already includes useful features like pkg-config, Autotools and Git.

Download a pre-built MinGW-w64 from drangon.org and extract it inside the MSYS directory. This already includes useful features like Yasm.

Start MSYS with msys.bat

In MSYS, run:

echo 'export PATH=.:/local/bin:/bin:/mingw64/bin' > .profile
source .profile

Check that it has worked with gcc -v

Compile ffmpeg and libraries

These steps are similar to the Linux/BSD version of this guide.

git config --global core.autocrlf false
 
git clone git://git.videolan.org/x264.git x264
cd x264
./configure --host=x86_64-w64-mingw32 --enable-static --enable-shared && make && make install
cd ..
 
git clone git://github.com/mstorsjo/fdk-aac.git fdk-aac
cd fdk-aac
./autogen.sh
./configure --host=x86_64-w64-mingw32 --enable-static --enable-shared && make && make install
cd ..
 
git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg
cd ffmpeg
./configure --enable-gpl --enable-nonfree --enable-libx264 --enable-libfdk_aac --enable-static --disable-shared --extra-cflags=-I/local/include --extra-ldflags='-L/local/lib -static' && make && make install

NOTE: configure on ffmpeg in mingw is slow. Be patient. You should also check for success after each library has compiled.

This should build ffmpeg.exe as a 64 bit static executable that can be run directly in Windows x64, with H.264 and AAC support. It does not need to be run from MSYS. In my testing, the 64 bit version is approx. 10% faster than the 32 bit version.

If you want it to use DLLs instead of creating a static executable, change --disable-shared to --enable-shared and remove the -static from the ldflags in the ffmpeg configure.

Tags: , ,

15 Responses to “Compile ffmpeg 64 bit on Windows with MSYS/MinGW-w64”

  1. Mic says:

    interesting, i find your expertise of visual basics, and coding very nice. And its funny because the codes are not too complex and hard to understand, and they have such simplistic but precise workings. If it isnt too much, George, do you think you could email me, i have a request to you, that i would like to know if you can do. which im sure you probably can.

  2. gaccy says:

    hi george i need this guide for windows xp 32
    i follow all of it but it stuck with libx264 not found
    what should i do

  3. George Helyar says:

    Hi gaccy,

    The guide is much the same for 32 bit Windows.

    For MSYS/MinGW, you can just use the MinGW-builds installer. You need to install the packages that I mentioned as already being bundled above (pkg-config [you can use pkg-config-lite], Autotools, Git, Yasm).

    Once you have that set up, it should be the same.

    You need to use git to download the source of x264, build it, install it and make sure that when you build ffmpeg, it knows where to find it (--extra-cflags and --extra-ldflags in the final configure line). This is what the shell commands above already do anyway though.

  4. gaccy says:

    hi george thanks for reply
    i found the problem is on this line
    –extra-ldflags=’-L/local/lib -static’
    if i delete the “-static” it should be fine
    but idk if it will become different build
    whats that -static function

  5. George Helyar says:

    -static makes it a static binary.

    This means that it puts all of the code it needs into one big executable. If you remove this, it should still work and the executable file will be smaller, but you will need to make sure you have all of the DLLs (libx264.dll, libavfilter, etc) in the same place.

  6. gaccy says:

    see… i got it
    thanks george

  7. fasihi01 says:

    I had to rename make.exe in msys\mingw64 to avoid the error “process_begin: CreateProcess(NULL, /bin/mkdir -p libAACdec/src, …) failed.” in the fdk-aac make step. It seems mingw binaries override msys binaries…

    also, i had run

    git config --global core.autocrlf false

    before cloning the ffmpeg repository.

  8. George Helyar says:

    Hi fasihi01, I also had the CreateProcess problem during my testing, although my solution was just to get make to output to a file and then run that as a shell script (make -n > build.sh && ./build.sh).

    I also ran into the auto CRLF problem during my testing, but I found that it was only applicable to external git binaries e.g. if you get msysgit and run its git.exe from within MSYS.

    Neither of these problems occurred when using the pre-built MSYS or MinGW-w64 that I linked in the post.

  9. fasihi01 says:

    Hi George,
    I followed your tutorial step by step, using the linked versions of MSYS and MinGW, and ran into the described problems.
    Anyway, thank you very much for this great tutorial!

  10. George Helyar says:

    Assuming that the files that I linked have not changed since the time of writing and that you extracted MinGW-w64 to the correct directory, this may happen if you already have an external git.exe on your system path, for example.

    You can change the order of precedence of your path by changing the PATH environment variable in your .profile. “.:/local/bin:/mingw64/bin:/bin” should first look for binaries in the current directory, then locally built binaries, then the MinGW-w64 binaries, then the MSYS binaries. If you want MSYS binaries to override MinGW binaries, /bin should be before /mingw64/bin.

    Once you have changed this file, “source .profile” runs the .profile script immediately so that the changes take effect. It is normally run automatically when you start MSYS.

    You can tell which is being run by running “which make“. /mingw64/bin/make and /bin/git both work correctly for me with no changes necessary.

  11. KP says:

    Was able to generate ffmpeg from git command. When I am adding ‘lib…codec’ of 3rd party and modify config, common.mak, Makefile and allcodecs.c file, getting error at ffmpeg_g.exe as undefined reference to ‘func name’

  12. George Helyar says:

    Hi KP,

    You need to compile the libraries on which ffmpeg depends according to your configure. You should not be modifying makefiles or source files manually. You add parameters to the configure such as --enable-libx264 to add that codec, and libx264 (in this example) must be compiled and available to the linker. The .a (static) and .so (shared) should be in /lobal/lib and you should configure with -L/local/lib ldflags as shown above to use them.

  13. Thanks for this little how-to. I’ve been having a surprisingly difficult time setting up a sane build environment with mingw/msys. I suspect the other guides I was looking at were a bit dated.

    No build errors this time! =D

  14. Eleazar says:

    Hi George thanks for the tutorial is great, I just have one problem with the ffmpeg configure command which yields this ” ERROR: libfaac not found” any help will be greatly appreciated.

  15. George Helyar says:

    Hi Eleazar,

    For AAC audio, it should be using libfdk_aac rather than libfaac. If you want to use libfaac instead, you can. The instructions are on the Linux/BSD version of this guide. However, I recommend switching to libfdk_aac, which is supposedly better, although I can’t hear the difference. Neither project has been updated recently, but libfdk_aac has been updated more recently than libfaac.

    This page should work with no mention of libfaac.

Leave a Reply