Compile FFmpeg for iOS ARM64
Compiling FFmpeg for the iOS arm64 architecture allows developers to
integrate powerful audio and video processing capabilities into modern
iOS applications. This guide provides a straightforward, step-by-step
walkthrough to configure your macOS environment, set up the required
build tools, and compile FFmpeg into static libraries (.a
files) optimized for 64-bit iOS devices.
Prerequisites
Before starting, ensure you have Xcode and its Command Line Tools
installed on your macOS system. You will also need
gas-preprocessor, which is required to compile the assembly
files in FFmpeg for iOS.
Install
gas-preprocessorby running the following commands in your Terminal:sudo curl -L https://github.com/libav/gas-preprocessor/raw/master/gas-preprocessor.pl -o /usr/local/bin/gas-preprocessor.pl sudo chmod +x /usr/local/bin/gas-preprocessor.plClone the official FFmpeg source code repository:
git clone https://git.ffmpeg.org/ffmpeg.git ffmpeg cd ffmpeg
Set Up Environment Variables
To cross-compile for iOS, you must point the compiler to the official iOS SDK provided by Xcode. Run these commands to define the target SDK, compiler, and assembler paths:
# Get the path of the iOS device SDK
SDK_PATH=$(xcrun --sdk iphoneos --show-sdk-path)
# Locate the clang compiler within Xcode
CC=$(xcrun --sdk iphoneos --find clang)
# Set up the assembler using gas-preprocessor
AS="gas-preprocessor.pl -as-one-line -- $CC"Configure the Build
Configure the FFmpeg build system for the arm64
architecture. This configuration disables shared libraries (since iOS
requires static linking for custom FFmpeg builds) and disables
unnecessary tools like the FFmpeg CLI program to keep the library size
small.
Run the following configuration command inside the
ffmpeg directory:
./configure \
--target-os=darwin \
--arch=arm64 \
--cc="$CC" \
--as="$AS" \
--sysroot="$SDK_PATH" \
--extra-cflags="-arch arm64 -miphoneos-version-min=12.0" \
--extra-ldflags="-arch arm64 -miphoneos-version-min=12.0" \
--enable-cross-compile \
--disable-shared \
--enable-static \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobeCompile the Libraries
Once the configuration process completes successfully, compile the source code using all available CPU cores to speed up the process, and then install the output files.
# Clean any previous build artifacts
make clean
# Compile using multiple CPU cores
make -j$(sysctl -n hw.ncpu)
# Install the headers and static libraries into a local folder
make install DESTDIR=$(pwd)/build_arm64Locate Your Compiled Files
Upon successful completion of the build, you will find the compiled
static libraries (.a files) and their headers in the
build_arm64 directory:
- Header Files:
build_arm64/usr/local/include/ - Static Libraries:
build_arm64/usr/local/lib/(includinglibavcodec.a,libavformat.a,libavutil.a, etc.)
You can now drag these .a library files and header
folders directly into your Xcode project to begin utilizing FFmpeg in
your iOS application.