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:

Check that it has worked with gcc -v

Compile ffmpeg and libraries

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

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.

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

  1. Mic

    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

    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 Post author

    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

    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 Post author

    -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. fasihi01

    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.

  7. George Helyar Post author

    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.

  8. fasihi01

    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!

  9. George Helyar Post author

    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.

  10. KP

    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’

  11. George Helyar Post author

    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.

  12. GranoblasticMan

    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

  13. Eleazar

    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.

  14. George Helyar Post author

    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.

  15. Takeshi

    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!

  16. Mark Yang

    While configuring ffmpeg below error occured

    Unknown OS ‘mingw64_nt-6.1’.

    What was wrong ??

  17. Mark Yang

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

  18. Nguyen Phong

    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.

  19. George Helyar Post author

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

  20. DC

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

    Any idea what might be issue?

    Please let me know.

  21. DC

    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

  22. George Helyar Post author

    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.

  23. Mark Eytcheson

    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.

  24. George Helyar Post author

    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.

  25. Jim Haberly

    This document saved me hours! Thank you so much George for this work.
    I would also love to see how to add x265 if you already have a guide on that.
    Cheers!

  26. George Helyar Post author

    Hi Jim,

    I’ll take a look into compiling x265 in detail at some point. For now, it seems to be a case of installing mercurial, installing cmake, and then cloning the source and running make-x86_64-w64-mingw32-Makefiles.sh, then follow the same procedure as the rest.

    If you have trouble with mercurial (hg) there are also some releases of the x265 source here.

    However, as far as I know, x265 is still not very practical for encoding/playing video yet. The quality is better for the same file size, but much more processing is required to encode/decode it. At the moment, you’re probably better using x264 and encoding at a higher quality CRF, which will produce a larger file than x265 would have but encode faster and play more smoothly (assuming you are not I/O bound) and on more devices. I haven’t looked for a while, so my information may be out of date.

Leave a Reply

Your email address will not be published. Required fields are marked *