FFmpeg & cross-compiling for Windows on Linux

Posted on September 13, 2009

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 https://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 https://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

2 Responses to “FFmpeg & cross-compiling for Windows on Linux”

  1. roboknight
    Apr 15, 2010

    This is how I got cross compiling to work (from a mac to pc … how’s that for a cross).
    First, I built the mingw32 tools for the Mac. I won’t go into that. It was long and painful, plus, if you are using linux, apt or yum or another package manager will go a long way to helping you get the tools.

    Second, I got ffmpeg from source using git:

    git clone git://git.ffmpeg.org/ffmpeg/
    cd ffmpeg
    git clone git://git.ffmpeg.org/libswscale/

    Once that was accomplished, I built a build directory:

    mkdir build
    cd build

    Then I used this configure line:
    ../configure –cross-prefix=/Users/bpw/WindowsTools/bin/i386-mingw32- –enable-cross-compile –arch=i386 –target-os=mingw32 –enable-memalign-hack

    Make sure when you use this that GCC_EXEC_PREFIX is unset or pointing to the location of your crt1.o file in your tools installation. In general though, having this set can cause a lot of inadvertent “non-configures”. Also note that the the –cross-prefix _includes_ the i386-mingw32- . You need to use _YOUR PREFIX_. There are probably a few other ways to provide the prefix, but this one is the easiest. Also, make sure your path points to your tools.

    At any rate, most of this is trivial information for people who cross-compile on a regular basis, but I discovered there is a lot of outdated info on cross-compiling ffmpeg (options that don’t exist anymore, options that have changed, new options). At any rate, this got me building. I tested ffmpeg on WindowsXP running under VirtualBox and it seemed to work great. I need to test it a little more heavily before I give it the final okay, but it at least built. I’m building on a Macbook Pro, so I think there might be some 64 bit issues, but maybe I won’t run into them because I’m going to a 32 bit target. At least I hope not.


  2. roboknight
    Apr 15, 2010

    Oh, one quick note to my previous post: all the dashes before options are doubled. This blog doesn’t register them unless you do something like quoting your text or something, I’d guess. Didn’t notice that when I was doing this, but I think a previous poster mentioned it also.



Categories

Archives