环境

  • ubunut 18.04 lts
  • ndk r20b
  • ffmpeg 4.4 N-103194-g00b579890d

手动编译

  1. 需要参数--enable-cross-compile才能启用clang
  2. ndk r20b的clang是需要单独指定的,--cross-prefix是拼接不出来的.

armeabi-v7a

./configure \
    --enable-cross-compile \
    --arch=arm \
    --target-os=android \
    --cc=/home/u0u0/ff/android-ndk-r20b/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi16-clang \
    --cxx=/home/u0u0/ff/android-ndk-r20b/toolchains/llvm/prebuilt/linux-x86_64/bin/armv7a-linux-androideabi16-clang++ \
    --sysroot=/home/u0u0/ff/android-ndk-r20b/toolchains/llvm/prebuilt/linux-x86_64/sysroot \
    --cross-prefix=/home/u0u0/ff/android-ndk-r20b/toolchains/llvm/prebuilt/linux-x86_64/bin/arm-linux-androideabi- \
    --prefix=/home/u0u0/ff/ffmpeg/build/armeabi-v7a \
    --disable-shared \
    --disable-x86asm \
    --enable-pthreads \
    --disable-doc \
    --enable-static \
    --enable-optimizations \
    --disable-debug

arm64-v8a

./configure \
    --enable-cross-compile \
    --arch=aarch64 \
    --target-os=android \
    --cc=/home/u0u0/ff/android-ndk-r20b/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang \
    --cxx=/home/u0u0/ff/android-ndk-r20b/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android21-clang++ \
    --sysroot=/home/u0u0/ff/android-ndk-r20b/toolchains/llvm/prebuilt/linux-x86_64/sysroot \
    --cross-prefix=/home/u0u0/ff/android-ndk-r20b/toolchains/llvm/prebuilt/linux-x86_64/bin/aarch64-linux-android- \
    --prefix=/home/u0u0/ff/ffmpeg/build/arm64-v8a \
    --disable-shared \
    --disable-x86asm \
    --enable-pthreads \
    --disable-doc \
    --enable-static \
    --enable-optimizations \
    --disable-debug

x86

x86编译有个错(https://trac.ffmpeg.org/ticket/7796),需要修改源码

libavutil/x86/asm.h:75:

--- #define HAVE_7REGS (ARCH_X86_64 || (HAVE_EBX_AVAILABLE && HAVE_EBP_AVAILABLE))
+++ #define HAVE_7REGS (ARCH_X86_64)
./configure \
    --enable-cross-compile \
    --arch=x86 \
    --target-os=android \
    --cc=/home/u0u0/ff/android-ndk-r20b/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android16-clang \
    --cxx=/home/u0u0/ff/android-ndk-r20b/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android16-clang++ \
    --sysroot=/home/u0u0/ff/android-ndk-r20b/toolchains/llvm/prebuilt/linux-x86_64/sysroot \
    --cross-prefix=/home/u0u0/ff/android-ndk-r20b/toolchains/llvm/prebuilt/linux-x86_64/bin/i686-linux-android- \
    --prefix=/home/u0u0/ff/ffmpeg/build/x86 \
    --disable-shared \
    --disable-x86asm \
    --enable-pthreads \
    --disable-doc \
    --enable-static \
    --enable-optimizations \
    --disable-debug

自动编译脚本



# put this file to ffmpeg src root dir

NDK=/home/ndk/android-ndk-r20b
TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64
SYSROOT=$TOOLCHAIN/sysroot
PATCHFILE=$(pwd)/libavutil/x86/asm.h

configure()
{
    CC=""
    CROSS_PREFIX=""
    ARCH=""
    CXX=""
    PREFIX=$(pwd)/android/$1
    if [ $1 == "armeabi-v7a" ]
    then
        echo "========== build android armeabi-v7a began =========="
        API=16
        ARCH=arm
        CC=$TOOLCHAIN/bin/armv7a-linux-androideabi$API-clang
        CXX=$TOOLCHAIN/bin/armv7a-linux-androideabi$API-clang++
        CROSS_PREFIX=$TOOLCHAIN/bin/arm-linux-androideabi-
        sed -i '75c #define HAVE_7REGS (ARCH_X86_64 || (HAVE_EBX_AVAILABLE && HAVE_EBP_AVAILABLE))' $PATCHFILE
    elif [ $1 == "x86" ]
    then
        echo "========== build android x86 began =========="
        API=16
        ARCH=x86
        CC=$TOOLCHAIN/bin/i686-linux-android$API-clang
        CXX=$TOOLCHAIN/bin/i686-linux-android$API-clang++
        CROSS_PREFIX=$TOOLCHAIN/bin/i686-linux-android-
        sed -i '75c #define HAVE_7REGS (ARCH_X86_64)' $PATCHFILE
    else
        echo "========== build android arm64-v8a began =========="
        API=21
        ARCH=arm64
        CC=$TOOLCHAIN/bin/aarch64-linux-android$API-clang
        CXX=$TOOLCHAIN/bin/aarch64-linux-android$API-clang++
        CROSS_PREFIX=$TOOLCHAIN/bin/aarch64-linux-android-
        sed -i '75c #define HAVE_7REGS (ARCH_X86_64 || (HAVE_EBX_AVAILABLE && HAVE_EBP_AVAILABLE))' $PATCHFILE
    fi
    ./configure \
        --enable-cross-compile \
        --arch=$ARCH \
        --target-os=android \
        --cc=$CC \
        --cxx=$CXX \
        --sysroot=$SYSROOT \
        --cross-prefix=$CROSS_PREFIX \
        --prefix=$PREFIX \
        --disable-shared \
        --disable-x86asm \
        --enable-pthreads \
        --disable-doc \
        --enable-static \
        --enable-optimizations \
        --disable-debug
}

build()
{
    make clean
    echo "build $1"
    configure $1
    make -j4
    make install
}

build x86
build arm64-v8a
build armeabi-v7a

标签: Android, ffmpeg

添加新评论