FFmpeg 交叉编译libx264、libx265、libfdk-aac流程

背景

FFmpeg 是一款强大的音视频处理工具,它是一种可插拔的架构设计。当需要使用某个编解码器、容器格式、网络协议时,只需要在编译文件中打开、配置,就可以在FFmpeg中使用。在播放器、推流器、视频编辑中经常都会使用到FFmpeg交叉编译第三方库,FFmpeg交叉编译第三方库可以说是音视频入门的基础知识,也是最重要的。通过学习了交叉编译的过程,加深对FFmpeg架构的设计。

编译第三方库

FFmpeg 最常使用的第三方库就是libx264、libx265、libfdk-aac。这里就介绍下libx264、libx265、libfdk-aac的流程。

libx264编译

  1. 下载libx264库
    可以在VideoLan下载libx264库。
  2. 编译脚本
    armv7a编译脚本:
#!/bin/bash
NDK=/Users/zhangjunling/Library/Android/sdk/ndk/android-ndk-r10d
export PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.6/prebuilt/darwin-x86_64
export CC="$PREBUILT/bin/arm-linux-androideabi-gcc --sysroot=${PLATFORM} -march=armv7-a"
export LD="$PREBUILT/bin/arm-linux-androideabi-ld"
export AS="$PREBUILT/bin/arm-linux-androideabi-gcc"
export AR="$PREBUILT/bin/arm-linux-androideabi-ar"
export RANLIB="$PREBUILT/bin/arm-linux-androideabi-ranlib"
export PLATFORM=$NDK/platforms/android-9/arch-arm 
export PREFIX=/Users/zhangjunling/study/CrossCompileTest/thirdparty/libx264/armv7a/
export PATH=$PATH:$PREBUILT/bin:$PLATFORM/usr/include:

./configure --prefix=$PREFIX \
--enable-static \
--enable-pic \
--enable-strip \
--disable-cli \
--disable-asm \
--extra-cflags= "-march=armv7-a  -mfloat-abi=softfp -mfpu=neon" \
--host=arm-linux \
--cross-prefix=$PREBUILT/bin/arm-linux-androideabi- \
--sysroot=$PLATFORM

make clean
make -j8
make install

arm64-v8a编译脚本:

#!/bin/bash
NDK=/Users/zhangjunling/Library/Android/sdk/ndk/android-ndk-r10d
PLATFORM=$NDK/platforms/android-21/arch-arm64
export PREBUILT=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64
export CC="$PREBUILT/bin/aarch64-linux-android-gcc --sysroot=${PLATFORM} -march=armv8-a"
export CXX="$PREBUILT/bin/aarch64-linux-android-g++ --sysroot=${PLATFORM}"
export LD="$PREBUILT/bin/aarch64-linux-android-ld"
export AS="$PREBUILT/bin/aarch64-linux-android-gcc"
export AR="$PREBUILT/bin/aarch64-linux-android-ar"
export RANLIB="$PREBUILT/bin/aarch64-linux-android-ranlib"
export PREFIX=/Users/zhangjunling/study/CrossCompileTest/thirdparty/libx264/arm64-v8a
export PATH=$PATH:$PREBUILT/bin:$PLATFORM/usr/include:

./configure --prefix=$PREFIX \
--enable-static \
--enable-pic \
--enable-strip \
--disable-cli \
--disable-asm \
--extra-cflags= "-march=armv8-a  -mfloat-abi=softfp -mfpu=neon" \
--host=arm-linux \
--cross-prefix=$PREBUILT/bin/aarch64-linux-android- \
--sysroot=$PLATFORM

make clean
make -j8
make install

libx265 编译

  1. 下载libx265库
    libx265库下载地址。
  2. 修改编译脚本
    aarch64-linux/crosscompile.cmake

# CMake toolchain file for cross compiling x265 for ARM arch
# This feature is only supported as experimental. Use with caution.
# Please report bugs on bitbucket
# Run cmake with: cmake -DCMAKE_TOOLCHAIN_FILE=crosscompile.cmake -G "Unix Makefiles" ../../source && ccmake ../../source

set(CMAKE_SYSTEM_NAME Android)

#此处设置Android的API版本
set(CMAKE_ANDROID_API 21)

#此处设置Android的ABI,如armeabi、armeabi-v7a、x86等
set(CMAKE_ANDROID_ARCH_ABI arm64-v8a)

#此处设置Android的NDK路径
set(CMAKE_ANDROID_NDK "/Users/zhangjunling/Library/Android/sdk/ndk_zjl/android-ndk-r10d")

#此处设置Android的系统目录,与ABI相关,如$NDK/platforms/android-9/arch-arm、/platforms/android-9/arch-x86
set(CMAKE_SYSROOT "/Users/zhangjunling/Library/Android/sdk/ndk_zjl/android-ndk-r10d/platforms/android-21/arch-arm64")

set(CMAKE_ANDROID_STL_TYPE "gnustl_static")
set(CMAKE_CXX_FLAGS "-std=c++11 ${CMAKE_CXX_FLAGS}")
set(CMAKE_CXX_STANDARD 11)

include_directories(../../source)

arm-linux/crosscompile.cmake<

你可能感兴趣的:(ffmpeg,ffmpeg,着色器,OPENGL)