android平台通过ndk给ijkplayer的ffmpeg编译libx264

这篇文章主要是用来备记得.脚本如下:

libx264 android平台编译脚本如下:

#! /usr/bin/env bash

#--------------------
set -e

#设置NDK目录
ANDROID_NDK=/Users/cievon/Documents/AndroidSDK/android-ndk-r10e
#设置x264保存目录
ROOT_PREFIX=$(pwd)/../build/x264
ROOT=$(pwd)

echo 1.prebuild
#创建保存目录
#mkdir $ROOT_PREFIX

if [ -z "$ANDROID_NDK" ]; then
    echo "You must define ANDROID_NDK before starting."
    echo "They must point to your NDK directories.\n"
    exit 1
fi

#--------------------
# common defines
#获取平台
FF_ARCH=$1
if [ -z "$FF_ARCH" ]; then
    echo "You must specific an architecture 'arm, armv7a, x86, ...'.\n"
    exit 1
fi

echo 2.configure
#配置android平台
FF_ANDROID_PLATFORM=android-9
#----- armv7a begin -----
if [ "$FF_ARCH" = "armv7a" ]; then
	#设置编译器
    PREBUILT=$ANDROID_NDK/toolchains/arm-linux-androideabi-4.9/prebuilt
    export PATH=$PATH:$PREBUILT/darwin-x86_64/bin/
    CROSS_PREFIX=$PREBUILT/darwin-x86_64/bin/arm-linux-androideabi-
	#设置平台编译连接路径
	PLATFORM=$ANDROID_NDK/platforms/$FF_ANDROID_PLATFORM/arch-arm
    HOST=arm-linux

    PREFIX=$ROOT_PREFIX/$FF_ARCH/

    FF_CFG_CONF="$FF_CFG_CONF --disable-asm"

elif [ "$FF_ARCH" = "armv5" ]; then
	#设置编译器
    PREBUILT=$ANDROID_NDK/toolchains/arm-linux-androideabi-4.9/prebuilt
    export PATH=$PATH:$PREBUILT/darwin-x86_64/bin/
    CROSS_PREFIX=$PREBUILT/darwin-x86_64/bin/arm-linux-androideabi-
	#设置平台编译连接路径
	PLATFORM=$ANDROID_NDK/platforms/$FF_ANDROID_PLATFORM/arch-arm
    HOST=arm-linux

    PREFIX=$ROOT_PREFIX/$FF_ARCH/
    
    FF_CFG_CONF="$FF_CFG_CONF --disable-asm"

elif [ "$FF_ARCH" = "arm64" ]; then
	#设置编译器
    FF_ANDROID_PLATFORM=android-21
    PREBUILT=$ANDROID_NDK/toolchains/aarch64-linux-android-4.9/prebuilt
    export PATH=$PATH:$PREBUILT/darwin-x86_64/bin/
    CROSS_PREFIX=$PREBUILT/darwin-x86_64/bin/aarch64-linux-android-
	#设置平台编译连接路径
    PLATFORM=$ANDROID_NDK/platforms/$FF_ANDROID_PLATFORM/arch-arm64
    HOST=aarch64-linux 

    PREFIX=$ROOT_PREFIX/$FF_ARCH/

elif [ "$FF_ARCH" = "x86" ]; then
	#设置编译器
    PREBUILT=$ANDROID_NDK/toolchains/x86-4.9/prebuilt
    export PATH=$PATH:$PREBUILT/darwin-x86_64/bin/
    CROSS_PREFIX=$PREBUILT/darwin-x86_64/bin/i686-linux-android-
	#设置平台编译连接路径
	PLATFORM=$ANDROID_NDK/platforms/$FF_ANDROID_PLATFORM/arch-x86
    HOST=i686-linux
    #i686-linux

    PREFIX=$ROOT_PREFIX/$FF_ARCH/

    FF_CFG_CONF="$FF_CFG_CONF --disable-asm"

elif [ "$FF_ARCH" = "x86_64" ]; then
	#设置编译器
    FF_ANDROID_PLATFORM=android-21
    PREBUILT=$ANDROID_NDK/toolchains/x86_64-4.9/prebuilt
    export PATH=$PATH:$PREBUILT/darwin-x86_64/bin/
    CROSS_PREFIX=$PREBUILT/darwin-x86_64/bin/x86_64-linux-android-
	#设置平台编译连接路径
	PLATFORM=$ANDROID_NDK/platforms/$FF_ANDROID_PLATFORM/arch-x86_64
    HOST=x86_64-linux

    PREFIX=$ROOT_PREFIX/$FF_ARCH/
    
    FF_CFG_CONF="$FF_CFG_CONF --disable-asm"

else
    echo "unknown architecture $FF_ARCH";
    exit 1
fi

echo --------
echo x264 make
echo --------

#创建输出目录
# mkdir $PREFIX

cd $ROOT/../x264-$FF_ARCH

#配置config参数
FF_CFG_CONF="$FF_CFG_CONF --prefix=$PREFIX"
# FF_CFG_CONF="$FF_CFG_CONF --enable-shared"
FF_CFG_CONF="$FF_CFG_CONF --enable-static"

FF_CFG_CONF="$FF_CFG_CONF --disable-cli"
FF_CFG_CONF="$FF_CFG_CONF --disable-opencl"
FF_CFG_CONF="$FF_CFG_CONF --disable-thread"

# FF_CFG_CONF="$FF_CFG_CONF --enable-pic"
# FF_CFG_CONF="$FF_CFG_CONF --enable-strip"

FF_CFG_CONF="$FF_CFG_CONF --disable-avs"
FF_CFG_CONF="$FF_CFG_CONF --disable-swscale"
FF_CFG_CONF="$FF_CFG_CONF --disable-lavf"
FF_CFG_CONF="$FF_CFG_CONF --disable-ffms"
FF_CFG_CONF="$FF_CFG_CONF --disable-gpac"
FF_CFG_CONF="$FF_CFG_CONF --disable-lsmash"

FF_CFG_CONF="$FF_CFG_CONF --host=$HOST"
FF_CFG_CONF="$FF_CFG_CONF --cross-prefix=$CROSS_PREFIX"
FF_CFG_CONF="$FF_CFG_CONF --sysroot=$PLATFORM"

echo $FF_CFG_CONF
echo
#编译 
./configure $FF_CFG_CONF
#构造
make
#安装
sudo make install


ijkplayer中脚本配置如下:

#设置
FF_DEP_X264=$(pwd)/build/x264/$FF_ARCH

# with x264
if [ -f "${FF_DEP_X264}/lib/libx264.a" ]; then
    echo "x264 detected"
    FF_CFG_FLAGS="$FF_CFG_FLAGS --enable-gpl --enable-libx264 --enable-encoder=libx264"
    FF_CFLAGS="$FF_CFLAGS -I${FF_DEP_X264}/include"
    FF_DEP_LIBS="$FF_DEP_LIBS -L${FF_DEP_X264}/lib -lx264"
fi


在编译时注意配置FF_ANDROID_PLATFORM参数和ijkplayer一致,避免出现无法找到文件问题

在arm64平台中需要开启asm功能,否则会有部分函数编译时无法被ffmpeg找到

你可能感兴趣的:(ffmpeg)