Media & Entertainment Industry Trends, Technology and Research

#3 Technical Series : How to compile and setup FFmpeg on Mac

Posted In Technical - By Nitin Narang on Tuesday, April 28th, 2015 With 1 Comment

FFmpeg is a rich multimedia framework which can handle most exhaustive image and video processing tasks. FFmpegFFmpeg on Mac can perform encoding, decoding, transcoding, muxing, demuxing, playback and streaming for audio and video content. In addition to open source, FFmpeg has unique advantage of supporting large number of media containers, codecs and file formats.

FFmpeg can be used on Mac by either downloading a static build or compiling FFmpeg for Mac. Compiling FFmpeg on Mac is easy and and similar to doing it on other Linux distributions. Below are step by step instructions to setup FFmpeg on Mac using Homebrew.  If you are a Windows user and want to compile FFmpeg for windows, please refer here to setup FFmpeg under Cygwin for Windows.

1. Install or Update Xcode

Latest version of Xcode (6.3.1) is quite bulky ~ 2.5 GB so it is going to take time. Download Xcode from App Store and install it.

XCode Installation

2. Install Homebrew

Homebrew is an excellent package manager and can save trouble to downloading, configuring and building binaries separately. Install Homebrew using below command

nitinnarang$ 
nitinnarang$ ruby -e "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/master/install)"
==> This script will install:
/usr/local/bin/brew
/usr/local/Library/...
/usr/local/share/man/man1/brew.1

Press RETURN to continue or any other key to abort
==> /usr/bin/sudo /bin/mkdir /usr/local

WARNING: Improper use of the sudo command could lead to data loss
or the deletion of important system files. Please double-check your
typing when using sudo. Type "man sudo" for more information.

To proceed, enter your password, or type Ctrl-C to abort.

Key in super user password and all dependencies start to get download and get installed. Once finished run “brew doctor” to confirm the status of brew.

nitinnarang$
nitinnarang$ brew doctor
Your system is ready to brew.

3. Use Homebrew to explore FFmpeg compile options 

Brew takes the pain of finding and downloading the dependencies. Use brew to find FFmpeg options. The command “brew options ffmpeg ” will provide all package option available for FFmpeg, some of these options are shown below

nitinnarang$
nitinnarang$ brew options ffmpeg
--with-faac
	Build with faac support
--with-fdk-aac
	Enable the Fraunhofer FDK AAC library
--with-ffplay
	Enable FFplay media player
...........................................................................
--without-x264
	Disable H.264 encoder
--without-xvid
	Disable Xvid MPEG-4 video encoder
--HEAD
	Install HEAD version

4. Select FFmpeg options and compile

One can select required FFmpeg options and run “brew install ffmpeg” along with the selected options. Brew will resolve all dependencies, download and compile the dependent libraries. Below command has most of the FFmpeg options selected

nitinnarang$
nitinnarang$ brew install ffmpeg --with-fdk-aac --with-ffplay --with-freetype --with-frei0r --with-libass --with-libvo-aacenc --with-libvorbis --with-libvpx --with-opencore-amr --with-openjpeg --with-opus --with-rtmpdump --with-schroedinger --with-speex --with-theora --with-tools --with-x265
==> Installing dependencies for ffmpeg: pkg-config, texi2html, yasm, x264, lame, libvo-aacenc, xvid, libpng, freetype, libogg, libvorbis, theora, libvpx, openssl, rtmpdump, o
==> Installing ffmpeg dependency: pkg-config
==> Downloading https://homebrew.bintray.com/bottles/pkg-config-0.28.yosemite.bottle.2.tar.gz
######################################################################## 100.0%

FFmpeg will get built without libfaac for licensing reasons. User can use libvo-aacenc as default audio encoder.

5. FFmpeg is ready to use

FFmpeg binaries are generated under “/usr/local/Cellar” with sym link created

nitinnarang$
nitinnarang$ which ffmpeg
/usr/local/bin/ffmpeg
nitinnarang$ cd /usr/local/bin/
nitinnarang$ ls -al ffmpeg 
lrwxr-xr-x  1 nitinnarang  admin  33 Apr 26 23:17 ffmpeg -> ../Cellar/ffmpeg/2.6.2/bin/ffmpeg

Run “ffmpeg” which display all compile option used for building the FFmpeg binary

nitinnarang$
nitinnarang$ ffmpeg
ffmpeg version 2.6.2 Copyright (c) 2000-2015 the FFmpeg developers
  built with Apple LLVM version 6.1.0 (clang-602.0.49) (based on LLVM 3.6.0svn)
  configuration: --prefix=/usr/local/Cellar/ffmpeg/2.6.2 --enable-shared --enable-pthreads --enable-gpl --enable-version3 --enable-hardcoded-tables --enable-avresample --cc=clang --host-cflags= --host-ldflags= --enable-libx264 --enable-libmp3lame --enable-libvo-aacenc --enable-libxvid --enable-libfreetype --enable-libtheora --enable-libvorbis --enable-libvpx --enable-librtmp --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libfaac --enable-libass --enable-ffplay --enable-libspeex --enable-libschroedinger --enable-libfdk-aac --enable-libopus --enable-frei0r --enable-libx265 --enable-libopenjpeg --disable-decoder=jpeg2000 --extra-cflags='-I/usr/local/Cellar/openjpeg/1.5.1_1/include/openjpeg-1.5 ' --enable-nonfree --enable-vda
  libavutil      54. 20.100 / 54. 20.100
  libavcodec     56. 26.100 / 56. 26.100
  libavformat    56. 25.101 / 56. 25.101
  libavdevice    56.  4.100 / 56.  4.100
  libavfilter     5. 11.102 /  5. 11.102
  libavresample   2.  1.  0 /  2.  1.  0
  libswscale      3.  1.101 /  3.  1.101
  libswresample   1.  1.100 /  1.  1.100
  libpostproc    53.  3.100 / 53.  3.100
Hyper fast Audio and Video encoder
usage: ffmpeg [options] [[infile options] -i infile]... {[outfile options] outfile}...

FFmpeg is ready to use… Happy image and video processing with FFmpeg.

References 1 and 2

About - Digital Architect, Media Technology Consultant and Machine Learning Practitioner. I have passion for TV technology, digital convergence and changing face of Media and Entertainment industry. Currently having fun with AI and Machine Learning.