Compile Statically Linked FFmpeg on macOS
Compiling a statically linked version of FFmpeg on macOS allows you
to produce a standalone binary that includes its third-party
dependencies—such as x264, x265, and libvpx—without requiring external
shared libraries on the target system. While macOS strictly forbids
statically linking the core C runtime (libSystem.dylib),
you can link all third-party codec and format libraries statically. This
guide walks you through setting up your build environment, compiling
essential static dependencies, configuring FFmpeg with static build
flags, and verifying the final binary.
1. Install Prerequisites
To build FFmpeg and its dependencies, you need the Xcode Command Line Tools and essential build utilities.
Open Terminal and install the Command Line Tools:
xcode-select --installNext, install build tools via Homebrew. Do not install the libraries
you want to statically link via standard Homebrew commands, as Homebrew
often defaults to dynamic .dylib files. Instead, install
only the build tools:
brew install autoconf automake libtool pkg-config nasm yasm cmakeCreate a working directory for your static build:
mkdir -p ~/ffmpeg-static/build ~/ffmpeg-static/target
cd ~/ffmpeg-staticSet environment variables to point to your target directory:
export TARGET_DIR="$HOME/ffmpeg-static/target"
export PKG_CONFIG_PATH="$TARGET_DIR/lib/pkgconfig"
export PATH="$TARGET_DIR/bin:$PATH"2. Build Static Dependencies
Below is an example of compiling x264 as a static
library. You can repeat this process for any other library (such as
x265, libvpx, or lame) using
their respective --enable-static --disable-shared
flags.
Building libx264 statically:
cd ~/ffmpeg-static/build
git clone --depth 1 https://code.videolan.org/videolan/x264.git
cd x264
./configure \
--prefix="$TARGET_DIR" \
--enable-static \
--enable-pic \
--disable-cli
make -j$(sysctl -n hw.ncpu)
make install3. Download and Configure FFmpeg
Clone the official FFmpeg repository or download a release tarball:
cd ~/ffmpeg-static/build
git clone --depth 1 https://git.ffmpeg.org/ffmpeg.git
cd ffmpegConfigure FFmpeg to favor static linking. The crucial flags are
--pkg-config-flags="--static" and setting the search paths
to your custom $TARGET_DIR:
./configure \
--prefix="$TARGET_DIR" \
--pkg-config-flags="--static" \
--extra-cflags="-I$TARGET_DIR/include" \
--extra-ldflags="-L$TARGET_DIR/lib" \
--bindir="$TARGET_DIR/bin" \
--enable-static \
--disable-shared \
--enable-pic \
--enable-gpl \
--enable-libx264Note: Add any additional flags for other dependencies you
compiled (e.g., --enable-libvpx,
--enable-libmp3lame).
4. Compile and Install
Compile FFmpeg using all available CPU cores:
make -j$(sysctl -n hw.ncpu)
make installThe resulting binary will be placed in
~/ffmpeg-static/target/bin/ffmpeg.
5. Verify the Static Build
macOS binaries will always link to fundamental system dynamic
libraries (such as libSystem.B.dylib and
CoreFoundation), but they should not reference external
third-party .dylib files.
Inspect the compiled binary using otool:
otool -L ~/ffmpeg-static/target/bin/ffmpegA properly linked build will only list system libraries located under
/usr/lib/ or /System/Library/Frameworks/. If
libraries like libx264 do not appear as separate
.dylib paths in the output, they have been successfully
compiled directly into the executable.