安装XCode
首先,必须安装XCode,XCode提供了Mac平台开发环境必须的gcc编译器。XCode安装后需要先打开一次,同意一下条款才能在命令行里使用。同时,如果你不确定你的Xcode版本是否提供了命令行工具,需要在终端里运行一下:
xcode-select --install
如果不提示安装Command Line Tools,说明就已经默认安装好了命令行工具了。
下载并安装brew
homebrew是一个Mac平台的包管理工具,类似Debian/Ubuntu的apt,提供了许多Mac没有的Unix/Linux工具,例如wget。安装homebrew很简单:
ruby -e "$(curl -fsSkL raw.github.com/mxcl/homebrew/go)"
安装依赖库
brew install automake yasm git pkg-config fdk-aac libass libtool libvorbis libvpx opus sdl sdl2 shtool texi2html theora wget x264 x265 xvid speex lame
git克隆ffmpeg并安装
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
cd ffmpeg
./configure --prefix=/usr/local/ffmpeg --enable-gpl --enable-nonfree --enable-libfdk-aac --enable-libmp3lame --enable-libx264 --enable-libx265 --enable-libass --enable-libspeex --enable-libopus --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libfreetype --enable-videotoolbox --enable-filter=delogo --enable-debug --disable-optimizations --enable-shared --enable-pthreads --enable-version3 --enable-hardcoded-tables --cc=clang --host-cflags= --host-ldflags= --disable-x86asm
sudo make &&sudo make install
配置环境变量
sudo nano ~/.bash_profile
添加以下代码:
export PATH="$PATH:/usr/local/ffmpeg/bin"
export PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig:/usr/local/Cellar/sdl2/2.0.8/lib/pkgconfig:/usr/local/ffmpeg/lib/pkgconfig"
PKG_CONFIG_PATH="$PKG_CONFIG_PATH:/usr/local/lib/pkgconfig:/usr/lib/pkgconfig:/usr/X11/lib/pkgconfig"
CFLAGS='freetype-config --cflags' LDFLAGS='freetype-config --libs'