Building FFmpeg 7 for Windows, Android & macOS
A comprehensive guide to compiling FFmpeg 7 using MSYS2 on Windows, cross-compiling for Android via NDK, and standard macOS builds, complete with usage examples.
Step 1: Essential Toolchains
Download and configure compilers for each platform
MSYS2
Provides a Unix-like environment on Windows, essential for running FFmpeg's configure script.
pacman -S base-devel mingw-w64-x86_64-toolchain yasmAndroid NDK
Contains the Clang/LLVM toolchain required to cross-compile Android .so libraries.
ls $NDK/toolchains/llvm/prebuiltHomebrew
The missing package manager for macOS. Used to install FFmpeg compilation dependencies like yasm.
/bin/bash -c "$(curl -fsSL https://raw.githubusercontent.com/Homebrew/install/HEAD/install.sh)"Step 2: Windows Build (x86_64)
Compile standard .dll and .exe for Windows
The build generates ffmpeg.exe and DLLs like avcodec-61.dll. You can use it directly in CMD or link it in Visual Studio C++ projects.
Step 3: Android NDK Cross-Compile
Generate .so libraries using Android NDK Toolchain
Copy the generated .so files (e.g., libavcodec.so) into your app's src/main/cpp/libs directory. Configure your CMakeLists.txt to link these libraries.
init {
System.loadLibrary("avutil")
System.loadLibrary("avcodec")
System.loadLibrary("your_native_lib")
}Step 4: macOS Compilation
Building standard Apple binaries
Reality Check: Cross-compiling Mac on Windows
Native cross-compilation for macOS on Windows is extremely complex and requires proprietary Apple SDKs (via tools like osxcross). In practice, developers run the following script on a real Mac, a macOS VM, or via GitHub Actions (macOS runners).
This will generate .dylib libraries. You can link these in Xcode for your Swift/Objective-C projects using an Objective-C++ wrapper, or use the generated ffmpeg CLI.
// FFmpegWrapper.h (Objective-C++)
#include <libavcodec/avcodec.h>
