This page explains how to configure and build FFmpeg on Windows. The required steps are:
You can get the FFmpeg source code in these ways:
C:\FFmpeg\ffmpeg
.
git clone --branch n7.1.2 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
.
To build FFmpeg, these tools and packages are required:
见 Qt for Windows - 构建从源 for recommended compilers that are also supported by Qt. You can install a supported MinGW-w64 compiler using the Qt Online Installer.
To install MSYS2, you can:
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 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.
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
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:
"C:\Program Files\Microsoft Visual Studio\2022\BuildTools\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
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, run:
../configure --prefix=../install --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
选项。
To configure FFmpeg for building with MSVC, specify the toolchain in addition to the other command line options:
../configure --prefix=../install --disable-doc --enable-network --enable-shared --toolchain=msvc
Once the
configure
command finishes, build and install FFmpeg using the
make
命令。
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.