FFmpeg & cross-compiling for Windows on Linux
Lately I have been trying to look into compiling ffmpeg for windows/mac/linux as a standalone executable. Compiling for Linux and Mac is pretty straightforward, however for Windows, it’s not that easy. I figured others would have issues too so here’s a quick summary of my experiments.
To compile FFmpeg for Windows, the recommended way is to leverage MinGW. You can set up MinGW on Windows or you can install it on a Linux box as a cross-compiler. Since I already had setup a Debian as a VM running inside VMWare Workstation for compiling FFmpeg on Linux, I figured I’d go that way.
A typical setup would be:
1. Download latest ffmpeg
2. Install gcc & mingw:
% apt-get install build-essentials
% apt-get install mingw
3. Compile ffmpeg
% ./configure –target-os=mingw32 –cross-prefix=i386-mingw32msvc-
Unfortunately, it would be too easy, right. You end up with this error most likely:
ERROR: MinGW runtime version must be >= 3.15.
so what versions do we have installed you say?
% su -
% apt-get install apt-show-versions
% apt-show-versions mingw32-runtime
mingw32-runtime/unstable uptodate 3.13-1
Yep. The latest and greatest mingw runtime debian package is 3.13.
So, I am going to show you how to upgrade it to 3.15 now. First, we need to download the 3.13 sources:
% apt-get build-dep mingw32-runtime
% apt-get source mingw32-runtime
This should download 3 files in your current directory:
mingw32-runtime_3.13-1.dsc
mingw32-runtime_3.13.orig.tar.gz
mingw32-runtime_3.13-1.diff.gz
and create the mingw32-runtime-3.13 folder.
Next we want to update with the latest MinGW sources:
% cd mingw32-runtime-3.13/upstream
% ls
mingw-runtime-3.13-20070825-1-src.tar.gz w32api-3.10-src.tar.gz
You need to go to the MinGW download site and download the 3.15 MinGW runtime and 3.13 Win32 API tar files.
% wget http://downloads.sourceforge.net/project/mingw/MinGW%20Runtime/mingwrt-3.15/mingwrt-3.15-mingw32-src.tar.gz
% wget http://downloads.sourceforge.net/project/mingw/MinGW%20API%20for%20MS-Windows/Current%20Release_%20w32api-3.13/w32api-3.13-mingw32-src.tar.gz
Unfortunately, the paths are not correct and you need to change a few things. We need to untar the downloaded files, rename the exported folder and re-tar so that the debian build is happy.
% tar -zxf mingwrt-3.15-mingw32-src.tar.gz
% mv mingwrt-3.15-mingw32 mingw-runtime-3.15
% tar -czf mingw-runtime-3.15-src.tar.gz mingw-runtime-3.15
% rm -rf mingw-runtime-3.15
Same thing for W32 Api:
% tar -zxf w32api-3.13-mingw32-src.tar.gz
% mv w32api-3.13-mingw32 w32api-3.13
% tar -zcf w32api-3.13-src.tar.gz w32api-3.13
% rm -rf w32api-3.13
Now remove the old stuff so that it doesn’t get confused:
% rm mingw-runtime-3.13-20070825-1-src.tar.gz
% rm mingwrt-3.15-mingw32-src.tar.gz
% rm w32api-3.13-mingw32-src.tar.gz
% rm w32api-3.10-src.tar.gz
Now you should have only 2 tars in the folder:
% ls
mingw-runtime-3.15-src.tar.gz w32api-3.13-src.tar.gz
Great. Now before we rebuild, we need to update the change log
% cd ..
% vim debian/changelog
Edit it so that the top now refers to new version 3.15:
mingw32-runtime (3.15-1) unstable; urgency=low
* runtime-3.15 / w32api-3.13
-- your_name < your_email > Sun, 13 Sep 2009 15:17:51 -0700
Alternatively you can download my version:
% wget http://plutinosoft.com/stuff/changelog
% mv changelog debian/
Great. You should have everything ready now to rebuild the debian package. In case you’ve had issues following the previous section, you can download my already updated folder or jump directly to building it:
% wget http://plutinosoft.com/stuff/mingw32-runtime-3.15.tar.gz
% tar -xzvf mingw32-runtime-3.15.tar.gz
% cd mingw32-runtime-3.15
% su -
Let’s build it now!
% apt-get install fakeroot
% debian/rules clean
% dpkg-buildpackage -rfakeroot -uc -b
% cd ..
Here we go, you should see a nice new .deb file:
% ls
mingw32-runtime_3.15-1_all.deb
Let’s install it:
% dpkg -i mingw32-runtime_3.15-1_all.deb
Voila! Ffmpeg is happy now ;-)
Enjoy.
Some additional resources that helped me greatly along the way:
* Debian.org apt howto
* VLC
* FFmpeg site
* MinGW site