How to compile ffmpeg/mplayer for MacOSX

This guide shows how to build ffmpeg, libav, mplayer/mencoder and mpv 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.3.0.tar.gz
  • zlib-1.2.8.tar.gz
  • bzip2-1.0.6.tar.gz
  • git-2.10.0
  • pkg-config-0.29.1.tar.gz
  • cmake-3.6.1.tar.gz
  • libressl-2.4.2.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.4.tar.gz
  • last_stable_x264.tar.bz2
  • libogg-1.3.2.tar.gz
  • libvorbis-1.3.5.tar.gz
  • libtheora-1.1.1.tar.bz2
  • gsm-1.0.13.tar.gz
  • amrwb-11.0.0.0.tar.bz2
  • amrnb-11.0.0.0.tar.bz2
  • speex-1.2rc2.tar.gz
  • flac-1.3.0.tar.gz
  • libxavs (via subversion)
  • vo-aacenc-0.1.3.tar.gz
  • vo-amrwbenc-0.1.3.tar.gz
  • libvpx-v1.1.0.tar.bz2
  • opus-1.1.3.tar.gz
  • twolame-0.3.13.tar.gz
  • openal-soft-1.13.tar.bz2
  • soxr-0.1.1-Source.tar.gz
  • fdk-aac-0.1.3.tar.gz
  • libutvideo (via git)
  • wavpack-4.70.0.tar.bz2
  • zeromq-4.1.5.tar.gz
  • georgmartius-vid.stab-release-0.98a-0-g94a4692.tar.gz
  • libilbc (via git)
  • libx265 (via hg)
  • snappy 1.1.3

Encoder/decoder media programs:

  • ffmpeg
  • libav
  • mplayer
  • mpv

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 libressl

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

Building yasm

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

Building pkg-config

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

Building git

cd ${CMPL}
curl -O https://www.kernel.org/pub/software/scm/git/git-2.10.4.tar.gz
tar xzpf git-2.10.0.tar.gz
cd git-2.10.0
./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.4.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.2.tar.gz
cd libogg-1.3.2
./configure --prefix=${TARGET} --disable-shared --enable-static
make -j 2 && make install

Building vorbis

cd ${CMPL}
tar xzpf ${MES}/libvorbis-1.3.5.tar.gz
cd libvorbis-1.3.5
./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.1.3.tar.gz
cd opus-1.1.3
./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-11.0.0.0.tar.bz2
cd amrwb-11.0.0.0
./configure --prefix=${TARGET} --disable-shared --enable-static
make -j 2 && make install

Building amrnb (downloads additional sources)

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

Building speex

cd ${CMPL}
tar xzpf ${MES}/speex-1.2rc2.tar.gz
cd speex-1.2rc2
./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.3.0.tar.gz
cd flac-1.3.0
./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://svn.code.sf.net/p/xavs/code/ xavs
./configure --prefix=${TARGET} --disable-asm
make -j 2  && make install

Building libsnappy

cd ${CMPL}
tar xzpf ${MES}/snappy-1.1.3.tar.gz
cd snappy-1.1.3
 ./configure --prefix=${TARGET} --disable-shared --enable-static
make -j2 && make install

Building vo-amrwbenc

cd ${CMPL}
tar xzpf ${MES}/vo-amrwbenc-0.1.3.tar.gz
cd vo-amrwbenc-0.1.3
./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 fdk-aac

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

Building twolame

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

Building libutvideo

cd ${CMPL}
git clone https://github.com/qyot27/libutvideo
cd libutvideo
./configure --prefix=${TARGET}
make -j 2 && make install

Building wav pack

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

Building zeromq

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

Building cmake

cd ${CMPL}
tar xzpf ${MES}/cmake-3.6.1.tar.gz
cd cmake-3.6.1
# Patch out Java for cmake
rm Modules/FindJava.cmake
sed "s/get_filename_component.JNIPATH/#get_filename_component(JNIPATH/g" Tests/CMakeLists.txt > Tests/CMakeLists.txt.new
mv Tests/CMakeLists.txt.new Tests/CMakeLists.txt
./configure --prefix=${TARGET}
make -j 2 && make install

Building OpenAL

cd ${CMPL}
tar xjpf ${MES}/openal-soft-1.13.tar.bz2
cd openal-soft-1.13
cmake -DCMAKE_INSTALL_PREFIX:PATH=${TARGET} -DLIBTYPE=STATIC .
make -j 2 && make install

Building libsoxr

cd ${CMPL}
tar xzpf ${MES}/soxr-0.1.1-Source.tar.gz
cd soxr-0.1.1-Source
cmake -DCMAKE_INSTALL_PREFIX:PATH=${TARGET} -DBUILD_SHARED_LIBS=OFF .
make -j 2 && make install

Building libvidstab

cd ${CMPL}
tar xzpf ${MES}/georgmartius-vid.stab-release-0.98a-0-g94a4692.tar.gz
cd georgmartius-vid.stab-release*
perl -p -i -e 's/vidstab SHARED/vidstab STATIC/' CMakeLists.txt
cmake -DCMAKE_INSTALL_PREFIX:PATH=${TARGET}  .
make -j 2 && make install

Building libilbc

cd ${CMPL}
git clone https://github.com/dekkers/libilbc.git
cd libilbc
sed '/TARGETS/s/ ilbc / /' CMakeLists.txt >CMakeLists.txt.new
mv CMakeLists.txt.new CMakeLists.txt
cmake -DCMAKE_INSTALL_PREFIX:PATH=${TARGET} .
make -j 2 && make install

Building libx265

cd ${CMPL}
hg clone https://bitbucket.org/multicoreware/x265
cd x265
cd source
cmake -DCMAKE_INSTALL_PREFIX:PATH=${TARGET} -DENABLE_SHARED=NO .
make -j 2 && make install

Building zlib

cd ${CMPL}
tar xzpf ${MES}/zlib-1.2.8.tar.gz
cd zlib-1.2.8
./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}
curl -O http://www.ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
tar xjpf ffmpeg-snapshot.tar.bz2
cd ffmpeg 

./configure --prefix=${TARGET} --as=yasm --extra-version=snowy --disable-shared --enable-static --extra-cflags="-I${TARGET}/include" --extra-ldflags="-L${TARGET}/lib ---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-libsnappy --enable-libvo-amrwbenc --enable-libvpx --enable-libgsm --enable-libopus --enable-libtwolame --enable-openal --enable-libsoxr  --enable-libfdk-aac --enable-libwavpack --enable-libutvideo --enable-libzmq --enable-libvidstab --enable-libilbc --enable-libx265
make -j 2 && make install

Building libav

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

./configure --prefix=${TARGET} --as=yasm --extra-version=snowy --disable-shared --enable-static --extra-cflags="-I${TARGET}/include" --extra-ldflags="-L${TARGET}/lib --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 --enable-libwavpack
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 and CXX=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 for compiling on MacOSX 10.8.x using Xcode 5.0

  • ffmpeg
    When building ffmpeg and linking against libutvideo, ffmpeg will state it can not find utvideo This is due to the fact it uses -std=c99 as a g++ command line argument. The dirty fix for this is to modify the configure script (gnu sed!) and set the compilers accordingly prior to running the configure script:

    export CXX=/usr/bin/clang++
    export CC=/usr/bin/clang
    sed "s/_ldflags='-std=c99'/_ldflags='-std=c++11'/g" -i configure
    sed "s/-std=c99$/-std-c++11/g"                      -i configure
    

Compilation notes for compiling on MacOSX 10.9.x using Xcode 5.0.1

  • flac-1.3.0
    Will refuse to compile, see https://trac.macports.org/ticket/40709 for further details. The fix described does not help.
  • cmake-2.8.12
    This is to stop cmake looking for java using the following crude patch prior to executing ./configure (using gnu sed):

    rm Modules/FindJava.cmake
    sed "s/get_filename_component.JNIPATH/#get_filename_component(JNIPATH/g" -i Tests/CMakeLists.txt
    
  • SDL-1.2.15
    When building ffplay, SDL is required but that fails to build. Hence a very crude patch to get it to build (using gnu sed):

    sed "/CGDirectPaletteRef palette;/d" -i ./src/video/quartz/SDL_QuartzVideo.h
    

    Source: http://hg.libsdl.org/SDL/rev/e9466ead70e5
    Also, –disable-x11-video is needed for the configure line because Mavericks is missing an X11 include.

  • libvpx (from git)
    Add –disable-unit-tests to the configure line when the build fails due to third party sources included.
  • mplayer
    An include directive needs to be wadded to libvo/vo_corevideo.m (gnu sed) prior to running configure:

    sed "27i#include <OpenGL/gl.h>" -i libvo/vo_corevideo.m
    

    Source http://trac.macports.org/ticket/40914

Compilation notes for compiling on MacOSX 10.9.x using Xcode 5.1

  • The clang 5.1 compiler does not support -falign-loops=16 and -fforce-addr anymore (hard error)
  • Prior to running configure for x264, libtheora and xavs, the configure script needs to be modified
    perl -p -i -e "s/-falign-loops=16//g" configure
    perl -p -i -e "s/-fforce-addr//g"     configure
    
  • Linking to libx265 can fail (ffmpeg is unable to find libx265)
    Add -lstdc++ to $CFLAGS

Compilation notes concerning mpv

  • mpv can be built but requires ffmpeg (libraries) to be present so in order to build mpv, everything up to and including ffmpeg must be compiled.
  • The man pages for mpv will only be created when docutils is provided.
    cd ${CMPL}
    export PYTHONPATH="${TARGET}/lib/python2.7/site-packages/"
    curl -L -O -s  http://iweb.dl.sourceforge.net/project/docutils/docutils/0.11/docutils-0.11.tar.gz
    tar xzpf docutils*
    cd docutils*
    python setup.py install --prefix="${TARGET}"
    
  • Last but not least, the mpv compilation step, without libass. Recently, the build system for mpv was changed to ‘waf’
    cd ${CMPL}
    curl -L -O -s https://github.com/mpv-player/mpv/archive/master.zip
    unzip -q master.zip
    cd mpv-master
    ./bootstrap.py
    export PKG_CONFIG=pkg-config
    ./waf configure  --prefix=${TARGET} --disable-libass-osd --disable-libass
    ./waf build
    ./waf install
    

Compilation notes concerning “missing” libraries

  • libbluray
    Requires libxml2 and freetype2 to compile, but blows up when linking to ffmpeg. I do not have a strong motive to investigate/fix this since I do not need libbluray…
  • game-music-emu-0.6.0
    Needs a patch in gme/CMakeLists.txt create a static library but somehow not all symbols (for 64bit) end up in that static library…
  • libass-0.12.1
    After being unable to find a set of working dependencies for libass (versions of the libraries libass requires) I investigated in how HomeBrew does this. Building expat, freetype, fribidi and fontconfig worked like a charm, even libass actually does compile. This was the test build setup:

    #!/bin/bash
    
    # run make with 4 threads
    export MKMU="make -j 4"
    
    export VOLNAME=Ramdisk
    export TARGET="/Volumes/${VOLNAME}/"
    export CMPL="/Volumes/${VOLNAME}/compile"
    export MES="/Volumes/${VOLNAME}/src"
    export PATH=${TARGET}/bin:$PATH
    
    # first, build pkg-config which references
    cd ${CMPL}  || exit 1
    tar xzpf ${MES}/pkg-config*
    cd pkg-config*
    ./configure --prefix=${TARGET} --with-pc-path=${TARGET}/lib/pkgconfig --with-internal-glib && $MKMU && make install
    
    # next, yam
    cd ${CMPL}
    tar xzpf ${MES}/yasm-1.2.0.tar.gz
    cd yasm-1.2.0
    ./configure --prefix=${TARGET} && $MKMU && make install
    
    # next, libexpat
    cd ${CMPL}
    tar xzpf ${MES}/expat-2.1.0.tar.gz
    cd expat-2.1.0
    ./configure --prefix=${TARGET} --disable-debug --disable-shared --enable-static && $MKMU && make install
    
    # next, libpng
    cd ${CMPL}
    tar xzpf ${MES}/libpng-1.6.16.tar.gz
    cd libpng-1.6.16
    ./configure --prefix=${TARGET} --disable-shared --enable-static && $MKMU && make install
    
    # next, freetype
    cd ${CMPL}
    tar xzpf ${MES}/freetype-2.5.5.tar.gz
    cd freetype-2.5.5
    ./configure --prefix=${TARGET} --disable-shared --enable-static && $MKMU && make install
    
    # next fribidi
    cd ${CMPL}
    tar xjpf ${MES}/fribidi-0.19.6.tar.bz2
    cd fribidi-0.19.6
    ./configure --prefix=${TARGET} --disable-shared --enable-static && $MKMU && make install
    
    # fontconfig
    cd ${CMPL}
    tar xzpf ${MES}/fontconfig-2.11.92.tar.gz
    cd fontconfig-2.11.92
    ./configure --prefix=${TARGET} --with-add-fonts=/Library/Fonts,~/Library/Fonts --disable-shared --enable-static && $MKMU && make install
    
    # libass
    cd ${CMPL}
    tar xzpf ${MES}/libass-0.12.1.tar.gz
    cd libass-0.12.1
    ./configure --prefix=${TARGET} --disable-shared --enable-static && $MKMU && make install
    
    # lua
    cd ${CMPL}
    tar xzpf ${MES}/lua-5.2.3.tar.gz
    cd lua-5.2.3
    make macosx install INSTALL_TOP=${TARGET}
    
    # create a lua.pc so mpv can find it
    cat >${TARGET}/lib/pkgconfig/lua.pc <<EOF
    prefix=/Volumes/Ramdisk
    exec_prefix=\${prefix}
    libdir=\${prefix}/lib/
    includedir=\${prefix}/include
    Name: lua
    Description: lua
    Requires:
    Version: 5.2.3
    Libs: -L\${libdir} -llua
    Cflags: -I\${includedir}
    EOF
    
    # fix fontconfig, using gnu sed
    sed "/^Libs: / s/-lfontconfig/-lfontconfig -lpng -lexpat -L\/Volumes\/Ramdisk\/lib -lfreetype/g" -i /Volumes/Ramdisk/lib/pkgconfig/fontconfig.pc
    
    # ffmpeg
    # set compiler flags
    export LDFLAGS="-L${TARGET}/lib $CFLAGS"
    export  CFLAGS="-I${TARGET}/include $LDFLAGS"
    cd ${CMPL}
    curl -O http://www.ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
    tar xjpf ffmpeg-snapshot.tar.bz2
    cd ffmpeg
    ./configure  --prefix=${TARGET} --disable-fontconfig --enable-libass --enable-static --disable-shared && $MKMU && make install
    
    # extend the python modules path
    export PYTHONPATH="${TARGET}/lib/python2.7/site-packages/"
    
    # build docutils so mpv can build its man pages
    cd ${CMPL}
    lftpget http://iweb.dl.sourceforge.net/project/docutils/docutils/0.12/docutils-0.12.tar.gz
    tar xzpf docutils*
    cd docutils*
    python setup.py install --prefix="${TARGET}"
    
    # this is needed for waf or it will not find an executable compiler
    export CC=clang
    
    # and build mpv
    cd ${CMPL}
    curl -L -O -s https://github.com/mpv-player/mpv/archive/master.zip
    unzip -q master.zip
    cd mpv-master
    
    ./bootstrap.py
    export PKG_CONFIG=pkg-config
    ./waf configure  --prefix=${TARGET}
    ./waf build
    ./waf install
    

    ffmpeg and mpv should be found in /Volumes/Ramdisk/bin and should support libass.
    When /Volumes/Ramdisk goes away, fontconfig will not be able to find its configuration file and cache anymore. So before you unmount /Volumes/Ramdisk, do the following:

    export FONTCONFIG_FILE=$HOME/.myfontconfig-fonts.conf
    cp /Volumes/Ramdisk/etc/fonts/fonts.conf $FONTCONFIG_FILE
    cp -R /Volumes/Ramdisk/var/cache/fontconfig $HOME/.fontconfig
    cd $HOME
    # copy mpv and/or ffmpeg to a different location
    umount /Volumes/Ramdisk
    

    The fontconfig library used by mpv should now be able to find the font configuration file and the cache. You may want to add the FONTCONFIG_FILE environment variable to your shell environment to make this a permanent solution.

  • 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.
  • libcaca-0.99.beta18
    The configure runs fine but when compiling it blows up with

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

    It does not blow up when using the gcc-4.2 from XCode 3 but things go awfully wrong when trying to link libcaca to ffmpeg, although the demo from libcaca work…

  • 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 03/09/2016]: Updated git to 2.10,0, libressl to 2.4.2, cmake to 3.6.1, zeromq to 4.1.5, libogg 1.3.2, opus to 1.1.3 and fdk-aac to 0.1.4
[Updated 28/03/2016]: Updated git to 2.7.4, libressl to 2.3.3, mercurial to 3.7.2, opus to 1.1.2, zeromq to 3.2.5, pgk-config to 0.29.1 and cmake to 3.5.1
[Updated 31/01/2016]: Removed vo-aaenc, added snap 1.1.3
[Updated 04/10/2015]: Added libressl 2.3.0
[Updated 03/10/2015]: Updated git to 2.4.5, cmake to 3.3.1, xvidcore to 1.3.4, libvorbis to 1.3.5, speex to 1.2.rc2
[Updated 19/02/2015]: Updated git to 2.3.0, cmake to 3.1.3, notes on compiling mpv with libass
[Updated 13/12/2014]: Updated git to 2.2.0, cmake to 3.0.2
[Updated 02/09/2014]: Updated yasm from 1.2.0 to 1.3.0
[Updated 18/08/2014]: Updated zeromq to 3.2.4, amrnb/wb to 11.0, zlib to 1.2.8 and git to 2.0.0
[Updated 03/06/2014]: Added compilation hints for ffmpeg/mpv concerning libass
[Updated 20/05/2014]: Added compilation hints for Xcode 5.1, libx265 and ffmpeg
[Updated 19/04/2014]: Added git to 1.9.2
[Updated 27/03/2014]: Added libx265
[Updated 15/03/2014]: Added compilation hints for Xcode 5.1
[Updated 02/02/2014]: Added libilbc
[Updated 30/01/2014]: Added vid.stab 0.98a
[Updated 26/01/2014]: Updated vorbis to 1.1.4, fdk-aac to 1.1.3, git to 1.8.5 and cmake to 2.8.12.1
[Updated 22/12/2013]: Updated pkg-config to 0.28, opus to 1.1 and libogg to 1.3.1
[Updated 02/12/2013]: Updated compilation hints for mpv
[Updated 20/11/2013]: Updated vo-aacenc and vo-amrwbenc to 1.0.3, wavpack to 4.70.1
[Updated 25/10/2013]: Added compilation hint for mplayer and Mac OS X 10.9 Mavericks
[Updated 24/10/2013]: Added compilation hints when using Xcode 5.0.1 on MacOSX 10.9 Mavericks
[Updated 20/09/2013]: Added compilation hints for mpv and ffmpeg when using Xcode 5
[Updated 01/09/2013]: Added compile information concerning libcaca, libass and mpv
[Updated 22/08/2013]: Updated xavs source location
[Updated 21/07/2013]: Added libutvideo, zeromq and wavpack
[Updated 19/07/2013]: Added fdk-aac
[Updated 18/07/2013]: Updated opus to 1.0.3, added cmake, openal and libsoxr
[Updated 12/06/2013]: Updated flac to 1.3.0
[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

303 thoughts on “How to compile ffmpeg/mplayer for MacOSX

  1. Everything great except the sed trick on libgsm which did not work for me. I had to manually edit Makefile

    I was even able to compile SVN version removing –disable-vhook and –enable-swscale

    THANKS!!!

    • Good point. I have used gnu sed 4.1.5 instead of the /usr/bin/sed supplied by Apple. I will add a note to the compilation process.

      • Hexeract I’ve got an issue as well with GSM following your instructions. I receive:

        perl -p -i -e “s#_ROOT)/inc#_ROOT)/include#g” Makefile
        Unmatched ) in regex; marked by <– HERE in m/_ROOT) <– HERE /inc/ at -e line 1.

        Thanks

  2. This is fantastic! I too had an issue with GSM but I didn’t need it anyway. This exactly what I needed to figure out how to compile a Mac binary. Thanks for the tutorial. I have spent hours digging to find the info you have provided in a simple format.

  3. I was trying to do the same but get some errors, then I found this article and works great (I have some troubles with lame lib, so not included)

    I only have one issue, X264 has some preset files that need to be placed somewhere, but I don’t know where with your method, the common place is “/usr/share/ffmpeg/”

    I was trying with the latest builds before but I get this error:
    dyld: Library not loaded: /usr/local/lib/libfaac.0.dylib

    with your guide I get this error:
    dyld: Library not loaded: /usr/local/lib/libmp3lame.0.dylib

    that’s why I dissable libmp3lame and get it to work well, but without pressets.

    I have all the files I use here:

    http://www.rodrigopolo.com/ffmpeg/osxcompile/

    Can you update your guide to work with the latests code, libmp3lame and x264 presets. thanks for the great job, help and for sharing!!!

    • The preset files simply go to $HOME/.ffmpeg/

      The guide, when followed exactly step by step, should result in static builds of ffmpeg or mplayer/encoder.

      You can, however, update the libraries you unpack and compile.
      I recompiled using xvidcore-1.2.2.tar.gz and x264-snapshot-20090528-2245.tar.bz2 without any troubles.

      Reading your file config_and_errors.txt the error is quite obvious:
      You are not using a sandbox to install to and use to link against.

      From what I suspect, both on MacOSX and Ubuntu, you simply did not use the –prefix=
      option of ./configure and hence everything was installed into /usr/local.

      For some odd reason you also built the shared libraries which, when you finally
      compiled ffmpeg, it happily linked against in /usr/local/include and /usr/local/lib.
      The resulting binary, when transferred to another box, will fail as shown.

      Setting up $TARGET and using it as an option for –prefix in the ./configure run
      is a very vital technique for this guide (and the success).

      Checking your ffmpeg binary shows:

      $ otool -L ffmpeg
      ffmpeg:
      /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
      /usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.4)
      /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.4)
      /usr/local/lib/libfaac.0.dylib (compatibility version 1.0.0, current version 1.0.0)
      /usr/local/lib/libfaad.2.dylib (compatibility version 3.0.0, current version 3.0.0)
      /usr/local/lib/libmp3lame.0.dylib (compatibility version 1.0.0, current version 1.0.0)
      /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)

      The resulting ffmpeg binary, if you followed the guide step by step, looks like this:

      $ otool -L ffmpeg
      ffmpeg:
      /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
      /usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.4)
      /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.4)
      /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)

      Does this information help you?

      If all fails, I can provide you with a working ffmpeg (and mplayer/mencoder).
      And the Ramdisk volume after a successful run.

      • Thanks a lot, I finllay did it, I’m making the compilation on Mac OS X on a MacBook Pro, I post my issues compiling on the FFmpeg user list and they give me this wonderfull link:

        http://www.tkn.tu-berlin.de/research/evalvid/

        Check it out, it hast all what FFmpeg can have!!! I will make a “FFmpeg H.264 AAC Injected FLV” guide to use a plug-in for wordpress I’m making, so I will post it here so you can check it out.

  4. Thanks for the great guide. Everything worked fine except the mplayer/mencoder build. Grabbing teh latest snapshot and using your config – it appears they made some changes and this is no longer recognized:

    –with-extraincdir=${TARGET}/include/ –with-extralibdir=${TARGET}/lib

    instead I was able to use:

    –extra-libs=${TARGET}/lib

    but there seems to be no equivalent for the –extra-inc.

    Attempting to compile yields:

    In file included from liba52/imdct.c:725:
    liba52/imdct_3dnow.h: In function ‘fft_asmb_3dnow’:
    liba52/imdct_3dnow.h:257: error: can’t find a register in class ‘GENERAL_REGS’ while reloading ‘asm’
    make: *** [liba52/imdct.o] Error 1

    oh well.. great job detailing rest of process.

    • Try the following when compiling from the subversion trunk:

      $ cd /Volumes/Ramdisk/compile/
      $ svn checkout svn://svn.mplayerhq.hu/mplayer/trunk mplayer
      $ cd mplayer
      $ ./configure –prefix=/Volumes/Ramdisk/sw –extra-cflags=”-I/Volumes/Ramdisk/sw/include” –extra-ldflags=”-L/Volumes/Ramdisk/sw/lib/”

      MPlayer SVN-r29404-4.0.1
      MEncoder SVN-r29404-4.0.1

      • Thanks for the reply – unfortunately still failed. It looks like its tryingto find something to do with a52 – could it be that a52 libs need to be compiled first? I’m gonna try that – I’ll let you know…

        — cut —
        cc -Wundef -Wdisabled-optimization -Wno-pointer-sign -Wdeclaration-after-statement -std=gnu99 -I/Volumes/Ramdisk/sw/include -D_LARGEFILE_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE64_SOURCE -Ilibdvdread4 -mdynamic-no-pic -falign-loops=16 -shared-libgcc -I. -I/Volumes/Ramdisk/sw/include -I/usr/X11/include -I/usr/X11/include/freetype2 -I/usr/X11/include -c -o libass/ass.o libass/ass.c
        In file included from liba52/imdct.c:725:
        liba52/imdct_3dnow.h: In function ‘fft_asmb_3dnow’:
        liba52/imdct_3dnow.h:257: error: can’t find a register in class ‘GENERAL_REGS’ while reloading ‘asm’
        make: *** [liba52/imdct.o] Error 1
        make: *** Waiting for unfinished jobs….

        • When researching your problem, I have read that using –disable-vdpau will avoid the error but the main problem may be with the gnu compiler version used.

          MPlayer really likes to choose its own compiler flags, I would not add any compiler specific options to the –extra-cflags, it will most likely break the compilation.

          Can you provide the shell script you used to compile and where it breaks?
          I just tried to reproduce your compilation error but could not do so.

          The only changes to the above guide are the usage of:

          – yasm-0.8.0.tar.gz
          – x264-snapshot-20090528-2245.tar.bz2
          – xvidcore-1.2.2.tar.gz

          But that should not have any effect on the compilation of a52…

          • Yes the research I read also indicated the vdpau and the compiler could be the problem. I disabled vdpau first but that had no effect, it was only after add the “-O3 -fomit-frame-pointer” was I able to complete the mplayer compilation. I am aslo using a bit newer components than in your guide:

            -yasm-0.8.0.tar.gz
            -x264-snapshot-20090625-2245.tar.bz2
            -xvidcore-1.2.1.tar.gz

            I tried xvidcore-1.2.2 but there were some errors in its compilation so I dropped back to the one listed in your guide and it worked fine.

            BTW – your guide and use of the ram disk and sandbox has revolutionized the way I compile now. I am just a tinkerer, but I have always wanted to build stuff in a “sandbox” type layout I just never knew how. Your guide worked so well, I actually used it on my Ubuntu box and build a fresh static copy of ffmpeg for it using your technique. Thank you VERY MUCH for this detailed guide – it has been a real eyeopener!

          • Thank you very much, I am glad the guide was helpful!

            xvidcore-1.2.2 should compile fine, as I used that when I tried to build mplayer from the SVN repository.

            This is the compiler I used: gcc version 4.0.1 (Apple Inc. build 5490)

            Using gcc 4.2 (gcc version 4.2.1 (Apple Inc. build 5566)) works too, but produces slightly larger binaries…

          • Hey you might be onto something there – just checked and I have gcc version 4.0.1 (Apple Inc. build 5465). I was unaware of a gcc update – I assumed those would be pulled in with the standard SystemUpdate utility – but apparently not – logging in now to ADC to see if I can find an update.

  5. If you get errors encoding with mp3 and lame like this:

    [libmp3lame @ 0x103a600]lame: output buffer too small (buffer index: 9405, free bytes: 387)
    Audio encoding failed

    Downgrade to the lame-3.98 (instead of lame-3.98.2) source code and recompile ffmpeg.

    Note the errors are erroneous, as the output does indeed include properly encoded audio – it just issues those warnings.

    • Weird, when I (re)compiled everything on Snow Leopard it failed at libtheora (which needed a –disable-asm configure flag)
      I used the gcc 4.2.1 shipping with Snow Leopard’s XCode 3.2

  6. There is an error in the “libvorbis” part…

    The option:
    –with-ogg-includes=/Volumes/Ramdisk/sw/include/

    Should be:
    –with-ogg-includes=${TARGET}/include/

    I got a great OS X Compilation ( http://rod.gs/Ml ) But now I’m trying to build one on Ubuntu, if I enable libvorbis I have all kind of issues, without it it works perfect, I’m very tired trying to do this, I’m willing to pay some one who want to build a static version like this but with ubuntu 9.04 (x32 and x64)

    • You are right, I have corrected this in the blog enttry.
      Thank you for pointing this out to me!

      For Ubuntu, you do not need to create a RamDisk, you can simply replace /Volumes/Ramdisk with a directory of your choice.

      I will update the posting to reflect my currently
      used setup on how to build ffmpeg/mplayer.

  7. I only got as far as the xvidcore which craps out with this error:

    ld: symbol(s) not found
    collect2: ld returned 1 exit status
    make: *** [libxvidcore.4.dylib] Error 1

    I’m just using whatever the current version of XCode is for Snow Leopard. All I really want is a mencoder and a mplayer binary. Can someone smarter than me hook me up?

    • If you have followed the guide, you should have deleted the libxvidcore.4.dylib after compiling and installing xvidcore.
      This will force the ffmpeg/mplayer/mencoder binary to be linked against the static version of xvidcore.

      Do no hesitate to contact me if you need further assistance.


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

        • Checking your xvidcore output log, I can only guess it may have to do with the fact you have an i7
          and neither yasm nor gcc 4.2.1 can produce good/proper assembly code.

          In that case, try to just use make without the “-j 4” option.
          If that does not help, try adding the “–disable-assembly” switch and see if that resolves the issue.

          • Uggg,
            This did not work on my i7 either. I tried the above suggestions.

            You might want to put a note at the top that this won’t work yet for i7’s. I spent a couple hours trying this out of desperation.

            I have been using mplayer to make videos of computer simulations for work and I just got this new machine and now I can’t run my code.
            If anyone has any suggestions on how to run mencoder on an i7 please let me know. Thank You!

          • Have you tried compiling mplayer using the guide on your new machine? What went wrong and where?

            If that does not help, try adding –enable-runtime-cpudetection option to the ./configure command line.

  8. x264 compile fails
    i get:
    Unknown option –enable-static, ignored
    Unknown option –disable-shared, ignored
    No working C compiler found.

    using snow leopard with gcc 4.2.1

    all other components compile fine

    • Use 2 dashes/hyphens:

      –enable-static –disable-shared

      It is also very important you change your directory to xvidcore/build/generic where the configure script resides.
      The c compiler gcc resides in /usr/bin/ so that should not really be a problem…

      • Hey very cool, and super helpful…

        Though, the x264 doesn’t worth w/ double dashes.

        $ ./configure –prefix=${TARGET} –disable-shared –enable-static

        Unknown option –disable-shared, ignored
        Unknown option –enable-static, ignored

        • I have just checked and you are right.
          The configure in recent daily tarballs does not have the –enable-static or –disable-shared option anymore, default is to build a static version.

          An update entry has been made to the posting, thank you for pointing this out to me.

  9. Pingback: Man Vs Mkv: The Story So Far « Baud Attitude
  10. Thank you. Great work. I needed a static build of ffmpeg with libmp3lame statical linked in ffmpeg on linux. I picked the the parts I needed and it worked out for me. This is the best page on the subject online!!! I did a lot of research before.

    • Thank you very much!

      You can even build ffmpg from the subversion repository using yasm 1.0, lame 3.98.3 and updated xiph (vorbis/ogg) libraries,
      if you are really into “bleeding edge” software versions :)

  11. I want to thank you so much for this! I was pulling my hair out for hours trying to get a static build of FFmpeg and your guide was the only one that worked.

    Also, great tip on using a ramdrive for the compilation. Really sped things up!

    One thing I had to change though. I got an error about amrwb not being found even though I compiled it. It turns out they only support the opencore-amr project now and I got an error that that module was missing. I removed the amrwb and amrnb builds and compiled the latest git source of the opencore-amr project and it worked fine.

    Other than that it was all smooth sailing :)

    • I am glad the guide was helpful.
      When I recompile ffmpeg myself I sometimes have to tweak the ./configure line but mostly I just drop an option or check if an option has been renamed.

  12. Hello,

    Excellent guide you have I’ve been using it for some time. Got a question though maybe you can help…I have a .flv video that will not properly convert using a recent mencoder build I did according to your guide. However a mencoder build from last year that I did not compile myself converts the video perfectly and I can’t figure out why. I’m thinking it’s the way it was built but I don’t know how to find the differences? Anyways I can post more details here if you wish or if you would like to send me an email I could chat with you there. Thanks again for the great guide!

    rc

    • It is very difficult to say what may have gone wrong withouth either knowing the source video or the encoding options used.
      I doubt it is a problem the way it is built but it depends audio/video encoding options used (and thus on the libraries).
      Other than that you might want to check the projects homepage for each codec for newer versions and try a recompile with more recent libraries.

      As I am not really a video encoding expert I can not really help you with any “magic” audio/video encoding hints.
      Better to ask on the mplayer mailing list MEncoder-users as described on the mplayer homepage.

  13. Hey thanks for the reply! Yes I know you would need more info and actually I did post on the forums but they couldn’t tell me too. It might have just been some random bad video. Actually the issue was with the built-in demuxer (lavf) and seemed the problem it was reading the original video at close to 60fps when it was really close to 30fps. This seemed to throw off the whole encoding (at least that’s my guess) and I couldn’t figure out why an old mencoder build read it correctly and my newer one didn’t. Anyways I appreciate the reply and I’ll keep checking. Thanks again!

    rc

  14. Hello again,

    I have another question that I’m thinking you might know the answer. Using your guide I have encountered the following error on a different Mac:

    Dyld Error Message:
    Library not loaded: /usr/X11/lib/libfreetype.6.dylib
    Reason: image not found

    I know this is a static build that should just work and the only thing I have added in addition to the guide here when building mencoder is –disable-x11 to avoid these kind of x11 issues but still I’m encountering this one. Would you have any idea why? Thanks again for the help and the great guide!

    rc

    • Only ffmpeg is really a static build, the mencoder/mplayer is as static as it can be but still
      requires some dynamic libraries.

      As mencoder/mplayer does a lot of autodetecting you might simply make the X11 includes “invisible” by renaming /usr/X11/include to /usr/X11/include.1 (and do not forget to change the directory name back after a successful build.

      This should stop mencoder/mplayer to find any libraries related to X11 and thus will be omitted during the compilation.

      You can always check which dynamic libraries a binary by using ‘otool -L’.

      In my quick test build, it looked like this:

      snowy@wintermute(/Volumes/Ramdisk/mplayer) $ otool -L ./mplayer
      ./mplayer:
      /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
      /usr/lib/libncurses.5.4.dylib (compatibility version 5.4.0, current version 5.4.0)
      /System/Library/Frameworks/QuickTime.framework/Versions/A/QuickTime (compatibility version 1.0.0, current version 1756.0.0)
      /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
      /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 152.0.0)
      /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
      /usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5)
      /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.1)
      /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 15.0.0)
      /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.6.3)
      /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
      /System/Library/Frameworks/OpenAL.framework/Versions/A/OpenAL (compatibility version 1.0.0, current version 1.0.0)
      /System/Library/Frameworks/CoreAudio.framework/Versions/A/CoreAudio (compatibility version 1.0.0, current version 1.0.0)
      /System/Library/Frameworks/AudioUnit.framework/Versions/A/AudioUnit (compatibility version 1.0.0, current version 1.0.0)
      /System/Library/Frameworks/AudioToolbox.framework/Versions/A/AudioToolbox (compatibility version 1.0.0, current version 1.0.0)
      /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 44.0.0)
      /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 227.0.0)
      /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 550.42.0)
      /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1038.35.0)
      /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 38.0.0)
      /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 751.42.0)
      /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.6.2)

      • Great that’s a good trick! So the output using otool means those files must reside on your system for the mencoder build to work correct? Thanks very much for the quick reply I think this issue is solved…

        rc

        • Checking a binary with ‘otool -L’ will show you if there is a missing reference and if not, show all dynamically linked libraries for a binary.

  15. Pingback: Quora
    • You could either make use of a media server such as Nullriver MediaLink or the Playstation Media Server that do transcoding on the fly.

      Another approach would be to to break up the MKV container using mkvtoolnix and repackaging that into a media container that the Playstation 3 can handle using ffmpeg or mencoder, depending on what video and audio format you have in the mkv file.
      Once you have a little script this should be the fastest and easiest way :)

      Using Handbrake may be the easiest but not the fastest (due to the re-encoding).

  16. hi again,

    just curious using your guide is there a way to build a universal build of ffmpeg for mac or must i build on the different architectures and then lipo them together? it’s hard to find universal ready-made builds on the internet. thanks!

    rc

    • There is no guide on how to build an universal binary since I have not written one :)
      I would also try the approach of compiling ffmpeg/mplayer on different architectures and then using lipo to “glue” them together.
      As some libraries want to make use of yasm you would need to check if you can disable assembler optimisations.

      You could also try to compile for both architectures on one machine using the following compiler flags (ppc example on an intel box):

      export CC=/usr/bin/gcc-4.0
      export CFLAGS=”-isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -mmacosx-version-min=10.4″
      export LDFLAGS=”-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch ppc -mmacosx-version-min=10.4″

      My best advice would be to first try and compile mplayer and ffmpeg as ppc binary and if that works, you can try each library if that will compile as ppc binary.

        • i followed your guide intel first for ffmpeg as always the best :-) just a few comments using otool -L it shows me this:

          /usr/lib/libSystem.B.dylib

          only one and i suppose that’s fine? other binaries i find often show 3 or 4 when using otool -L. and i noticed if you double-click the finished binary under configuration where all the libraries are this one is not included:

          libavcore

          that is often included in other binaries again not quite sure what that means? but the building was just fine although i did have to follow the post from #12 about using opencore-amr project. i’ll let you know how i make out with the universal one thanks!

          • It should be fine although you have to check the output of ffmpeg -formats
            to see if a codec you want/need is missing.

            My build looks the same:

            snowy@wintermute(~) $ otool -L /Users/snowy/.bin/ffmpeg
            /Users/snowy/bin/ffmpeg:
            /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)

  17. Hello,
    bare with me this is my first big compiling project.
    can’t get pass xvidcore, I’m getting (last 3 lines):

    ld: symbol(s) not found
    collect2: ld returned 1 exit status
    make: *** [libxvidcore.4.dylib] Error 1

    I also tried $ make && make install same result.

    • I can only guess what may have gone wrong.

    • What version of Xcode are you using?
    • What was the complete configure command line?
    • Is the error from trying to compile xvidcore?
    •  

      Example compilation of xvidcore:

       

      snowy@wintermute(/Volumes/Ramdisk) $ tar xzpf xvidcore-1.3.1.tar.gz
      snowy@wintermute(/Volumes/Ramdisk) $ cd xvidcore
      snowy@wintermute(/Volumes/Ramdisk/xvidcore) $ cd build/generic
      snowy@wintermute(/Volumes/Ramdisk/xvidcore/build/generic) $ ./configure –prefix=/Volumes/Ramdisk
      […some configure output…]
      snowy@wintermute(/Volumes/Ramdisk/xvidcore/build/generic) $ make
      [..some make outout…]
      /usr/bin/ranlib: file: libxvidcore.a(timer.o) has no symbols
      ranlib: file: libxvidcore.a(timer.o) has no symbols
      L: libxvidcore.4.dylib

      —————————————————————
      Xvid has been successfully built.

      * Binaries are currently located in the ‘=build’ directory
      * To install them on your system, you can run ‘# make install’
      as root.
      —————————————————————

      snowy@wintermute(/Volumes/Ramdisk/xvidcore/build/generic) $ make install
      D: /Volumes/Ramdisk/lib
      I: /Volumes/Ramdisk/lib/libxvidcore.4.dylib
      I: /Volumes/Ramdisk/lib/libxvidcore.a
      D: /Volumes/Ramdisk/include
      I: /Volumes/Ramdisk/include/xvid.h

       
      Then you can delete libxvidcore.4.dylib and make ffmpeg link against the static version of xvidcore (libxvidcore.a)

      • i686-apple-darwin10-gcc-4.2.1 (GCC) 4.2.1 (Apple Inc. build 5664)
        on OSX 10.6.7

        using :
        $ tar xzpf xvidcore-1.3.1.tar.gz
        $ cd xvidcore
        $ cd build/generic
        $ ./configure –prefix=/Volumes/Ramdisk

        I get (last 5 lines):
        A: plugins/x86_asm/plugin_ssim-a.asm
        L: libxvidcore.a
        ar: libxvidcore.a is a fat file (use libtool(1) or lipo(1) and ar(1) on it)
        ar: libxvidcore.a: Inappropriate file type or format
        make: *** [=build/libxvidcore.a] Error 1

        I have to use

        • What version of Xcode ist installed?
          Are you trying to compile an universal binary?

          Please execute the following in a new shell:

          $ unset CFLAGS
          $ unset CXXFLAGS
          $ unset LDFLAGS
          $ unset CC
          $ tar xzpf xvidcore-1.3.1.tar.gz
          $ cd xvidcore
          $ cd build/generic
          $ ./configure
          $ make

           

          Does that work?

          • Not working, getting (last 3 lines):

            ranlib: archive member: libxvidcore.a(plugin_ssim-a.o) cputype (7) does not match previous archive members cputype (16777223) (all members must match)

            ranlib: for architecture: x86_64 file: libxvidcore.a(timer.o) has no symbols

            make: *** [libxvidcore.a] Error 1

            I’m using xcode 3.2.6 and gcc 4.2.1 on Snow 10.6.7

  18. Can you try manually setting CFLAGS prior to running configure?

    $ expot CFLAGS=”-m64″
    $ export CPPFLAGS=$CFLAGS

    $ tar xzpf xvidcore-1.3.1.tar.gz
    $ cd xvidcore
    $ cd build/generic
    $ ./configure –prefix=/Volumes/Ramdisk

    If that fails, in a new shell at a new location:

    $ expot CFLAGS=”-m32″
    $ export CPPFLAGS=$CFLAGS

    $ tar xzpf xvidcore-1.3.1.tar.gz
    $ cd xvidcore
    $ cd build/generic
    $ ./configure –prefix=/Volumes/Ramdisk

    If both fail, retry both steps by adding –disable-assembly to the configure command line.

    Does that help?

  19. Forgive me for being an ignoramus. I tried to install git. I only changed the version to a newer one (1.7.4.4) and had to use a .tar.gz as the .tar.bz2 one downloaded into Terminal and froze it. So anyway, it was going well until I got an error. I would appreciate any advice as to what to do next.

    (The /sw directory was created by fink, which is how I installed all the dependent files. But it only can get a pretty old version of ffmpeg)

    . . . . CC xdiff/xpatience.o
    AR xdiff/lib.a
    LINK git-daemon
    ld: warning: in /sw/lib/libiconv.dylib, file was built for i386 which is not the architecture being linked (x86_64)
    Undefined symbols:
    "_libiconv_open", referenced from:
    _reencode_string in libgit.a(utf8.o)
    "_libiconv", referenced from:
    _reencode_string in libgit.a(utf8.o)
    "_libiconv_close", referenced from:
    _reencode_string in libgit.a(utf8.o)
    _reencode_string in libgit.a(utf8.o)
    ld: symbol(s) not found
    collect2: ld returned 1 exit status
    make: *** [git-daemon] Error 1
    Jims-MacBook-Pro:git-1.7.4.4 jim$

    • You are trying to link libiconv 32bit to a 64bit binary which will not work.
      There are two possible solutions:

      – Build a x86_64 libiconv to link against
      – Build a 32bit git binary by setting CFLAGS to -arch i386

    • Thank you for the information! Maybe I should put up a link list of where to get all the supporting libraries.

  20. hi again,

    have you ever tried to build libfreetype? So in the ffmpeg part i passed –enable-libfreetype and i added the following build instructions prior to building ffmpeg:

    $ cd ${CMPL}
    $ tar xjpf ${MES}/freetype-2.4.5.tar.bz
    $ cd freetype-2.4.5
    $ ./configure –prefix=${TARGET} –disable-shared –enable-static
    $ make -j 4 && make install

    the freetype seems to build fine but i always get freetype2 not found when ffmpeg starts to build and it quits. any idea why?

    rc

    • The ./configure script executes a subroutine called check_pkg_config to detect libfreetype2 which looks like this:

      check_pkg_config(){
          log check_pkg_config "$@"
          pkg="$1"
          headers="$2"
          funcs="$3"
          shift 3
          $pkg_config --exists $pkg 2>/dev/null || return
          pkg_cflags=$($pkg_config --cflags $pkg)
          pkg_libs=$($pkg_config --libs $pkg)
          check_func_headers "$headers" "$funcs" $pkg_cflags $pkg_libs "$@" &&
              set_safe ${pkg}_cflags $pkg_cflags   &&
              set_safe ${pkg}_libs   $pkg_libs
      }
      

      As you can see, the subroutine completely disregards any CFLAGS or LDFLAGS
      you may have set and soley relies on the existence of a program/script named ‘pkg-config’
      which it queries for as seen on the last line of config.log:

      check_pkg_config freetype2 ft2build.h freetype/freetype.h FT_Init_FreeType

      Futher information concerning pkg-config can be found here:
      http://people.freedesktop.org/~dbn/pkg-config-guide.html

      Anyway, for libfreetype2 to be found, a simple shell script emulation of pkg-config will do:

      #!/bin/bash
      
      case $1 in
          --exists)
              exit 0
          ;;
          --cflags)
              /Volumes/Ramdisk/bin/freetype-config --cflags
          ;;
          --libs)
              /Volumes/Ramdisk/bin/freetype-config --libs
          ;;
      esac
      
      exit 0
      

      Put that into ${TARGET}/bin prior to compiling ffmpeg and it should find freetype2 and successfully compile (and do not forget to modify the /Volumes/Ramdisk path inside the script accordingly).

      • Well I couldn’t get it to work maybe I’m doing something wrong. Here is a little bit of the output below when it quits in case it helps. So basically I did everything like the first time but now I made a file pkg-config.sh and placed it in ${TARGET}/bin before ffmpeg started to build. It’s a copy of what you posted only I changed the path to match my ${TARGET}. Did I do it wrong?

        rmdir /Volumes/Ramdisk/sw/include/freetype2/freetype/internal
        rmdir: /Volumes/Ramdisk/sw/include/freetype2/freetype/internal: No such file or directory
        make: [install] Error 1 (ignored)
        /usr/bin/install -c -m 644 ./builds/unix/ft2unix.h \
        /Volumes/Ramdisk/sw/include/ft2build.h
        /usr/bin/install -c -m 644 ./builds/unix/ftconfig.h \
        /Volumes/Ramdisk/sw/include/freetype2/freetype/config/ftconfig.h
        /usr/bin/install -c -m 644 /Volumes/Ramdisk/compile/freetype-2.4.5/objs/ftmodule.h \
        /Volumes/Ramdisk/sw/include/freetype2/freetype/config/ftmodule.h
        /usr/bin/install -c -m 755 ./builds/unix/freetype-config \
        /Volumes/Ramdisk/sw/bin/freetype-config
        /usr/bin/install -c -m 644 ./builds/unix/freetype2.m4 \
        /Volumes/Ramdisk/sw/share/aclocal/freetype2.m4
        /usr/bin/install -c -m 644 ./builds/unix/freetype2.pc \
        /Volumes/Ramdisk/sw/lib/pkgconfig/freetype2.pc
        ERROR: freetype2 not found

        If you think configure made a mistake, make sure you are using the latest
        version from Git. If the latest version fails, report the problem to the
        ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
        Include the log file “config.log” produced by configure as this will help
        solving the problem.
        logout

        [Process completed]

        • The script must be called ‘pkg-config’ not ‘pkg-config.sh’.
          Also, make it executable by ‘chmod 755 pkg-config’

          • Hi hexeract,

            I met troubles when compiling ffmpeg.
            When I add the –enable-libopencv flag, configure give the error message: opencv not found.
            I installed opencv, and have tried opencv-2.0, opencv-2.1, opencv-2.2, opencv-2.3, the result is the same.

            could you give some suggestions?

            Thanks.

          • The problem of ffmpeg not finding opencv has two reasons: It gnores CFLAGS and LDFLAGS concerning the check for opencv and uses pkg-config to obtain opencv specific compiler and linker flags.

             
            Diving deep into the configure script for ffmpeg reveal two shell functions responsible for checking the availablity of opencv.

             
            Within the configure script, it uses require-pkg_config to detect and (if found, set the CFLAGS and LDFLAGS accordingly).

             
            Actual configure line checking for opencv:

             
            require_pkg_config opencv opencv/cxcore.h cvCreateImageHeader
            

             
            require_pkg_config:

            require_pkg_config(){
                pkg="$1"
                check_pkg_config "$@" || die "ERROR: $pkg not found"
                add_cflags    $(get_safe ${pkg}_cflags)
                add_extralibs $(get_safe ${pkg}_libs)
            }
            

             
            check_pkg_config which is called by require_pkg_config

            check_pkg_config(){
                log check_pkg_config "$@"
                pkg="$1"
                headers="$2"
                funcs="$3"
                shift 3
                $pkg_config --exists $pkg 2>/dev/null || return
                pkg_cflags=$($pkg_config --cflags $pkg)
                pkg_libs=$($pkg_config --libs $pkg)
                check_func_headers "$headers" "$funcs" $pkg_cflags $pkg_libs "$@" &&
                    set_safe ${pkg}_cflags $pkg_cflags   &&
                    set_safe ${pkg}_libs   $pkg_libs
            }
            

             
            Be sure to create a 2GB sized Ramdisk :)

             
            The first step is to create a file in ${TARGET}/bin called ‘pkg-config’. Do not forget to change the path if you have named your ramdisk differently.

            #!/bin/bash
            
            case $1 in
                --exists)
                    exit 0
                ;;
                --cflags)
                    echo "-I/Volumes/Ramdisk/include -I/Volumes/Ramdisk/include/opencv"
                ;;
                --libs)
                     echo "-L/Volumes/Ramdisk/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann" 
                ;;
            esac
            

             
            In order to build opencv the ‘cmake’ program is required, so we need to build it.

            cd /Volumes/Ramdisk
            mkdir compile
            cd compile
            curl -O http://www.cmake.org/files/v2.8/cmake-2.8.5.tar.gz
            tar xzpf cmake-2.8.5
            cd cmake-2.8.5
            ./configure --prefix=/Volumes/Ramdisk
            make -j 2
            make install
            

             
            Building opencv

            export PATH=/Volumes/Ramdisk/bin:$PATH
            cd /Volumes/Ramdisk
            cd compile
            curl -O http://switch.dl.sourceforge.net/project/opencvlibrary/opencv-unix/2.3/OpenCV-2.3.0.tar.bz2
            tar xjpf OpenCV-2.3.0.tar.bz2
            cd OpenCV-2.3.0
            mkdir release
            cd release
            cmake -D CMAKE_BUILD_TYPE=RELEASE -D CMAKE_INSTALL_PREFIX=/Volumes/Ramdisk -D BUILD_SHARED_LIBS=NO .. 
            make -j 2
            make install
            

             
            Building ffmpeg

            cd /Volumes/Ramdisk
            cd compile
            git clone git://git.videolan.org/ffmpeg.git
            cd ffmpeg
            ./configure --prefix=/Volumes/Ramdisk --enable-libopencv --enable-static --disable-shared --disable-yasm
            

             
            Sadly, this will blow up, checking the config.log shows:

            Undefined symbols for architecture i386:
              "std::basic_string<char, std::char_traits<char>, std::allocator<char> >::basic_string(char const*, std::allocator<char> const&)", referenced from:
                  cv::OutOfMemoryError(unsigned long)in libopencv_core.a(alloc.o)
                  _cvSetMemoryManager in libopencv_core.a(alloc.o)
                  _cvSetIPLAllocators in libopencv_core.a(array.o)
                  _cvReleaseMat in libopencv_core.a(array.o)
                  _cvInitMatHeader in libopencv_core.a(array.o)
                  _cvCreateMatHeader in libopencv_core.a(array.o)
                  _cvInitMatNDHeader in libopencv_core.a(array.o)
            

             
            When researching the error message it seems that additional linking to libstdc++ is required. A minor change to pkg-config is required to make the configure run of ffmpeg to be successful:

            #!/bin/bash
            
            case $1 in
                --exists)
                    exit 0
                ;;
                --cflags)
                    echo "-I/Volumes/Ramdisk/include -I/Volumes/Ramdisk/include/opencv"
            
                ;;
                --libs)
                     echo "-lstdc++ -L/Volumes/Ramdisk/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann"
                ;;
            esac
            exit 0
            

             
            With this modification, the ffmpeg ./configure run works fine and ffmpeg builds:

            /Volumes/Ramdisk/bin/ffmpeg 
            ffmpeg version N-31743-g324b8ad, Copyright (c) 2000-2011 the FFmpeg developers
              built on Aug  3 2011 19:22:19 with gcc 4.2.1 (Apple Inc. build 5666) (dot 3)
              configuration: --prefix=/Volumes/Ramdisk --enable-libopencv --enable-static --disable-shared --disable-yasm
              libavutil    51. 11. 1 / 51. 11. 1
              libavcodec   53.  9. 1 / 53.  9. 1
              libavformat  53.  6. 0 / 53.  6. 0
              libavdevice  53.  2. 0 / 53.  2. 0
              libavfilter   2. 27. 5 /  2. 27. 5
              libswscale    2.  0. 0 /  2.  0. 0
            Hyper fast Audio and Video encoder
            usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...
            
            Use -h to get full help or, even better, run 'man ffmpeg'
            

             
            I am not sure how to use opencv via ffmpeg but I hope you can retrace my steps successfully to compile ffmpeg linking against opencv.

          • It works. Thank you very much! I have another question. When I use frei0r filter like this
            ffmpeg -i 123.avi -vf “frei0r=distort0r:0.5:0.01” /Volumes/123.mp4
            ffmpeg gives the following error message
            [frei0r @ 0x16029a0] Could not find module ‘distort0r’
            Error initializing filter ‘frei0r’ with args ‘distort0r:0.5:0.01’
            I have no idea about this, please help me.
            Thanks again.

          • Thank you!
             
            Checking the libavfilter documentation, section 8.12:
            To enable compilation of this filter you need to install the frei0r header and configure FFmpeg with –enable-frei0r.
            I assume you need compile frei0r and then compile ffmpeg accordingly.
             
            If you already have ffmpeg compiled with (a recent version of) frei0r the only advice I can give you is to ask on the ffmpeg user mailing list for assistance.

          • Actually there is also another way to solve the opencv problem as I found out.

            If you already have pkg-config installed locally say under /usr/bin/pkg-config, and opencv is statically compiled successfully then all you need to do is pass to the configure option the following:

            ./configure –extra-cflags=”-I/home/ubuntu/ffmpeg2012/build/include/opencv -I/home/ubuntu/ffmpeg2012/build/include” –extra-libs=”-lstdc++ -L/home/ubuntu/ffmpeg2012/build/lib -lopencv_core -lopencv_imgproc -lopencv_highgui -lopencv_ml -lopencv_video -lopencv_features2d -lopencv_calib3d -lopencv_objdetect -lopencv_contrib -lopencv_legacy -lopencv_flann” .. other config options

            If you need to find out what to put within the extra-libs and extra cflags for static libs just use pkg-config like so:

            pkg-config –libs –static opencv

          • Concerning opencv, see my comment “2011/08/03 at 14:31”.

            I did not include the compilation steps for opencv in the main article because I do not think that many people require this feature (and also adds quite an overhead to the overall proceess and final result).

  21. Hi Hexeract,

    I have been following your post several weeks and I’ve got to make a Bash Script to automate de process of compiling FFmpeg in Mac OS X 10.6 (Snow Leopard) with the following tools:
    – Git
    – Mercurial
    – Nasm
    – Yasm
    – Lame
    – FAAD2
    – FAAC
    – Libvpx (WebM – VP8)
    – OpenCore-AMR
    – SDL
    – x264
    – FFmpeg

    I am missing (Theora, Vorbis, Xvid…) those will come later.

    I have been doing some research and I am been unable to make a static link. otool -L shows me:
    otool -L /usr/local/bin/ffmpeg
    /usr/local/bin/ffmpeg:
    /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 15.0.0)
    /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 38.0.0)
    /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 152.0.0)
    /System/Library/Frameworks/AudioToolbox.framework/Versions/A/AudioToolbox (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/AudioUnit.framework/Versions/A/AudioUnit (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
    /usr/local/lib/libopencore-amrwb.0.dylib (compatibility version 1.0.0, current version 1.0.0)
    /usr/local/lib/libopencore-amrnb.0.dylib (compatibility version 1.0.0, current version 1.0.0)
    /usr/local/lib/libmp3lame.0.dylib (compatibility version 1.0.0, current version 1.0.0)
    /usr/local/lib/libfaac.0.dylib (compatibility version 1.0.0, current version 1.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.11)
    /usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5)
    /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
    /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 227.0.0)
    /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 44.0.0)
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 550.43.0)
    /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 751.62.0)
    /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1038.36.0)

    Any ideas? I am up to sharing the bash script and credit with you.

    Thanks in advance.

    • For what its worth – I started a bash script in 2009 when this thread first started and I am happy to share it with you in case you can use it. I haven’t run it in a while, but if I remember correctly it worked at the time to automate the process. It is a menu driven script. Obviously the sources may have changed and other intricacies may have changed but maybe it can help you get a start. You can download my bash script here: http://cl.ly/1A3N3d3A1G3d132V1g2h

      • Thank you very much for sharing your script!

        I already have a set of shell scripts to automatically build ffmpeg, ffmpeg-libav and mplayer but they are crude and should never see the light of day :)
        If you are interested please contact me again and I will send them via email to you (or any other interested party).

      • Great! I definitelly will take a look at it. I’ll probably have to make many changes to mine before it sees the light as Hexeract says :P…

        I’ll take some time tonight (8 pm here now) and will get back to you tomorrow with some feedback.

        Many thanks in advance!!!!!

      • Any chance any of the scripts available supports binaries that work all the way back to Tiger as well as PPC? I’d like to build a super-fat ffmpeg binary that works on basically every Mac system still in use. There is a lame binary available online that is built like that, but no ffmpeg binary like that as far as I’ve seen.

        • Basically, the best approach would be to build each architecture seperatly and then “glueing” them together using ‘lipo’.

          To create PPC binaries you need Xcode 3 and the following environment setup:

          export CC=/usr/bin/gcc-4.0
          export CFLAGS=”-isysroot /Developer/SDKs/MacOSX10.4u.sdk -arch ppc -mmacosx-version-min=10.4″
          export LDFLAGS=”-Wl,-syslibroot,/Developer/SDKs/MacOSX10.4u.sdk -arch ppc -mmacosx-version-min=10.4″

          Trying to use multiple ‘-arch’ arguments will just break compilation for some media libraries.

          I remember I once tried to do that but it was quite a lot of hassle to do it on an Intel machine
          and as I did not need a PPC binary I let it be.

          If you do have a PPC machine it would be interesting to know if my guide helps in compiling a PPC only version (since that would be built by default).

  22. I already have a bash script :)
    Actually, I have 4. One for each program and a script that compiles all the media codec libraries.

    Judging from your ‘otool -L’ output, I suspect quite a few of those come from the SDL you include.
    Why would you want to include SDL on MacOSX?

    Concerning OpenCore AMR:
    I used the following source archive: vo-amrwbenc-0.1.1.tar.gz
    Simply unpacking and compiling it:

    $ tar xzpf vo-amrwbenc-0.1.1.tar.gz
    $ cd vo-amrwbenc-0.1.1
    $ ./configure –prefix=/Volumes/Ramdisk –enable-static –disable-shared

    Provides libraries that can be statically linked to ffmpeg.

    The path shown in the output of ‘otool -L’ is ‘/usr/local/lib’
    I would think you compiled it without –disable-shared and the target was /usr/local/.

    In any case I do not recommend compiling to /usr/local/ but to a ram disk instead.
    It will keep your system clean and you do not need to worry about breaking things.

    This is what my output looks like:

    snowy@wintermute(~) $ ffmpeg -version
    ffmpeg version N-32911-gbf85b90-snowy, Copyright (c) 2000-2011 the FFmpeg developers
    built on Sep 25 2011 10:28:48 with gcc 4.2.1 (Apple Inc. build 5666) (dot 3)
    configuration: –prefix=/Volumes/ffmpeg-latest/ –as=yasm –extra-version=snowy –disable-shared –enable-static –disable-ffplay –disable-ffserver –enable-gpl –enable-pthreads –enable-gray –enable-postproc –enable-libfaac –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-libvo-aacenc –enable-libvo-amrwbenc –enable-nonfree –enable-version3 –enable-runtime-cpudetect
    libavutil 51. 17. 0 / 51. 17. 0
    libavcodec 53. 17. 0 / 53. 17. 0
    libavformat 53. 13. 0 / 53. 13. 0
    libavdevice 53. 4. 0 / 53. 4. 0
    libavfilter 2. 43. 5 / 2. 43. 5
    libswscale 2. 1. 0 / 2. 1. 0
    libpostproc 51. 2. 0 / 51. 2. 0
    ffmpeg N-32911-gbf85b90-snowy
    libavutil 51. 17. 0 / 51. 17. 0
    libavcodec 53. 17. 0 / 53. 17. 0
    libavformat 53. 13. 0 / 53. 13. 0
    libavdevice 53. 4. 0 / 53. 4. 0
    libavfilter 2. 43. 5 / 2. 43. 5
    libswscale 2. 1. 0 / 2. 1. 0
    libpostproc 51. 2. 0 / 51. 2. 0

    snowy@wintermute(~) $ otool -L .bin/ffmpeg
    .bin/ffmpeg:
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.0)

  23. JUST GREAT!!!

    I have been able to make a better binary (more library independent) than mine thanks to your recommendations. Making the Ramdisk just made my day!!!!

    Thank you very much.

    I have a question. Why do you compile section “Building libav’s ffmpeg” after FFmpeg? Aren’t the libs into FFmpeg git repository? If they are needed to be compiled, shouldn’t it be done before building FFmpeg?

    Thanks in advance.

    • I may have been unclear in the guide :( I will fix that.

      I do not build libav’s ffmpeg _after_ ffmpeg. I build either of the three after all “base libraries” have been successfully compiled.
      Most likely building libav’s ffmpeg after ffmpeg will work and will not introduce any unwanted dependencies.

        • You are welcome to publish the blog posting on gist.github.com.
          If you do, please make a reference to the original source.

          Also, I do update the blog posting when a new version of a library is available or configure flags change.

  24. I would like to compile FFmpeg with freetype and libass. Any help for this is welcome !
    TIA

  25. Well, two issues. I cannot get the Freetype to compile correctly (I think). And compiling libass gives this error:

    “checking for FREETYPE… configure: error: in `/Volumes/tempdisk/compile/libass-0.10.0′:
    configure: error: The pkg-config script could not be found or is too old. Make sure it
    is in your PATH or set the PKG_CONFIG environment variable to the full
    path to pkg-config.
    Alternatively, you may set the environment variables FREETYPE_CFLAGS
    and FREETYPE_LIBS to avoid the need to call pkg-config.
    See the pkg-config man page for more details.
    To get pkg-config, see .
    See `config.log’ for more details.”

    It would be great if you figure out how to compile both because with 0.90 it should be (finally) possible to hardcode subtitles.
    I am a bit of a noob with compiling though following your steps I manage to do it every time. As said, I am a bit of a noob to try it with freetype and libass :-) :-)

  26. That is easy to solve. Create a “fake” pkg-config script. Please check the other comments of this posting where I describe on how to build the pkg-config script for freetype2 (once freetype2 was successfully compiled and installed into the Ramdisk).

    libass actually has quite a few dependencies and a bad configure script since it will state it has found other dependencies which clearly are not available:

    – enca
    – fontconfig
    – fribidi

    Once you compile freetype2, enca, fontconfig and fribidi the compilation of libass will fail
    since some types will not match… I am not enough of a programmer to fix this and I have not yet found enough information about how others managed to fix it. I would suspect not using the latest fribidi might help but this assumption is untested…

    • As stated previously, compiling libass itself is not the problem, the dependencies are and I stopped at “fribidi”. If you do manage to take the time and find out which version will actually work with libass, please let me know…

  27. It would be great some-one could manage to compile FFmpeg with LibASS support. Reading above it doesn’t seems to be easy.

    • It must be possible since both Handbrake and VLC have libass support (as far as I know). If only there was access to their build infrastructure/scripts…
      The latter would probably show which versions have to be used and will play nicely together to get a (static) libass library…

      If anyone does have any helpful suggestions/hints, please do not hesitate to make a comment on this blog or contact me.

  28. Pingback: Compiling FFmpeg/MPlayer with single command | Video Gorillas
      • That guide is not really of any help, finding the libraries can be a hassle but is not too difficult.
        Mentioning that freetype is needed is merely a hint, but does not mention of the other dependencies libass actually has…

        The guide provides an overview of what can be included but has no step to step compilation documentation.

    • There must be a working set of versions of freetype, enca, frontconfig and fribidi for libass to compile (since it obviously has been done for VLC and the win32 static ffmpeg binary that is mentioned in the URL you have provided) but it seems everyone is keeping it secret on how to actually build libass. Even the libass author fails to document on how to build libass… go figure..

      Sadly, the site you mention does not provide exact versions for the libass dependencies (and even fails to mention there are any!), so I am back to square one.
      Nevertheless, if I have some spare time at the weekend I will give it another (most likely futile) try.

    • the pkg-config part is easy, I assume you need that for freetype to be found?
      Please search the comments where I have described on how to set up a “dummy” pkg-config.
      If you need a different pkg-config modify accordingly.

      All that pkg-config does is to supply the include path and library path and the configure picks up on the result.

  29. Hi,

    I know this is not exactly ffmpeg, but do you know how to build dvdauthor on Mac? I keep getting an error that I need libpng(-devel) but I haven’t been able to figure it out. Thought it won’t hurt to ask. :-)

    • The program dvdauthor was not written with libpng 1.5.x in mind which has changed some internals thus breaking a source code line in ./src/spuunmux.c. Also, in the same file, the reference for the zlib.h include file is missing. The two perl lines fixes the problems in a very crude fashion.

      On my box MacOSX 10.7.3, latest Xcode and installed command line tools via Xcode, the following script works and results in a dvdauthor binary:

       

      #!/bin/bash
      
      NAME=Ramdisk
      SIZE=2097152
      
      DISK_ID=$(hdid -nomount ram://$SIZE)
      newfs_hfs -v ${NAME} ${DISK_ID}
      diskutil mount ${DISK_ID}
      
      export CC=clang
      
      cd /Volumes/Ramdisk/
      
      BASEDIR=$(pwd)
      
      mkdir $BASEDIR/sw
      
      mkdir $BASEDIR/sources
      cd    $BASEDIR/sources
      
      export LDFLAGS="-L$BASEDIR/sw/lib"
      export  CFLAGS="-I$BASEDIR/sw/include"
      
      curl -O http://zlib.net/zlib-1.2.6.tar.gz
      tar xzpf zlib*
      cd zlib*
      ./configure --prefix=$BASEDIR/sw --static
      make && make install
      
      cd $BASEDIR/sources
      
      curl -O http://dfn.dl.sourceforge.net/project/libpng/libpng15/1.5.10/libpng-1.5.10.tar.gz
      tar xzpf libpng*
      cd libpng*
      ./configure --prefix=$BASEDIR/sw --enable-static --disable-shared
      make && make install
      
      
      cd $BASEDIR/sources
      
      curl -O http://garr.dl.sourceforge.net/project/dvdauthor/dvdauthor/0.7.0/dvdauthor-0.7.0.tar.gz
      tar xzpf dvdauthor*
      cd dvdauthor*
      
      FIXME=./src/spuunmux.c
      
      perl -p -i -e "s;<png.h>;<png.h>\n#include <zlib.h>\n" $FIXME
      perl -p -i -e "s;png_ptr->jmpbuf;png_jmpbuf(png_ptr);" $FIXME
      
      ./configure --prefix=$BASEDIR/sw 
      make && make install
      
      clear
      cd $BASEDIR/sw/bin
      ls -l dvdauthor
      ./dvdauthor -version
      otool -L ./dvdauthor
      

      Hope this helps.

      • As always you’re the best! :-) Thanks for the help. Just curious this is a static build right? I used your script on 10.7.3 (worked perfectly) and with otool -L I got this:

        /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
        /usr/lib/libxml2.2.dylib (compatibility version 10.0.0, current version 10.3.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
        /usr/lib/libicucore.A.dylib (compatibility version 1.0.0, current version 46.1.0)

        But on an older Mac with Xcode 3 I removed the exportCC=clang line and got this:

        /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
        /usr/lib/libxml2.2.dylib (compatibility version 9.0.0, current version 9.16.0)
        /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 111.1.7)
        /usr/lib/libicucore.A.dylib (compatibility version 1.0.0, current version 36.0.0)
        /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)

        Anything to be concerned about you think? Some older dvdauthor binaries I found on the internet even show different results so I’m not sure? Thanks again!

        • That looks about right. You can never really build a “truly” static binary on MacOSX,
          you will always end up with at least libSystem*dylib…

          What you can do is to avoid too many “outside” dependencies and have the binary just depend on the (minima) set of system libraries provided by the operating system.

          This is my otool -L output:

          ./dvdauthor:
          /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
          /usr/lib/libxml2.2.dylib (compatibility version 10.0.0, current version 10.3.0)
          /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
          /usr/lib/libicucore.A.dylib (compatibility version 1.0.0, current version 46.1.0)

          That binary should be able to run on any other 10.7.x System. If you target an older operating system you will probably have to use the gcc provided by Xcode 3,x and use the following environment variables for CC, CFLAGS and LDFLAGS, which you can place right after setting LDFLAGS and CFLAGS in the script:

          export CC=”/Developer-old/usr/bin/gcc-4.0″
          export CFLAGS=”$CFLAGS -isysroot /Developer-old/SDKs/MacOSX10.4u.sdk -arch i386 -mmacosx-version-min=10.4″
          export LDFLAGS=”$LDFLAGS -Wl,-syslibroot,/Developer-old/SDKs/MacOSX10.4u.sdk -arch i386 -mmacosx-version-min=10.4″

          This will produce the following file:

          otool -L:
          ./dvdauthor:
          /usr/lib/libiconv.2.dylib (compatibility version 5.0.0, current version 5.0.0)
          /usr/lib/libxml2.2.dylib (compatibility version 9.0.0, current version 9.16.0)
          /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.3)
          /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 88.3.11)
          /usr/lib/libicucore.A.dylib (compatibility version 1.0.0, current version 32.0.0)
          /usr/lib/libgcc_s.1.dylib (compatibility version 1.0.0, current version 1.0.0)

          file /Volumes/Ramdisk/sw/bin/dvdauthor:
          /Volumes/Ramdisk/sw/bin/dvdauthor: Mach-O executable i386

          As I do not have access to a 10.4 machine I can not verify that this binary will actually run.

    • I have not had any spare time to play around with that problem. Also, as I do not need that functionality myself, the priority for this is very low.

      You can try yourself, it is just a matter of trying various combinations of the required dependencies until libass compiles, from there on, compiling ffmpeg should not be a problem..

  30. Hello,

    Thanks for the awesome guide. I’ve followed your guide step-by-step and there are 2 things I wanted to mention:

    1) Although using ‘–disabled-shared –enabled-static’ there are several dylib files in ${TARGET}/lib which have to be deleted before compiling ffmpeg. Otherwise the dynamic libraries are used, even, if you specify ‘–disabled-shared –enabled-static’ for ffmpeg.
    2) otool -L ./ffmpeg
    ./ffmpeg:
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 125.2.11)
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 550.44.0)
    /System/Library/Frameworks/VideoDecodeAcceleration.framework/Versions/A/VideoDecodeAcceleration (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.6.3)
    /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.6.2)

    I have no idea where the /System/Library/Frameworks/* are coming from.

    • Can you list the .dylib files in your ${TARGET}/lib?
      This will help me cross-check with my own build environment.

      • Hi,

        Thanks for your quick reply. Here are the .dylib files in my ${TARGET}/lib (I had to install them again, since I had deleted them to compile ffmpeg…):

        libfaac.0.0.0.dylib
        libfaac.0.dylib -> libfaac.0.0.0.dylib
        libfaac.dylib -> libfaac.0.0.0.dylib
        libfaad.2.0.0.dylib
        libfaad.2.dylib -> libfaad.2.0.0.dylib
        libfaad.dylib -> libfaad.2.0.0.dylib
        libmp3lame.0.dylib
        libmp3lame.dylib -> libmp3lame.0.dylib
        libogg.0.dylib
        libogg.dylib -> libogg.0.dylib
        libopencore-amrnb.0.dylib
        libopencore-amrnb.dylib -> libopencore-amrnb.0.dylib
        libopencore-amrwb.0.dylib
        libopencore-amrwb.dylib -> libopencore-amrwb.0.dylib
        liborc-0.4.0.dylib
        liborc-0.4.dylib -> liborc-0.4.0.dylib
        liborc-test-0.4.0.dylib
        liborc-test-0.4.dylib -> liborc-test-0.4.0.dylib

        Btw, do you see the /System/Library/Frameworks/* in your binary? In any case, do you have any idea why they are there?

        • This is my otool output:

          snowy@snowcrash(/Volumes/ffmpeg-latest) $ otool -L bin/ffmpeg
          bin/ffmpeg:
          /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
          /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 635.21.0)
          /System/Library/Frameworks/VideoDecodeAcceleration.framework/Versions/A/VideoDecodeAcceleration (compatibility version 1.0.0, current version 1.0.0)
          /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.7.0)
          /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.7.0)
          snowy@snowcrash(/Volumes/ffmpeg-latest) $

          You can not build a “truly” static binary on OSX, you will always have some libSystem*.dynlib dependency.

          Checking my $TARGET/lib does not show any .dylib files…

          Do you have a script or do you follow each step manually?

          Are you using the versions as shown in the posting?

          • I don’t have a script yet, so I have done everything manually.

            I’ve used a few more recent versions: vo-aacenc-0.1.2.tar.gz, vo-amrwbenc-0.1.2.tar.gz, zlib-1.2.7.tar.gz, libvpx-v1.1.0.tar.bz2.
            I’ve also used 2 additional packages: orc-0.4.16.tar.gz, opencore-amr-0.1.3.tar.gz.

            Oh, and for ffmpeg 0.11 you get an error, when using ‘–enable-libfaad’ with configure.

            It is also interesting that you compile gsm, but do not add it to the options when configuring ffmpeg. I thought you have to add ‘–enable-libgsm’.

          • Thank you very much for your report!
            I have updated the posting to reflect all changes made to the compilation workflow.

            Checking on libgsm, your observation was correct. Indeed I omitted –enable-libgsm
            assuming ffmpeg would find it automatically. Sadly, this was not the case.
            Another fix to the Makefile of gsm-1.0-pl13 will install the gsm.h header file
            into include/gsm/ where ffmpeg searches for it when provided with –enable-libgsm

            Yet I was unable to reproduce the creation of the dynamic libraries.
            What you can do is to delete those libraries after each step since ffmpeg
            will have no other choice but to use the static libraries..

            Checking the configure flags, there is no –enable-libfaad and hence I doubt
            ffmpeg really uses that… Maybe mplayer/mencoder does :)

            If you happen to compile ffmpeg on a regular basis I strongly advise you to
            make (large) shell script to automate the compilation.
            Saves a lot of time and spares you from headaches :)

          • No worries, I’ll write a script soon. :-) I’m just pretty busy with other stuff right now…
            It doesn’t really matter that there are dynamic libs as well, since I could work around it by deleting them. It’s just weird that they are created with ‘–disabled-shared –enable-static’.

          • Basically, what you see in the posting is the main part of the script, I just have some error checking and creating a DMG when everything ran successfully.

            I still do not understand how you get the shared libs when using –disable-shared –enable-static. With my test runs, they never were built when using those options. You can always “clean” out $TARGET/lib after each step, although that not be an elegant way of “avoiding” shared libraries.

          • You are welcome!
            If you need any further help, I would be more than happy to assist.

  31. When compiling with –enable-libass I get this error:

    checking for FREETYPE… yes
    checking for FRIBIDI… yes
    checking for FONTCONFIG… yes
    checking for HARFBUZZ… yes
    checking for ENCA… yes

    In file included from ass_cache.c:27:
    ./ass_utils.h:30:10: fatal error: ‘enca.h’ file not found
    #include
    ^
    In file included from ass_fontconfig.c:32:
    ./ass_utils.h:30:10: fatal error: ‘enca.h’ file not found
    #include
    ^
    In file included from ass_font.c:33:
    ./ass_fontconfig.h:29:10: fatal error: ‘fontconfig/fontconfig.h’ file not found
    #include
    ^
    In file included from ass.c:38:
    ./ass_utils.h:30:10: fatal error: ‘enca.h’ file not found
    #include

    Any thoughts?

    • libass is being unfaithful to you concerning the dependencies that are found.

      You need to compile the required dependencies (enca, fontconfig, fribidi) and make sure that libass, when it compiles) can find the include/library files.

      As stated previously, I have not managed to compile libass and I have not found any good documentation on how other projects who seem to use libass have managed to get a working library.

      • As you can see in my previous mail Enva, Fontconfig, Fribidi and Harfbuzz (also needed).
        Libass finds those libs with no issues – in fact it compiles libass correctly minus the above files. Though other files in the same folder are found and compiled.

        Anyway, if someone can help me out .. let me know

        • Manage to compile Libass but I cannot get it compile into FFmpeg.

          Libraries have been installed in:
          /Volumes/tempdisk/sw/lib

          If you ever happen to want to link against installed libraries
          in a given directory, LIBDIR, you must either use libtool, and
          specify the full pathname of the library, or use the `-LLIBDIR’
          flag during linking and do at least one of the following:
          – add LIBDIR to the `DYLD_LIBRARY_PATH’ environment variable
          during execution

          See any operating system documentation about shared libraries for
          more information, such as the ld(1) and ld.so(8) manual pages.
          ———————————————————————-
          test -z “/Volumes/tempdisk/sw/include/ass” || .././install-sh -c -d “/Volumes/tempdisk/sw/include/ass”
          /usr/bin/install -c -m 644 ass.h ass_types.h ‘/Volumes/tempdisk/sw/include/ass’
          make[2]: Nothing to be done for `install-exec-am’.
          test -z “/Volumes/tempdisk/sw/lib/pkgconfig” || ./install-sh -c -d “/Volumes/tempdisk/sw/lib/pkgconfig”
          /usr/bin/install -c -m 644 libass.pc ‘/Volumes/tempdisk/sw/lib/pkgconfig’

          • From the text you show it is unclear why ffmpeg fails to use libass.
            It only shows a very small bit from the libass make install run.

            Can you provide me with the exact version numbers of the libraries you used to compile libass?
            Preferably with all configure options for each library. This should enable me to retrace your steps.

  32. libass only compiles with 0.9.9 – all newer versions gives a lot of errors.
    Make sure you also compile ENCA, FRIBIDI, FONTCONFIG and FREETYPE (you can use the latest versions for those sources)

    I feel we are getting close. :)

    • libass compiles on both ffmpeg 10, 11 and the git version as I found out today.

      You just need to add the following into the configure command:

      ./configure –extra-libs = ‘-lass -lfontconfig -lexpat -lenca -lm -lfribidi -lfreetype -lz -lbz2 -lxml2’ –extra-ldflags= ‘-lass -lfontconfig -lexpat -lenca -lm -lfribidi -lfreetype -lz -lbz2 -lxml2’ …

      The above works for me on a ubuntu box for a static compile

      • I never doubted that libass will compile with ffmpeg.

        The problem was to figure out which versions of libass, enca, fribidi, freetype and others will work together to produce a static and working libass which can be used to link with ffmpeg….

        • Can you please be a little more specific as to what did not work and what you have tried?

  33. FYI I tried the above instructions but it doesn’t work. To be more exact it works with SL and Lion.
    But with ML it gives too many errors to mention here (almost every source you try to compile gives errors).
    Any update in the tutorial for OSX10.8 ?

    • I recompiled ffmpeg after I have updated to Mountain Lion and the only problem I have encountered was that libvpx did not compile and I had get it from the repository using git.
      Other than that, my compilation whent fine.

      Did you upgrade XCode to 4.4? Did you install the “Command Line Tools”?
      Can you post the complete output of your compilation run?

    • Why should it not build on an i7 with Ivy Bridge?
      I compile on a MacBook Pro with Core i7 and have not had any problems. Can you be more specific about the problems you run into when following the guide?

  34. libvpx could not be compiled. Ogg, Vorbis and Theora also gave a lot of errors.
    I am using a rMBP with Xcode4.4 Maybe it is because of Xcode 4.4 ?

    • Ok, now I got ogg, vorbis and theora compiled without problems.
      I also tried to compile older version of libvpx but to no luck. Anyone got this compiled on ML?

      • What did you do to “fix” the compilation of ogg, vorbis and theora. Compiling the three depends a lot in which sequence you compile each. Order is important.

        Concerning libvpx, try this:

        xport 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 && $MKMU && make install
        unset CFLAGS
        unset LDFLAGS

        instead of using the libvpx-1.0.0.

        This is what it should look like:

        snowy@snowcrash(~/Downloads) $ export CFLAGS=-I/usr/include
        snowy@snowcrash(~/Downloads) $ export LDFLAGS=-L/usr/lib
        snowy@snowcrash(~/Downloads) $ git clone http://git.chromium.org/webm/libvpx.git
        Cloning into ‘libvpx’…
        remote: Counting objects: 21726, done.
        remote: Compressing objects: 100% (5146/5146), done.
        remote: Total 21726 (delta 17164), reused 20829 (delta 16336)
        Receiving objects: 100% (21726/21726), 8.80 MiB | 676 KiB/s, done.
        Resolving deltas: 100% (17164/17164), done.
        snowy@snowcrash(~/Downloads) $ cd libvpx
        snowy@snowcrash(~/Downloads/libvpx) $ export PATH=/Volumes/Ramdisk/bin:$PATH
        snowy@snowcrash(~/Downloads/libvpx) $ type -a yasm
        yasm is /Volumes/Ramdisk/bin/yasm
        snowy@snowcrash(~/Downloads/libvpx) $ ./configure –as=yasm –disable-shared –enable-static –enable-vp8
        Configuring selected codecs
        enabling vp8_encoder
        enabling vp8_decoder
        Configuring for target ‘x86_64-darwin11-gcc’
        enabling x86_64
        enabling runtime_cpu_detect
        enabling mmx
        enabling sse
        enabling sse2
        enabling sse3
        enabling ssse3
        enabling sse4_1
        using yasm
        enabling postproc
        enabling unit_tests
        Creating makefiles for x86_64-darwin11-gcc libs
        Creating makefiles for x86_64-darwin11-gcc examples
        Creating makefiles for x86_64-darwin11-gcc docs
        snowy@snowcrash(~/Downloads/libvpx) $ make -j 8 &>/dev/null && echo “compile worked”
        compile worked
        snowy@snowcrash(~/Downloads/libvpx) $

        (I did omit the make install and unsetting of both CFLAGS and LDFLAGS but I think you get the idea :)

  35. Hoeray, using the latest git it works. Although it still displays a lot of compile errors (warnings) it compiles into FFmpeg very well.
    BTW: you do not need to use –as=yasm and –enable-vp8 – those are the defaults for libvpx

    Question: What does $MKMU do?

    Also, how can I purge the previously compiled bits in the usr/lib ? I mean, ones you compiled libvpx, next time you compile it again it skips 90% if the compiling (because it is already done previously).

    • $MKMU is just a “fancy alias” for make -j 2.

      You are talking about “bits” in /usr/lib. Are you not compiling to a Ramdisk as target?
      The reason the guide creates a Ramdisk is to speed up the compiliation process and to be able to just eject it and thus purge everything without leaving any traces in the system.

      If you have managed to use –prefix=/usr (so you get your libraries in /usr/lib, your includes in /usr/include and your binaries in /usr/bin) this may seem like a good idea at first but you have your system cluttered and purging everything will be a lot of manual work.

      The reasoning behind this does puzzle me since you would have had to build ffmpeg/libav/mplayer to a different directory target as not to risk depedencies between ffmpeg/libav/mplayer. Those will not show up while everything is running on your system but as soon as you moved your ffmpeg/libav/mplayer binary to a “clean” system, it most likely will break.

      You can check the library dependencies for a binary using tool.
      Here is my output for ffmpeg:

      $ otool -L ffmpeg
      ffmpeg:
      /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
      /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 744.0.0)
      /System/Library/Frameworks/VideoDecodeAcceleration.framework/Versions/A/VideoDecodeAcceleration (compatibility version 1.0.0, current version 1.0.0)
      /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.8.0)
      /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
      /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.8.0)

      If you do plan to build ffmpeg more than once or twice a year I advise you to set up a bunch of build scripts, one script to build the media libaries and another to build the final product.
      On my machine, it takes about 8 to 10 minutes (Core i7, 2.5GhZ)

      Although one could really speed up the compilation by using gnu parallels and builing the libraries which do not have dependencies on each other (unlike ogg, theora and vorbis) in parallel. But that is a lot of work just to gain a few minutes. Not to speak on how to actually document what is happening without confusing the reader of the guide even more…

      From your remark, I assume you do not want to keep building the media libraries but
      just want to recompile ffmpeg. In that case, just stop when you have created all the libraries and create a DMG from the Ramdisk using the following command:

      hdiutil create -format UDBZ -volname medialibs -srcfolder /Volumes/Ramdisk $HOME/Downloads/medialibs

      In order to compile ffmpeg/libav/mplayer you just mount the DMG (which will not be a Ramdisk anymore!) and just proceeed as described in the guide. Once the product is created you can create a new DMG containing everything or you could even compile ffmpeg to a completely different target location and make a DMG out of that. The choices are endless :)

  36. I do use a ramdisk. But even when I remove the ramdisk and make a new one the libvpx isn’t compiled fully (only about 10 lines are showed – the first time I compiled libvpx it did take a while and got about +100 lines. Strange…

    The ffmpeg binary I compiled has this as dependencies – so it looks good for a static build.
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 744.0.0)
    /System/Library/Frameworks/VideoDecodeAcceleration.framework/Versions/A/VideoDecodeAcceleration (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.8.0)
    /usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5)
    /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.8.0)

    • I did not investigate as to why libvpx 1.0.0 behaves differently with XCode 4.4.
      For me, it always failed when compiled from the script but when manually navigating to the source directory and reissuing the configure && make command it worked..

      It was easier to try if the git version works and just use that.

  37. BTW nice trick with the dmg ! Will use that for sure.

    Another thingy: I did read about other asking this but how can we add libass?

    • By compiling libass? :)

      As stated previously, I do not need libass and I am really not willing to sit down and figure out this complete mess of depenencies libass has and which combination of versions of libass and its dependencies will result in a static libass library…

      If you can provide me with a guide I will try to follow it and if it works include it into the guide.

    • If you do I strongly recommend you write a script and expand it bit by bit as you go along, this will save you a lot of time in the long run since you will do many compilation runs. Also, make heavy use of a Ramdisk so you can restart the compilation run from scratch.

      Check the other comments as to what to watch out for and how you set up pkg-config for specific libraries required by libass.

  38. When following the above instructions and compile FFmpeg on a Mountain Lion Mac, the FFmpeg cannot be used on Lion or SL. How can I compile a FFmpeg on ML and make it also work on previous OS X versions?

    • If you plan to distribute the ffmpeg you build you need to modify the configure flags because the flags used in the posting create a non-distributable version of ffmpeg. The current XCode only provides SDKs for 10.7 and 10.8. This should enable you to build a version for Lion.

       
      To build a version for an older version of the Apple operating system you need to use Xcode 3.x. On my machine it resides in /Developer-old.

       
      I have successfully created a binary with the following changes:

        Set the compiler flags prior building everything

        export CC="/Developer-old/usr/bin/gcc-4.2"
        export CFLAGS="-isysroot /Developer-old/SDKs/MacOSX10.5.sdk        -mmacosx-version-min=10.5"
        export CXXFLAGS=$CFLAGS
        export LDFLAGS="-Wl,-syslibroot,/Developer-old/SDKs/MacOSX10.5.sdk -mmacosx-version-min=10.5"
        export CCP="/Developer-old/usr/bin/cpp-4.2"
        

       

        Omit the following configure flags from the ffmpeg configure run

      • –enable-gsm
      • –enable-libvpx

       
      This resulted in a working binary for me but I can not test it on a 10.5 machine since I do not have such a machine.
      If you really need libgsm and libvpx you would need to investigate on how to compile those libraries with the above compiler environment variables.
       
      You might even be able to create a binary for 10.4 but what you will NOT be able to do is to create a universal binary.
      For this to work, you would need to build a version on a ppc machine and one on an x86 machine and use ‘lipo’ to glue them together. That is, if both builds actually succeed…

  39. Partially. I can get a binary that works for OSX10.7 an OSX10.8
    That is good enough for me.

  40. A few suggestions/corrections (ML, Xcode 4.4.1):

    – change the tar commands to tar xpf. I believe modern versions automatically detect the compressor in the source file and do the proper procedure, whereas when you explicit tar xzpf with a tar.xz or tar.bz2 files, you get an error.

    – in the gsm procedure:
    perl -p -i -e “s#_ROOT)/inc#_ROOT)/include#g” Makefile
    I found that the proper syntax should be:
    perl -p -i -e “s#_ROOT\)/inc#_ROOT\)/include#g” Makefile
    that is, the “)” must be quoted.

    – in the mplayer compilation procedure:
    ./configure –prefix=${TARGET} –as=yasm –disable-shared –enable-static –enable-vp8
    something between your command and your site environment reformatted “–” to a midsize dash, just like LaTeX does to “–“. The previous command instances are OK though.

    And last but not least, I didn’t manage to compile mplayer:

    libavcodec/x86/mpegaudiodec.c:262:16: error: use of undeclared identifier ‘HAVE_SSE3_EXTERNAL’
    } else if (EXTERNAL_SSE3(mm_flags)) {
    ^
    ./libavutil/x86/cpu.h:37:37: note: expanded from macro ‘EXTERNAL_SSE3’
    #define EXTERNAL_SSE3(flags) CPUEXT(flags, _EXTERNAL, SSE3)
    ^
    ./libavutil/x86/cpu.h:26:6: note: expanded from macro ‘CPUEXT’
    (HAVE_ ## cpuext ## suffix && ((flags) & AV_CPU_FLAG_ ## cpuext))
    ^
    :33:1: note: expanded from macro ‘HAVE_’
    HAVE_SSE3_EXTERNAL
    ^
    1 error generated.
    make[1]: *** [libavcodec/x86/mpegaudiodec.o] Error 1
    make[1]: *** Waiting for unfinished jobs….
    make: *** [ffmpeg/libavcodec/libavcodec.a] Error 2

    Thanks for any help,

    • Thank you very much for your bug reports and feedback!

      1. bsdtar versus gnutar
        You are right. After testing with bsdtar (the tar provided by Apple on MacOSX) and gnutar both showed the behaviour you have described. Nevertheless, older tar version may not work if the correct flag to uncompress is missing. Also, I think it is better to have explicit command line parameters instead of “implicit” ones. Makes debugging a lot easier.

        Just to make sure, I have checked my guide if I was using x or j on the “wrong” archive but I somehow managed not to mix them up :)

      2. perl expression
        You are right! I am using perl on the guide but using gnu sed in my internal build scripts. Should eat my dogfood more often :(
        The guide will be updated

      3. midsize dash
        This will also be fixed in a few moments!
      4. Compiling mplayer fails
        Happens to me too, sometimes. I simply wait a few days and retry, ususally the problem vanishes and the build is successful. This is assuming you are compiling from the svn repository. MPlayer obtains ffmpeg from git and the following posting on the ffmpeg-cvslog suggests that you might have just caught a time window where the git repository of ffmpeg was in an inconsistent state and thus the build failed.
  41. Hi,

    How can we build ffplay? I have followed your instructions and removed the –disable-ffplay but it still doesn’t build. Any ideas? Thanks!

    r

    • In order to buidl ffplay you need to build libSDL.

      Insert this into your build workflow:

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

      And remove the –disable-ffplay from the ffmpeg configure line.

      BUT:
      You will add plenty of library references in the ffmpeg binary when using SDL:

      without SDL:
      /Users/snowy/.bin/ffmpeg:
      /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
      /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 744.12.0)
      /System/Library/Frameworks/VideoDecodeAcceleration.framework/Versions/A/VideoDecodeAcceleration (compatibility version 1.0.0, current version 1.0.0)
      /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.8.0)
      /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
      /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.8.0)

      With SDL:
      /Volumes/ffmpeg-latest/bin/ffmpeg:
      /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
      /System/Library/Frameworks/Cocoa.framework/Versions/A/Cocoa (compatibility version 1.0.0, current version 19.0.0)
      /System/Library/Frameworks/ApplicationServices.framework/Versions/A/ApplicationServices (compatibility version 1.0.0, current version 45.0.0)
      /System/Library/Frameworks/Carbon.framework/Versions/A/Carbon (compatibility version 2.0.0, current version 155.0.0)
      /System/Library/Frameworks/AudioToolbox.framework/Versions/A/AudioToolbox (compatibility version 1.0.0, current version 1.0.0)
      /System/Library/Frameworks/AudioUnit.framework/Versions/A/AudioUnit (compatibility version 1.0.0, current version 1.0.0)
      /System/Library/Frameworks/IOKit.framework/Versions/A/IOKit (compatibility version 1.0.0, current version 275.0.0)
      /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
      /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 744.12.0)
      /System/Library/Frameworks/VideoDecodeAcceleration.framework/Versions/A/VideoDecodeAcceleration (compatibility version 1.0.0, current version 1.0.0)
      /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.8.0)
      /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
      /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.8.0)
      /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1187.34.0)
      /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 57.0.0)
      /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
      /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 945.11.0)

      Considering that you get a “no frills” player when compiling mplayer and you can also use VLC I never thought it was really “worth” it to add libSDL to the build instructions just to be able to build ffplay.

      But in any case, that is how you do it :)

  42. Following the above instructions, I have no luck compiling the MPlayer
    Is it even possible to compile mplayer?

    • Yes it is. Can you elaborate as to what goes wrong and where? Do you have a complete output of your compile run?

    • It certainly should be possible to compile mplayer; people do. In fact, the “homebrew” framework on MacOS does the job so cleanly that I lost interest on this thread.

      http://mxcl.github.com/homebrew/

      “brew install mplayer” was all it took me…

      • I am aware that using homebrew will provide a working mplayer binary and it will probably be sufficient for the needs of Luk.
        It would be interesting to know if Luk just wants to be able to play media content (where I would advise using VLC instead) or to decode/encode media content (where I would advise using ffmpeg).

        • The build itself didn’t fail, but the end result, if memory serves, was not having font rendering support (onscreen display wouldn’t work), but I might be wrong. Since in the past I had followed your guide with good results, despite the time it took to properly arrange the environment (I think I also contributed a fix), I decided not to invest the time on debugging the procedure and went instead on experimenting homebrew. Time was right, my macports had gone nuts, by chance I had a window of time in which a fresh installation of macports wouldn’t go past the second package, which led me to try yet again homebrew. The framework itself had a straightforward installation, and since compiling mplayer on macports always led to an unusable build (usually onscreen display woudln’t work, or something else), I decided to give homebrew a try: the mplayer installation completed without a hitch and the binary worked as perfectly as it should.

          I’m just leaving the positive feedback of an alternative here, for those who are not willing to invest that much time on a single package that they consider indispensable on their systems…

          • Your feedback is very much welcome and showing other options of obtaining mplayer/ffmpeg is too!

            I do not have homebrew/macports on my system and thus I can only guess that a broken on-screen-display of mplayer could be the result of mplayer linking to the “wrong” freetype/fontconfig library instead of the one from X11.

            Just curious: What are you using mplayer for?

          • Yes, I suspect font support libs are usually the culprit.

            I use mplayer to watch movies/series when watching on a notebook, for instance, or whenever without an external home theater support (rarely have the time though). But mostly I can quickly check reencodings that I perform with either Handbrake or ffmpeg. No other player is that quick or convenient to respond to short and long fast forward/backward (arrows). This way I fly through a material in a matter of seconds, checking subtitle synchronism and successful video/audio rendering.

  43. HI Guys,

    I would please install libfdk_aac and libfaac using port in my mac, that because ffmpeg was built using it. Someone got it?

    • Try this:

      # next, cmake (so OpenAL can be compiled)
      cd ${CMPL}
      tar xjpf ${MES}/cmake-2.8.11.2.tar.gz
      cd cmake*
      ./configure –prefix=${TARGET}
      make -j 2 && make install

      And then a static build of OpenAL

      # next, OpenAL
      cd ${CMPL}
      tar xjpf ${MES}/openal-soft-1.13.tar.bz2
      cd openal*
      cmake -DCMAKE_INSTALL_PREFIX:PATH=${TARGET} -DLIBTYPE=STATIC .
      make -j 2 && make install

      Both compilation steps should complete successfully. Then simply add the –enable-openal configure flag to ffmpeg.
      Trying to compile ffmpeg with openal-soft-1.14 or newer will fail…

    • What exactly goes wrong when you try to compile it?

      I have downloaded the source http://mediaarea.net/download/binary/mediainfo/0.7.64/MediaInfo_CLI_0.7.64_GNU_FromSource.tar.bz2 and simply executed the ./CLI_Compile.sh script which resulted in a usable binary:

      snowy@snowcrash(~/Downloads/MediaInfo_CLI_GNU_FromSource) $ ls -l MediaInfo/Project/GNU/CLI/mediainfo
      -rwxrwxr-x  1 snowy  snowy  5936276 Jul 30 08:23 MediaInfo/Project/GNU/CLI/mediainfo
      
      snowy@snowcrash(~/Downloads/MediaInfo_CLI_GNU_FromSource) $ otool -L MediaInfo/Project/GNU/CLI/mediainfo 
      MediaInfo/Project/GNU/CLI/mediainfo:
      	/usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
      	/usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 169.3.0)
      	/usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 56.0.0)
      snowy@snowcrash(~/Downloads/MediaInfo_CLI_GNU_FromSource) $ 
      

      For me to be able to help you better it would be helpful to know the steps you have tried when compiling something and what went wrong at which step.

      Personal curiosity: Is ffprobe not sufficient for your use case? What does mediainfo do better?

      • not sure why i had problems before seems to build fine now and with less dependancies that the one i normally download from their site :-)

        never tried ffprobe i will have to do that thanks for the tip and help!

  44. Hi! I’ve started to build now on Mavericks, but I still have a Mac with Mountain Lion too. I have noticed this when trying to use my build from Mavericks on Mountain Lion:

    dyld: lazy symbol binding failed: Symbol not found: ___sincos_stret
    Referenced from: /Volumes/Mavericks (iMac)/Users/mahalko/z2-myDesktop/ffmpeg
    Expected in: /usr/lib/libSystem.B.dylib

    dyld: Symbol not found: ___sincos_stret
    Referenced from: /Volumes/Mavericks (iMac)/Users/mahalko/z2-myDesktop/ffmpeg
    Expected in: /usr/lib/libSystem.B.dylib

    Trace/BPT trap: 5

    Do you have any idea why is this? I only found these differences:

    (build Mavericks)
    /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
    /usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5)
    /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)

    (old build Lion)
    /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
    /usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5)
    /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)

    If I have to go back and build on older OS I can, but I’d rather do it in Mavericks if possible :-)

    Thanks for the help!

    • It is probably easier to build on the older Mac OS X since you already have (I hope) a build script set up :)
      Either build for each Mac OS X version specifically or build on the oldest Mac OS X version and use the binary on all later versions…

  45. Great guide, and worked first time for me on Lion (but I’m used to building for tux/win). There is one gotcha that caught me out. Its nothing to do with the scripts but is handy to be aware of. Although the builds are ‘static’ they do have some dependencies, and when I tried to run my build on another system it failed because of a missing framework. Tracking back the issue was because I had built on a system running Jack, and the other system wasn’t. Uninstalling Jack on my build system led to a ‘static’ build that was portable to a vanilla machine. One to be aware of….

    • This is correct.

      You can not build a “truly” static binary on MacOSX (see ).
      In addition, you do need to be aware of what stuff you already have on your system which may or may not be found/used by the configure run of ffmpeg.

      The idea of the guide was to be able to get a binary which is only dependent on the system but not any media de-/encoder libraries (which you would always would have to drag along in order for the binary to work in addition to “polluting” your system (unnecessarily)).
      Hence all libaries used are being compiled as static libraries so they are “included” into the binary itself.

    • Did you have any specific problems adding libbluray? I will check nevertheless if I can add libbluray to the build instructions.

      • I looked into the issue, libblurary requires libxml2 and freetype. And with freetype, I run into the same problem as with with libass:

        gcc -L/Volumes/ffmpeg-latest//lib -Wl,-dynamic,-search_paths_first -o /var/folders/fq/1bvdpl7s4k7_xrtdykx_cczw0000gn/T//ffconf.8LWfpCm4 /var/folders/fq/1bvdpl7s4k7_xrtdykx_cczw0000gn/T//ffconf.NIl4a2kL.o -lbluray -lm -lbz2 -lz -pthread
        clang: warning: argument unused during compilation: '-pthread'
        Undefined symbols for architecture x86_64:
          "_FT_Done_Face", referenced from:
              _textst_render_free in libbluray.a(textst_render.o)
          "_FT_Done_FreeType", referenced from:
              _textst_render_free in libbluray.a(textst_render.o)
          "_FT_GlyphSlot_Embolden", referenced from:
              __render_line in libbluray.a(textst_render.o)
          "_FT_GlyphSlot_Oblique", referenced from:
              __render_line in libbluray.a(textst_render.o)
          "_FT_Init_FreeType", referenced from:
              _textst_render_init in libbluray.a(textst_render.o)
          "_FT_Load_Char", referenced from:
              __render_line in libbluray.a(textst_render.o)
          "_FT_New_Face", referenced from:
              _textst_render_add_font in libbluray.a(textst_render.o)
          "_FT_Set_Char_Size", referenced from:
              __render_line in libbluray.a(textst_render.o)
          "_xmlCleanupParser", referenced from:
              _meta_parse in libbluray.a(meta_parse.o)
          "_xmlDocGetRootElement", referenced from:
              _meta_parse in libbluray.a(meta_parse.o)
          "_xmlFree", referenced from:
              __parseManifestNode in libbluray.a(meta_parse.o)
          "_xmlFreeDoc", referenced from:
              _meta_parse in libbluray.a(meta_parse.o)
          "_xmlGetProp", referenced from:
              __parseManifestNode in libbluray.a(meta_parse.o)
          "_xmlNodeGetContent", referenced from:
              __parseManifestNode in libbluray.a(meta_parse.o)
          "_xmlReadMemory", referenced from:
              _meta_parse in libbluray.a(meta_parse.o)
          "_xmlStrEqual", referenced from:
              __parseManifestNode in libbluray.a(meta_parse.o)
        ld: symbol(s) not found for architecture x86_64
        clang: error: linker command failed with exit code 1 (use -v to see invocation)
        ERROR: libbluray not found
        

        Resarching the problem it seems others have run into the same error but I could not find a solution…

        • As you can see from the beginning of each line you are missing paths to freetype2 and libxml .. Either export CFLAGS and LDFLAGS env. settings for those 2 or, even better, export full path to pkg-config prior to compiling:

          export PKG_CONFIG=“/exact/path/to/pkgconfig/binary/pkg-config”
          export PKG_CONFIG_PATH=“/path/to/pkgconfig/bindir/bin”
          export PKG_CONFIG_LIBDIR=“/path/to/pkgconfig/libdir/lib/pkgconfig”

          • Something is odd because building libxml2 and freetype work flawlessly and I can even build libbluray without any problems. Just when I execute the configure for ffmpeg everything “blows” up. The CFLAGS and LDFLAGS are set (as shown in the article) so that should not really be an issue and I can verify that I do see libbluray.a in the libs/ directory of where it should be.

            In any case I will try your suggestion and report back later if it was successful (or not :)

          • Ah .. Try with the old bluraylib release, I think 0.2.3 should work just fine .. From 0.3.0 they’ve added subtitle support and thats what makes a trouble to ffmpeg and mplayer .. You dont need sub support in that lib since mplayer will take care of subs anyway .. on Maverics MPlayer wont enable latest libbluray during compilation and if you force enable it it wont compile giving the xml errors at the end..With old bluraylib release everything is fine..

    • I have not yet tried. When libx265 first came out there was no support for it and ffmpeg (as far as I know) built their own h265 en-/decoder.

      • FFmpeg 2.2 has support for this but compiling a static build seems to be problematic. Although it works with Homebrew.

          • Oh. I thought it had both. Then I will definately need to look into this :)

        • When I do run into problems when compiling things for ffmepg, I also tend to look at how howbrew/macports/fink may have solved the problem.

  46. Tried to compile FFmpeg with libx265 (with cmake -DCMAKE_INSTALL_PREFIX:PATH=${TARGET} -DLIBTYPE=STATIC). But it doesn’t create a static build of x265
    Any guidelines for creating an OSX FFmpeg with libx265?

    • Personally, I do not like cmake much because it is a real hassle to find out how to make it build a static library. I will look into it when I get home.

    • So far, this is how you build libx265 as a static library:


      # next, libx265
      #hg clone https://bitbucket.org/multicoreware/x265
      tar xzpf ${MES}/x265-20140327.tar.gz
      cd x265
      cd source
      cmake -DCMAKE_INSTALL_PREFIX:PATH=${TARGET} -DENABLE_SHARED=NO .
      make

      And should then produce:


      snowy@snowcrash(/Volumes/ffmpeg-latest/compile/x265/source) $ make install
      [ 64%] Built target common
      [ 91%] Built target encoder
      [ 91%] Built target x265-static
      [100%] Built target cli
      Install the project...
      -- Install configuration: "Release"
      -- Installing: /Volumes/ffmpeg-latest/lib/libx265.a
      -- Installing: /Volumes/ffmpeg-latest/include/x265.h
      -- Installing: /Volumes/ffmpeg-latest/include/x265_config.h
      -- Installing: /Volumes/ffmpeg-latest/lib/pkgconfig/x265.pc
      -- Installing: /Volumes/ffmpeg-latest/bin/x265
      snowy@snowcrash(/Volumes/ffmpeg-latest/compile/x265/source) $

      Passing the –enable-libx265 flag to ffmpeg then should result in


      snowy@snowcrash(~) $ .bin/ffmpeg -codecs | grep 265
      ffmpeg version 2.2.git-snowy Copyright (c) 2000-2014 the FFmpeg developers
      built on Mar 27 2014 21:10:58 with Apple LLVM version 5.1 (clang-503.0.38) (based on LLVM 3.4svn)
      configuration: --prefix=/Volumes/ffmpeg-latest/ --as=yasm --extra-version=snowy --disable-shared --enable-static --enable-pthreads --enable-gray --enable-postproc --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-libspeex --enable-bzlib --enable-zlib --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libxavs --enable-libvpx --enable-libgsm --enable-libopus --enable-libtwolame --enable-openal --enable-libsoxr --enable-libfdk-aac --enable-libwavpack --enable-libutvideo --enable-libvidstab --enable-libzmq --enable-libilbc --enable-libx265 --enable-nonfree --disable-doc --enable-gpl --enable-version3
      libavutil 52. 69.100 / 52. 69.100
      libavcodec 55. 55.100 / 55. 55.100
      libavformat 55. 35.101 / 55. 35.101
      libavdevice 55. 11.100 / 55. 11.100
      libavfilter 4. 3.100 / 4. 3.100
      libswscale 2. 5.102 / 2. 5.102
      libswresample 0. 18.100 / 0. 18.100
      libpostproc 52. 3.100 / 52. 3.100
      DEV.L. hevc H.265 / HEVC (High Efficiency Video Coding) (encoders: libx265 )
      snowy@snowcrash(~) $

      I hope this helps!

  47. Great! :-) Looking forward to this.

    BTW as far as I know you can only compile libx265 with cmake. But a static is possible because there are windows static binaries available. Not yet for OSX though

  48. I’m trying to build static ffmpeg with x265. But I encounter the error “x265 not found” while configuring ffmpeg.

    The error is occurring at the following command.
    gcc -Wl,-dynamic,-search_paths_first -I/usr/local/include -L/usr/local/lib -o /var/folders/qk/x9k9r6f955d75dnv5dd2rgm00000gn/T//ffconf.d6F8MxUY /var/folders/qk/x9k9r6f955d75dnv5dd2rgm00000gn/T//ffconf.s7CTCJEP.o -lm -lx265 -lbz2 -lz -pthread

    and the error message is “Undefined symbols for architecture x86_64:”

    I use cmake-2.8.12.2、ffmpeg-2.2.1、mercurial-2.9.2、pkg-config-0.28、x265 version 0.8、yasm-1.2.0

    How can I solve it?

    P.S.
    I can build shared library x265 and this build ffmpeg fine.

    • There is too little information to make a good guess as to what goes wrong. I suspect pkg-config can not find the x265 library (was it successfully built, does it provide a static library to link against?).

      Have you tried to follow the guide and built a ffmpeg binary from the current HEAD repository using a RamDisk (as to not clutter your system)?

      • Following your guide, using RamDisk, I *think* I could successfully build x265. x265 binary works fine. but I’m not sure that libx265.a is built successfully. Here’s part of ffmpeg’s config.log which related with x265.

        check_pkg_config x265 x265.h x265_encoder_encode
        pkg-config –exists –print-errors x265
        check_func_headers x265.h x265_encoder_encode -I/Volumes/Ramdisk/include -L/Volumes/Ramdisk/lib -lx265
        check_ld cc -I/Volumes/Ramdisk/include -L/Volumes/Ramdisk/lib -lx265
        check_cc -I/Volumes/Ramdisk/include -L/Volumes/Ramdisk/lib
        BEGIN /var/folders/qk/x9k9r6f955d75dnv5dd2rgm00000gn/T//ffconf.AFKyF5jC.c
        1 #include
        2 long check_x265_encoder_encode(void) { return (long) x265_encoder_encode; }
        3 int main(void) { return 0; }
        END /var/folders/qk/x9k9r6f955d75dnv5dd2rgm00000gn/T//ffconf.AFKyF5jC.c
        gcc -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -DPIC -I/Volumes/Ramdisk//include -L/Volumes/Ramdisk//lib -std=c99 -mdynamic-no-pic -fomit-frame-pointer -fPIC -pthread -I/Volumes/Ramdisk/include -L/Volumes/Ramdisk/lib -c -o /var/folders/qk/x9k9r6f955d75dnv5dd2rgm00000gn/T//ffconf.F1zJVrvQ.o /var/folders/qk/x9k9r6f955d75dnv5dd2rgm00000gn/T//ffconf.AFKyF5jC.c
        gcc -L/Volumes/Ramdisk//lib -Wl,-dynamic,-search_paths_first -I/Volumes/Ramdisk/include -L/Volumes/Ramdisk/lib -o /var/folders/qk/x9k9r6f955d75dnv5dd2rgm00000gn/T//ffconf.gvAxmmeR /var/folders/qk/x9k9r6f955d75dnv5dd2rgm00000gn/T//ffconf.F1zJVrvQ.o -lx265 -lx264 -lm -lbz2 -lz -pthread
        Undefined symbols for architecture x86_64:
        “std::basic_ios<char, std::char_traits >::widen(char) const”, referenced from:
        x265::ScanGenerator::GetNextIndex(unsigned int, unsigned int)in libx265.a(TComRom.cpp.o)
        “std::basic_ostream<char, std::char_traits >::put(char)”, referenced from:
        x265::ScanGenerator::GetNextIndex(unsigned int, unsigned int)in libx265.a(TComRom.cpp.o)
        “std::basic_ostream<char, std::char_traits >::flush()”, referenced from:
        x265::ScanGenerator::GetNextIndex(unsigned int, unsigned int)in libx265.a(TComRom.cpp.o)
        “std::basic_ostream<char, std::char_traits >::operator<<(int)", referenced from:
        x265::ScanGenerator::GetNextIndex(unsigned int, unsigned int)in libx265.a(TComRom.cpp.o)
        "std::ios_base::Init::Init()", referenced from:
        global constructors keyed to ain libx265.a(api.cpp.o)
        global constructors keyed to ain libx265.a(common.cpp.o)
        global constructors keyed to ain libx265.a(TComRom.cpp.o)
        global constructors keyed to ain libx265.a(param.cpp.o)
        global constructors keyed to ain libx265.a(bitcost.cpp.o)
        global constructors keyed to ain libx265.a(encoder.cpp.o)
        global constructors keyed to ain libx265.a(primitives.cpp.o)

        "std::ios_base::Init::~Init()", referenced from:
        global constructors keyed to ain libx265.a(api.cpp.o)
        global constructors keyed to ain libx265.a(common.cpp.o)
        global constructors keyed to ain libx265.a(TComRom.cpp.o)
        global constructors keyed to ain libx265.a(param.cpp.o)
        global constructors keyed to ain libx265.a(bitcost.cpp.o)
        global constructors keyed to ain libx265.a(encoder.cpp.o)
        global constructors keyed to ain libx265.a(primitives.cpp.o)

        "std::basic_ostream<char, std::char_traits >& std::__ostream_insert<char, std::char_traits >(std::basic_ostream<char, std::char_traits >&, char const*, long)”, referenced from:
        x265::ScanGenerator::GetNextIndex(unsigned int, unsigned int)in libx265.a(TComRom.cpp.o)
        “std::cerr”, referenced from:
        x265::ScanGenerator::GetNextIndex(unsigned int, unsigned int)in libx265.a(TComRom.cpp.o)
        “std::terminate()”, referenced from:
        x265::BitCost::setQP(unsigned int)in libx265.a(bitcost.cpp.o)
        x265::Encoder::Encoder()in libx265.a(encoder.cpp.o)
        x265::Encoder::Encoder()in libx265.a(encoder.cpp.o)
        x265::Encoder::~Encoder()in libx265.a(encoder.cpp.o)
        x265::Encoder::~Encoder()in libx265.a(encoder.cpp.o)
        x265::Encoder::~Encoder()in libx265.a(encoder.cpp.o)
        x265::Encoder::create() in libx265.a(encoder.cpp.o)

        “vtable for __cxxabiv1::__class_type_info”, referenced from:
        typeinfo for x265::TEncCfgin libx265.a(encoder.cpp.o)
        typeinfo for x265_encoderin libx265.a(encoder.cpp.o)
        typeinfo for x265::JobProviderin libx265.a(encoder.cpp.o)
        typeinfo for x265::FrameFilterin libx265.a(encoder.cpp.o)
        typeinfo for x265::TComPicYuvin libx265.a(TComPicYuv.cpp.o)
        typeinfo for x265::ThreadPoolin libx265.a(threadpool.cpp.o)
        typeinfo for x265::FrameFilterin libx265.a(framefilter.cpp.o)

        NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
        “vtable for __cxxabiv1::__si_class_type_info”, referenced from:
        typeinfo for x265::ThreadPoolImplin libx265.a(threadpool.cpp.o)
        typeinfo for x265::PoolThreadin libx265.a(threadpool.cpp.o)
        typeinfo for x265::TComBitCounterin libx265.a(framefilter.cpp.o)
        typeinfo for x265::SEIRecoveryPointin libx265.a(frameencoder.cpp.o)
        typeinfo for x265::SEIGradualDecodingRefreshInfoin libx265.a(frameencoder.cpp.o)
        typeinfo for x265::SEIDisplayOrientationin libx265.a(frameencoder.cpp.o)
        typeinfo for x265::SEIActiveParameterSetsin libx265.a(frameencoder.cpp.o)

        NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
        “vtable for __cxxabiv1::__vmi_class_type_info”, referenced from:
        typeinfo for x265::Encoderin libx265.a(encoder.cpp.o)
        typeinfo for x265::FrameEncoderin libx265.a(frameencoder.cpp.o)
        typeinfo for x265::TEncSbacin libx265.a(TEncSbac.cpp.o)
        typeinfo for x265::MotionEstimatein libx265.a(motion.cpp.o)
        NOTE: a missing vtable usually means the first non-inline virtual member function has no definition.
        “operator delete[](void*)”, referenced from:
        x265::BitCost::destroy() in libx265.a(bitcost.cpp.o)
        x265::Encoder::create() in libx265.a(encoder.cpp.o)
        x265::Encoder::destroy() in libx265.a(encoder.cpp.o)
        x265::TComPicSym::destroy() in libx265.a(TComPicSym.cpp.o)
        x265::FrameEncoder::destroy() in libx265.a(frameencoder.cpp.o)
        x265::FrameEncoder::init(x265::Encoder*, int)in libx265.a(frameencoder.cpp.o)
        x265::FrameEncoder::compressFrame() in libx265.a(frameencoder.cpp.o)

        “operator delete(void*)”, referenced from:
        _x265_encoder_open_7 in libx265.a(api.cpp.o)
        x265::Encoder::~Encoder()in libx265.a(encoder.cpp.o)
        x265::Encoder::create() in libx265.a(encoder.cpp.o)
        x265::Encoder::destroy() in libx265.a(encoder.cpp.o)
        x265::Encoder::encode(bool, x265_picture const*, x265_picture*, x265::NALUnitEBSP**)in libx265.a(encoder.cpp.o)
        x265::FrameEncoder::~FrameEncoder()in libx265.a(encoder.cpp.o)
        non-virtual thunk to x265::FrameEncoder::~FrameEncoder()in libx265.a(encoder.cpp.o)

        “operator new[](unsigned long)”, referenced from:
        x265::BitCost::setQP(unsigned int)in libx265.a(bitcost.cpp.o)
        x265::BitCost::CalculateLogs() in libx265.a(bitcost.cpp.o)
        x265::Encoder::create() in libx265.a(encoder.cpp.o)
        x265::TComPicSym::create(int, int, int, unsigned int, unsigned int, unsigned int)in libx265.a(TComPicSym.cpp.o)
        x265::FrameEncoder::init(x265::Encoder*, int)in libx265.a(frameencoder.cpp.o)
        x265::FrameEncoder::compressFrame() in libx265.a(frameencoder.cpp.o)
        x265::TComLoopFilter::create(unsigned int)in libx265.a(TComLoopFilter.cpp.o)

        “operator new(unsigned long)”, referenced from:
        _x265_encoder_open_7 in libx265.a(api.cpp.o)
        x265::Encoder::create() in libx265.a(encoder.cpp.o)
        x265::Encoder::encode(bool, x265_picture const*, x265_picture*, x265::NALUnitEBSP**)in libx265.a(encoder.cpp.o)
        x265::TComPicSym::create(int, int, int, unsigned int, unsigned int, unsigned int)in libx265.a(TComPicSym.cpp.o)
        x265::TComPicSym::allocSaoParam(x265::TComSampleAdaptiveOffset*) in libx265.a(TComPicSym.cpp.o)
        x265::ThreadPool::allocThreadPool(int) in libx265.a(threadpool.cpp.o)
        x265::FrameEncoder::compressFrame() in libx265.a(frameencoder.cpp.o)

        “___cxa_pure_virtual”, referenced from:
        vtable for x265::Threadin libx265.a(threading.cpp.o)
        vtable for x265::WaveFrontin libx265.a(wavefront.cpp.o)
        “___dynamic_cast”, referenced from:
        x265::JobProvider::flush() in libx265.a(threadpool.cpp.o)
        “___gxx_personality_v0”, referenced from:
        _x265_encoder_open_7 in libx265.a(api.cpp.o)
        Dwarf Exception Unwind Info (__eh_frame) in libx265.a(api.cpp.o)
        Dwarf Exception Unwind Info (__eh_frame) in libx265.a(bitcost.cpp.o)
        x265::Encoder::Encoder()in libx265.a(encoder.cpp.o)
        x265::Encoder::Encoder()in libx265.a(encoder.cpp.o)
        x265::Encoder::~Encoder()in libx265.a(encoder.cpp.o)
        x265::Encoder::~Encoder()in libx265.a(encoder.cpp.o)

        ld: symbol(s) not found for architecture x86_64
        collect2: ld returned 1 exit status
        ERROR: x265 not found

        Also here’s x265.pc

        prefix=/Volumes/Ramdisk
        exec_prefix=${prefix}
        libdir=${exec_prefix}/lib
        includedir=${prefix}/include

        Name: x265
        Description: H.265/HEVC video encoder
        Version: 0.8
        Libs: -L${libdir} -lx265
        Libs.private: -lstdc++ -l/usr/lib/clang/4.2/lib/darwin/libclang_rt.osx.a
        Cflags: -I${includedir}

        • Hm. Which OSX / XCode version are you using to build?Also, check what cmake options I use to create a static library for x265.

          What I would do:

          – build pkg-config, cmake, yasm, git
          – Create a static x265 library with the cmake options shown in the article
          – get the latest ffmpeg and just try to link the x265 to that ffmpeg with the specific configure option and see how that goes.

          Currently. I am building ffmpeg/mpv on OSX 10.9.2 Mavericks with the latest XCode.

          • I’m now downgrading my OSX to Mountain Lion 10.8.5/Xcode 4.6. But this phenomenon occurs on OSX 10.9.2/XCode5.1 first.

            I followed your guide and now using Ramdisk.
            1.build yasm
            2.build pkg-config
            3.build git
            4.build cmake
            5.build mercurial
            6.build x265
            7.trying to build ffmpeg with “./configure –prefix=${TARGET} –enable-gpl –enable-libx265”

            Would you provide x265 build items for me?

          • What went wrong with the compilation of ffmpeg? :)

            If you provide me with a working email I can send you a link with a DMG of my RamDisk with lib/ include/ and compile/ directories intact.

      • Sent you an email with the URL of my ffmpeg-latest-build.dmg. As it is about 500MB I doubt you will want it as an email :)

        • Thanks for sending me URL for your latest ffmpeg build DMG.

          Now I have copied cmake-2.8.12.1, ffmpeg, and x265 source to ffmpeg-latest disk image. also copied pkg-config, yasm binary to ffmpeg-latest disk image. Of Course I have copied these items on appropriate place on the disk image.
          In this condition, I sadly reproduce the problem “x265 not found”…

          In addition, I have found that build result (byte size) of libx265.a is differ by based cmake version. With cmake-2.8.12.1, libx265.a is 2,802,512bytes and with cmake-2.8.12.2, libx265.a is 2,802,520bytes. I’m not sure this difference is meaningful or not.

          I’m totally puzzled now…

          Do you have any suggestion for this poor boy? :-(

          P.S.
          I’m using latest command line tools for Xcode (command_line_tools_for_osx_mavericks_april_2014)

          • Strange. Just by chance, did you modify $PATH to look like this at the very beginning of compiling?

            PATH=${TARGET}/bin:$PATH
            

            $TARGET being /Volumes/ffmpeg-latest/ (if you have followed the article).

            This will make ffmpeg (and other configure scripts) use pkg-config in the Ramdisk and thus will help ffmpeg find the third party libraries. As stated before, sometimes it just looks at include/ and libs/ and sometimes it uses pkg-config to locate the library header(s) and library.

            Can you try and just follow the article step by step (omitting third party libraries you do not want and also the corresponding configure flags to ffmpeg)? Does it also fail?

    • Here’s copy and paste of your E-mail.

      > Did you check config.log of ffmpeg where exactly it fails?

      ya, I have checked config.log. I used diff command and the difference between your libx265a’s result and my build libx265.a are only temp file which ffmpeg configure script creates.

      > I am not sure but I think either your x265 does not build properly or for some reason ffmpeg is unable to link against it.

      Well, me too think so. since your libx265a’s and my build libx265.a are same in size if cmake’s version is same…

      > Not really….

      > Prior to compiling ffmpeg I do set CFLAGS and LDFLAGS explicitly:

      > # set compiler flags
      > export LDFLAGS=”-L${TARGET}/lib $CFLAGS”
      > export CFLAGS=”-I${TARGET}/include $LDFLAGS”

      Of course I set these flags explicitly.

      > > Should we talk about this issue via web?

      > Yes, it may help others if they run into the same problem as you did.
      > (And I do hope we are able to resolve this issue).

      OK, I copy and paste this E-mail on the web page.

      Here’s reply for your comment.

      $PATH is set properly. So $TARGET is /Volumes/ffmpeg-latest/. I created ramdisk which name is ffmpeg-latest.

      Yes, I have retried with ramdisk which name is ffmpeg-latest today. the condition are:

      1.pkg-config source is copied from your disk image which you sent me. Also, tried x265.pc which you sent me, so the difference is not exists.

      2.yasm source is copied from your disk image which you sent me. I compiled yasm based on your article’s procedure.

      3.cmake source is copied from your disk image which you sent me. I compiled yasm based on your article’s procedure. Also tried x265.a which you sent me, so the difference is not exists.

      4.for the purpose of comparing, I downloaded x264 and build it based on your article’s procedure.

      The result is x264’s configure check have passed and x265’s configure check have failed.
      In addition, I can build ffmpeg with –enable-libx264 successfully.

      ffmpeg version 2.2.git Copyright (c) 2000-2014 the FFmpeg developers
      built on Apr 20 2014 12:30:05 with Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
      configuration: –prefix=/Volumes/ffmpeg-latest/ –as=yasm –enable-gpl –enable-libx264
      libavutil 52. 76.100 / 52. 76.100
      libavcodec 55. 58.103 / 55. 58.103
      libavformat 55. 37.100 / 55. 37.100
      libavdevice 55. 13.100 / 55. 13.100
      libavfilter 4. 4.100 / 4. 4.100
      libswscale 2. 6.100 / 2. 6.100
      libswresample 0. 18.100 / 0. 18.100
      libpostproc 52. 3.100 / 52. 3.100
      V….. libx264 libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 (codec h264)
      V….. libx264rgb libx264 H.264 / AVC / MPEG-4 AVC / MPEG-4 part 10 RGB (codec h264)

      I can’t suppose what is happening. Why x265 hates me???

      • After setting up a minimal build system to reproduce your problem I have both good and bad news.

        The good news: I am able to reproduce the problem.

        The bad news: I have no idea what actually goes wrong. What really puzzles me that my build with many more third party libraries _does_ find libx265 and uses it.

        • I’m now asking “x265-devel — Development for x265 mailing list” to what is happening. I wrote that is libx265 properly build or not in the mail. If I would get anything, I’ll write the result here.

          Anything I can help about your bad news? If you told me about “third party libraries”, I would cooperate.

      • I believe this to be a bug with libx265.

        In order to be able to link libx265 to ffmpeg it requires -lstdc++ as a compiler flag yet it does not provide it via pkg-config when ffmpeg asks for the -ldflags of libx265. It should add -lstdc++ to its Libs: line of the x265.pc file.

        ffmpeg version 2.2.git-snowy Copyright (c) 2000-2014 the FFmpeg developers
          built on Apr 20 2014 20:01:42 with Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
          configuration: --prefix=/Volumes/ffmpeg-x265/ --as=yasm --extra-version=snowy --disable-shared --enable-static --enable-libx265 --enable-gpl
          libavutil      52. 77.100 / 52. 77.100
          libavcodec     55. 58.105 / 55. 58.105
          libavformat    55. 37.101 / 55. 37.101
          libavdevice    55. 13.100 / 55. 13.100
          libavfilter     4.  4.100 /  4.  4.100
          libswscale      2.  6.100 /  2.  6.100
          libswresample   0. 18.100 /  0. 18.100
          libpostproc    52.  3.100 / 52.  3.100
         DEV.L. hevc                 H.265 / HEVC (High Efficiency Video Coding) (encoders: libx265 )
        

        The following script does not “fix” x265.pc but just includes the -lstdc++ in the $LDFLAGS. Please test if this shell script produces a working ffmpeg binary with libx265.

        #!/bin/bash
        # Yes, I know this could be a Makefile
        # Someday, when I have enough time... 
        
        # basic error checking
        set -e
        
        # use the llvm compiler
        export CC="/usr/bin/clang"
        export CXX="/usr/bin/clang++"
        
        # name the ramdisk 
        export VOLNAME=ffmpeg-x265
        
        # create a 1.5 GB ramdisk
        DISK_ID=$(hdid -nomount ram://5145728)
        newfs_hfs -v ${VOLNAME} ${DISK_ID}
        diskutil mount ${DISK_ID}
        
        # set up shortcuts
        export TARGET="/Volumes/${VOLNAME}/"
        export   CMPL="/Volumes/${VOLNAME}/compile"
        export   PATH=${TARGET}/bin:$PATH
        
        # set up the directories
        mkdir -p ${CMPL}
        
        # build pkg-config with proper pc-path
        cd ${CMPL} 
        curl -LO http://pkgconfig.freedesktop.org/releases/pkg-config-0.28.tar.gz
        tar xzpf pkg-config-0.28.tar.gz 
        cd pkg-config-0.28 
        ./configure --silent --prefix=${TARGET} --with-pc-path=${TARGET}/lib/pkgconfig --with-internal-glib 
        make 
        make install
        
        # next, yasm
        cd ${CMPL} 
        curl -LO http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
        tar xzpf yasm-1.2.0.tar.gz
        cd yasm-1.2.0
        ./configure --silent --prefix=${TARGET}
        make
        make install
        
        # next, cmake 
        cd ${CMPL}
        curl -LO http://www.cmake.org/files/v2.8/cmake-2.8.12.2.tar.gz
        tar xzpf cmake-2.8.12.2.tar.gz
        cd cmake-2.8.12.2 
        rm Modules/FindJava.cmake
        perl -p -i -e "s/get_filename_component.JNIPATH/#get_filename_component(JNIPATH/g" Tests/CMakeLists.txt
        ./configure --prefix=${TARGET} 
        make
        make install
        
        # export python modules path
        export PYTHONPATH="${TARGET}/lib/python2.7/site-packages/"
        
        # next, docutils for mecurial
        cd ${CMPL}
        curl -L -s -O http://iweb.dl.sourceforge.net/project/docutils/docutils/0.11/docutils-0.11.tar.gz 
        tar xzpf docutils-0.11.tar.gz
        cd docutils-0.11 
        python setup.py install --prefix=${TARGET}
        
        # next, mecurial
        cd ${CMPL}
        curl -LO http://mercurial.selenic.com/release/mercurial-2.9.2.tar.gz 
        tar xzpf mercurial-2.9.2.tar.gz 
        cd mercurial-2.9.2
        export CFLAGS="-Wno-error=unused-command-line-argument-hard-error-in-future"
        make all
        make install PREFIX="${TARGET}"
        unset CFLAGS
        
        # next, x265
        cd ${CMPL}
        hg clone https://bitbucket.org/multicoreware/x265
        cd x265
        cd source
        cmake -DCMAKE_INSTALL_PREFIX:PATH=${TARGET} -DENABLE_SHARED=NO . 
        make
        make install
        
        # compiler environment for ffmpeg 
        unset LDFLAGS CFLAGS MYFLAGS
        export MYFLAGS="-L${TARGET}/lib -I${TARGET}/include -lstdc++"
        export LDFLAGS="$MYFLAGS"
        export  CFLAGS="$MYFLAGS"
        
        # next, ffmpeg
        cd ${CMPL} 
        curl -LO  http://www.ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
        tar xjpf ffmpeg-snapshot.tar.bz2
        cd ffmpeg 
        ./configure --prefix=${TARGET} \
                    --as=yasm \
                    --extra-version=snowy \
                    --disable-shared \
                    --enable-static \
                    --enable-libx265 \
                    --enable-gpl 
                    
        make
        make install
        
        # check the result
        /Volumes/ffmpeg-x265/bin/ffmpeg -codecs | grep 265 
        
        • GREAT !! You are smart. Your script solves this problem!!
          By editing x265.pc based on your comment, also solve this problem!!
          I’m very happy. Thanks so much!!

          I’ll also write this issue for libx265 (x265.pc) to x265-devel mailing list.

          BTW, LDFLAGS and CFLAGS for ffmpeg seems differ from article’s one except -lstdc++. Which one should be used?

          Your article’s LDFLAGS and CFLAGS for ffmpeg
          export LDFLAGS=”-L${TARGET}/lib $CFLAGS”
          export CFLAGS=”-I${TARGET}/include $LDFLAGS”

          Your script’s LDFLAGS and CFLAGS for ffmpeg
          export LDFLAGS=”-L${TARGET}/lib -I${TARGET}/include -lstdc++”
          export CFLAGS=”-L${TARGET}/lib -I${TARGET}/include -lstdc++”

          • Thank you. The reason the “full build” always worked is because some other third party library included -lstdc++ and x265 was built very late in the process.

            If you follow the article (=full blown build) you can use the CFLAGS/LDFLAGS used there, if you want to make a small and specialized build, better use the one from the comment (or patch x265.pc) since you will need -lstdc++ for x265.

    • You are welcome. I am glad the problem was solved with a workaround. I saw your posting to the x265-devel mailing list (via gmane.org), my guess is that it is a bug.

      When looking at the config.log output from ffmpeg it is clear that it indeed does find x265 but it fails to link since the x265 library has symbols the linker can not resolve.

      In any case, you now have a workaround/fix :)

      • Well, We should wait how x265 development team acts for this issue.
        Anyway, thanks for workaround.
        We, Japanese, say “Arigatougozaimashita” which mean “Thank you” , and “Otsukaresamadeshita” which means “Was cheers for good work”.

        • After talking with x265 development team, adding “-lstdc++” flags should not be the corrective action.
          Instead, configure ffmpeg with –pkg-config-flags=–static option, this issue is solved.
          By adding –static, x265.pc gives -lc++ or -lstdc++ with –cflags to ffmpeg.
          Since we are using llvm, -lc++ would be given.

          In addition, x265.pc’s Libs.private line contains absolute path of libclang_rt.osx.a to be linked. This was minor bug in x265. I confirmed “-l” is removed today.

          One more.
          I have confirmed that x264 no longer have CFLAGS=”$CFLAGS -falign-loops=16″ line in it’s configure script.

          • Great news!

            So it wasn’t a bug after all. Although I think it is counter-intuitive having to pass a special flag to ffmpeg for pkg-config. Either all other third party libraries are doing it wrong :) or x265 is just special when it comes to static compilation.

            Thank you also for the information concerning x264!

  49. Me also questioned why x265 only requires –pkg-config-flag. Tehy said as follows:

    Most other software either is not C++, and thus does not
    need the C++ runtime, or “work around” it by adding the C++
    runtime explicitly to the returned CFLAGS, even though it
    is technically wrong to do so.
    They also said that setting CFLAGS to Libs.private is the dicision of x265 team leader.

  50. Hi,

    thanks for the great work. Wanted to let you know that flac-1.3, libvpx-1.3, … compile fine with the newest Xcode 5.1 (or higher) on Mavericks or Mountain Lion. Using:

    export CC=”clang”
    export CPP=”clang -E”
    export CXX=”clang++”
    export CXXCPP=”clang++ -E”
    export LDFLAGS=”-stdlib=libc++”
    export CXXFLAGS=”-stdlib=libc++”
    allows to compile ffmpeg, mplayer, mencoder with nearly all libraries you are using (still some problems with utvideo, libzmq).

    • Thanks for the feedback!
      I will check if I can successfully build flac again and link it to ffmpeg.

      Concerning utvideo, that will build but it will refuse to link, unless the configure script of ffmpeg is modified as shown the the article. I basically have no idea why this needs to be done but it works..

      What problems do you have with zeromq?

      • In fact I am building everything with clang and the settings (export CC=”clang”; export CPP=”clang -E”; export CXX=”clang++”, …), not only flac, libvpx, … and it works fine: “built on … with Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)”. Guess it’s time to move forward and use the newest Xcode Tools. I was even able to compile Mkvtoolnix with the newest clang on OS X.

        UTvideo: I get the error message that utvideo is not found, but since I don’t care that much about them, I never tried to fix the problem.

    • Adding libbluray itself is not the problem. Its dependencies are :)

      You need libxml2, freetype (which in turn requires more things) and a JRE. If you can satisfy the dependencies I do not see what you should not be able to add libbluray to the ffmpeg build. As I do dnot have a JRE installed (nor a bluray drive) there is no need for me to go through the trouble of building libbluray.

        • Do you need it for a private project or commercially?

           
          What I would do if I really needed libbluray myself:

        • Create a VM with MacOSX 10.9.x
        • Install the latest Xcode
        • Create a directory /Volumens/ffmpeg
        • Build everything up to ffmpeg as described in the article
        • Create a snapshot of the virtual machine
        • Build ffmpeg and see if that works
        • Revert to the snapshot if ffmpeg was successfully built
        • Build libbluray and see where the build fails
        • Satisfy the missing dependencies for libbluray until all are resolved
        • Build ffmpeg and link against libbluray and hope all goes well
        • If not, try to find out where things went wrong
        • Add /Volumes/Ramdisk/bin to your $PATH
        • Test
        •  
          If you really need ffmpeg on MacOSX with libbluray support, have you tried installing ffmpeg via Homebrew? Looking at the formula for ffmpeg it seems that libbluray is supported.

           
          Is that suggestion a viable option for you?

  51. I have just noticed that for ffmpeg/libav you have:-

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

    I would have expected:-

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

    or is there some special reason for the swap over? (in my tests both flags were empty before the export anyway. So the net result is CFLAGS gets both a -L and a -I.

    • It is an (stupid) error in the article. $LDFLAGS never sees the “new” value for $CFLAGS which is defined in the following line. The idea behind this was to have both CFLAGS and LDFLAGS to be passed to the linker and the compiler so everything can be found/linked.

      I read on the ffmpeg mailing list that you should pass –with-ldflags and –with-cflags to the configure of ffmpeg which is a better solution anyway.

      • My default script for my sandbox build on linux has always used:-

        –extra-ldflags=”-L${TARGET}/lib” \
        –extra-cflags=” -I${TARGET}/include” \

        and this seems to work in your scripts as well.

  52. hi,

    i keep running into following error when trying to build with vidstab:

    gcc -D_ISOC99_SOURCE -D_FILE_OFFSET_BITS=64 -D_LARGEFILE_SOURCE -DPIC -I/Volumes/Ramdisk/sw/include -std=c99 -mdynamic-no-pic -fomit-frame-pointer -fPIC -pthread -c -o /var/folders/zd/5sm6605s16s5mpd0gtycs9m00000gn/T//ffconf.UwwEK7q6.o /var/folders/zd/5sm6605s16s5mpd0gtycs9m00000gn/T//ffconf.txfsbEfx.c
    gcc -L/Volumes/Ramdisk/sw/lib -Wl,-dynamic,-search_paths_first -o /var/folders/zd/5sm6605s16s5mpd0gtycs9m00000gn/T//ffconf.ifOQoFSQ /var/folders/zd/5sm6605s16s5mpd0gtycs9m00000gn/T//ffconf.UwwEK7q6.o -ltheoraenc -ltheoradec -logg -lspeex -lopencore-amrwb -lopencore-amrnb -lmp3lame -lgsm -lm -lbz2 -lz -pthread
    check_pkg_config vidstab >= 0.98 vid.stab/libvidstab.h vsMotionDetectInit
    false –exists –print-errors vidstab >= 0.98
    ERROR: vidstab not found

    i have gone line by line and vidstab installs without error. but always errors when starting to build ffmpeg. everything seems to be in the right place, any ideas?

    • Looks weird. Are those the last lines of config.log? I will check if I can reproduce the problem later this evening.

    • I am unable to reproduce the problem.

      My result:

      snowy@snowcrash(/Volumes/ffmpeg-vidstab/compile/ffmpeg) $ ${TARGET}/bin/ffmpeg -filters | grep vidstab
      ffmpeg version 2.2.git-snowy Copyright (c) 2000-2014 the FFmpeg developers
        built on May  7 2014 21:46:19 with Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
        configuration: --prefix=/Volumes/ffmpeg-vidstab/ --extra-cflags=' -I/Volumes/ffmpeg-vidstab//include' --extra-ldflags=-L/Volumes/ffmpeg-vidstab//lib --as=yasm --extra-version=snowy --disable-shared --enable-static --enable-libvidstab --enable-gpl
        libavutil      52. 81.100 / 52. 81.100
        libavcodec     55. 60.103 / 55. 60.103
        libavformat    55. 37.102 / 55. 37.102
        libavdevice    55. 13.101 / 55. 13.101
        libavfilter     4.  5.100 /  4.  5.100
        libswscale      2.  6.100 /  2.  6.100
        libswresample   0. 18.100 /  0. 18.100
        libpostproc    52.  3.100 / 52.  3.100
       ... vidstabdetect    V->V       Extract relative transformations, pass 1 of 2 for stabilization (see vidstabtransform for pass 2).
       ... vidstabtransform V->V       Transform the frames, pass 2 of 2 for stabilization (see vidstabdetect for pass 1).
      snowy@snowcrash(/Volumes/ffmpeg-vidstab/compile/ffmpeg) $ 
      

      Script used:

      #!/bin/bash
      
      # basic error checking
      set -e
      
      # use the llvm compiler
      export CC="/usr/bin/clang"
      export CXX="/usr/bin/clang++"
      
      # name the ramdisk 
      export VOLNAME=ffmpeg-vidstab
      
      # create a 1.5 GB ramdisk
      DISK_ID=$(hdid -nomount ram://5145728)
      newfs_hfs -v ${VOLNAME} ${DISK_ID}
      diskutil mount ${DISK_ID}
      
      # set up shortcuts
      export TARGET="/Volumes/${VOLNAME}/"
      export   CMPL="/Volumes/${VOLNAME}/compile"
      export   PATH=${TARGET}/bin:$PATH
      
      # set up the directories
      mkdir -p ${CMPL}
      
      # build pkg-config with proper pc-path
      cd ${CMPL} 
      curl -LO http://pkgconfig.freedesktop.org/releases/pkg-config-0.28.tar.gz
      tar xzpf pkg-config-0.28.tar.gz 
      cd pkg-config-0.28 
      ./configure --silent --prefix=${TARGET} --with-pc-path=${TARGET}/lib/pkgconfig --with-internal-glib 
      make 
      make install
      
      # next, yasm
      cd ${CMPL} 
      curl -LO http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
      tar xzpf yasm-1.2.0.tar.gz
      cd yasm-1.2.0
      ./configure --silent --prefix=${TARGET}
      make
      make install
      
      # next, cmake 
      cd ${CMPL}
      curl -LO http://www.cmake.org/files/v2.8/cmake-2.8.12.2.tar.gz
      tar xzpf cmake-2.8.12.2.tar.gz
      cd cmake-2.8.12.2 
      rm Modules/FindJava.cmake
      perl -p -i -e "s/get_filename_component.JNIPATH/#get_filename_component(JNIPATH/g" Tests/CMakeLists.txt
      ./configure --prefix=${TARGET} 
      make
      make install
      
      # next, vidstab (requires cmake)
      cd ${CMPL}
      curl -LO https://github.com/georgmartius/vid.stab/tarball/release-0.98b
      tar xzpf release-0.98b 
      cd georgmartius-vid.stab*
      perl -p -i -e  's/vidstab SHARED/vidstab STATIC/'  CMakeLists.txt
      cmake -DCMAKE_INSTALL_PREFIX:PATH=${TARGET} . && $MKMU && make -s install
      
      # next, ffmpeg
      cd ${CMPL} 
      curl -LO  http://www.ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
      tar xjpf ffmpeg-snapshot.tar.bz2
      cd ffmpeg 
      ./configure --prefix=${TARGET} \
                  --extra-cflags=" -I${TARGET}/include" \
                  --extra-ldflags="-L${TARGET}/lib" \
                  --as=yasm \
                  --extra-version=snowy \
                  --disable-shared \
                  --enable-static \
                  --enable-libvidstab \
                  --enable-gpl 
                  
      make
      make install
      
      # check
      ${TARGET}/bin/ffmpeg -filters | grep vidstab
      
      • Ok I was able to get it working. Actually not sure where I went wrong but I wasn’t explicitly building pkg-config so guessing that was probably it. Thanks for the help!

  53. If you want to compile with libass you need to modify fontconfig.pc in lib/pkgconfig/.

    Replace the line
    Libs: -L${libdir} -lfontconfig
    with
    Libs: -L${libdir} -lfontconfig -lfreetype -lexpat
    if you are using expat. I compiled with libxml2 (–without-python) and used “-llibxml2” instead of “-lexpat”.

    • If libxml2 has been used, add
      sed -i.bak ‘s/-L${libdir} -lfontconfig/-L${libdir} -lfontconfig -lfreetype -liconv -lxml2/’ $PKG_CONFIG_PATH/fontconfig.pc
      or
      sed -i.bak ‘s/-L${libdir} -lfontconfig/-L${libdir} -lfontconfig -lfreetype -liconv -lexpat/’ $PKG_CONFIG_PATH/fontconfig.pc
      if expat is uesd, right before ffmpeg gets compiled.

    • Thanks for the hint, I will try that out and see if the ffmpeg compilation blows up :)
      It it works, I will include it into the guide.

    • My current ffmpeg binary:


      snowy@snowcrash(~) $ sw_vers
      ProductName: Mac OS X
      ProductVersion: 10.9.3
      BuildVersion: 13D65

      snowy@snowcrash(~) $ ffmpeg -version
      ffmpeg version 2.2.git-snowy Copyright (c) 2000-2014 the FFmpeg developers
      built on Jun 19 2014 10:59:33 with Apple LLVM version 5.1 (clang-503.0.40) (based on LLVM 3.4svn)
      configuration: --prefix=/Volumes/ffmpeg-latest/ --as=yasm --extra-version=snowy --disable-shared --enable-static --enable-pthreads --enable-gray --enable-postproc --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-libspeex --enable-bzlib --enable-zlib --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libxavs --enable-libvpx --enable-libgsm --enable-libopus --enable-libtwolame --enable-openal --enable-libsoxr --enable-libfdk-aac --enable-libwavpack --enable-libutvideo --enable-libvidstab --enable-libzmq --enable-libilbc --enable-libx265 --enable-nonfree --disable-doc --enable-gpl --enable-version3
      libavutil 52. 89.100 / 52. 89.100
      libavcodec 55. 67.100 / 55. 67.100
      libavformat 55. 43.100 / 55. 43.100
      libavdevice 55. 13.101 / 55. 13.101
      libavfilter 4. 8.100 / 4. 8.100
      libswscale 2. 6.100 / 2. 6.100
      libswresample 0. 19.100 / 0. 19.100
      libpostproc 52. 3.100 / 52. 3.100

      snowy@snowcrash(~) $ otool -L .bin/ffmpeg
      .bin/ffmpeg:
      /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.0.0)
      /System/Library/Frameworks/QTKit.framework/Versions/A/QTKit (compatibility version 1.0.0, current version 1.0.0)
      /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1056.13.0)
      /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.8.0)
      /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.8.0)
      /System/Library/Frameworks/AVFoundation.framework/Versions/A/AVFoundation (compatibility version 1.0.0, current version 2.0.0)
      /System/Library/Frameworks/CoreMedia.framework/Versions/A/CoreMedia (compatibility version 1.0.0, current version 1.0.0)
      /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 855.16.0)
      /System/Library/Frameworks/VideoDecodeAcceleration.framework/Versions/A/VideoDecodeAcceleration (compatibility version 1.0.0, current version 1.0.0)
      /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
      /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1197.1.1)
      /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
      /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)
      snowy@snowcrash(~) $

      It does reference qtkit. What exactly is the problem? Are you trying to build ffmpeg on Yosemite and it fails?

      • No I didn’t try Yosemite. But on mine they are missing:

        /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
        /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 635.21.0)
        /System/Library/Frameworks/VideoDecodeAcceleration.framework/Versions/A/VideoDecodeAcceleration (compatibility version 1.0.0, current version 1.0.0)
        /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.7.0)
        /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
        /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
        /usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5)
        /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
        /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.7.0)

        What did you do to get qtkit/avfoundation to show up as a dependency?

        • It is hard to tell what you may be doing wrong, too little information…

          When was the last time you built ffmpeg? What ffmpeg version is the otool -L output from? What version of Xcode are you running? What MacOSX Version are you running? Did you follow the article or did you omit some third party libraries?

          • I just built yesterday with FFmpeg 2.2.3 on Lion with Xcode 4.6.3. I followed the article but left a few third party libraries out the ones I don’t need. I suppose I could try to build on Mavericks and include all libraries to see if that makes a difference…

  54. Pingback: FFMPEG installation for a video script
  55. Ever seen anything like this:

    HTML doc/ffprobe.html
    HTML doc/ffmpeg.html
    i686-apple-darwin11-llvm-gcc-4.2: -lstdc++: linker input file unused because linking not done
    HTML doc/ffserver.html
    Unknown open() mode ‘:encoding(utf-8-strict)’ at /usr/bin/texi2html line 11111.
    make: *** [doc/ffprobe.html] Error 255
    make: *** Waiting for unfinished jobs….
    Unknown open() mode ‘:encoding(utf-8-strict)’ at /usr/bin/texi2html line 11111.
    make: *** [doc/ffmpeg.html] Error 255
    Unknown open() mode ‘:encoding(utf-8-strict)’ at /usr/bin/texi2html line 11111.
    make: *** [doc/ffserver.html] Error 255
    logout

    [Process completed]

    I get this when trying to build ffmpeg 2.6 or 2.6.1 with the same script as 2.5.4 which was fine?

    • I compile ffmpeg using –disable-doc but you can always update your local texi2html installation. I do not have a texi2html installation on my machine so I think yours is not OS native?

      However, I do generate man pages using the following snippet:

      # grab the current man pages
      for i in ffmpeg ffprobe ffserver ffplay
      do
          pod2man5.16 doc/${i}.pod /Users/snowy/.man/man1/${i}.1
      done
      

      and have prefixed $MANPATH with the target man directory shown in the snippet.

      Does this help you?

  56. I followed this guide to build mplayer on MacOS X Yosemite 10.10.3 on iMac Retina 5K using Xcode 6.3.1 (6D1002), because I’m trying to test out playing some 4K H265 and other large vids. I found I needed to put in /usr/local/etc/mplayer.conf with “lavdopts=threads=8” (Resource Monitor basically said only 4 of 8 cores being used but if I tried threads=4 then it failed, so I looked closer at threads=8 in resource monitor, and the peaks of the 4 mostly used cores would spill over into the 4 unused ones (odd but OK)).

    I’m not getting subtitles or on screen display (OSD), and no writing at all when it should be telling me stuff (you goofed, this is the new setting, where I am, etc). Are there missing fonts? Where should I look for errors in this? I omitted X11 when building mplayer.

    My biggest problem so far though and why I’m writing here to begin with is fullscreen doesn’t get rid of the background under the top bar and background under the bottom program icons (even though it does get rid of the top bar and bottom program icons themselves). Do you know a way to get mplayer to black those out, and use that space if possible? Aha, I think writing this query got me to think of the problem clearly, and I think setting the background to black will be a workaround. Trying now … ok, it works, mostly. This is a workaround because it takes away my awesome backgrounds, but it almost works perfectly. It becomes apparent that the resized window space of mplayer leaves one pixel each at the lower left and lower right bright (probably some border color).

    Also, while poking around with various options, I noticed VO diagnostics wouldn’t give my resolution, which I currently have set to 5120×2880. I tried setting -screenw 5120 and -screenh 2880, but I get a stupid error for that:

    $ mplayer -screenw 5120 -screenh 2880 -slang eng Tears.of.Steel.2012.2160p.DMRip.Eng.HDCL.mkv
    The screenw option must be <= 4096: 5120
    Error parsing option on the command line: -screenw
    MPlayer SVN-r37389-4.2.1 (C) 2000-2015 MPlayer Team
    $

    I mean c'mon.

    As for building issues, I ran into very few, as in none. I had to conform versions a bit and got most of it from Gentoo distfiles or plundering search engines and the like, and some version sites.

    • I would recommend building ‘mpv’ but you will need add libass if you want an OSD or need subtitles.
      There article has a compilation hint concerning this topic.
      Personally, I just use mpv without OSD (easier to build) and use the few keyboard shortcuts.

      Also, if you set threads to 0 it should use (depending on the de-/encoder used within ffmpeg).
      The mpv media player can run in fullscreen by pressing the key ‘f’, or use the ‘-fs’ option to start in full screen mode.

  57. I got a message about not finding NUMA. It looks like build files were created, but what does this mean? Am I missing a numa pkg?

    $ cmake -DCMAKE_INSTALL_PREFIX:PATH=${TARGET} -DENABLE_SHARED=NO .
    — cmake version 3.2.2
    — Detected x86 target processor
    — Could NOT find NUMA (missing: NUMA_ROOT_DIR NUMA_INCLUDE_DIR NUMA_LIBRARY)
    — Found Yasm 1.3.0 to build assembly primitives
    — hg found at /opt/local/bin/hg
    — x265 version 1.7+37-dc4fcfc574ad
    — Configuring done
    — Generating done
    — Build files have been written to: /Volumes/Ramdisk/compile/x265/source

    • As long as it builds fine, I would not worry. It may just be looking for NUMA because of your environment / libraries / headers present and/or missing…

  58. Pingback: BlackBerry 10 向けにffmpegをコンパイルする際のメモ | ワタシのメモ
  59. Just tried the updated pkg-config (0.2.9 released in September) and found it fails to compile on Yosemite with “Undefined symbols for architecture x86_64:[…]” errors, 0.28 is fine.

    • I sometimes look for new versions of packages I use for compiling ffmpeg/mpv but that may have slipped past me. I will check if it also fails with my build setup (read: horrible mess of shell scripts).

      • Indeed, it does break.

        Using the following configure line:

        ./configure –silent –prefix=${TARGET} –with-pc-path=${TARGET}/lib/pkgconfig –with-internal-glib

        And my error is


        echo > glib-public-headers.txt.tmp && mv glib-public-headers.txt.tmp glib-public-headers.txt
        Making all in .
        CC pkg.o
        CC parse.o
        CC rpmvercmp.o
        CC main.o
        CCLD pkg-config
        Undefined symbols for architecture x86_64:
        "_CFRelease", referenced from:
        _find_folder in libglib-2.0.a(libglib_2_0_la-gutils.o)
        "_CFStringGetCString", referenced from:
        _find_folder in libglib-2.0.a(libglib_2_0_la-gutils.o)
        "_CFStringGetCStringPtr", referenced from:
        _find_folder in libglib-2.0.a(libglib_2_0_la-gutils.o)
        "_CFStringGetLength", referenced from:
        _find_folder in libglib-2.0.a(libglib_2_0_la-gutils.o)
        "_CFURLCopyFileSystemPath", referenced from:
        _find_folder in libglib-2.0.a(libglib_2_0_la-gutils.o)
        "_CFURLCreateFromFSRef", referenced from:
        _find_folder in libglib-2.0.a(libglib_2_0_la-gutils.o)
        "_FSFindFolder", referenced from:
        _find_folder in libglib-2.0.a(libglib_2_0_la-gutils.o)
        "_kCFAllocatorSystemDefault", referenced from:
        _find_folder in libglib-2.0.a(libglib_2_0_la-gutils.o)
        ld: symbol(s) not found for architecture x86_64
        clang: error: linker command failed with exit code 1 (use -v to see invocation)
        make[2]: *** [pkg-config] Error 1
        make[1]: *** [all-recursive] Error 1
        make: *** [all] Error 2

        When things like that suddenly break I usually look at the corresponding homebrew recipe on how they might have solved the problem (patch or the like).
        Source: pkg-config 0.29 Homebrew
        They used


        LDFLAGS="-framework Foundation -framework Cocoa"

        And indeed, I managed to successfully compile pkg-config.

        Hope this helps.

  60. Hi hexeract
    I’m totally newbie but wanted to try anyway to build my own ffmpeg since i’d like to use a few non free codecs.
    My question (silly i guess) is, since till now i wasn’t able to produce a valid (w/o dependencies) : is it the same using a usb drive instead of ramdisk? if the answer is yes then i’m lost :)
    regards and thanks for this awesome guide

    • I could have just used a directory on the the harddisk or a USB drive. The choice of using a ramdisk was for speed. And easier cleanup
      (To get rid of everything all I need to do is to unmount the ramdisk).

      As to a static build, on MacOSX you can not create a “true” static build. You will always have some sort of dependency (SystemB for example).

      You can check your run time dependencies using the command ‘otool -L ffmpeg’.

      If you do see references to your non free codecs this may be due to the fact that you also need to compile those codecs/libraries to be static.
      Sometimes, the build process does not allow for a static build to be specified and simply will build both variants.
      You can delete the *.dylib files in the target library directory from where ffmpeg will look for them when it compiles.

      That does the output of ‘otool -L ffmpeg’ look like? What is your build process overall (so I can try and reproduce the problem).

  61. Oh another question, if i eventually decide to use the newest pig-config 0.29 will it keep all the informations about all previous installs or do i have to recompile everything again?

    • If you do not clean your build directory (and the target compile directories) there is no real need to recompile everything. pkg-config is just a tool ffmpeg uses to find 3rd party libraries.

      You may run into a problem when building pkg-config 0.2.9 so prior to building pkg-config 0.2.9 please define LDFLAGS so it will build without any errors.


      export LDFLAGS="-framework Foundation -framework Cocoa"
      ./configure ......
      make
      unset LDFLAGS

      • Hmmm, I did exactly as explained, and had a successful build of pkg-config 0.2.9, but now ffmpeg complains at each enabled codec telling it can’t find it into pkg-config. Well. I guess time to delete everything and retry with a new fresh start. Reading all the comments anyway i was already prepared to do so, as me too would like to get it boils under 10.11 and Xcode 7. My previous test were all made on 10.8 Xcode 4.6.3. So time to evolve.
        Thanks for your quick reply. I will let you know how it goes.

        • Well, something was different or it would have succeeded :-)
          Without seeing the commands you have used it is difficult to tell what may have gone wrong. Did you also set the path so your pkg-config is used instead of the system provided?
          Can you provide me with a transcript of your build process?

    • I have not tried as ffmpeg has an internal version of snappy and the source repository requires the autoconf toolchain to be installed for it to be able to create a configure file. To add a complete autoconf toolchain just for one project/source/library is possible, but, in my opinion, not worth it.

      Technically, you would, as said, need to build the autoconf tool chain, run autoconf and then run the configure and add the –use-libsnappy configure flag to ffmpeg.

          • I used the following archive: https://github.com/google/snappy/releases/download/1.1.3/snappy-1.1.3.tar.gz

            Just insert into the build process:


            cd ${CMPL}
            tar xzpf ${MES}/snappy*.tar.gz
            cd snappy*
            ./configure --prefix=${TARGET} --disable-shared --enable-static && $MKMU && make -s install

            And add –enable-libsnappy to the configure command line when building ffmpeg.

            I tested the encoding process using the following command line:


            fmpeg -i 831332_DRAG-v1b8a5-1300.mp4 -vcodec hap -format hap_q out.mov

            Looks good to me:

            snowy@snowcrash(~/Downloads) $ ffmpeg -i 831332_DRAG-v1b8a5-1300.mp4 -vcodec hap -format hap_q out.mov
            ffmpeg version N-78189-g6cc1567-snowy Copyright (c) 2000-2016 the FFmpeg developers
            built with Apple LLVM version 7.0.2 (clang-700.1.81)
            configuration: --prefix=/Volumes/ffmpeg-latest/ --as=yasm --extra-version=snowy --disable-shared --enable-static --extra-cflags=-I/Volumes/ffmpeg-latest//include --extra-ldflags='-L/Volumes/ffmpeg-latest//lib -lstdc++' --enable-pthreads --enable-gray --enable-postproc --enable-libfaac --enable-libmp3lame --enable-libtheora --enable-libvorbis --enable-libx264 --enable-libxvid --enable-libspeex --enable-bzlib --enable-zlib --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libvo-aacenc --enable-libvo-amrwbenc --enable-libxavs --enable-libvpx --enable-libgsm --enable-libopus --enable-libtwolame --enable-openal --enable-libsoxr --enable-libfdk-aac --enable-libwavpack --enable-libutvideo --enable-libvidstab --enable-libzmq --enable-libx265 --enable-libsnappy --enable-nonfree --disable-doc --enable-gpl --enable-version3 --enable-openssl
            libavutil 55. 16.100 / 55. 16.100
            libavcodec 57. 22.102 / 57. 22.102
            libavformat 57. 23.101 / 57. 23.101
            libavdevice 57. 0.101 / 57. 0.101
            libavfilter 6. 27.100 / 6. 27.100
            libswscale 4. 0.100 / 4. 0.100
            libswresample 2. 0.101 / 2. 0.101
            libpostproc 54. 0.100 / 54. 0.100
            Input #0, mov,mp4,m4a,3gp,3g2,mj2, from '831332_DRAG-v1b8a5-1300.mp4':
            Metadata:
            major_brand : isom
            minor_version : 512
            compatible_brands: isomiso2avc1mp41
            encoder : Lavf56.12.103
            Duration: 00:55:27.48, start: 0.036281, bitrate: 1094 kb/s
            Stream #0:0(und): Video: h264 (High) (avc1 / 0x31637661), yuv420p, 1280x720 [SAR 1:1 DAR 16:9], 1026 kb/s, 30 fps, 30 tbr, 15360 tbn, 60 tbc (default)
            Metadata:
            handler_name : VideoHandler
            Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 63 kb/s (default)
            Metadata:
            handler_name : SoundHandler
            Output #0, mov, to 'out.mov':
            Metadata:
            major_brand : isom
            minor_version : 512
            compatible_brands: isomiso2avc1mp41
            encoder : Lavf57.23.101
            Stream #0:0(und): Video: hap (HapY / 0x59706148), rgba, 1280x720 [SAR 1:1 DAR 16:9], q=2-31, 200 kb/s, 30 fps, 15360 tbn, 30 tbc (default)
            Metadata:
            handler_name : VideoHandler
            encoder : Lavc57.22.102 hap
            Stream #0:1(und): Audio: aac (LC) (mp4a / 0x6134706D), 44100 Hz, mono, fltp, 128 kb/s (default)
            Metadata:
            handler_name : SoundHandler
            encoder : Lavc57.22.102 aac
            Stream mapping:
            Stream #0:0 -> #0:0 (h264 (native) -> hap (native))
            Stream #0:1 -> #0:1 (aac (native) -> aac (native))
            Press [q] to stop, [?] for help
            frame= 534 fps= 48 q=-0.0 size= 168058kB time=00:00:17.80 bitrate=77344.3kbits/s dup=1 drop=0 speed=1.59x

          • Hmm.. I keep getting ERROR: snappy not found when compiling FFmpeg with –enable-libsnappy
            Although snappy is correctly build.

          • Then you need to look at the configure.log where things fail. Did you just build it or did you also install it at a location ffmpeg (and/or pkg-config) can find it?

  62. Also, libass 0.13.1 does not seem to require fontconfig anymore. But I am unable to get FFmpeg compiled with the libass source. Anyone else having luck with this?

    • libass 0.13.1 still requires fontconfig but will drop support for fontconfig versions older than 2.10.92.
      The fontconfig library is still needed unless the platform is MacOSX or Windows. Interesting. I will look into that.
      (I did see the minutes long scan for fonts as I build a version of ffmpeg to create a mpv binary with subtitles support).

      When trying to compile libass and then ffmpeg, what error messages do you get?

      • I will try again and put the error messages here later today. But from what I understand you do not need to compile fontconfig anymore for OSX (not sure for Windows). It now uses CoreText instead (for OSX) to rendering the tekst strings.

        Stay tuned..

        • This is how I build ffmpeg using libass (and then building mpv).


          #!/bin/bash

          # use the llvm compiler
          export CC="/usr/bin/clang"
          export CXX="/usr/bin/clang++"

          # create the ramdisk
          export VOLNAME=mpv-osd-master

          #DISK_ID=$(hdid -nomount ram://52428800)
          # 1.5 GB
          DISK_ID=$(hdid -nomount ram://3145728)
          newfs_hfs -v ${VOLNAME} ${DISK_ID}
          diskutil mount ${DISK_ID}

          # set up shortcuts
          export MCB="/Users/snowy/tmptmp/mediaencoding"
          export MES=${MCB}/base/
          export TARGET="/Volumes/${VOLNAME}/"
          export CMPL="/Volumes/${VOLNAME}/compile"
          export PATH=${TARGET}/bin:$PATH

          # set up the directories
          mkdir -p ${CMPL}

          # run make with 4 threads
          export MKMU="make -j 4"

          # no directory, no fun
          cd ${CMPL} || exit 1

          # next, yasm
          cd ${CMPL}
          tar xzpf ${MES}/yasm*.tar.gz
          cd yasm-*
          ./configure --prefix=${TARGET} && $MKMU && make install

          # next, pkg-config
          cd ${CMPL}
          tar xzpf ${MES}/pkg-config*
          cd pkg-config*
          export LDFLAGS="-framework CoreFoundation -framework Carbon"
          ./configure --prefix=${TARGET} --with-pc-path=${TARGET}/lib/pkgconfig --with-internal-glib && $MKMU && make install
          unset LDFLAGS

          # building libressl
          puts "Building libressl"
          cd ${CMPL}
          tar xzpf ${MES}/libressl-*tar.gz
          cd libressl*
          ./configure --prefix=${TARGET} --enable-static --disable-shared && $MKMU && make -s install

          # next, libpng
          cd ${CMPL}
          tar xzpf ${MES}/libpng*.tar.gz
          cd libpng*
          ./configure --prefix=${TARGET} --disable-shared --enable-static && $MKMU && make install

          # next, freetype
          cd ${CMPL}
          tar xzpf ${MES}/freetype*.tar.gz
          cd freetype*
          ./configure --prefix=${TARGET} --disable-shared --enable-static && $MKMU && make install

          # next fribidi
          cd ${CMPL}
          tar xjpf ${MES}/fribidi*.tar.bz2
          cd fribidi*
          ./configure --prefix=${TARGET} --disable-shared --enable-static && $MKMU && make install

          # libass
          cd ${CMPL}
          tar xzpf ${MES}/libass*.tar.gz
          cd libass*
          ./configure --prefix=${TARGET} --disable-fontconfig --disable-shared --enable-static && $MKMU && make install

          # lua
          cd ${CMPL}
          tar xzpf ${MES}/lua*.tar.gz
          cd lua*
          make macosx install INSTALL_TOP=${TARGET}

          # create a lua.pc so mpv can find it
          cat >${TARGET}/lib/pkgconfig/lua.pc <<EOF
          prefix=/Volumes/mpv-osd-master
          exec_prefix=\${prefix}
          libdir=\${prefix}/lib/
          includedir=\${prefix}/include
          Name: lua
          Description: lua
          Requires:
          Version: 5.3.2
          Libs: -L\${libdir} -llua
          Cflags: -I\${includedir}
          EOF

          # ffmpeg
          # set compiler flags
          cd ${CMPL}
          curl -O http://www.ffmpeg.org/releases/ffmpeg-snapshot.tar.bz2
          tar xjpf ffmpeg-snapshot.tar.bz2
          cd ffmpeg
          ./configure --prefix=${TARGET} \
          --extra-cflags="-I${TARGET}/include" \
          --extra-ldflags="-L${TARGET}/lib -lpng -framework CoreText" \
          --enable-openssl \
          --enable-libass \
          --enable-static \
          --disable-shared && $MKMU && make install

          # and build mpv
          cd ${CMPL}
          git clone https://github.com/mpv-player/mpv.git
          cd mpv

          ./bootstrap.py
          export PKG_CONFIG=pkg-config

          # something broke finding "ar", this is a crude way to fix it
          sed '/ctx.find_program.ar/d' -i wscript

          # configure the damn thing
          ./waf configure --prefix=${TARGET} --disable-debug-build --disable-manpage-build

          # linking fails if not linked to libpng
          # so we add it to the list of libraries to link to
          # very crude approach, if anyone knows better, please let me know
          sed "s/'fribidi',/'fribidi', 'png',/g" -i build/c4che/_cache.py

          # and, hoorary, this should build
          ./waf build
          ./waf install

          # check if build was successful
          if [ ! -e $TARGET/bin/mpv ]
          then
          echo "Build failed. KABOOM"
          sleep 30
          exit 1
          fi

          # and copy it
          cp $TARGET/bin/mpv $HOME/.bin/mpv-osd

          # cleanup
          cd ${TARGET} && rm -rf include
          cd ${TARGET} && rm -rf lib
          cd ${TARGET} && rm -rf compile

          # create the disk image
          cd $HOME
          hdiutil create -size 300m -volname ${VOLNAME} -srcfolder /Volumes/${VOLNAME} $HOME/Downloads/${VOLNAME}

          # eject the ram disk
          cd $HOME
          diskutil unmount /Volumes/${VOLNAME}

          # and move the DMG to a safe place
          mv $HOME/Downloads/${VOLNAME}.dmg $HOME/tmptmp/mediaencoding/diskimages/

          Versions used:

        • yasm-1.3.0.tar.gz
        • pkg-config-0.29.tar.gz
        • libressl-2.3.1.tar.gz
        • libpng-1.6.21.tar.gz
        • freetype-2.6.tar.gz
        • fribidi-0.19.7.tar.bz2
        • libass-0.13.1.tar.gz
        • lua-5.3.2.tar.gz
        • Does this help you?

          • It is used/needed to display the on-screen-display/-controller overlay. Checking the resulting binary I do get subtitles and some basic on screen display but not the “player controls”. I will need to look into that but it is not really a feature I am dying to have so the priority is very low for fixing this issue.

          • You also should use
            export LDFLAGS=”-framework CoreFoundation -framework Cocoa” for compiling pig-config
            Carbon is deprecated.

          • To be more correct:
            export LDFLAGS=”-framework Foundation -framework Cocoa”

          • I always get this error when compiling FFmppeg (libass compiles fine)
            I am compiling on OSX10.8 – maybe thats the problem?

            CC ffmpeg_opt.o
            CC ffmpeg_filter.o
            ffmpeg.c: In function ‘write_frame’:
            ffmpeg.c:699: warning: ‘destruct’ is deprecated (declared at ./libavcodec/avcodec.h:1444)
            CC ffmpeg_videotoolbox.o
            CC ffprobe.o
            AR libavdevice/libavdevice.a
            AR libavfilter/libavfilter.a
            AR libavformat/libavformat.a
            AR libavcodec/libavcodec.a
            AR libpostproc/libpostproc.a
            AR libswresample/libswresample.a
            AR libswscale/libswscale.a
            AR libavutil/libavutil.a
            HOSTLD doc/print_options
            GENTEXI doc/avoptions_codec.texi
            GENTEXI doc/avoptions_format.texi
            POD doc/ffmpeg.pod
            POD doc/ffprobe.pod
            POD doc/ffmpeg-all.pod
            POD doc/ffprobe-all.pod
            POD doc/ffmpeg-utils.pod
            POD doc/ffmpeg-scaler.pod
            POD doc/ffmpeg-resampler.pod
            POD doc/ffmpeg-codecs.pod
            POD doc/ffmpeg-bitstream-filters.pod
            POD doc/ffmpeg-formats.pod
            POD doc/ffmpeg-protocols.pod
            POD doc/ffmpeg-devices.pod
            POD doc/ffmpeg-filters.pod
            POD doc/libavutil.pod
            POD doc/libswresample.pod
            POD doc/libswscale.pod
            POD doc/libavcodec.pod
            POD doc/libavformat.pod
            POD doc/libavdevice.pod
            POD doc/libavfilter.pod
            MAN doc/ffmpeg.1
            MAN doc/ffprobe.1
            MAN doc/ffmpeg-all.1
            MAN doc/ffprobe-all.1
            MAN doc/ffmpeg-utils.1
            MAN doc/ffmpeg-scaler.1
            MAN doc/ffmpeg-resampler.1
            MAN doc/ffmpeg-codecs.1
            MAN doc/ffmpeg-bitstream-filters.1
            MAN doc/ffmpeg-formats.1
            MAN doc/ffmpeg-protocols.1
            MAN doc/ffmpeg-devices.1
            MAN doc/ffmpeg-filters.1
            MAN doc/libavutil.3
            MAN doc/libswscale.3
            MAN doc/libswresample.3
            MAN doc/libavcodec.3
            MAN doc/libavformat.3
            MAN doc/libavdevice.3
            MAN doc/libavfilter.3
            LD ffmpeg_g
            Undefined symbols for architecture x86_64:
            “_CTFontCollectionCreateMatchingFontDescriptors”, referenced from:
            _match_fonts in libass.a(ass_coretext.o)
            “_CTFontCollectionCreateWithFontDescriptors”, referenced from:
            _match_fonts in libass.a(ass_coretext.o)
            “_CTFontCopyFamilyName”, referenced from:
            _get_fallback in libass.a(ass_coretext.o)
            “_CTFontCreateForString”, referenced from:
            _get_fallback in libass.a(ass_coretext.o)
            “_CTFontCreateWithName”, referenced from:
            _get_fallback in libass.a(ass_coretext.o)
            “_CTFontDescriptorCopyAttribute”, referenced from:
            _check_postscript in libass.a(ass_coretext.o)
            _check_glyph in libass.a(ass_coretext.o)
            _match_fonts in libass.a(ass_coretext.o)
            “_CTFontDescriptorCreateWithAttributes”, referenced from:
            _match_fonts in libass.a(ass_coretext.o)
            “_kCTFontCharacterSetAttribute”, referenced from:
            _check_glyph in libass.a(ass_coretext.o)
            “_kCTFontDisplayNameAttribute”, referenced from:
            _match_fonts in libass.a(ass_coretext.o)
            “_kCTFontFamilyNameAttribute”, referenced from:
            _match_fonts in libass.a(ass_coretext.o)
            “_kCTFontFormatAttribute”, referenced from:
            _check_postscript in libass.a(ass_coretext.o)
            “_kCTFontNameAttribute”, referenced from:
            _match_fonts in libass.a(ass_coretext.o)
            “_kCTFontSlantTrait”, referenced from:
            _match_fonts in libass.a(ass_coretext.o)
            “_kCTFontTraitsAttribute”, referenced from:
            _match_fonts in libass.a(ass_coretext.o)
            “_kCTFontURLAttribute”, referenced from:
            _match_fonts in libass.a(ass_coretext.o)
            “_kCTFontWeightTrait”, referenced from:
            _match_fonts in libass.a(ass_coretext.o)
            “_kCTFontWidthTrait”, referenced from:
            _match_fonts in libass.a(ass_coretext.o)
            ld: symbol(s) not found for architecture x86_64
            collect2: ld returned 1 exit status
            make: *** [ffmpeg_g] Error 1
            make: *** Waiting for unfinished jobs….

          • I had the same problem. Please take note on how I compile ffmpeg using --extra-ldflags="-L${TARGET}/lib -lpng -framework CoreText"

          • I see.. so lpng is needed for the new libass ? Do you know why? :-)
            Will try it today

            Thanks for the help.

          • Actually, both freetype and libass use libpng but do not link the statically built libpng to their own statically built library. When ffmpeg gets compiled, everything gets linked together and then trouble starts when the references are not satisfied. With ffmpeg, it was unhappy when it linked freetype and libass as PNG functions could not be resolved. Then libass called CoreText functions so I had to add -framework CoreText to the linking stage so those function calls could be resolved.

            It was a work of trial and error and some reading :-)

    • OK, got it working now. But libpng was not needed. It was “-framework CoreText” that did the job.

      Thanks for the valuable help !!

  63. If you still having problem with building and linking schroedinger, the following may help you…

    1.To build schroedinger, we have to build without test suite. See the last part of the following URL:
    https://github.com/Homebrew/legacy-homebrew/blob/master/Library/Formula/schroedinger.rb

    2.To link schroedinger with ffmpeg, we need small code-hacking on schroedinger/schrodecoder.c
    See the comment of dezi on the following URL:
    https://github.com/Homebrew/legacy-homebrew/issues/15734

    • Thank you for the hint, I will look at it. The last time I tried to build schroedinger things did not go well and as I did not have a real need for it I just let it be…

  64. Hi,

    Do you know why with ffmpeg 3.0.2 the dependancies are like this:

    /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 635.21.0)
    /System/Library/Frameworks/VideoDecodeAcceleration.framework/Versions/A/VideoDecodeAcceleration (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.7.0)
    /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
    /usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5)
    /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
    /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 53.0.0)
    /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.7.0)

    But with ffmpeg 3.1.2 they are like this:

    /usr/lib/libstdc++.6.dylib (compatibility version 7.0.0, current version 52.0.0)
    /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 635.21.0)
    /System/Library/Frameworks/AudioToolbox.framework/Versions/A/AudioToolbox (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/CoreMedia.framework/Versions/A/CoreMedia (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/VideoDecodeAcceleration.framework/Versions/A/VideoDecodeAcceleration (compatibility version 1.0.0, current version 1.0.0)
    /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.7.0)
    /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
    /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 159.1.0)
    /usr/lib/libbz2.1.0.dylib (compatibility version 1.0.0, current version 1.0.5)
    /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
    /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 53.0.0)
    /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.7.0)

    All else being equal built on a Mac. Is there any solution to this?

    • I do not really know, I think ffmpeg added a lot of support for the MacOS X platform.

      Mine has the following shared library dependencies:

      Users/snowy/.bin/ffmpeg:
      /usr/lib/libc++.1.dylib (compatibility version 1.0.0, current version 120.1.0)
      /System/Library/Frameworks/QuartzCore.framework/Versions/A/QuartzCore (compatibility version 1.2.0, current version 1.11.0)
      /System/Library/Frameworks/AppKit.framework/Versions/C/AppKit (compatibility version 45.0.0, current version 1404.46.0)
      /System/Library/Frameworks/OpenGL.framework/Versions/A/OpenGL (compatibility version 1.0.0, current version 1.0.0)
      /System/Library/Frameworks/QTKit.framework/Versions/A/QTKit (compatibility version 1.0.0, current version 1.0.0)
      /System/Library/Frameworks/Foundation.framework/Versions/C/Foundation (compatibility version 300.0.0, current version 1258.0.0)
      /System/Library/Frameworks/CoreVideo.framework/Versions/A/CoreVideo (compatibility version 1.2.0, current version 1.5.0)
      /System/Library/Frameworks/AVFoundation.framework/Versions/A/AVFoundation (compatibility version 1.0.0, current version 2.0.0)
      /System/Library/Frameworks/CoreMedia.framework/Versions/A/CoreMedia (compatibility version 1.0.0, current version 1.0.0)
      /System/Library/Frameworks/CoreFoundation.framework/Versions/A/CoreFoundation (compatibility version 150.0.0, current version 1258.1.0)
      /System/Library/Frameworks/VideoToolbox.framework/Versions/A/VideoToolbox (compatibility version 1.0.0, current version 1.0.0)
      /System/Library/Frameworks/AudioToolbox.framework/Versions/A/AudioToolbox (compatibility version 1.0.0, current version 492.0.0)
      /System/Library/Frameworks/VideoDecodeAcceleration.framework/Versions/A/VideoDecodeAcceleration (compatibility version 1.0.0, current version 1.0.0)
      /usr/lib/libiconv.2.dylib (compatibility version 7.0.0, current version 7.0.0)
      /System/Library/Frameworks/Security.framework/Versions/A/Security (compatibility version 1.0.0, current version 57337.40.83)
      /usr/lib/libSystem.B.dylib (compatibility version 1.0.0, current version 1226.10.1)
      /System/Library/Frameworks/CoreGraphics.framework/Versions/A/CoreGraphics (compatibility version 64.0.0, current version 600.0.0)
      /usr/lib/libz.1.dylib (compatibility version 1.0.0, current version 1.2.5)
      /System/Library/Frameworks/CoreServices.framework/Versions/A/CoreServices (compatibility version 1.0.0, current version 728.9.0)
      /System/Library/Frameworks/CoreImage.framework/Versions/A/CoreImage (compatibility version 1.0.1, current version 2.0.0)
      /usr/lib/libobjc.A.dylib (compatibility version 1.0.0, current version 228.0.0)

      • The latest FFmpeg builds also have support for CoreImage fx. So you can use any CoreImage effect which is great.
        There is also no way to get rid of the dependencies, even if you disable those video filters.

  65. Pingback: Compiling mpv for MacOS X | Simple Things
  66. Pingback: FFMPEG Installation | Optunus Technologies
  67. could i try to compile mpv on snow leopard? i would need it for youtube-viewer to work correctly. thanks

  68. Pingback: ffmpegコンパイルガイド – 桃源老師のつぶやき
  69. Someting new

    Udating recently to new
    pkg-config-0.29.2
    libbluray-1.0.0
    fdk-aac-0.1.5
    all went good except for a small one which insisted on not being recognised by ffmpeg : –> zeromq
    everytime same message library not found in pkg-config

    the solution i found to this is simply modifying a bit the instructions to generate a .pc file
    cat >${TARGET}/lib/pkgconfig/zmq.pc <<EOF
    prefix=/Volumes/YOUR_VOLUME
    exec_prefix=\${prefix}
    libdir=\${prefix}/lib/
    includedir=\${prefix}/include
    Name: zeromq
    Description: 0MQ c++ library
    Version: 4.2.1 *Here Goes The Actual Version Number Of Your Build
    Libs: -L${libdir} -lzmq
    Libs.private: -lstdc++ -L/Volumes/YOUR_VOLUME/lib -lsodium
    Cflags: -I${includedir}
    EOF

    Well probably i was the only one affected by this since i didn't notice any comment on the matter
    anyway now is all fine
    hope this will also be helpful to someone else.
    cheers H,

    • Thanks for the update versions for zeromq, fdk-aac and pkg-config-0.29.2, building with the newer versions as we speak. I do try to keep the posting updated but not as much as I used to. When I have time I do check for updated versions of the various third party libraries but mostly I just build ffmpeg/mpv every now and then and if all works, I am happy :-)

      • No problem.
        without your precious guide i would never be able to get it done.
        as all my previous tentative showed :)
        I just happened to have a few more updates to add of you’r interested, libvpx-1.6.1, fontconfig-2.12.1, and opus-1.1.3.
        About vpx, i also added to the ./conf –enable-vp9 –enable-vp9-highbitdepth and its working pretty well.
        cheers

        • Thanks for the updates!
          For libvpx, I directly pull it from the git

          export CFLAGS=-I/usr/include
          export LDFLAGS=-L/usr/lib
          cd build
          git clone https://chromium.googlesource.com/webm/libvpx
          cd libvpx
          ./configure --prefix=${TARGET} --as=yasm --disable-shared --enable-static --enable-vp8 --enable-vp9 --disable-unit-tests
          make
          make install
          unset CFLAGS
          unset LDFLAGS
          

          opus is up to 1.1.4 from what I can tell in my local repsitory and for libass, I build without fontconfig since it was difficult enough to avoid all the dependencies when dealing with freetype and fontconfig. which I only use for mpv anyway. See the following link https://hexeract.wordpress.com/2016/08/13/compiling-mpv-for-macos-x/

          • Whooops,
            i totally missed the new release of opus libs, thank you.
            As per mpv, i’m also very found of it.
            Since the latest builds of vlc seem to be lacking some important
            improvements, which i didn’t investigate much, but fact is many audio files lately do not play
            at all, in both releases (2.2.5.1 and 3.0) so differently from you i use the prebuilt one as for instance i’m unable to find a way to add a few features to make it more user friendly. i must sound blasphemous now i guess…

  70. Any update for this? The latest FFmpeg versions do not compile when following this tutorial.

    • Can you be more specific what goes wrong when you try to follow the guide and what errors do you get?

      I have stopped updating the guide as I was only updating the versions of the third party software anyway and usually that does not break compilation.

Leave a comment