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=21

Step 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 install

Step 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 install

Key Configuration Parameters Explained