Cross-compiling x264 for win32 on Ubuntu Linux


March 29th, 2010

The total lack of documentation on compiling x264 (and dependencies) for win32 on a linux32 system is henceforth rectified. This guide assumes you are using Ubuntu 9.10 and the packaged version of mingw32. Newer versions of the below packages might require additional/less wrangling.

Required packages in the base system:

sudo apt-get install pkg-config yasm subversion cvs git-core mingw32

Create the basic tree for installing win32-compatible dependancies to:

mkdir -p ~/win32-x264/{src,lib,include,share,bin}

Place this helper script at ~/win32-x264/mingw and chmod +x it:

#!/bin/sh
export CC=i586-mingw32msvc-gcc
export CXX=i586-mingw32msvc-g++
export CPP=i586-mingw32msvc-cpp
export AR=i586-mingw32msvc-ar
export RANLIB=i586-mingw32msvc-ranlib
export ADD2LINE=i586-mingw32msvc-addr2line
export AS=i586-mingw32msvc-as
export LD=i586-mingw32msvc-ld
export NM=i586-mingw32msvc-nm
export STRIP=i586-mingw32msvc-strip
 
export PATH="/usr/i586-mingw32msvc/bin:$PATH"
export PKG_CONFIG_PATH="$HOME/win32-x264/lib/pkgconfig/"
exec "$@"

Now to install pthread & zlib:

cd ~/win32-x264/src
wget -qO - ftp://sourceware.org/pub/pthreads-win32/pthreads-w32-2-8-0-release.tar.gz | tar xzvf -
cd pthreads-w32-2-8-0-release
make GC-static CROSS=i586-mingw32msvc-
cp libpthreadGC2.a ../../lib
cp *.h ../../include
cd ~/win32-x264/src
wget -qO - http://zlib.net/zlib-1.2.4.tar.gz | tar xzvf -
cd zlib-1.2.4
../../mingw ./configure
# Remove references to "-lc" from the Makefile (tells GCC to link output with libc, which is implied anyway, and explicit declaration causes a script error)
sed -i"" -e 's/-lc//' Makefile
make
DESTDIR=../.. make install prefix=

Installing FFmpeg:

cd ~/win32-x264/src
svn checkout svn://svn.ffmpeg.org/ffmpeg/trunk ffmpeg
cd ffmpeg
# Delete references to -Wmissing-prototypes, a GCC warning that fails when cross-compiling
sed -i"" -e '/missing-prototypes/d' configure
./configure \
    --target-os=mingw32 --cross-prefix=i586-mingw32msvc- --arch=x86 --prefix=../.. \
    --enable-memalign-hack --enable-gpl --enable-avisynth --enable-postproc --enable-runtime-cpudetect \
    --disable-encoders --disable-muxers --disable-network --disable-devices
make
make install

Installing FFmpegsource:

cd ~/win32-x264/src
svn checkout http://ffmpegsource.googlecode.com/svn/trunk/ ffms
cd ffms
../../mingw ./configure --host=mingw32 --with-zlib=../.. --prefix=$HOME/win32-x264
../../mingw make
make install

Installing GPAC:
Special thanks to the GPAC dev who kindly assisted me in beating the terrible configure/Makefile scripts into shape.

cd $HOME/win32-x264/src
# Create a CVS auth file on your machine
cvs -d:pserver:anonymous@gpac.cvs.sourceforge.net:/cvsroot/gpac login
cvs -z3 -d:pserver:anonymous@gpac.cvs.sourceforge.net:/cvsroot/gpac co -P gpac
cd gpac
chmod +rwx configure src/Makefile
# Hardcode cross-prefix
sed -i'' -e 's/cross_prefix=""/cross_prefix="i586-mingw32msvc-"/' configure
../../mingw ./configure --static --use-js=no --use-ft=no --use-jpeg=no --use-png=no --use-faad=no --use-mad=no --use-xvid=no --use-ffmpeg=no --use-ogg=no --use-vorbis=no --use-theora=no --use-openjpeg=no --disable-ssl --disable-opengl --disable-wx --disable-oss-audio --disable-x11-shm --disable-x11-xv --disable-fragments--use-a52=no --disable-xmlrpc --disable-dvb --disable-alsa --static-mp4box --extra-cflags="-I$HOME/win32-x264/include -I/usr/i586-mingw32msvc/include" --extra-ldflags="-L$HOME/win32-x264/lib -L/usr/i586-mingw32msvc/lib"
# Fix pthread lib name
sed -i"" -e 's/pthread/pthreadGC2/' config.mak
# Add extra libs that are required but not included
sed -i"" -e 's/-lpthreadGC2/-lpthreadGC2 -lwinmm -lwsock32 -lopengl32 -lglu32/' config.mak
make
# Make will fail a few commands after building libgpac_static.a (i586-mingw32msvc-ar cr ../bin/gcc/libgpac_static.a ...). That's fine, we just need libgpac_static.a
cp bin/gcc/libgpac_static.a ../../lib/
cp -r include/gpac ../../include/

Building x264:

cd ~/win32-x264/src
git clone git://git.videolan.org/x264.git
cd x264
./configure --cross-prefix=i586-mingw32msvc- --host=i586-pc-mingw32 --extra-cflags="-I$HOME/win32-x264/include" --extra-ldflags="-L$HOME/win32-x264/lib"
make

Leave to cool for 15 minutes. Serves four.

Changelog:

  • 20100518: Updated ffmpeg configure args. ffms build needs mingw wrapper. Add cvs to required packages.

9 Responses to “Cross-compiling x264 for win32 on Ubuntu Linux”

  1. Compiling WebM into FFMpeg for Windows on May 20, 2010 10:29 pm

    [...] used this cross compiling X264 using Ubuntu as a base for part of my script. The entire script follows but if you want to make sure you get a [...]

  2. gow on June 13, 2010 2:17 am

    sorry I'm new in linux, what is this mean, I don't understand.

    Place this helper script at ~/win32-x264/mingw and chmod +x it:

    #!/bin/sh
    export CC=i586-mingw32msvc-gcc
    export CXX=i586-mingw32msvc-g++
    export CPP=i586-mingw32msvc-cpp
    export AR=i586-mingw32msvc-ar
    export RANLIB=i586-mingw32msvc-ranlib
    export ADD2LINE=i586-mingw32msvc-addr2line
    export AS=i586-mingw32msvc-as
    export LD=i586-mingw32msvc-ld
    export NM=i586-mingw32msvc-nm
    export STRIP=i586-mingw32msvc-strip

    export PATH="/usr/i586-mingw32msvc/bin:$PATH"
    export PKG_CONFIG_PATH="$HOME/win32-x264/lib/pkgconfig/"
    exec "$@"

  3. visvel on September 6, 2010 8:43 pm

    thanks this is very useful.
    however the CPAC configure is heavily messed up nowadays; fails at zlib and dlopen checks
    do you think you could update this script?
    great job

  4. Alex Jurkiewicz on September 6, 2010 8:53 pm

    Just remove the checks for those two items, and hardcode them to 'yes'.

  5. Juan Ramos on November 24, 2010 10:03 pm

    Thanks a lot for this. It worked really fine, and by the way I learnt some new shell commands (newbie).

  6. temp5556 on February 13, 2012 1:57 pm

    Before installing GPAC make sure zlib is there on your system else install following package.

    sudo apt-cache search zlib
    sudo apt-get install zlib-bin zlib1g zlib1g-dev zlibc

  7. ramprasad85 on July 17, 2012 7:43 am

    I tried to cross compile x264 with ffms.
    unfortunately ffms compilation fails.
    Here is the output of running configure

    ../../mingw ./configure --host=mingw32 --with-zlib=../.. --prefix=$HOME/win32-x264

    [ed: snip]

    Here is the part of the output of make

    ../../mingw make

    CXX src/core/videoutils.lo
    src/core/videoutils.cpp: In function 'SwsContext* GetSwsContext(int, int, PixelFormat, int, int, int, int, PixelFormat, int, int, int64_t)':
    src/core/videoutils.cpp:82: error: 'av_opt_set_int' was not declared in this scope
    src/core/videoutils.cpp: In function 'int::parse_vp8(AVCodecParserContext*, AVCodecContext*, const uint8_t**, int*, const uint8_t*, int)':
    src/core/videoutils.cpp:296: error: 'AV_PICTURE_TYPE_P' was not declared in this scope
    src/core/videoutils.cpp:296: error: 'AV_PICTURE_TYPE_I' was not declared in this scope
    make: *** [src/core/videoutils.lo] Error 1

    Please help me with this.

    Also, compiling FFMPEG (for lavf support) also failed. but it worked when I removed --disable-encoders

    Also, I think x264 for win32 is now compiled using komisar, but there seems no step by step instructions on doing it, can you kindly give us such a thing as well.

    Thanks and Regards

  8. Ramprasad85 on July 18, 2012 8:20 am

    using git to get ffmpeg made it work.

  9. roger on July 27, 2012 4:29 am

    Maybe you could rename libpthreadGC2.a to just libpthread.a?

Comments are closed.

Misc