Build ffplay and ffmpeg 2.6.2 on Mac OSX 10.10.2

Every few years we need ffmpeg and ffplay for some little job. The ffmpeg suite is my go-to swiss-army knife for whipping video into shape. Unfortunately, the compilation process is challenging. Here is a summary of the recipe I used to build these tools on OSX 10.10.2. It was not exactly straightforward. That’s why I wrote it down.

To jump to the end, theĀ most difficult part was getting SDL-1 to build. (https://www.libsdl.org) I tried using SDL-2 with ffplay, but that combination did not compile correctly. ffplay requires SDL-1, and SDL-1 required some manual edits to get it installed.

Here is what is on my system:

I do not use Homebrew (brew) and I do not use Macports (ports).

I’ll present each of the steps as a little BASH function. On my system, these are all put in one large .bash script, but I run each one by hand. This process is not automated.

Set the location where the libraries and binaries will build. Add these locations to your search path and the dynamic library search path. I like to build these tools in their own location, out of the way.

PREFIX=/Users/sheffler/video/myffmpeg06
USRSRC=/Users/sheffler/video/myffmpeg06

export DYLD_LIBRARY_PATH=${PREFIX}/lib
export PATH=${PREFIX}/bin:${PATH}

First build YASM. YASM is an assembler used by x264 and ffmpeg.

function build_yasm {
    cd ${USRSRC}
    wget http://www.tortall.net/projects/yasm/releases/yasm-1.2.0.tar.gz
    tar xzvf yasm-1.2.0.tar.gz
    cd yasm-1.2.0
    ./configure --prefix=${PREFIX}
    make
    make install
}

Now build x264. This builds the head. If you desire a particular commit, use the ‘git checkout’ line.

function build_h264 {
    # h.264 video encoder
    cd ${USRSRC}
    git clone git://git.videolan.org/x264
#    git checkout 0c7dab9
    cd x264
    ./configure --prefix=${PREFIX} --enable-static
    make
    make install
}

Build some encoders: MP3 and AAC. These are good to have around.

function build_lame {
    # mp3 audio encoder
    cd ${USRSRC}
    curl -#LO http://downloads.sourceforge.net/project/lame/lame/3.99/lame-3.99.tar.gz
    tar xzvf lame-3.99.tar.gz
    cd lame-3.99
    ./configure --prefix=${PREFIX} --enable-static
    make
    make install
}

function build_faac {
    cd ${USRSRC}
    curl -#LO http://downloads.sourceforge.net/project/faac/faac-src/faac-1.28/faac-1.28.tar.gz
    tar xzvf faac-1.28.tar.gz
    cd faac-1.28
    ./configure --prefix=${PREFIX} --enable-static
    make
    make install
}

Build OGG, Theora and Vorbis.

function build_libogg {
    # libtheora and libvorbis
    cd ${USRSRC}
    curl -L#O http://downloads.xiph.org/releases/ogg/libogg-1.3.0.tar.gz
    gunzip libogg-1.3.0.tar.gz
    tar -xvf libogg-1.3.0.tar
    cd libogg-1.3.0
    ./configure --prefix=${PREFIX}
    make
    make install
}

function build_libtheora {
    # theora video encoder
    cd ${USRSRC}
    curl -L#O http://downloads.xiph.org/releases/theora/libtheora-1.1.1.tar.gz
    tar xzvf libtheora-1.1.1.tar.gz
    cd libtheora-1.1.1
    ./configure --with-ogg=${PREFIX} --prefix=${PREFIX}
    make
    make install
}

function build_libvorbis {
    # Vorbis audio encoder
    cd ${USRSRC}
    curl -L#O http://downloads.xiph.org/releases/vorbis/libvorbis-1.3.2.tar.gz
    tar xzvf libvorbis-1.3.2.tar.gz
    cd libvorbis-1.3.2
    ./configure --prefix=${PREFIX}
    make
    make install
}

Build the latest VPX library, that includes VP8 and VP9.

function build_vp8 {
    # VP8 Video encoder
    cd ${USRSRC}
    git clone https://chromium.googlesource.com/webm/libvpx
    cd libvpx
    git checkout v1.4.0
    ./configure --prefix=${PREFIX}
    make
    make install
}

Now things start to get tricky. ffplay is going to need pkg-config and SDL-1. This part took some trial and error. My system does not have GLIB on it, so I compiled using the “–with-internal-glib” flag.

function build_pkgconfig {
    curl -O http://pkgconfig.freedesktop.org/releases/pkg-config-0.28.tar.gz
    gunzip pkg-config-0.28.tar.gz
    tar xvf pkg-config-0.28.tar
    cd pkg-config-0.28
    ./configure --prefix=${PREFIX} --with-internal-glib
    make
    make install
}

Now, compile SDL-1.2.15. This part is NOT straightforward, and required some patches and hand-edits.

Download and unpack the SDL source.

 curl -O http://www.libsdl.org/release/SDL-1.2.15.tar.gz
 gunzip SDL-1.2.15.tar.gz
 tar xvf SDL-1.2.15.tar
 cd SDL-1.2.15

But you’re still not done. If you try compiling this, you will find that the compiler complains about conflicting definitions. I solved it by editing the file SDL_x11sym.h to look like this below. (Notice the second “_Xconst” declaration.)

#ifdef LONG64
SDL_X11_MODULE(IO_32BIT)
#if SDL_VIDEO_DRIVER_X11_CONST_PARAM_XDATA32
SDL_X11_SYM(int,_XData32,(Display *dpy,register _Xconst long *data,unsigned len),(dpy,data,len),return)
#else
SDL_X11_SYM(int,_XData32,(Display *dpy, register _Xconst long *data,unsigned len),(dpy,data,len),return)
#endif
SDL_X11_SYM(void,_XRead32,(Display *dpy,register long *data,long len),(dpy,data,len),)
#endif

Now try compiling SDL.

cd SDL-1.2.15
./configure --prefix=${PREFIX} -x-includes=/opt/X11/include -x-libraries=/opt/X11/lib
make
make install

If you make it past this, you should be able to compile ffmpeg and ffplay cleanly. Here is my little recipe. Notice that I explicitly set the CPPFLAGS and LDFLAGS variables to include my local distribution and the location of SDL.

function build_ffmpeg {
    # FFMPEG
    cd ${USRSRC}

    curl -O http://ffmpeg.org/releases/ffmpeg-2.6.2.tar.bz2
    bunzip2 ffmpeg-2.6.2.tar.bz2
    tar -xvf ffmpeg-2.6.2.tar
    cd ffmpeg-2.6.2

    export CPPFLAGS="-I${PREFIX}/include -I${PREFIX}/include/SDL"
    export LDFLAGS="-L${PREFIX}/lib -L${PREFIX}/lib/SDL" 

    ./configure --prefix=${PREFIX} --enable-gpl --enable-nonfree --enable-pthreads --enable-libmp3lame --enable-libtheora --enable-libfaac --enable-libvorbis --enable-libvpx --enable-libx264 --enable-version3 --disable-mmx --arch=x86_64 --cpu=core2

    make -j 4
    make install
}

If all goes well, you will find the ffmpeg and ffplay binaries on your path, and if you run ‘ffmpeg -help’ or ‘ffplay -help’ there will not be an error.

Let me know if this recipe helps at all, or if you have an improvement for the SDL step. This all seemed very difficult.

3 thoughts on “Build ffplay and ffmpeg 2.6.2 on Mac OSX 10.10.2”

  1. Thank you very much for this! It is refreshing to have a how-to-compile article that is both instructive and helpful, and doesn’t just recommend to blindly follow an existing system (like Homebrew/MacPorts/Fink).

    I did notice that the Gentoo patch for SDL was unnecessary, however, and that your modification to SDL_x11sym.h was slightly over-complex. (It can read like this:

    #ifdef LONG64
    SDL_X11_MODULE(IO_32BIT)
    SDL_X11_SYM(int,_XData32,(Display *dpy,register _Xconst long *data,unsigned len),(dpy,data,len),return)
    SDL_X11_SYM(void,_XRead32,(Display *dpy,register long *data,long len),(dpy,data,len),)
    #endif

    )

Leave a Reply

Your email address will not be published. Required fields are marked *