Compile FFmpeg with libvpx on macOS

This guide provides a step-by-step walkthrough for compiling FFmpeg from source on macOS with native libvpx support, enabling you to encode and decode VP8 and VP9 video formats. By leveraging Homebrew to handle essential build tools and dependencies, you can configure, build, and install a custom FFmpeg binary tailored to your system.

1. Install Xcode Command Line Tools

Before compiling software from source, install Apple's command-line developer tools:

xcode-select --install

If a prompt appears, click Install and wait for the download and installation process to complete.

2. Install Required Dependencies via Homebrew

Ensure you have Homebrew installed. Then, install pkg-config, the assemblers (nasm and yasm), and libvpx:

brew install pkg-config nasm yasm libvpx

Note: On Apple Silicon Macs, Homebrew installs packages into /opt/homebrew, whereas Intel Macs use /usr/local.

3. Set Environment Variables

Set the PKG_CONFIG_PATH variable so the FFmpeg build system can locate the libvpx headers and libraries:

For Apple Silicon (M1/M2/M3/M4):

export PKG_CONFIG_PATH="/opt/homebrew/lib/pkgconfig:$PKG_CONFIG_PATH"

For Intel:

export PKG_CONFIG_PATH="/usr/local/lib/pkgconfig:$PKG_CONFIG_PATH"

4. Clone the FFmpeg Source Code

Download the latest stable source code from the official FFmpeg Git repository:

git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg
cd ffmpeg

5. Configure the Build

Run the configure script with --enable-libvpx along with standard flags:

./configure \
  --prefix=/usr/local \
  --enable-gpl \
  --enable-version3 \
  --enable-nonfree \
  --enable-libvpx \
  --pkg-config-flags="--static"

If you prefer not to install the binary system-wide into /usr/local, adjust the --prefix flag to a directory of your choice (e.g., --prefix=$HOME/ffmpeg-build).

6. Compile and Install

Compile the source code using multiple cores to speed up the process, then install the compiled binaries:

make -j$(sysctl -n hw.logicalcpu)
sudo make install

If you configured a user-owned directory in --prefix, you can omit sudo.

7. Verify the Installation

Confirm that the new FFmpeg build includes libvpx support:

ffmpeg -version

Look for --enable-libvpx in the configuration output. You can also confirm encoder availability:

ffmpeg -encoders | grep vpx

The output will display libvpx-vp8 and libvpx-vp9, confirming the installation was successful.