Skip to content

Instantly share code, notes, and snippets.

@ercansormaz
Last active July 4, 2026 13:28
Show Gist options
  • Select an option

  • Save ercansormaz/506de91dc1dab800c753cd1f86d74c3a to your computer and use it in GitHub Desktop.

Select an option

Save ercansormaz/506de91dc1dab800c753cd1f86d74c3a to your computer and use it in GitHub Desktop.
Build FFmpeg from Source with AV1, x264, x265, fdk-aac and More (macOS Guide)

👉 Read the Blog Post

# ============================================================
# FFmpeg Build Script (macOS / Source-based Installation)
# ============================================================
# This script builds FFmpeg 8.1 from source with support for
# AV1, x264, x265, fdk-aac, libmp3lame, opus, libvpx, freetype 
# and OpenSSL.
#
# All dependencies are compiled and installed into an isolated
# directory under $HOME/Applications/ffmpeg_library to ensure
# a clean, reproducible, and fully static build.
#
# Updated at 2026-07-04
# ============================================================

brew install cmake pkg-config meson

mkdir -p $HOME/Applications/ffmpeg_sources
mkdir -p $HOME/Applications/ffmpeg_library


# === nasm === #
# Assembler for optimizing SIMD (CPU vector instructions).
# Required for high-performance video encoding with codecs like x264, x265, and libvpx.
cd $HOME/Applications/ffmpeg_sources
curl https://www.nasm.us/pub/nasm/releasebuilds/3.02/nasm-3.02.tar.gz -o nasm.tar.gz
mkdir -p nasm && tar -zxvf nasm.tar.gz -C ./nasm --strip-components=1 && rm nasm.tar.gz
cd nasm
./configure --prefix="$HOME/Applications/ffmpeg_library"
make && make install


export PATH="$HOME/Applications/ffmpeg_library/bin:$PATH"


# === x264 === #
# H.264 video encoder library (widely used for MP4 and streaming formats).
# Enables FFmpeg to encode and decode H.264 video streams.
cd $HOME/Applications/ffmpeg_sources
git clone --branch stable --depth 1 --single-branch https://code.videolan.org/videolan/x264.git
cd x264
./configure --prefix="$HOME/Applications/ffmpeg_library" --enable-static
make && make install


# === x265 === #
# H.265 / HEVC encoder library (successor to H.264 with better compression).
# Used for modern high-efficiency video compression.
cd $HOME/Applications/ffmpeg_sources
git clone --branch '4.2' --depth 1 --single-branch https://bitbucket.org/multicoreware/x265_git.git x265
# Choose build directory based on CPU architecture (here for Apple Silicon).
cd x265/build/aarch64-darwin
cmake -DCMAKE_FIND_ROOT_PATH="$HOME/Applications/ffmpeg_library" -DCMAKE_INSTALL_PREFIX="$HOME/Applications/ffmpeg_library" ../../source
make && make install


# === fdk-aac === #
# High-quality AAC audio encoder from Fraunhofer.
# Enables advanced AAC audio encoding (superior to the built-in native AAC encoder).
cd $HOME/Applications/ffmpeg_sources
git clone --branch 'v2.0.3' --depth 1 --single-branch https://github.com/mstorsjo/fdk-aac.git
cd fdk-aac
mkdir build && cd build
cmake -DCMAKE_FIND_ROOT_PATH="$HOME/Applications/ffmpeg_library" -DCMAKE_INSTALL_PREFIX="$HOME/Applications/ffmpeg_library" -DCMAKE_BUILD_TYPE=Release ../
make && make install


# === lame === #
# MP3 audio encoder library.
# Provides support for encoding audio to the MP3 format.
cd $HOME/Applications/ffmpeg_sources
curl -O -L https://downloads.sourceforge.net/project/lame/lame/3.100/lame-3.100.tar.gz
mkdir -p lame && tar -zxvf lame-3.100.tar.gz -C ./lame --strip-components=1 && rm lame-3.100.tar.gz
cd lame
./configure --prefix="$HOME/Applications/ffmpeg_library" --disable-shared --enable-nasm
make && make install


# === opus === #
# Opus audio codec for low latency and high quality audio (used in VoIP, WebRTC, etc).
# Adds Opus encoding/decoding capabilities to FFmpeg.
cd $HOME/Applications/ffmpeg_sources
git clone --branch 'v1.6.1' --depth 1 --single-branch https://github.com/xiph/opus.git
cd opus
mkdir build && cd build
cmake -DCMAKE_FIND_ROOT_PATH="$HOME/Applications/ffmpeg_library" -DCMAKE_INSTALL_PREFIX="$HOME/Applications/ffmpeg_library" -DCMAKE_BUILD_TYPE=Release ../
make && make install


# === libvpx === #
# VP8 and VP9 video codec library from Google.
# Required for encoding/decoding WebM and VP9 video formats.
cd $HOME/Applications/ffmpeg_sources
git clone --branch 'v1.16.0' --depth 1 --single-branch https://chromium.googlesource.com/webm/libvpx.git
cd libvpx
./configure --prefix="$HOME/Applications/ffmpeg_library" --disable-examples --disable-unit-tests --enable-vp9-highbitdepth
make && make install


# === freetype === #
# Font rendering engine used for subtitles and text overlays (drawtext filter).
# Enables FFmpeg to render text in videos.
cd $HOME/Applications/ffmpeg_sources
git clone --branch 'VER-2-14-3' --depth 1 --single-branch https://gitlab.freedesktop.org/freetype/freetype.git
cd freetype
mkdir build && cd build
cmake -DCMAKE_FIND_ROOT_PATH="$HOME/Applications/ffmpeg_library" -DCMAKE_INSTALL_PREFIX="$HOME/Applications/ffmpeg_library" -DCMAKE_BUILD_TYPE=Release ../
make && make install


# === openssl === #
# SSL/TLS library for HTTPS, RTMPS, and secure streaming protocols.
# Enables FFmpeg to handle secure connections and encrypted media streams.
cd $HOME/Applications/ffmpeg_sources
git clone --branch 'openssl-4.0.1' --depth 1 --single-branch https://github.com/openssl/openssl.git
cd openssl
./Configure --prefix="$HOME/Applications/ffmpeg_library"
make && make install


# === SVT-AV1 === #
# AV1 video encoder library developed by Intel and contributors.
# Enables FFmpeg to encode AV1 video streams with high performance and scalability.
cd $HOME/Applications/ffmpeg_sources
git clone --branch 'v4.1.0' --depth=1 --single-branch https://gitlab.com/AOMediaCodec/SVT-AV1.git
cd SVT-AV1/Build
cmake .. -G"Unix Makefiles" -DCMAKE_BUILD_TYPE=Release -DCMAKE_FIND_ROOT_PATH="$HOME/Applications/ffmpeg_library" -DCMAKE_INSTALL_PREFIX="$HOME/Applications/ffmpeg_library" ..
make && make install


# === dav1d === #
# High-performance AV1 video decoder library developed by VideoLAN and FFmpeg.
# Enables FFmpeg to efficiently decode AV1 video streams with low CPU usage.
cd $HOME/Applications/ffmpeg_sources
git clone --branch '1.5.3' --depth=1 --single-branch https://code.videolan.org/videolan/dav1d.git
cd dav1d
mkdir build && cd build
meson setup ..  --buildtype=release --prefix="$HOME/Applications/ffmpeg_library"
ninja -C . && ninja -C . install


# === FFmpeg === #
# The main FFmpeg build linking all previously built libraries.
# Enables support for AV1, H.265, H.264, AAC, MP3, Opus, VP9, SSL, and text rendering.
cd $HOME/Applications/ffmpeg_sources
git clone --branch 'release/8.1' --depth 1 --single-branch https://git.ffmpeg.org/ffmpeg.git
cd ffmpeg
PKG_CONFIG_PATH="$HOME/Applications/ffmpeg_library/lib/pkgconfig" ./configure \
 --prefix="$HOME/Applications/ffmpeg-8.1" \
 --pkg-config-flags="--static" \
 --extra-cflags="-I$HOME/Applications/ffmpeg_library/include" \
 --extra-ldflags="-L$HOME/Applications/ffmpeg_library/lib"  \
 --extra-libs=-lpthread \
 --extra-libs=-lm  \
 --enable-gpl \
 --enable-libfdk_aac \
 --enable-libfreetype \
 --enable-libmp3lame \
 --enable-libopus  \
 --enable-libvpx  \
 --enable-libx264 \
 --enable-libx265 \
 --enable-libsvtav1 \
 --enable-libdav1d \
 --enable-nonfree  \
 --enable-pthreads \
 --enable-version3 \
 --enable-openssl
make && make install


# === Add library path to the executables === #
# Ensures ffmpeg and ffprobe can locate linked libraries at runtime.
install_name_tool -add_rpath $HOME/Applications/ffmpeg_library/lib \
$HOME/Applications/ffmpeg-8.1/bin/ffmpeg
install_name_tool -add_rpath $HOME/Applications/ffmpeg_library/lib \
$HOME/Applications/ffmpeg-8.1/bin/ffprobe
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment