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 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
echo 'git config --global core.autocrlf false' >> .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 clone git:// x264
cd x264
./configure --host=x86_64-w64-mingw32 --enable-static --enable-shared && make && make install
cd ..
git clone git:// fdk-aac
cd fdk-aac
./configure --host=x86_64-w64-mingw32 --enable-static --enable-shared && make && make install
cd ..
git clone 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.

You may also want to use --enable-avisynth (64 bit port). SDL is required for ffplay.

Tags: , ,

25 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 > && ./

    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.

  16. Takeshi says:

    Hello George,

    first of all, thank you for a great tutorial. I’ve successfully compiled the 64 bit version, but i’m wondering if these same tools can compile for 32 bit as well. Upon researching a little, i found this configuration: –extra-cflags=-m32 which, supposedly would force the compiler to generate 32 bit binaries, but in my case, it just spat out an error on ./configure saying “gcc is unable to create an executable file. C compiler test failed.”. Seems to me that either the tools aren’t capable of compiling for 32 bits as well as 64 bits or I’m doing something wrong. Will I have to setup two separate tool chains to be able to compile both versions? Also, how would I go about adding libass support? Thank you very much!

  17. Mark Yang says:

    While configuring ffmpeg below error occured

    Unknown OS ‘mingw64_nt-6.1’.

    What was wrong ??

  18. Mark Yang says:

    PNG end/dec feature needed but with your way this features are not working
    How can I use PNG enc/dec .?

  19. Nguyen Phong says:

    Dear Sir,

    With this way only compile ffmpeg and ffprobe. So, how to compile wit ffplay and ffserver. I try some way, but can not successe. Pls help me. Thanks so much.

  20. George Helyar says:

    As per the last line of the article, ffplay can be compiled in this way but requires SDL. I have not tried ffserver.

  21. DC says:

    While executing configure command, I am getting
    Unknown OS ‘msys_nt-6.1’.

    Any idea what might be issue?

    Please let me know.

  22. DC says:

    Getting the following error. Can you please help me with it?

    ERROR: libfdk_aac not found

    THis is the configure command:
    $ ./configure –target-os=mingw32 –enable-version3 –enable-libfdk_aac –enable-static –disable-shared –extra-cflags=-I/local/include –extra-ldflags=’-L/local/lib -static’ && make && make install

  23. George Helyar says:

    You need to build and install the library before trying to use it.

    libfdk_aac is the second build step here, where you git clone fdk-aac, autogen, configure, make and make install.

    It also needs to be able to find it, which is where the extra-cflags and extra-ldflags come into the final configure step.

  24. Mark Eytcheson says:

    No success yet with this. when a run make I get the following:
    C:\Git\mingw64\bin\ar.exe: libavco: No such file or directory
    library.mak:40: recipe for target ‘libavcodec/libavcodec.a’ failed

    The library.mak seems to be cutting off the end of the filenames.
    I am not very familiar with makefiles and am perplexed. Please help?
    The libavfilter and libavdevice libraries built, but then the build stopped.

  25. George Helyar says:

    Hi Mark,

    I have not seen that problem before. It may be related to maximum path sizes. MAX_PATH on Windows is 260 characters. UNC paths have a higher limit but aren’t supported everywhere.

    You could try using subst to map your msys directory to a drive letter, then running msys.bat from there, or just extracting MSYS to a shorter path (I use D:\msys\).

    The “C:\Git\mingw64” seems to imply that you haven’t followed this article, which is related to MSYS and not just MinGW.

Leave a Reply