wiki:

CompilationGuide

/

MacOSX


Version 16 (modified by cbsrobot, 5 years ago) (diff)

add "cd .." to make it more copy paste friendly

Compiling on Mac OS X is as easy as any other *nix machine, there are just a few caveats.



XCode

Starting with Lion 10.7, Xcode is available for free from the Mac App Store and is required to compile anything on your Mac. Make sure you install the Command Line Tools from Preferences > Downloads > Components. Older versions are still available with an AppleID and free Developer account at developer.apple.com

The general procedure is ./configure <flags>; make && sudo make install, but some use a different configuration scheme, or none at all.



Compiling on OSX using Homebrew for the dependencies

First install homebrew and some dependencies:

# install homebrew
ruby <(curl -fsSkL raw.github.com/mxcl/homebrew/go)
# install dependencies
brew install automake celt faac git lame libass libtool libvorbis libvpx \
libvo-aacenc opencore-amr openjpeg opus sdl schroedinger shtool speex texi2html \
theora wget x264 xvid yasm

Install fdk-aac (atm. there is no recipe for it):

git clone git://opencore-amr.git.sourceforge.net/gitroot/opencore-amr/fdk-aac
cd fdk-aac
autoreconf -fvi
./configure --disable-shared
make && make install
cd ..

Install libaacplus (atm. there is no recipe for it):

wget http://217.20.164.161/~tipok/aacplus/libaacplus-2.0.2.tar.gz
tar xzf libaacplus-2.0.2.tar.gz
cd libaacplus-2.0.2
# libtool on osx is quite different from the gnu libtool, which is called glibtool on osx
sed -i '.bck' -e 's/libtool/glibtool/' autogen.sh
./autogen.sh
make && make install
cd ..

Mac OS X Lion comes with Freetype already installed (older versions may need 'X11' selected during installation), but in an atypical location: /usr/X11. Running freetype-config in Terminal can give the locations of the individual folders, like headers, and libraries, so be prepared to add lines like CFLAGS=`freetype-config --cflags` LDFLAGS=`freetype-config --libs` PKG_CONFIG_PATH=$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig:/usr/X11/lib/pkgconfig before ./configure or add them to your $HOME/.profile file.

Install ffmpeg

git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg
cd ffmpeg
./configure --enable-gpl --enable-version3 --enable-nonfree --enable-postproc --enable-libaacplus \
--enable-libass --enable-libcelt --enable-libfaac --enable-libfdk-aac --enable-libfreetype --enable-libmp3lame \
--enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenjpeg --enable-openssl \
--enable-libopus --enable-libschroedinger --enable-libspeex --enable-libtheora --enable-libvo-aacenc \
--enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --prefix=/usr/local
make && make install

Finally install qt-faststart. This is a useful tool if you're showing your H.264 MP4 videos on the web. It relocates some data in the video to allow playback to begin before the file is completely downloaded. Usage: qt-faststart input.mp4 output.mp4. Code:

make tools/qt-faststart



Manual install of the dependencies

Freetype

Mac OS X Lion comes with Freetype already installed (older versions may need 'X11' selected during installation), but in an atypical location: /usr/X11. Running freetype-config in Terminal can give the locations of the individual folders, like headers, and libraries, so be prepared to add lines like CFLAGS=`freetype-config --cflags` LDFLAGS=`freetype-config --libs` before ./configure when configuring packages that require freetype like gd and png.

Pkg-config & GLib

Pkg-config is necessary for detecting some of the libraries you can compile into FFmpeg, and it requires GLib which is not included in Mac OS X (but almost every other *nix distribution). You may either download pkg-config 0.23, or download the large tarball from Gnome.org and compile it. Pkg-config is available from Freedesktop.org.

To compile GLib, you must also download gettext from GNU.org and edit the file stpncpy.c to add "#undef stpncpy" just before "#ifndef weak_alias". Lion has its own (incompatible) version of the stpncpy function, which overlaps in gettext. Compile gettext as usual. Compile GLib with LIBFFI_CFLAGS=-I/usr/include/ffi LIBFFI_LIBS=-lffi ./configure;make && sudo make install

To compile pkg-config, run GLIB_CFLAGS="-I/usr/local/include/glib-2.0 -I/usr/local/lib/glib-2.0/include" GLIB_LIBS="-lglib-2.0 -lgio-2.0" ./configure --with-pc-path="/usr/X11/lib/pkgconfig:/usr/X11/share/pkgconfig:/usr/lib/pkgconfig:/usr/local/lib/pkgconfig"

Yasm

Yasm is available from tortall.net and is necessary for compiling C code that contains machine-independent Assembler code. To compile, run ./configure --enable-python; make && sudo make install



Additional libraries

These are just some examples. Run .configure --help for all available options.

FAAC (AAC) is available at audiocoding.com. Enabling support in ffmpeg requires the --enable-libfaac --enable-nonfree configure options.

Lame (MP3) is available at http://sourceforge.net/projects/lame/files/lame/, and adds MP3 encoding to FFmpeg. Enabling support in ffmpeg requires --enable-libmp3lame.

Libass (Subtitle) is available at http://code.google.com/p/libass/. In order to compile with --enable-libass you need Freetype installed.

OpenJPEG (Jpeg 2000) is available at http://code.google.com/p/openjpeg/downloads/list . Compile with --enable-libopenjpeg .

Schroedinger, which adds Dirac codec support, is available from diracvideo.org. To compile schroedinger, you need ORC, available from entropywave.com. Compile orc with the standard procedure, making sure you delete the "testsuite" folder, which won't compile. When compiling schroedinger, make sure pkg-config and yasm are already installed.

Speex is available at xiph.org. Compile with --enable-libspeex .

Theora, Ogg and Vorbis are available at theora.org. Compile with --enable-libtheora .

VPX is available at http://code.google.com/p/webm/downloads/list. Compile with --enable-libvpx .

x264 is available at http://www.videolan.org/developers/x264.html. FFmpeg depends on x264 when compiled with --enable-libx264 and x264 depends on FFmpeg when compiled with --enable-lavf-input . The best way to handle it is to install x264 first without --enable-lavf-input then compile FFmpeg with --enable-libx264 and finally compile x264 again with --enable-lavf-input .

XVid is available from xvid.org. Compile with --enable-libxvid .



Compiling

Once you have compiled all of the codecs/libraries you want, you can now download the FFmpeg source either with git or the from release tarball links on the website. Study the output of ./configure --help and make sure you've enabled all the features you want, remembering that --enable-nonfree and --enable-gpl will be necessary for some of the dependencies above. A sample command is:

./configure --enable-nonfree --enable-libcdio --enable-libschroedinger --enable-libfaac --enable-libfreetype --enable-libmp3lame --enable-libopenjpeg --enable-libspeex --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libxvid --enable-openssl --enable-zlib --enable-gpl

make
make install

Install qt-faststart (optional)

This is a useful tool if you're showing your H.264 MP4 videos on the web. It relocates some data in the video to allow playback to begin before the file is completely downloaded. Usage: qt-faststart input.mp4 output.mp4. Code:

make tools/qt-faststart