Building FFmpeg from source on macOS

This page explains how to configure and build FFmpeg on macOS. This involves:

  • Get the FFmpeg source code.
  • Install the required dependencies.
  • Configure FFmpeg from the command line.
  • Build the development libraries.

Get the FFmpeg source code

You can get the FFmpeg source code in these ways:

  • Download from the FFmpeg download page.
  • Clone from git. For example, this command clones the version 7.1 of the FFmpeg sources to ~/ffmpeg.
    % git clone --branch n7.1 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.

Prerequisites

To build FFmpeg, these tools and packages are required:

Installing Homebrew

To install Homebrew, run:

% /bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"

Installing Homebrew packages

To install Homebrew package Yasm, run:

% brew install yasm

Configuring and building FFmpeg

Create a 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 option.

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 command.

% 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.

Configuring and Building FFmpeg Universal Binaries

To create universal binaries on macOS (for example, for both x86_64 and arm64 architectures), follow these steps:

  • Configure and build FFmpeg for arm64 architecture:
    % ../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 and build FFmpeg for x86_64 architecture:
    % ../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
  • Combine the builds into a universal binary using lipo.

© 2024 The Qt Company Ltd. Documentation contributions included herein are the copyrights of their respective owners. The documentation provided herein is licensed under the terms of the GNU Free Documentation License version 1.3 as published by the Free Software Foundation. Qt and respective logos are trademarks of The Qt Company Ltd. in Finland and/or other countries worldwide. All other trademarks are property of their respective owners.