编译 android ffmpeg x264(armv7 和 arm64)全过程

编译 ffmpeg x264(armv7 和 arm64)全过程

ffmpeg版本:ffmpeg-3.4.6

x264版本:2018.4.4号的版本

ndk版本:android-ndk-r11c

mac版本:10.14.4

1. 生成toolchain

1)r11c 64位toolchain

./make-standalone-toolchain.sh --arch=arm64 --platform=android-21 --ndk-dir=/opt/android/android-ndk-r11c --install-dir=/opt/android/android-ndk11c-21-aarch64-toolchain
  1. r11c armv7 toolchain
./make-standalone-toolchain.sh --arch=arm --platform=android-21 --ndk-dir=/opt/android/android-ndk-r11c --install-dir=/opt/android/android-ndk11c-21-armv7-toolchain
2.编译x264

1)64为x264编译脚本

#!/bin/bash
NDK=/opt/android/android-ndk-r11c
SYSROOT=/opt/android/android-ndk-r11c/platforms/android-21/arch-arm64
TOOLCHAIN=/opt/android/android-ndk11c-21-aarch64-toolchain


function build_one
{
./configure \
--prefix=$PREFIX \
--enable-static \
--enable-pic \
--host=aarch64-linux-android \
--cross-prefix=$TOOLCHAIN/bin/aarch64-linux-android- \
--sysroot=$SYSROOT \
--extra-cflags="-Os -fpic" \
--extra-ldflags=""


make clean
make -j4
make install

}
CPU=armv8a
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS=""
build_one
  1. 32位编译脚本
#!/bin/bash
NDK=/opt/android/android-ndk-r11c
SYSROOT=/opt/android/android-ndk-r11c/platforms/android-21/arch-arm
TOOLCHAIN=/opt/android/android-ndk11c-21-armv7-toolchain


function build_one
{
./configure \
--prefix=$PREFIX \
--enable-static \
--enable-pic \
--host=arm-linux-androideabi \
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
--sysroot=$SYSROOT \
--extra-cflags="-Os -fpic" \
--extra-ldflags=""


make clean
make -j4
make install

}
CPU=armv7a
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS=""
build_one
3、编译带x264的ffmpeg

1)64位编译脚本

#!/bin/bash
#Change NDK to your Android NDK location
NDK=/opt/android/android-ndk-r11c
PLATFORM=$NDK/platforms/android-21/arch-arm64
PREBUILT=/opt/android/android-ndk11c-21-aarch64-toolchain
PREFIX=./android/armeabi64-v8a 

GENERAL="\
--enable-small \
--enable-cross-compile \
--extra-libs="-lgcc" \
--arch=aarch64 \
--cc=$PREBUILT/bin/aarch64-linux-android-gcc  \
--cross-prefix=$PREBUILT/bin/aarch64-linux-android-  \
--nm=$PREBUILT/bin/aarch64-linux-android-nm  \
--extra-cflags="-I/opt/compile/x264/android/armv8a/include" \
--extra-ldflags="-L/opt/compile/x264/android/armv8a/lib" "


MODULES="\
--enable-gpl \
--enable-libx264 "

function build_ARM64-v8a
{
./configure \
--logfile=conflog.txt \
--target-os=android \
--prefix=$PREFIX \
${GENERAL} \
--sysroot=$PLATFORM \
--disable-shared \
--enable-static \
--extra-cflags="" \
--extra-ldflags="-lx264 -Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog" \
${MODULES} \
--disable-doc  \
--enable-asm

make clean
make
make install
}
build_ARM64-v8a

echo Android ARM64-v8a builds finished
  1. armv7编译脚本
#!/bin/bash
#Change NDK to your Android NDK location
NDK=/opt/android/android-ndk-r11c
PLATFORM=$NDK/platforms/android-21/arch-arm
PREBUILT=/opt/android/android-ndk11c-21-armv7-toolchain
PREFIX=./android/armeabi-v7 

GENERAL="\
--enable-small \
--enable-cross-compile \
--extra-libs="-lgcc" \
--arch=arm \
--cc=$PREBUILT/bin/arm-linux-androideabi-gcc  \
--cross-prefix=$PREBUILT/bin/arm-linux-androideabi-  \
--nm=$PREBUILT/bin/arm-linux-androideabi-nm  \
--extra-cflags="-I/opt/compile/x264/android/armv7a/include" \
--extra-ldflags="-L/opt/compile/x264/android/armv7a/lib" "


MODULES="\
--enable-gpl \
--enable-libx264 \
--enable-encoder=libx264 "

function build_ARM-v7
{
./configure \
--logfile=conflog.txt \
--target-os=android \
--prefix=$PREFIX \
${GENERAL} \
--sysroot=$PLATFORM \
--disable-shared \
--enable-static \
--cpu=armv7-a \
--extra-cflags="-march=armv7-a" \
--extra-ldflags="-lx264 -Wl,-rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -nostdlib -lc -lm -ldl -llog" \
${MODULES} \
--disable-doc  \
--enable-asm

make clean
make
make install
}



build_ARM-v7

echo Android build_ARM-v7 builds finished
4、编译的ffmpeg静态库生成 只包含一个libffmpeg.so的动态库

1)64位,在lib目录里执行以下脚本

#!/bin/bash
#Change NDK to your Android NDK location
NDK=/opt/android/android-ndk-r11c
PLATFORM=$NDK/platforms/android-21/arch-arm64
PREBUILT=/opt/android/android-ndk11c-21-aarch64-toolchain

$PREBUILT/bin/aarch64-linux-android-ld -rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -L./ -soname libffmpeg.so -shared -nostdlib -Bsymbolic --whole-archive --no-undefined -o libffmpeg.so \
    /opt/compile/x264/android/armv8a/lib/libx264.a \
    libavcodec.a \
    libavfilter.a \
    libswresample.a \
    libavformat.a \
    libavutil.a \
    libswscale.a \
    libpostproc.a \
    libavdevice.a \
    -lc -lm -lz -ldl -llog --dynamic-linker=/system/bin/linker $PREBUILT/lib/gcc/aarch64-linux-android/4.9/libgcc.a 


#strip
$PREBUILT/bin/aarch64-linux-android-strip  ./libffmpeg.so

echo generate ffmpeg finished
  1. 32位
#!/bin/bash
#Change NDK to your Android NDK location
NDK=/opt/android/android-ndk-r11c
PLATFORM=$NDK/platforms/android-21//arch-arm
TOOLCHAIN=/opt/android/android-ndk11c-21-armv7-toolchain

$TOOLCHAIN/bin/arm-linux-androideabi-ld -rpath-link=$PLATFORM/usr/lib -L$PLATFORM/usr/lib -L./ -soname libffmpeg.so -shared -nostdlib -Bsymbolic --whole-archive --no-undefined -o libffmpeg.so \
    /opt/compile/x264/android/armv7a/lib/libx264.a \
    libavcodec.a \
    libavfilter.a \
    libswresample.a \
    libavformat.a \
    libavutil.a \
    libswscale.a \
    libpostproc.a \
    libavdevice.a \
    -lc -lm -lz -ldl -llog --dynamic-linker=/system/bin/linker $TOOLCHAIN/lib/gcc/arm-linux-androideabi/4.9/libgcc.a 

echo generate ffmpeg finished

你可能感兴趣的:(编译 android ffmpeg x264(armv7 和 arm64)全过程)