This page explains how to configure and build FFmpeg on macOS. The required steps are:
You can get the FFmpeg source code in these ways:
~/ffmpeg
.
git clone --branch n7.1.2 https://git.ffmpeg.org/ffmpeg.git ffmpeg
It is recommended to use the same FFmpeg version as documented in the Qt Multimedia main page .
The following paragraphs assumes that you store the FFmpeg source code under
~/ffmpeg
.
To build FFmpeg, these tools and packages are required:
To install Homebrew, run:
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"
To install Homebrew package Yasm, run:
brew install yasm
创建
build
directory inside the
~/ffmpeg
directory and navigate into it:
mkdir ~/ffmpeg/build cd ~/ffmpeg/build
To configure FFmpeg, run:
../configure --prefix=/usr/local/ffmpeg --disable-doc --enable-network --enable-shared
The
--prefix
argument specifies a path where the FFmpeg development libraries are installed after building. The documentation is not needed, but network features should be enabled. To build FFmpeg as static libraries, omit the
--enable-shared
选项。
In the previous code snippet, an absolute path was used for
--prefix
argument intentionally. If you specify a relative path (for example,
../install
), the dependencies will be referenced using this relative path and not the correct one using
@rpath
. Using absolute paths makes an FFmpeg build non-portable. To use relative paths and make FFmpeg build portable, you need to manually fix dependencies using
otool
.
Once the
configure
command finishes, build and install FFmpeg using the
make
命令。
make -j install
If the build completes without errors, FFmpeg development libraries are installed in the
/usr/local/ffmpeg
directory. If you build Qt Multimedia, this path is stored in the
FFMPEG_DIR
variable used when configuring Qt Multimedia.
To create universal binaries on macOS (for example, for both x86_64 and arm64 architectures), follow these steps:
../configure --prefix=/usr/local/ffmpeg/arm64 --disable-doc --enable-network \
--enable-shared --enable-cross-compile --arch=arm64 --cc="clang -arch arm64"
make -j install
../configure --prefix=/usr/local/ffmpeg/x86_64 --disable-doc --enable-network \
--enable-shared --enable-cross-compile --arch=x86_64 --cc="clang -arch x86_64"
make -j install