Building ffmpeg for Windows with MSYS and MinGW
It took me the better part of a day to convince the snotty ffmpeg source code that it’s quite alright to be compiled under Windows even if it was written originally for Linux.
For those of you who don’t know what ffmpeg is and for some reason are still reading this, ffmpeg is a library of codecs for every conceivable audio and video format out there. The best part about it is that it doesn’t depend on the codecs you have installed on your system (which is a particular nightmare on Windows-based machines).
As for me, I was trying to extract the first image of video files to use as thumbnails in a video upload tool I’m working on.
We’ll start with downloading some tools of the trade and the source for ffmpeg.
- Download MinGW from here.
- Download MSYS from here.
- Download updated bash for MSYS from here.
- Get the latest snapshot of ffmpeg from here (here’s a direct link).
Let’s install the tools.
- Install MinGW (choose “MinGW base tools” and “MinGW make”) into c:\mingw
- Install MSYS into c:\msys\1.0
- After MSYS installation it will run a postinstall script. It will ask you some questions which you should answer as following:
Do you wish to continue with the post install? [yn ] -> y
Do you have MinGW installed? [yn ] -> y
Where is your MinGW installation? -> C:/mingw - Copy bash-2.05b-MSYS.tar.bz2 to c:\msys\1.0 and extract it (bash.exe should go into C:\MSYS\1.0\bin).
We need to do this because ffmpeg’s configure script doesn’t work with bash 2.0.4 that comes with MSYS. - Extract the ffmpeg sources. I’ll assume you’ve extracted them to c:\work\ffmpeg .
Now it’s time to build the library.
- Create a file called myconfig in c:\work\ffmpeg and copy the following into it:
#!/bin/sh
./configure –extra-cflags="-mno-cygwin -mms-bitfields"
–extra-ldflags="-Wl,–add-stdcall-alias" –enable-memalign-hack
–target-os=mingw32 –enable-shared –disable-static - Run c:\msys\1.0\msys.bat. Run the following commands in the shell that starts:
$ cd /c/work/ffmpeg
$ ./myconfig
$ make - In order to run ffmpeg.exe, collect the binary files and put them together in one folder:
ffmpeg\ffmpeg.exe
ffmpeg\libavcodec\avcodec-51.dll
ffmpeg\libavformat\avformat-51.dll
ffmpeg\libavutil\avutil-49.dll
31 Comments on “Building ffmpeg for Windows with MSYS and MinGW”
I’m following that perfectly (except for fixing the switch prefixes) and I get:
Unknown option “–enable-mingw32″.
See ./configure –help for available options.
and when I remove –enable-mingw32 I get:
gcc is unable to create an executable file.
If gcc is a cross-compiler, use the –cross-compile option.
Only do this if you know what cross compiling means.
C compiler test failed.
If you think configure made a mistake, make sure you are using the latest
version from SVN. If the latest version fails, report the problem to the
ffmpeg-devel@mplayerhq.hu mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file “config.err” produced by configure as this will help
solving the problem.
what’s going on here
They seem to have removed the –enable-mingw32 option and offer to use –target-os=mingw32 instead. I’ve updated the post.
Thanks for letting me know.
The link for updated bash is source, not binary.
Sorry about that crabby last comment, I’m actually very grateful that there’s at least one place on the web that bothers to go into this stuff properly - thank you.
It looks like ./configure has gone through more changes since you wrote this - it no longer seems to like a lot of the options specified here, and also when I try to get around that I get the error “line 181: pr: command not found” a few dozen times.
If you do figure out how to do this with the current version of ./configure, please post it here so I could update the post.
>“line 181: pr: command not foundâ€
it’s in the faq,
pr is not part of the main msys,
you need to get it from coreutils
http://sourceforge.net/project/showfiles.php?group_id=2435&package_id=24963&release_id=46827
So, how do we build ffmpeg for windows, but using a linux host, with cross-compiling ?
That’s a bit out of my league I’m afraid.
hello when i try to do ./myconfig it give me some error like that and i really dont know of to fixe the problem:
$ ./myconfig
Broken shell detected. Trying alternatives.
Trying shell bash
Unknown option “–extra-cflags=-mno-cygwin”.
See ./configure –help for available options.
./myconfig: –extra-ldflags=-Wl,–add-stdcall-alias: command not found
./myconfig: –target-os=mingw32: command not found
I have installed all stuff with upgrade 2.05 for msys. the bash.exe is in the bin folder and others extracted folders are added to 1.0 folder.
Last Question is the last ffmpeg from svn have the ‘-vhook’ option includ if we build like you do ?
Great guide, thanks! To comment on the previous posts:
Link to the binary bash:
http://downloads.sourceforge.net/mingw/bash-2.05b-MSYS.tar.bz2
This config worked for me (removed most of the arguments):
#!/bin/sh
./configure –enable-memalign-hack
Hi,
I followed these instructions to install ffmpeg.
I installed MinGW and MSYS according to the instructions. Also included bash.exe.
./myconfig does not work.
Shows the error message…..
Unknown option “–extra-cflags=-mno-cygwin”.
See ./configure –help for available options.
./myconfig.txt: line 3: –extra-ldflags=-Wl,–add-stdcall-alias: command not found
./myconfig.txt: line 4: –target-os=mingw32: command not found
I also included –enable-vhook
But error message will come.
[./configure ....] is one line.
not copy! Otherwise be splited 3 lines.
Hello friends I have same error. I download batch File.
$ ./myconfig
Broken shell detected. Trying alternatives.
Trying shell bash
Unknown option “–extra-cflags=-mno-cygwin”.
See ./configure –help for available options.
./myconfig: –extra-ldflags=-Wl,–add-stdcall-alias: command not found
./myconfig: –target-os=mingw32: command not found
Can u please slove this Issue? I am very near to do it but now I am totally stuck in the middle.
please any help?
Harpal
how can i use these tools to compile ffmpeg for
linux.
Red Hat Enterprise Linux 5 PAE 2.6.18-8.el5PAE
is our shared server.
how to include the lame libraries within an ffmpeg binary for a linux version using MINGW.
Hello friend,
I did it on windows xp and it is great.
I will suggest you to read the things very carefully.
I am so happy now.
harpal
Substitute all the “-” typing the “-” after copy/paste all the instructions on the myconfig file… That’s the problem.
Ando also use 2 “-”, like this:
#!/bin/sh
./configure –extra-cflags=”-mno-cygwin -mms-bitfields” –extra-ldflags=”-Wl,-add-stdcall-alias” –enable-memalign-hack –target-os=mingw32 –enable-shared –disable-static
The problem is that when we post here, 2 — turn into 1 -. For instance, I’ve written –(two )extra-cflags=…. and maybe you’ll see just - (one)
I did all as the instruction,but i got some troubles, error is:
$ ./myconfig
error, no memalign() but sse enabled, either disable it or use –enable-memalign-hack
(I really don’t know which positions is used with 2 –)
I am also getting the memalign error:
“Error, no memalign() but SSE enabled, disable it or use –enable-memalign-hack.”
I have an old Athlon Thunderbird CPU that doesn’t have SSE.
Anyone know a solution?
Hi all,
Thanks for your posts. I could install MINGW + MSYS with the new bash and configure FFMPEG using the mycompile script. Great.
However, the make fails. It gives a lot of “undefined reference”. A few examples below:
c:/ffmpeg/libavutil/log.c:45: undefined reference to ‘__getreent’
c:/ffmpeg/libavutil/mem.c:45: undefined reference to ‘memalign’
Do you know what could be the problem ? Do I miss a library ?
Hi,
I followed all your steps to complie the FFMpeg, but after I run the ./myconfig in the mingw32, there’s errers : ”
gcc is unable to create an executeable file.
C compiler test failed.
”
Could you please help me ? what I should do to fix this problem ? Thank you very much.
If possible, could we make friends ?
msn : netwheat@hotmail.com
skype : iamwheat
yahoo : wheatinthesky
Regards
Richard
The solution is as followed:
download the coreutils and in the myconfig just put:
#!/bin/sh
./configure –extra-cflags=”-mno-cygwin -mms-bitfields” –extra-ldflags=”-Wl,-add-stdcall-alias” –enable-memalign-hack –target-os=mingw32 –enable-shared –disable-static
=>- becomes — only when it’s between “” it’s a single -
Greetings
Hi, I am green at this and need help. I have followed the guide up to the point of executing the Make command.I am getting the message ***No rule to make target ‘libavdevice/avdevide.dll’needed by ‘all’ .Stop
How do I resolve this?
regards Keka
Extract coreutils downloaded from http://downloads.sourceforge.net/mingw/coreutils-5.97-MSYS-1.0.11-snapshot.tar.bz2?modtime=1188741011&big_mirror=1
into c:/msys/1.0 so that it overwrites items in subdirs (bin, lib, etc.) I opened the .tar.bz2 with 7zip, went down 2 levels, highlighted the 4 or 5 folders, copied them and pasted in c:\mingw.
decend to c:\mingw\libexec\mingw32\3.45\
copy the 6 .exe’s there.
ascend to c:\mingw\bin
paste.
Update make:
download from http://downloads.sourceforge.net/mingw/make-3.81-MSYS-1.0.11-2.tar.bz2?modtime=1206477681&big_mirror=1
extract bin and share folder to c:\msys\1.0 (allow to overwrite)
start c:\msys\1.0\msys.bat
type out:
./configure –extra-cflags-”-mnt-cygwin -mms-bitfields” –extra-ldflags=”-Wl, -add-stdcall-alias” –enable-memalign-hack –enable-shared –disable-static –target-os=mingw32_nt-6.0
double - before ‘extra’ ‘enable’ ‘disable’ and ‘target’. Wl is a capital W and a small L.
**target OS I put mingw32_nt-6.0. My windows boot is Vista. Not sure if it is required to be that way but it worked.
(or you can put in myconfig and run c/work/ffmpeg/myconfig. I’m just used to typing out ./configure lines because I end up compiling a lot of stuff on linux and the myconfig method seems like the long way around to me.)
Run make, et voila! Enjoy.
ADDENDUM:
You will also need ffmpeg/libavdevice/avdevice-52.dll
(and avformat is avformat-52.dll with latest ffmpeg)
Happy ffmpeging
Hi, nice guide! I followed all your steps, and I have made all the dll (avcodec-51.dll, avformar-52.dll, avutil-49.dll and avdevice-52.dll) but I have another problem!
When I want to encode a frame with Visual Studio and I use the avcodec_encode_video, at the second call of this function there is an exception:
Eccezione first-chance occurred in avcodec-51.dll in EncodeMpeg4.exe: 0xC00000FD: Stack overflow.
Eccezione non gestita occurred in avcodec-51.dll in EncodeMpeg4.exe: 0xC00000FD: Stack overflow.
Someone tell me there is a problem with the stack alignment.
This kinf of error appear only when I encode a frame (AVPicture in PIX_FMT_YUV420P) not appear when I decode a stream of byte with the avcodec_decode_video.
Obviously I have made any kind of initialization like avcodec_init, av_register_all, avcodec_register_all, …
Any idea?
Thanx in advance :)
The following myconfig worked for me
./configure –extra-cflags=”-mno-cygwin -mms-bitfields” –extra-ldflags=”-Wl -add-stdcall-alias” –enable-memalign-hack –target-os=mingw32 –enable-shared –disable-static
How ever I had to make some changes to msys to get all of this to work properly
1)Install msysDTS (msysDTK-1.0.1.exe)
2)Install MSYS Core 1.0.11. (msysCORE-1.0.11-2007.01.19-1.tar.bz2)
3)Install msys coreutils (coreutils-5.97-MSYS-1.0.11-snapshot.tar.bz2)
4)Update bash to v.31 (bash_3.1_MSYS-1.0.11)
5)Update make to version 3.81 (make-3.81-MSYS-1.0.11-2)
got all of the above from http://downloads.sourceforge.net/mingw/
or
http://sourceforge.net/project/showfiles.php?group_id=2435
Then compile went cleanly..
Hope this helps some of the folks..
One other thing.. as Jer noted above…
ALL configure options are preceded with a DOUBLE DASH.
…this discussion board strips off the double dash i just noticed, so when you cutr and paste you will get errors unless you put them back
./configure —extra-cflags=”-mno-cygwin -mms-bitfields” —extra-ldflags=”-Wl -add-stdcall-alias” —enable-memalign-hack —target-os=mingw32 —enable-shared —disable-static