Build FFmpeg for Android armeabi-v7a arm64-v8a
Building FFmpeg for Android requires configuring the build script to
target specific CPU architectures like armeabi-v7a (32-bit
ARM) and arm64-v8a (64-bit ARM). This guide provides a
straightforward, step-by-step tutorial on how to configure the Android
NDK toolchain and set the appropriate compilation flags to compile
FFmpeg successfully for these modern Android platforms.
Prerequisites
Before starting, ensure you have downloaded the following: 1. FFmpeg Source Code: Download and extract the source code from the official FFmpeg website. 2. Android NDK: Download and install the Android NDK (r19 or newer is recommended, as it standardizes the Clang toolchain).
Step 1: Set Up Environment Variables
First, define the paths to your NDK and define the host operating system. Run these commands in your terminal or include them at the beginning of your build script.
# Path to your Android NDK
export NDK=/path/to/android-ndk-r25c
# Host OS (change 'linux-x86_64' to 'darwin-x86_64' for macOS or 'windows-x86_64' for Windows)
export HOST_OS=linux-x86_64
export TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/$HOST_OS
# Minimum Android API level
export API=21Step 2: Configure and Build for arm64-v8a (64-bit)
The arm64-v8a architecture is the standard for modern
64-bit Android devices. To configure the FFmpeg build for this target,
use the following ./configure script:
# Create a build directory
OUT_DIR=./android/arm64-v8a
./configure \
--prefix=$OUT_DIR \
--target-os=android \
--arch=aarch64 \
--cpu=armv8-a \
--enable-cross-compile \
--cc=$TOOLCHAIN/bin/aarch64-linux-android$API-clang \
--cxx=$TOOLCHAIN/bin/aarch64-linux-android$API-clang++ \
--cross-prefix=$TOOLCHAIN/bin/llvm- \
--sysroot=$TOOLCHAIN/sysroot \
--extra-cflags="-march=armv8-a" \
--extra-ldflags="" \
--enable-shared \
--disable-static \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-avdevice
# Compile and install
make clean
make -j$(nproc)
make installStep 3: Configure and Build for armeabi-v7a (32-bit)
The armeabi-v7a architecture supports older 32-bit ARM
devices. The setup requires pointing to the armv7a compiler
while setting the cross-prefix to the standard 32-bit toolchain.
# Create a build directory
OUT_DIR=./android/armeabi-v7a
./configure \
--prefix=$OUT_DIR \
--target-os=android \
--arch=arm \
--cpu=armv7-a \
--enable-cross-compile \
--cc=$TOOLCHAIN/bin/armv7a-linux-androideabi$API-clang \
--cxx=$TOOLCHAIN/bin/armv7a-linux-androideabi$API-clang++ \
--cross-prefix=$TOOLCHAIN/bin/llvm- \
--sysroot=$TOOLCHAIN/sysroot \
--extra-cflags="-march=armv7-a -mfloat-abi=softfp -mfpu=neon" \
--extra-ldflags="" \
--enable-shared \
--disable-static \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-avdevice
# Compile and install
make clean
make -j$(nproc)
make installKey Configuration Parameters Explained
--target-os=android: Instructs FFmpeg that the target operating system is Android.--arch: Specifies the target CPU architecture family (armfor 32-bit,aarch64for 64-bit).--cpu: Instructs the compiler to optimize the code for the selected instruction set architecture (armv7-aorarmv8-a).--ccand--cxx: Points to the target-specific Clang compiler binaries inside the NDK toolchain directory. For 32-bit ARM, the target compiler is prefixed witharmv7a-linux-androideabi, whereas for 64-bit, it isaarch64-linux-android.--cross-prefix: Points to LLVM binutils (llvm-) for standard cross-compilation tools likear,as, andstrip.--sysroot: Sets the logical root directory for headers and libraries inside the NDK.