- Qt 6.9
- Qt Multimedia
- Building Qt Multimedia from sources
- Building FFmpeg from source
- Building FFmpeg from source on Windows
- Qt 6.9.1 Reference Documentation

Building FFmpeg ◦ Building FFmpeg on macOS

# Building FFmpeg from source on Windows

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

- Get the FFmpeg source code.
- Install the required dependencies.
- Configure FFmpeg from the command line for MSVC or for MinGW-w64.
- 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 `C:\FFmpeg\ffmpeg`.

       C:\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 `C:\FFmpeg\ffmpeg`.

## Prerequisites

To build FFmpeg, these tools and packages are required:

- Microsoft Visual Studio compiler (MSVC) or MinGW-w64.
- MSYS2.
- MSYS packages (perl, make, yasm, and diffutils).

See Qt for Windows - Building from Source for recommended compilers that are also supported by Qt. You can install a supported MinGW-w64 compiler using the Qt Online Installer.

### Installing MSYS2

To install MSYS2, you can:

- Use the MSYS2 installer.
- Use the winget package manager.

       winget install msys2.msys2

The instructions in this document rely on MSYS2 installed to `C:\msys64\`, which is the default path when using `winget`.

Once installed, start the `MSYS2 MINGW64` shell from the Windows start menu, and use it to install the necessary libraries.

     pacman -S --noconfirm perl make yasm diffutils

Before building FFmpeg, MSYS2 must have a compiler in its `PATH`. This is done differently for MSVC and MinGW-w64. Prepare the MSYS2 environment for the compiler you use.

### Preparing the MSYS environment for building with Mingw-w64

For MinGW-w64 installed under `C:\Qt\Tools\mingw1310_64\bin`, you can add it to the `PATH` by exporting the PATH environment variable.

     $ export PATH=/c/Qt/Tools/mingw1310_64/bin:$PATH

Note that it is also possible to install MinGW-w64 using pacman.

     $ pacman -S mingw-w64-x86_64-toolchain

### Preparing the MSYS2 environment for the MSVC

Building FFmpeg with the MSVC compiler under MSYS2 requires that MSYS2 is started with the appropriate C and C++ compiler in the path. For a 64 bit build, you can:

- Start Visual Studio x64 Native Tools Command Prompt from the Windows start menu.
- Enable the MSVC compiler from an existing command prompt by running:

       "C:\Program Files\Microsoft Visual Studio\2022\Professional\VC\Auxiliary\Build\vcvarsall.bat" amd64

From this command prompt, launch the MSYS2 shell with the options to select the MINGW64 environment and enable path inheritance.

     C:\msys64\msys2_shell.cmd -mingw64 -full-path

This launches a new shell window where you can verify that the MSVC compiler is available.

     $ which cl.exe

## Configuring and building FFmpeg

From the prepared MSYS2 shell, navigate to the `/c/FFmpeg` directory. In this directory, create a `build` directory which will contain the FFmpeg build artifacts, and navigate into it.

     $ cd /c/FFmpeg/build

To configure FFmpeg for building with MinGW-w64, run:

     $ ../ffmpeg/configure --prefix=../install --disable-doc --enable-network --enable-shared

To configure FFmpeg for building with MSVC, specify the toolchain in addition to the other command line options:

     $ ../ffmpeg/configure --prefix=../install --disable-doc --enable-network --enable-shared --toolchain=msvc

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.

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 `C:\FFmpeg\install` directory. If you build Qt Multimedia, this path is stored in the `FFMPEG_DIR` variable used when configuring Qt Multimedia.

Building FFmpeg ◦ Building FFmpeg on macOS