Building FFmpeg for Windows on Linux – Part 2 – Setting Up the Build Environment and Extra Libraries



Building FFmpeg for Windows on Linux – Part 2 – Setting Up the Build Environment and Extra Libraries

In the last article, I explained how to install Ubuntu 10.10 64-bit using the VirtualBox software and get the instance of Ubuntu all up to date.  This article will focus on getting our build environment set up for compiling FFmpeg.  This part is arguably the most difficult as it involves not only setting up the compilation tools, but also cross-compiling additional libraries to be used with FFmpeg that are not included by default.  If you using the same exact software and versions as described in my introduction, this should be as easy as following directions step by step.  Let’s get started…

 

  1. Open a terminal window in the Ubuntu guest system (Applications -> Accessories -> Terminal).  Most of the work will be performed here for the rest of this series.
  2. Most of the hard work has been done for us by a gentleman who maintains the site at arrozcru.org.  To use his libraries for cross-compiling, download and import his gpg key and update your packages list
    • Download and import the gpg key to your system
      ~$ gpg --keyserver www.keyserver.net --recv-key 0x25E635F9
       ~$ gpg --export --armor 0x25E635F9 | sudo apt-key add -
    • Add the apt repositories to your sources.list file
      ~$ echo "deb http://apt.arrozcru.org ./" | sudo tee -a /etc/apt/sources.list
       ~$ echo "deb-src http://apt.arrozcru.org ./" | sudo tee -a /etc/apt/sources.list
    • Update your package list
      ~$ sudo apt-get update
  3. Set up and install the cross toolchain.  If you are working with a version of Ubuntu other than 10.10 or the 32-bit version, be sure to follow Option 1 to recompile the toolchain.  If you are using Ubuntu 10.10 64-bit, be sure to follow Option 2.
    • Option 1
      1. Create cross toolchain directory and install dev tools
        ~$ mkdir cross
         ~$ cd cross
         ~/cross$ sudo apt-get install dpkg-dev debhelper autotools-dev libmpfr-dev libgmp3-dev libppl0.10-dev libcloog-ppl-dev libmpc-dev
      2. Install the mingw api and runtime
        ~/cross$ sudo apt-get install mingw32-w32api mingw32-runtime
      3. Recompile and deploy mingw binutils
        ~/cross$ apt-get source --compile mingw32-binutils
         [lots of output not shown here]
         ~/cross$ sudo dpkg -i mingw32-binutils_*.deb
      4. Recompile and deploy mingw gcc 4.4
        ~/cross$ apt-get source --compile mingw32-gcc-4.4
         [lots of output not shown here]
         ~/cross$ sudo dpkg -i mingw32-gcc-4.4_*.deb
      5. Install mingw binutils and gcc
        ~/cross$ sudo apt-get install mingw32-binutils mingw32-gcc-4.4
    • Option 2
      ~$ sudo apt-get install mingw32-w32api mingw32-runtime mingw32-gcc-4.4 mingw32-binutils
  4. Patch the cross toolchain with Arrozcru’s patches
    • Install patch to patch the cross toolchain
      ~$ sudo apt-get install patch
    • Download patches from Arrozcru
      ~$ mkdir mingw32-patches
       ~$ cd mingw32-patches
       ~/mingw32-patches$ wget http://fate.arrozcru.org/mingw32/patches/tempnam.diff
       ~/mingw32-patches$ wget http://fate.arrozcru.org/mingw32/patches/strcasecmp.diff 
       ~/mingw32-patches$ wget http://fate.arrozcru.org/mingw32/patches/nomt.diff
    • Patch the cross toolchain
      ~/mingw32-patches$ cd /usr/i686-mingw32
       /usr/i686-mingw32$ sudo patch -p2 < /home/corpapps/mingw32-patches/tempnam.diff
       /usr/i686-mingw32$ sudo patch -p2 < /home/corpapps/mingw32-patches/strcasecmp.diff
       /usr/i686-mingw32$ sudo patch -p2 < /home/corpapps/mingw32-patches/nomt.diff
  5. Compile extra libs as needed
    • Get and build libfaac
      1. Download and extract faac-1.28.tar.bz2
        ~$ wget http://downloads.sourceforge.net/faac/faac-1.28.tar.bz2
         ~$ tar -xvf faac-1.28.tar.bz2
      2. Configure and build libfaac
        ~$ cd faac-1.28
         ~/faac-1.28$ ./configure --host=i686-mingw32 --prefix=/usr/i686-mingw32 --enable-static --disable-shared --with-mp4v2=no
         ~/faac-1.28$ make
         [lots of output not included here]
         ~/faac-1.28$ sudo make install
  6. Install extra libs from Arrozcru’s apt repository
    • You will need to determine what libraries to install using
      ~$ apt-cache search mingw32-
    • Install each library one at a time using sudo apt-get install mingw32-<pkg-name> or copy/paste the string below
      ~$ sudo apt-get install mingw32-ocaml mingw32-libmp3lame mingw32-bzip2 mingw32-libcloog-ppl mingw32-libsdl mingw32-libppl mingw32-libx264 mingw32-libopenjpeg mingw32-polarssl mingw32-libmpc mingw32-libfaad2 mingw32-librtmp mingw32-libtheora mingw32-libxvid mingw32-libmpfr mingw32-openssl mingw32-libgmp mingw32-libschroedinger mingw32-liborc mingw32-libvorbis mingw32-libogg mingw32-libspeex mingw32-pthreads mingw32-directx mingw32-zlib mingw32-libgsm mingw32-liboil mingw32-libopencore-amr
That’s it!  The hardest part of cross-compiling FFmpeg for Windows is in the setup; getting the cross-compiler and the libraries ready.  One thing to notes is that several times when trying to download the gpg key for arrozcru, the keyserver timed out.  I did have luck removing the keyserver argument and attempting to download it with the following command
~$ gpg --recv-key 0x25E635F9
In the next and final article, I will outline how to setup the directories we’ll use for downloading the FFmpeg source, configuring and building it.