Build ffplay and ffmpeg 2.6.2 on Mac OSX 10.10.2

原文链接:http://www.tsheffler.com/blog/2015/05/14/build-ffplay-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.

Build ffplay and ffmpeg 2.6.2 on Mac OSX 10.10.2_第1张图片

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:

  • xcode 6, clang 6.1.0
  • X11 headers and libraries in /opt/X11 (get XQuartz from here http://xquartz.macosforge.org/landing/).

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-configand 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
  • edit src/video/quartz/SDL_QuartzVideo.h and remove the line with CGDirectPaletteRef (see http://hg.libsdl.org/SDL/rev/e9466ead70e5)
  • And apply this patch https://sources.gentoo.org/cgi-bin/viewvc.cgi/gentoo-x86/media-libs/libsdl/files/libsdl-1.2.15-const-xdata32.patch. I edited the named files by hand.

But you’re still not done. If you try compiling this, you will find that the compiler complains about conflicting definitions.

1.2.15 have bug, it fixed in below:

http://hg.libsdl.org/SDL/rev/e9466ead70e5

 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.

你可能感兴趣的:(Build ffplay and ffmpeg 2.6.2 on Mac OSX 10.10.2)