Brew 编译 FFmpeg 4.2.2

Apr 14, 2020 • 预计阅读时间 2 分钟

只需要直接编译的话,直接看这里:

https://github.com/cntrump/brew-build-FFmpeg

编译过程笔记

FFmpeg.org 已经提供了编译好的静态版本: Static builds for macOS 64-bit

如果需要在这个版本的基础上增加 AAC 的支持,就需要自己编译。

先安装 pkg-config:

brew install pkg-config

某些依赖库需要源码编译,所以也需要安装:

brew install openssl svn cmake automake libtool

配置编译环境:

./configure --cc=/usr/bin/clang --prefix=/opt/FFmpeg --extra-version=tessus --enable-avisynth --enable-fontconfig --enable-gpl --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libmysofa --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvmaf --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-version3 --pkg-config-flags=--static --disable-ffplay

可能会遇到以下错误:

  • nasm/yasm not found or too old. Use –disable-x86asm for a crippled build.

    brew install yasm

  • ERROR: aom >= 1.0.0 not found using pkg-config

    brew install aom

  • ERROR: libass not found using pkg-config

    brew install libass

  • ERROR: libbluray not found using pkg-config

    brew install libbluray

  • ERROR: dav1d >= 0.2.1 not found using pkg-config

    brew install dav1d

  • ERROR: libgsm not found

    brew install libgsm

  • ERROR: libmodplug not found using pkg-config

    brew install libmodplug

  • ERROR: libmp3lame >= 3.98.3 not found

    brew install lame

  • ERROR: libmysofa not found

    git clone https://github.com/hoene/libmysofa.git
    cd ./libmysofa/build
    cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF ..
    make && make insall
    

    PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

  • ERROR: libopencore_amrnb not found

    brew install opencore-amr

  • ERROR: openh264 not found using pkg-config

    brew install openh264

  • ERROR: libopenjp2 >= 2.1.0 not found using pkg-config

    brew install openjpeg

  • ERROR: opus not found using pkg-config

    brew install opus

  • ERROR: rubberband >= 1.8.1 not found using pkg-config

    brew install rubberband

  • ERROR: shine not found using pkg-config

    git clone https://github.com/toots/shine.git
    cd ./shine
    ./bootstrap
    ./configure --prefix=/usr/local --disable-shared
    make && make install
    

    PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

  • ERROR: libsnappy not found

    brew install snappy

  • ERROR: libsoxr not found

    brew install libsoxr

  • ERROR: speex not found using pkg-config

    brew install speex

  • ERROR: libtheora not found

    brew install theora

  • ERROR: libtwolame not found

    brew install twolame

  • ERROR: vidstab >= 0.98 not found using pkg-config

    brew install libvidstab

  • ERROR: libvmaf >= 1.3.9 not found using pkg-config

    brew install libvmaf

  • ERROR: libvo_amrwbenc not found

    # https://sourceforge.net/projects/opencore-amr/files/vo-amrwbenc/vo-amrwbenc-0.1.3.tar.gz/download
    curl -O https://iweb.dl.sourceforge.net/project/opencore-amr/vo-amrwbenc/vo-amrwbenc-0.1.3.tar.gz
    tar -zxvf ./vo-amrwbenc-0.1.3.tar.gz
    cd ./vo-amrwbenc-0.1.3
    ./configure --prefix=/usr/local --disable-shared
    make && make install
    

    PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

  • libvpx enabled but no supported decoders found

    brew install libvpx

  • ERROR: libwavpack not found

    brew install wavpack

  • ERROR: libwebp >= 0.2.0 not found using pkg-config

    brew install webp

  • ERROR: libx264 not found

    brew install x264

  • ERROR: x265 not found using pkg-config

    brew install x265

  • ERROR: libxavs not found

    # https://sourceforge.net/projects/xavs/
    svn checkout https://svn.code.sf.net/p/xavs/code/trunk xavs
    cd ./xavs
    ./configure --prefix=/usr/local --host=x86_64-darwin --disable-asm
    make && make install
    

    PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

  • ERROR: libxvid not found

    brew install xvid

  • ERROR: zimg >= 2.7.0 not found using pkg-config

    brew install zimg

  • ERROR: libzmq not found using pkg-config

    brew install zmq

  • ERROR: zvbi-0.2 not found using pkg-config

    # https://sourceforge.net/projects/zapping/files/zvbi/
    curl -O https://svwh.dl.sourceforge.net/project/zapping/zvbi/0.2.35/zvbi-0.2.35.tar.bz2
    tar -jxvf ./zvbi-0.2.35.tar.bz2
    cd ./zvbi-0.2.35
    ./configure --prefix=/usr/local --disable-shared
    make && make install
    

    PKG_CONFIG_PATH=/usr/local/lib/pkgconfig

支持 FDK-AAC

FFmpeg 增加配置参数:--enable-nonfree --enable-libfdk-aa

brew install fdk-aac

支持 TLS (OpenSSL)

FFmpeg 增加配置参数:--enable-openssl --extra-cflags="-I/usr/local/opt/openssl/include" --extra-ldflags="-L/usr/local/opt/openssl/lib"

PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig

Build.sh

#!/bin/sh

set -e

brew install pkg-config openssl svn cmake automake libtool yasm aom libass libbluray dav1d libgsm libmodplug lame opencore-amr openh264 openjpeg opus rubberband snappy libsoxr speex theora twolame libvidstab libvmaf libvpx wavpack webp x264 x265 xvid zimg zmq fdk-aac

cd /tmp

if [ -d ./libmysofa ]; then
  rm -rf ./libmysofa
fi

git clone https://github.com/hoene/libmysofa.git
cd ./libmysofa/build
cmake -DCMAKE_INSTALL_PREFIX=/usr/local -DBUILD_SHARED_LIBS=OFF -DBUILD_TESTS=OFF ..
make install mysofa-static

cd ../..

if [ -d ./shine ]; then
  rm -rf ./shine
fi

git clone https://github.com/toots/shine.git
cd ./shine
./bootstrap
./configure --prefix=/usr/local --disable-shared
make && make install

cd ..

if [ -d ./vo-amrwbenc-0.1.3 ]; then
  rm -rf ./vo-amrwbenc-0.1.3
fi

curl -O https://iweb.dl.sourceforge.net/project/opencore-amr/vo-amrwbenc/vo-amrwbenc-0.1.3.tar.gz
tar -zxvf ./vo-amrwbenc-0.1.3.tar.gz
cd ./vo-amrwbenc-0.1.3
./configure --prefix=/usr/local --disable-shared
make && make install

cd ..

if [ -d ./xavs ]; then
  rm -rf ./xavs
fi

svn checkout https://svn.code.sf.net/p/xavs/code/trunk xavs
cd ./xavs
./configure --prefix=/usr/local --host=x86_64-darwin --disable-asm
make && make install

cd ..

if [ -d ./zvbi-0.2.35 ]; then
  rm -rf ./zvbi-0.2.35
fi

curl -O https://svwh.dl.sourceforge.net/project/zapping/zvbi/0.2.35/zvbi-0.2.35.tar.bz2
tar -jxvf ./zvbi-0.2.35.tar.bz2
cd ./zvbi-0.2.35
./configure --prefix=/usr/local --disable-shared
make && make install

cd ..

FFMPEG_VERSION=4.2.2

if [ -d ./FFmpeg-${FFMPEG_VERSION} ]; then
  rm -rf ./FFmpeg-${FFMPEG_VERSION}
fi

curl -O https://FFmpeg.org/releases/FFmpeg-${FFMPEG_VERSION}.tar.bz2
tar -jxvf ./FFmpeg-${FFMPEG_VERSION}.tar.bz2
cd ./FFmpeg-${FFMPEG_VERSION}

export PKG_CONFIG_PATH=/usr/local/opt/openssl/lib/pkgconfig

MIN_TARGET=10.9

./configure --cc=/usr/bin/clang --prefix=/usr/local --extra-version=lvv.me --enable-avisynth --enable-fontconfig --enable-gpl --enable-libaom --enable-libass --enable-libbluray --enable-libdav1d --enable-libfreetype --enable-libgsm --enable-libmodplug --enable-libmp3lame --enable-libmysofa --enable-libopencore-amrnb --enable-libopencore-amrwb --enable-libopenh264 --enable-libopenjpeg --enable-libopus --enable-librubberband --enable-libshine --enable-libsnappy --enable-libsoxr --enable-libspeex --enable-libtheora --enable-libtwolame --enable-libvidstab --enable-libvmaf --enable-libvo-amrwbenc --enable-libvorbis --enable-libvpx --enable-libwavpack --enable-libwebp --enable-libx264 --enable-libx265 --enable-libxavs --enable-libxvid --enable-libzimg --enable-libzmq --enable-libzvbi --enable-version3 --pkg-config-flags=--static --disable-ffplay --enable-nonfree --enable-libfdk-aac --enable-openssl --extra-cflags="-I/usr/local/opt/openssl/include -mmacosx-version-min=${MIN_TARGET}" --extra-ldflags="-L/usr/local/opt/openssl/lib -mmacosx-version-min=${MIN_TARGET}"

make -j `sysctl -n hw.logicalcpu_max`
make install

echo finished.
FFmpeg
版权声明:如果转发请带上本文链接和注明来源。

lvv.me

iOS/macOS Developer

Nginx 重定向 HTTP 请求到 HTTPS 端口

高质量 H.264 视频编码推荐设置