FFmpeg

This tutorial will explain how to configure and build FFmpeg so the executable can be published and distributed as a standalone with no dependency or any special configuration for Mac OS X.
First of all, Xcode need to be install on your machine from the Install DVD. This will install all the necessary packages and software.
Git (http://git.or.cz/) can also be installed his you want to easily update x264 later.

Dependencies

Each of the following dependencies are libraries which need to be compiled and installed. It is important that the libraries must not be compiled as shared.

The headers (*.h) need to be installed in the include system directory (/usr/include) and the static libraries (*.a) need to be installed in the library system directory (/usr/lib).
The following commands contains the installation basic instructions.

XviD
Even if avcodec contains a native MPEG-4/XviD encoder, it is better to have the XviD original core.
xvidcore source can be downloaded from http://www.xvid.org/
To build and configure xvidcore, you need to be in the folder build/generic.

$ cd build/generic
$ ./configure –disable-assembly
$ make -j3
$ cd ../..
$ sudo cp src/xvid.h /usr/include
$ sudo cp build/generic/=build/libxvidcore.a /usr/lib

MP3
MP3 audio support using Lame.
lame source can be downloaded from http://lame.sourceforge.net/

$./configure –disable-decoder –disable-shared
$ make -j3
$ sudo mkdir -p /usr/include/lame
$ sudo cp include/lame.h /usr/include/lame
$ sudo cp libmp3lame/.libs/libmp3lame.a /usr/lib

OGG/Vorbis
OGG support using libogg and libvorbis.
Both sources can be downloaded from http://downloads.xiph.org/releases/ogg/ and http://downloads.xiph.org/releases/vorbis/

OGG
$ ./configure
$ make -j3
$ sudo mkdir -p /usr/include/ogg
$ sudo cp include/ogg/*.h /usr/include/ogg
$ sudo cp .libs/libogg.a lib

Vorbis
$ ./configure –disable-oggtest –disable-shared
$ make -j3
$ sudo mkdir -p /usr/include/vorbis
$ sudo cp include/vorbis/*.h /usr/include/vorbis
$ sudo cp .libs/*.a lib

A/52 – AC-3
Support of A/52 decoding also known as AC-3
liba52 source can be downloaded from http://liba52.sourceforge.net/

$ ./configure
$ make -j3
$ sudo mkdir -p /usr/include/a52dec
$ sudo cp include/a52.h /usr/include/a52dec/a52.h
$ sudo cp liba52/.libs/liba52.a /usr/lib

AAC
Support for AAC encoding and decoding.
faac and faad2 can be downloaded from http://www.audiocoding.com/

FAAC
$ ./bootstrap
$ ./configure
$ make -j3
$ sudo cp include/*.h /usr/include
$ sudo cp libfaac/.libs/libfaac.a /usr/lib

FAAD2
$ ./bootstrap
$ ./configure –without-bmp –without-xmms –without-drm –without-mpeg4ip
$ make -j3
$ sudo cp include/*.h /usr/include
$ sudo cp libfaad/.libs/libfaad.a /usr/lib

x264
Support H.264/MPEG4 AVC encoding
x264 can be downloaded from http://git.videolan.org/gitweb.cgi?p=x264.git or its git repository git clone git://git.videolan.org/x264.git

$ ./configure –enable-pthread –enable-pic
$ make -j3
$ sudo cp x264.h /usr/include
$ sudo cp libx264.a /usr/lib

FFmpeg

Sources

First step is to download FFmpeg source code from its subversion repository. By doing so, you have the last version of the software and if updates need to be done, it is easier to manage.

$ svn checkout svn://svn.mplayerhq.hu/ffmpeg/trunk ffmpeg

Configure

$ ./configure –enable-pthreads –disable-vhook –disable-mmx –enable-gpl –enable-postproc –enable-swscale –disable-ffserver –disable-ffplay –enable-libxvid–enable-libmp3lame –enable-libvorbis –enable-liba52 –enable-libfaac –enable-libfaad –enable-libx264

For more explanations on the configure options, see the configure help.
mmx is disabled because it provokes FFmpeg to crash on MacIntel.
vhook is disabled because it is not fully implemented and so to be replace by avfilter.
ffplay and ffserver are disable because this tutorial is focussing on ffmpeg encoder habilities.

Compilation
GNU Make version 3.81 is required, it appears that the version 3.80 crashes during ffmpeg compilation.

$ make -j3

Portability
To check if ffmpeg is library independent, use otool to verify if the libraries will be on every systems.

$ otool -L ffmpeg

All libraries need to be:
/usr/lib/libz.*
/usr/lib/libz2.*
/usr/lib/libSystem.*
(/usr/lib/libgcc_s*)

If not, some static libraries (*.a) are not present in /usr/lib.

On Mac OS X, if an application is compiled on a specific system then this application will only run on the same systems/CPU type or above. For example, if FFmpeg is compiled on Leopard Intel then it will work only on Leopard Intel. If it is compiled on Tiger PPC then it will rum on PPC only Leopard and Tiger.

To have a universal binary and due to the libx264 compilation option restrictions, ffmpeg and all libraries needs to be compiled on a PPC and on an Intel-based Mac. Then the 2 ffmpeg need to create the universal binary using lipo.

$ lipo -create ffmpeg.ppc ffmpeg.i386 -output ffmpeg

If ffmpeg is created on Mac OS X Tiger (10.4.*), ffmpeg will work on Leopard (10.5.*).
To obtain a working binary for Tiger when compiled on Leopard, every libraries and ffmpeg need to be compiled using the gcc option -mmacosx-version-min=10.4 .

References
[1] http://howto-pages.org/ffmpeg/
[2] http://ffmpeg.mplayerhq.hu/
[3] http://x264.nl/
[4] http://trac.macports.org/browser/trunk/dports/multimedia/ffmpeg/Portfile

Comments are closed.