wiki:

CompilationGuide

/

macOS


Version 5 (modified by slhck, 3 weeks ago) (diff)

grammar and introduction, update descriptions

There are a few ways to get FFmpeg on macOS:

  1. Use a package manager like Homebrew or MacPorts to install ffmpeg. These will automatically keep your FFmpeg installation up-to-date. See the Homebrew section below for more info.
  1. Download a static build for macOS. This is as easy as extracting and running the downloaded binary. One disadvantage with static builds is that updates have to be performed manually. Also, they may not contain all encoders or filters you want.
  1. Build it yourself. Compiling on macOS is as easy as on any other *nix machine. Download the source, then run ./configure with the needed flags, make and make install. However, the configuration options have to be set manually, and you will need to install third-party libraries yourself. See the compilation section below for more info.

ffmpeg through Homebrew

Homebrew is a command-line package manager, which is similar to apt-get on popular Linux distributions. In order to use it, you need to install brew first, if you haven't already:

/usr/bin/ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Follow the on-screen instructions. This will take a few minutes while it's installing the necessary developer tools for macOS. Then, run:

brew install ffmpeg

to get the latest released version with minimal configuration (and library dependency) options. These versions are packaged as Homebrew formulas and will take care of all the dependencies and the installation itself.

Specifying additional options

You can run brew info ffmpeg to see additional install options, e.g. in order to enable libfdk_aac or libvpx, which are highly recommended. Here is an example with some additional options:

brew install ffmpeg \
    --with-tools \
    --with-fdk-aac \
    --with-freetype \
    --with-fontconfig \
    --with-libass \
    --with-libvorbis \
    --with-libvpx \
    --with-opus \
    --with-x265

Updating ffmpeg

To later upgrade your ffmpeg version to the latest released, simply run:

brew update && brew upgrade ffmpeg

Installing Git HEAD

If you want to install the latest Git version of ffmpeg instead of the release version, follow the above directions, but add a --HEAD to the install command. For example:

brew install ffmpeg --with-tools --with-fdk-aac --with-libvpx --with-x265 --HEAD

Compiling FFmpeg yourself

Xcode

Xcode is required to compile software on your Mac. Install Xcode by downloading it from the website or using the Mac App Store.

After installing Xcode, install the Command Line Tools from Preferences > Downloads > Components. You can also install the tools via your shell:

xcode-select --install

Installing dependencies with Homebrew

To get some dependencies for ffmpeg, you can install Homebrew.

ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"

Then:

brew install automake fdk-aac git lame libass libtool libvorbis libvpx \
opus sdl shtool texi2html theora wget x264 x265 xvid nasm

Tip: If you don't want to use Homebrew to get the dependencies, see the section below. Using Homebrew will however save you time in setting up all the needed tools.

Manual install of the dependencies without Homebrew

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 macOS (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. Mac OS X 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"

Nasm

Nasm is an assembler required for x264. The latest version is available at nasm.us.

Additional libraries

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

  • x264 encodes H.264 video. Use --enable-gpl --enable-libx264.
  • fdk-aac encodes AAC audio. Use --enable-libfdk-aac.
  • libvpx is a VP8 and VP9 encoder. Use --enable-libvpx.
  • libvorbis encodes Vorbis audio . Requires libogg. Use --enable-libvorbis.
  • libopus encodes Opus audio.
  • LAME encodes MP3 audio. Use --enable-libmp3lame.
  • libass is a subtitle renderer. Use --enable-libass.

Freetype

macOS already comes with freetype installed (older versions may need X11 selected during installation), but in an atypical location: /opt/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:/opt/X11/lib/pkgconfig

in your ./configure command.

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:

git clone http://source.ffmpeg.org/git/ffmpeg.git ffmpeg
cd ffmpeg
./configure  --prefix=/usr/local --enable-gpl --enable-nonfree --enable-libass \
--enable-libfdk-aac --enable-libfreetype --enable-libmp3lame \
--enable-libtheora --enable-libvorbis --enable-libvpx --enable-libx264 --enable-libx265 --enable-libopus --enable-libxvid
make

After successful compilation, running sudo make install will install the ffmpeg binaries with superuser rights. You can also set a prefix during configuration, e.g. --prefix="$HOME/bin, where no root rights are needed for make install.