How to compile ffmpeg/mplayer for MacOSX

This guide shows how to build ffmpeg, libav, mplayer and mencoder binaries on MacOSX.
See the bottom of this post for a revision history.
 
What you need before you start:

  • Xcode
  • Some patience
  • Some experience in using a command line interface

 
Miscellaneous:

  • yasm-1.2.0.tar.gz
  • zlib-1.2.7.tar.gz
  • bzip2-1.0.6.tar.gz
  • git-1.7.3.5
  • pkg-config-0.27.1.tar.gz

 
Encoder/decoder media libraries:

  • lame-3.99.5.tar.gz
  • faad2-2.7.tar.bz2
  • faac-1.28.tar.bz2
  • xvidcore-1.3.2.tar.gz
  • last_stable_x264.tar.bz2
  • libogg-1.3.0.tar.gz
  • libvorbis-1.3.3.tar.gz
  • libtheora-1.1.1.tar.bz2
  • gsm-1.0.13.tar.gz
  • amrwb-7.0.0.3.tar.bz2
  • amrnb-7.0.0.2.tar.bz2
  • speex-1.2rc1.tar.gz
  • flac-1.2.1.tar.gz
  • libxavs (via subversion)
  • vo-aacenc-0.1.2.tar.gz
  • vo-amrwbenc-0.1.2.tar.gz
  • libvpx-v1.1.0.tar.bz2
  • opus-1.0.2.tar.gz
  • twolame-0.3.13.tar.gz

 
Encoder/decoder media programs:

  • ffmpeg
  • libav
  • mplayer

 
Trying to compile versions obtained directly from the repositories may or may not break or require different configure flags. You can always try and using the stable release source code which should not require too many changes to the configure options.

 
This guide was written with MacOSX 10.6.x and Xcode 3.x in mind, for compiling on newer MacOSX/Xcode versions see compilation notes at the bottom of this posting.

 
Create the Ramdisk

VOLNAME=Ramdisk
DISK_ID=$(hdid -nomount ram://26214400)
newfs_hfs -v ${VOLNAME} ${DISK_ID}
diskutil mount ${DISK_ID}

 
Create some shortcuts

export MES=/Users/snowy/tmptmp/mediaencoding/base/
export TARGET="/Volumes/${VOLNAME}/"
export CMPL="/Volumes/${VOLNAME}/compile"
export PATH=${TARGET}/bin:$PATH
mkdir ${CMPL}

 
Building yasm

cd ${CMPL}
tar xzpf ${MES}/yasm-1.2.0.tar.gz
cd yasm-1.2.0
./configure --prefix=${TARGET}
make -j 2 && make install

 
Building pkg-config

cd ${CMPL} 
tar xzpf ${MES}/pkg-config-0.27.1.tar.gz
cd pkg-config-0.27.1
./configure --prefix=${TARGET} --with-pc-path=${TARGET}/lib/pkgconfig --with-internal-glib 
make -j 2 && make install

 
Building git

cd ${CMPL}
curl -O  http://kernel.org/pub/software/scm/git/git-1.7.3.5.tar.bz2
tar xjpf git-1.7.3.5.tar.bz2
cd git-1.7.3.5
./configure --prefix=${TARGET}/git
make && make install
PATH=${TARGET}/git/bin:$PATH

 
Building lame

cd ${CMPL}
tar xzpf ${MES}/lame-3.99.5.tar.gz
cd lame-3.99.5
./configure --prefix=${TARGET} --disable-shared --enable-static
make -j 2 && make install

 
Building faad

cd ${CMPL}
tar xjpf ${MES}/faad2-2.7.tar.bz2
cd faad2-2.7
./configure --prefix=${TARGET} --disable-shared --enable-static
make -j 2 && make install

 
Building faac

cd ${CMPL}
tar xjpf ${MES}/faac-1.28.tar.bz2
cd faac-1.28
./configure --prefix=${TARGET} --disable-shared --enable-static
make -j 2 && make install

 
Building xvidcore (and removing the dynamic library)

cd ${CMPL}
tar xzpf ${MES}/xvidcore-1.3.2.tar.gz
cd xvidcore
cd build/generic
./configure --prefix=${TARGET}
make -j 2 && make install
rm ${TARGET}/lib/libxvidcore.4.dylib

 
Building x264

cd ${CMPL}
curl -O ftp://ftp.videolan.org/pub/videolan/x264/snapshots/last_stable_x264.tar.bz2
tar xjpf last_stable_x264.tar.bz2
cd x264*stable 
./configure --prefix=${TARGET} --disable-shared --enable-static 
make -j 2 && make install && make install-lib-static

 
Building ogg

cd ${CMPL}
tar xzpf ${MES}/libogg-1.3.0.tar.gz
cd libogg-1.3.0
./configure --prefix=${TARGET} --disable-shared --enable-static
make -j 2 && make install

 
Building vorbis

cd ${CMPL}
tar xzpf ${MES}/libvorbis-1.3.3.tar.gz
cd libvorbis-1.3.3
./configure --prefix=${TARGET} --with-ogg-libraries=${TARGET}/lib --with-ogg-includes=${TARGET}/include/ --enable-static --disable-shared
make -j 2 && make install

 
Building theora

cd ${CMPL}
tar xjpf ${MES}/libtheora-1.1.1.tar.bz2
cd libtheora-1.1.1
./configure --prefix=${TARGET} --disable-asm --with-ogg-libraries=${TARGET}/lib --with-ogg-includes=${TARGET}/include/ --with-vorbis-libraries=${TARGET}/lib --with-vorbis-includes=${TARGET}/include/ --enable-static --disable-shared
make -j 2 && make install

 
Building libopus

cd ${CMPL}
tar xjpf ${MES}/opus-1.0.2.tar.gz
cd opus-1.0.2
./configure --prefix=${TARGET} --disable-shared --enable-static 
make -j 2 && make install

 
Building gsm

cd ${CMPL}
tar xzpf ${MES}/gsm-1.0.13.tar.gz
cd gsm-1.0-pl13
mkdir -p ${TARGET}/man/man3
mkdir -p ${TARGET}/man/man1
mkdir -p ${TARGET}/include/gsm
perl -p -i -e  "s#^INSTALL_ROOT.*#INSTALL_ROOT = $TARGET#g"  Makefile
perl -p -i -e  "s#_ROOT\)/inc#_ROOT\)/include#g"             Makefile
sed "/GSM_INSTALL_INC/s/include/include\/gsm/g"              Makefile > Makefile.new
mv Makefile.new Makefile
make -j 2 && make install

 
Building amrwb (downloads additional sources)

cd ${CMPL}
tar xjpf ${MES}/amrwb-7.0.0.3.tar.bz2
cd amrwb-7.0.0.3
./configure --prefix=${TARGET} --disable-shared --enable-static
make -j 2 && make install

 
Building amrnb (downloads additional sources)

cd ${CMPL}
tar xjpf ${MES}/amrnb-7.0.0.2.tar.bz2
cd amrnb-7.0.0.2
./configure --prefix=${TARGET} --disable-shared --enable-static
make -j 2 && make install

 
Building speex

cd ${CMPL}
tar xzpf ${MES}/speex-1.2rc1.tar.gz
cd speex-1.2rc1
./configure --prefix=${TARGET} --with-ogg-libraries=${TARGET}/lib --with-ogg-includes=${TARGET}/include/ --enable-static --disable-shared
make -j 2 && make install

 
Building flac

cd ${CMPL}
tar xzpf ${MES}/flac-1.2.1.tar.gz
cd flac-1.2.1
./configure --prefix=${TARGET} --disable-asm-optimizations --disable-xmms-plugin --with-ogg-libraries=${TARGET}/lib --with-ogg-includes=${TARGET}/include/ --enable-static --disable-shared
make -j 2 && make install

 
Building xavs

cd ${CMPL} 
svn co https://xavs.svn.sourceforge.net/svnroot/xavs xavs
cd xavs/trunk
./configure --prefix=${TARGET} --disable-asm
make -j 2  && make install

 
Building vo-aaenc

cd ${CMPL} 
tar xzpf ${MES}/vo-aacenc-0.1.2.tar.gz
cd vo-aacenc-0.1.2 
./configure --prefix=${TARGET} --disable-shared --enable-static
make -j 2  && make install

 
Building vo-amrwbenc

cd ${CMPL} 
tar xzpf ${MES}/vo-amrwbenc-0.1.2.tar.gz
cd vo-amrwbenc-0.1.2 
./configure --prefix=${TARGET} --disable-shared --enable-static
make -j 2  && make install

 
Building libvpx

cd ${CMPL} 
tar xjpf libvpx-v1.1.0.tar.bz2
cd libvpx-v1.1.0
./configure --prefix=${TARGET} --as=yasm --disable-shared --enable-static --enable-vp8
make -j 2 && make install

 
Building twolame

cd ${CMPL} 
tar xzpf twolame-0.3.13.tar.gz
cd twolame-0.3.13 
./configure --prefix=${TARGET} --disable-shared --enable-static
make -j 2 && make install

 
Building zlib

cd ${CMPL}
tar xzpf ${MES}/zlib-1.2.7.tar.gz
cd zlib-1.2.7
./configure --prefix=${TARGET} --static
make -j 2 && make install

 
Building bzip2

cd ${CMPL}
tar xzpf ${MES}/bzip2-1.0.6.tar.gz
cd bzip2-1.0.6
make
make install PREFIX=${TARGET}

 
 
Up to here, the compilation path for ffmpeg, libav and mplayer are the same.
Now you can build either ffmpeg, libav or mplayer.

 
Building ffmpeg

cd ${CMPL} 
git clone git://git.videolan.org/ffmpeg.git
cd ffmpeg

export LDFLAGS="-L${TARGET}/lib $CFLAGS"
export  CFLAGS="-I${TARGET}/include $LDFLAGS"

./configure --prefix=${TARGET} --as=yasm --extra-version=snowy --disable-shared --enable-static --disable-ffplay --disable-ffserver --enable-gpl --enable-pthreads --enable-postproc --enable-gray --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-libspeex --enable-bzlib --enable-zlib --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libxavs --enable-nonfree --enable-version3 --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvpx --enable-libgsm --enable-libopus --enable-libtwolame
make -j 2 && make install

 
Building libav

cd ${CMPL} 
git clone git://git.libav.org/libav.git
cd libav

export LDFLAGS="-L${TARGET}/lib $CFLAGS"
export  CFLAGS="-I${TARGET}/include $LDFLAGS"

./configure --prefix=${TARGET} --as=yasm --extra-version=snowy --disable-shared --enable-static --enable-gpl --enable-pthreads --enable-gray --enable-libfaac --enable-libfaad --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-libspeex --enable-bzlib --enable-zlib --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libxavs --enable-nonfree --enable-version3 --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libvpx  --enable-libgsm
make -j 2 && make install

 
Building mplayer/mencoder

If you do not want mplayer/mencoder to make use of X11, simply rename /usr/X11/include prior to configure/make (and do not forget to revert the change after the build was successful)

If Xcode 4.x is installed, mplayer/mencoder will not link successfully and thus the gcc-4.2/g++-4.2 from Xcode 3.x has to be used to compile and link mplayer/mencoder.

if [ -e /Developer-old ]
then 
  export   CC=/Developer-old/usr/bin/gcc-4.2
  export CXX=/Developer-old/usr/bin/g++-4.2
fi
 

And the actual mplayer/mencoder compilation step

cd ${CMPL}
svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer
cd mplayer
./configure --prefix=${TARGET} --extra-cflags="-I${TARGET}/include/" --extra-ldflags="-L${TARGET}/lib"
make -j 2 && make install

After a successful run, you should be able to just grab the ffmpeg or
mplayer/mencoder binaries from ${TARGET}/bin and use them :)

 
If you really need ffplay, simply compile libSDL somewhere in the workflow (preferably after yasm has been built and before bzip2) and remove –disable-ffplay / –disable-avplay from the configure options.

BUT: The resulting ffmpeg/avconv binaries will have a lot more depencies to system libraries, considering that mplayer can also play media files without a GUI and there is also VLC available I personally do not see much point in building ffplay, but in any case, this is how you would do it.

cd ${CMPL}
tar xzpf ${MES}/SDL-1.2.15.tar.gz
cd SDL-1.2.15 
./configure --prefix=${TARGET} --disable-shared --enable-static && $MKMU && make install
make -j 2 && make install

 
If ffmpeg/libav fails to build resulting in the following error:

libswscale/x86/yuv2rgb_mmx.c: In function 'ff_yuv2rgb_init_mmx':
libswscale/x86/yuv2rgb_mmx.c:77: error: 'yuv420_rgb24_MMX2' undeclared (first use in this function)
libswscale/x86/yuv2rgb_mmx.c:77: error: (Each undeclared identifier is reported only once
libswscale/x86/yuv2rgb_mmx.c:77: error: for each function it appears in.)
libswscale/x86/yuv2rgb_mmx.c:78: error: 'yuv420_bgr24_MMX2' undeclared (first use in this function)

Execute the following lines to fix a spelling(?) mistake(?) in the source code prior to running configure and make:

perl -p -i -e  "s/24_MMX2/24_MMX/g"                     libswscale/x86/yuv2rgb_mmx.c
perl -p -i -e  "s/HAVE_MMX2/HAVE_MMX/g"                 libswscale/x86/yuv2rgb_mmx.c
perl -p -i -e  "s/AV_CPU_FLAG_MMX2/AV_CPU_FLAG_MMX/g"   libswscale/x86/yuv2rgb_mmx.c

 
Compilation notes for compiling on MacOSX 10.7.x using Xcode 4.2.x
ffmpeg/libav:

  • Compiler
    Set export CC=clang as the very first step so everything is being compiled by clang
  • Ramdisk
    Use ram://2097152 unless you want to create a really, really big RamDisk
  • zlib library
    Remove the lib/libz.so* files which are being created for some unknown reason..

 
mplayer/mencoder:

  • Compiler
    Set export CC=clang as the very first step so everything is being compiled by clang

 
Compilation notes for compiling on MacOSX 10.7.x using Xcode 4.3.x

  • Compiler
    If “upgrading” from Xcode 4.2.1 to Xcode 4.3 things will break. Especially if /Developer was moved to trash as Xcode 4.3 suggests you should do.
    Prior to upgrading to XCode 4.3 uninstall XCode 4.2.1 using ‘sudo /Developer/Library/uninstall-devtools –mode=all’.
    After this has succeeded, install Xcode 4.3 from the App Store and then download the command line tools from within XCode (Prefernces->Downloads->Command Line Tools)

 
Compilation notes for compiling on MacOSX 10.8.x using Xcode 4.4.x

  • libvpx
    Sometimes compiling 1.0.0 worked, sometimes not. You can build libvpx from git when compiling on Mountain Lion with XCode 4.4:

    export CFLAGS=-I/usr/include
    export LDFLAGS=-L/usr/lib
    cd ${CMPL} 
    git clone http://git.chromium.org/webm/libvpx.git
    cd libvpx
    ./configure --prefix=${TARGET} --as=yasm --disable-shared --enable-static --enable-vp8
    make -j 2 && make install
    unset CFLAGS
    unset LDFLAGS
    

 
Compilation notes concerning “missing” libraries

  • libass-0.10.1
    I have never managed to find a set of versions of the depenencies to compile libass.

  • frei0r-plugins-1.4
    Requires autoheader from the GNU Autoconf package and somehow resists installing frei0r.h to the correct location when using ‘make install’. Actually, it does not install the header at all. Which is kind of sad because ffmpeg would really really like to find that header file.

  • soxr-0.1.1
    Requires cmake, xz decompressor to even start compiling, I do not see the benefit for the effort to provide the prerequisites.

  • libcaca-0.99.beta18
    The configure runs fine but when compiling it blows up with

    ...
    dither.c:XXX: warning: alias definitions not supported; ignored'
    ...
    

    No libcaca on OSX I guess..

  • schroedinger-1.0.11
    Requires ‘orc’ and compilation still breaks with

    Undefined symbols for architecture x86_64:
      "__schro_decode_prediction_only", referenced from:
          _schro_init in libschroedinger-1.0.a(libschroedinger_1.0_la-schro.o)
      "__schro_telemetry", referenced from:
          _schro_init in libschroedinger-1.0.a(libschroedinger_1.0_la-schro.o)
    ld: symbol(s) not found for architecture x86_64
    

 
Revision history:
[Updated 15/05/2013]: Added twolame-0.3.13.tar.gz, remarks about missing libraries
[Updated 10/02/2013]: Provided a compilation note concerning ffplay and SDL-1.2.15.tar.gz
[Updated 09/01/2013]: Updated opus to 1.0.2
[Updated 12/09/2012]: Added pkg-config and libopus
[Updated 10/09/2012]: Fixed the perl expression for gsm
[Updated 28/07/2012]: Added remark on how to compile libvpx from the git repository
[Updated 30/05/2012]: libvpx does not need “special” CFLAGS/LDFLAGS anymore
[Updated 30/05/2012]: Fixed the gsm.h header location, added –enable-libgsm
[Updated 30/05/2012]: Updated zlib to 1.2.6, libvpx to 1.1.0, vo-aacenc/vo-amrwbenc to 0.1.2
[Updated 21/04/2012]: Updated zlib to 1.2.6
[Updated 02/03/2012]: Updated lame to 3.99.5
[Updated 18/02/2012]: Added libvpx compilation hints when using Xcode 4.3
[Updated 10/02/2012]: Updated libvorbis to 1.3.3, using libvpx v1.0.0 instead of git repository
[Updated 29/01/2012]: Updated lame to 3.99.4
[Updated 20/12/2011]: Added libvpx
[Updated 19/12/2011]: Hints about compiling on 10.7.x (Lion)
[Updated 13/12/2011]: Updated yasm to 1.2.0, fixed a spelling mistake
[Updated 23/10/2011]: Updated lame to 3.99
[Updated 25/09/2011]: Updated libogg to 1.3.0
[Updated 16/09/2011]: libav does not support –disable-ffplay and –disable-ffserver anymore
[Updated 06/08/2011]: Added vo-aacenc and vo-amrwbenc
[Updated 28/07/2011]: Added libxavs, cleaned up the article a little
[Updated 23/06/2011]: x264 requires an extra make install command for the library and include files
[Updated 03/06/2011]: Provided compilation workaround for ffmpeg/libav
[Updated 01/06/2011]: Updated Xvid to 1.3.2
[Updated 29/03/2011]: Added libav compilation hint
[Updated 26/03/2011]: Updated Xvid to 1.3.1, new ffmpeg git location, Xcode 4 hint for mplayer
[Updated 24/02/2011]: Updated Xvid to 1.3.0, yasm to 1.1.0
[Updated 12/02/2011]: mplayer wants to download ffmpeg via git
[Updated 23/01/2011]: ffmpeg is now being obtained via git, updated libvorbis and libogg
[Updated 28/11/2010]: Fixed zlib static compilation, added a hint for X11 mencoder/mplayer
[Updated 21/09/2010]: Updated bzip2 version and ffmpeg-svn configure options
[Updated 20/06/2010]: Updated some libaries/components
[Updated 20/02/2010]: Recent tarballs of x264 do not require –enable-static –disable-shared configure options
[Updated 06/09/2009]: Using more recent library versions. Can compile on Snow Leopard
[Updated 09/12/2009]: You can also visit EvalVid for static ffmpeg binaries (MacOS X/Win32/Linux)

About these ads

About this entry