ffmpeg 裁剪定制编译过多次了 这里记录下 主题部分
关于ffmpeg自定义编解码器
FFmpeg codec HOWTO - MultimediaWiki
ubuntu 18.04
ffmpeg:
v4.2.2
ndk :android-ndk-r20b-linux-x86_64
fdk-aac 0.1.5
x264: 0.164.x
wget http://jaist.dl.sourceforge.net/project/opencore-amr/fdk-aac/fdk-aac-0.1.5.tar.gz
tar -xvf fdk-aac-0.15.tar.gz
编写编译文件
touch build_fdk_aac_clang_android.sh
- #!/bin/bash
- NDK=$ANDROID_NDK_HOME # 这里需要替换成你本地的 NDK 路径,其他的不用修改
- HOST_TAG=linux-x86_64
- TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/$HOST_TAG
- ANDROID_LIB_PATH="$(pwd)/android"
- echo $ANDROID_LIB_PATH
-
- API=21
-
- function build_android
- {
- echo "Build fdk-aac for android $CPU"
- ./configure \
- --host=$HOST \
- --disable-shared \
- --enable-static \
- --prefix="$ANDROID_LIB_PATH/$CPU" \
- CPPFLAGS="-fPIC"
-
- make clean
- make -j8
- make install
- echo "Build fdk-aac for android $CPU completed"
- }
-
- # armeabi-v7a
- CPU=armeabi-v7a
- HOST=arm-linux-android
- export AR=$TOOLCHAIN/bin/arm-linux-androideabi-ar
- export AS=$TOOLCHAIN/bin/arm-linux-androideabi-as
- export LD=$TOOLCHAIN/bin/arm-linux-androideabi-ld
- export RANLIB=$TOOLCHAIN/bin/arm-linux-androideabi-ranlib
- export STRIP=$TOOLCHAIN/bin/arm-linux-androideabi-strip
- export CC=$TOOLCHAIN/bin/armv7a-linux-androideabi$API-clang
- export CXX=$TOOLCHAIN/bin/armv7a-linux-androideabi$API-clang++
- build_android
-
- # arm64-v8a
- CPU=arm64-v8a
- HOST=aarch64-linux-android
- export AR=$TOOLCHAIN/bin/aarch64-linux-android-ar
- export AS=$TOOLCHAIN/bin/aarch64-linux-android-as
- export LD=$TOOLCHAIN/bin/aarch64-linux-android-ld
- export RANLIB=$TOOLCHAIN/bin/aarch64-linux-android-ranlib
- export STRIP=$TOOLCHAIN/bin/aarch64-linux-android-strip
- export CC=$TOOLCHAIN/bin/aarch64-linux-android$API-clang
- export CXX=$TOOLCHAIN/bin/aarch64-linux-android$API-clang++
- build_android
-
-
wget https://code.videolan.org/videolan/x264/-/archive/master/x264-master.tar.bz2
tar -xvf x264-master.tar.bz2
编写编译文件
touch build_x264_clang_android.sh
- #!/bin/bash
- export NDK=$ANDROID_NDK_HOME # 这里需要替换成你本地的 NDK 路径,其他的不用修改
- TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64
- export API=21
-
- function build_android
- {
- ./configure \
- --prefix=$PREFIX \
- --disable-cli \
- --enable-static \
- --enable-pic \
- --host=$my_host \
- --cross-prefix=$CROSS_PREFIX \
- --sysroot=$NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot \
-
- make clean
- make -j8
- make install
- }
-
- #arm64-v8a
- PREFIX=$(pwd)/android/arm64-v8a
- my_host=aarch64-linux-android
- export TARGET=aarch64-linux-android
- export CC=$TOOLCHAIN/bin/$TARGET$API-clang
- export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++
- CROSS_PREFIX=$TOOLCHAIN/bin/aarch64-linux-android-
- build_android
-
- #armeabi-v7a
- PREFIX=$(pwd)/android/armeabi-v7a
- my_host=armv7a-linux-android
- export TARGET=armv7a-linux-androideabi
- export CC=$TOOLCHAIN/bin/$TARGET$API-clang
- export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++
- CROSS_PREFIX=$TOOLCHAIN/bin/arm-linux-androideabi-
- build_android
-
wget https://ffmpeg.org/releases/ffmpeg-4.2.2.tar.bz2
或者github
GitHub - FFmpeg/FFmpeg: Mirror of https://git.ffmpeg.org/ffmpeg.git
脚本
touch build_ffmpeg_aac_x264_android.sh
- #!/bin/bash
- #你自己的NDK路径.
- export NDK=$ANDROID_NDK_HOME
- TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64
-
- function build_android
- {
-
- ./configure \
- --prefix=$PREFIX \
- --enable-neon \
- --enable-nonfree \
- --enable-hwaccels \
- --enable-gpl \
- --enable-postproc \
- --enable-shared \
- --disable-debug \
- --enable-small \
- --enable-jni \
- --enable-mediacodec \
- --enable-decoder=h264_mediacodec \
- --disable-static \
- --disable-doc \
- --enable-ffmpeg \
- --disable-ffplay \
- --disable-ffprobe \
- --disable-avdevice \
- --disable-doc \
- --disable-symver \
- --enable-libx264 \
- --enable-libfdk-aac \
- --enable-encoder=libx264 \
- --enable-encoder=libfdk_aac \
- --cross-prefix=$CROSS_PREFIX \
- --target-os=android \
- --arch=$ARCH \
- --cpu=$CPU \
- --cc=$CC \
- --cxx=$CXX \
- --enable-cross-compile \
- --sysroot=$SYSROOT \
- --extra-cflags="-I$X264_INCLUDE -I$FDK_INCLUDE -Os -fpic $OPTIMIZE_CFLAGS" \
- --extra-ldflags="-lm -L$FDK_LIB -L$X264_LIB $ADDI_LDFLAGS"
-
- make clean
- make
- make install
-
- echo "编译成功 $CPU"
-
- }
-
-
- #armv8-a
- ARCH=arm64
- CPU=armv8-a
- API=21
- CC=$TOOLCHAIN/bin/aarch64-linux-android$API-clang
- CXX=$TOOLCHAIN/bin/aarch64-linux-android$API-clang++
- SYSROOT=$NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot
- CROSS_PREFIX=$TOOLCHAIN/bin/aarch64-linux-android-
- PREFIX=$(pwd)/android/$CPU
- OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU "
-
- BASE_PATH=/home/t/third_parts
- LIB_TARGET_ABI=arm64-v8a
-
- #指定 fdk-aac 的头文件和静态库目录
- FDK_INCLUDE=$BASE_PATH/fdk-aac-0.1.5/android/$LIB_TARGET_ABI/include
- FDK_LIB=$BASE_PATH/fdk-aac-0.1.5/android/$LIB_TARGET_ABI/lib
-
- #指定 x264 的头文件和静态库目录
- X264_INCLUDE=$BASE_PATH/x264-master/android/$LIB_TARGET_ABI/include
- X264_LIB=$BASE_PATH/x264-master/android/$LIB_TARGET_ABI/lib
-
- build_android
-
-
- #armv7-a
- ARCH=arm
- CPU=armv7-a
- API=21
- CC=$TOOLCHAIN/bin/armv7a-linux-androideabi$API-clang
- CXX=$TOOLCHAIN/bin/armv7a-linux-androideabi$API-clang++
- SYSROOT=$NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot
- CROSS_PREFIX=$TOOLCHAIN/bin/arm-linux-androideabi-
- PREFIX=$(pwd)/android/$CPU
- OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU "
-
- BASE_PATH=/home/t/third_parts
- LIB_TARGET_ABI=armeabi-v7a
- FDK_INCLUDE=$BASE_PATH/fdk-aac-0.1.5/android/$LIB_TARGET_ABI/include
- FDK_LIB=$BASE_PATH/fdk-aac-0.1.5/android/$LIB_TARGET_ABI/lib
- X264_INCLUDE=$BASE_PATH/x264/android/$LIB_TARGET_ABI/include
- X264_LIB=$BASE_PATH/x264/android/$LIB_TARGET_ABI/lib
-
- build_android
-
可以静态库动态库同时编译
关于 pkg-config
ffmpeg 5.0后内部 mediaocodec 已支持硬编 h264