• ffmpeg x264 x265 fdk-aac 编译记录


    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 

    1.1  下载编译fdk-aac 

     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

    1. #!/bin/bash
    2. NDK=$ANDROID_NDK_HOME # 这里需要替换成你本地的 NDK 路径,其他的不用修改
    3. HOST_TAG=linux-x86_64
    4. TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/$HOST_TAG
    5. ANDROID_LIB_PATH="$(pwd)/android"
    6. echo $ANDROID_LIB_PATH
    7. API=21
    8. function build_android
    9. {
    10. echo "Build fdk-aac for android $CPU"
    11. ./configure \
    12. --host=$HOST \
    13. --disable-shared \
    14. --enable-static \
    15. --prefix="$ANDROID_LIB_PATH/$CPU" \
    16. CPPFLAGS="-fPIC"
    17. make clean
    18. make -j8
    19. make install
    20. echo "Build fdk-aac for android $CPU completed"
    21. }
    22. # armeabi-v7a
    23. CPU=armeabi-v7a
    24. HOST=arm-linux-android
    25. export AR=$TOOLCHAIN/bin/arm-linux-androideabi-ar
    26. export AS=$TOOLCHAIN/bin/arm-linux-androideabi-as
    27. export LD=$TOOLCHAIN/bin/arm-linux-androideabi-ld
    28. export RANLIB=$TOOLCHAIN/bin/arm-linux-androideabi-ranlib
    29. export STRIP=$TOOLCHAIN/bin/arm-linux-androideabi-strip
    30. export CC=$TOOLCHAIN/bin/armv7a-linux-androideabi$API-clang
    31. export CXX=$TOOLCHAIN/bin/armv7a-linux-androideabi$API-clang++
    32. build_android
    33. # arm64-v8a
    34. CPU=arm64-v8a
    35. HOST=aarch64-linux-android
    36. export AR=$TOOLCHAIN/bin/aarch64-linux-android-ar
    37. export AS=$TOOLCHAIN/bin/aarch64-linux-android-as
    38. export LD=$TOOLCHAIN/bin/aarch64-linux-android-ld
    39. export RANLIB=$TOOLCHAIN/bin/aarch64-linux-android-ranlib
    40. export STRIP=$TOOLCHAIN/bin/aarch64-linux-android-strip
    41. export CC=$TOOLCHAIN/bin/aarch64-linux-android$API-clang
    42. export CXX=$TOOLCHAIN/bin/aarch64-linux-android$API-clang++
    43. build_android

    1.2 x264

    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

    1. #!/bin/bash
    2. export NDK=$ANDROID_NDK_HOME # 这里需要替换成你本地的 NDK 路径,其他的不用修改
    3. TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64
    4. export API=21
    5. function build_android
    6. {
    7. ./configure \
    8. --prefix=$PREFIX \
    9. --disable-cli \
    10. --enable-static \
    11. --enable-pic \
    12. --host=$my_host \
    13. --cross-prefix=$CROSS_PREFIX \
    14. --sysroot=$NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot \
    15. make clean
    16. make -j8
    17. make install
    18. }
    19. #arm64-v8a
    20. PREFIX=$(pwd)/android/arm64-v8a
    21. my_host=aarch64-linux-android
    22. export TARGET=aarch64-linux-android
    23. export CC=$TOOLCHAIN/bin/$TARGET$API-clang
    24. export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++
    25. CROSS_PREFIX=$TOOLCHAIN/bin/aarch64-linux-android-
    26. build_android
    27. #armeabi-v7a
    28. PREFIX=$(pwd)/android/armeabi-v7a
    29. my_host=armv7a-linux-android
    30. export TARGET=armv7a-linux-androideabi
    31. export CC=$TOOLCHAIN/bin/$TARGET$API-clang
    32. export CXX=$TOOLCHAIN/bin/$TARGET$API-clang++
    33. CROSS_PREFIX=$TOOLCHAIN/bin/arm-linux-androideabi-
    34. build_android

    1.3 ffmpeg

    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

    1. #!/bin/bash
    2. #你自己的NDK路径.
    3. export NDK=$ANDROID_NDK_HOME
    4. TOOLCHAIN=$NDK/toolchains/llvm/prebuilt/linux-x86_64
    5. function build_android
    6. {
    7. ./configure \
    8. --prefix=$PREFIX \
    9. --enable-neon \
    10. --enable-nonfree \
    11. --enable-hwaccels \
    12. --enable-gpl \
    13. --enable-postproc \
    14. --enable-shared \
    15. --disable-debug \
    16. --enable-small \
    17. --enable-jni \
    18. --enable-mediacodec \
    19. --enable-decoder=h264_mediacodec \
    20. --disable-static \
    21. --disable-doc \
    22. --enable-ffmpeg \
    23. --disable-ffplay \
    24. --disable-ffprobe \
    25. --disable-avdevice \
    26. --disable-doc \
    27. --disable-symver \
    28. --enable-libx264 \
    29. --enable-libfdk-aac \
    30. --enable-encoder=libx264 \
    31. --enable-encoder=libfdk_aac \
    32. --cross-prefix=$CROSS_PREFIX \
    33. --target-os=android \
    34. --arch=$ARCH \
    35. --cpu=$CPU \
    36. --cc=$CC \
    37. --cxx=$CXX \
    38. --enable-cross-compile \
    39. --sysroot=$SYSROOT \
    40. --extra-cflags="-I$X264_INCLUDE -I$FDK_INCLUDE -Os -fpic $OPTIMIZE_CFLAGS" \
    41. --extra-ldflags="-lm -L$FDK_LIB -L$X264_LIB $ADDI_LDFLAGS"
    42. make clean
    43. make
    44. make install
    45. echo "编译成功 $CPU"
    46. }
    47. #armv8-a
    48. ARCH=arm64
    49. CPU=armv8-a
    50. API=21
    51. CC=$TOOLCHAIN/bin/aarch64-linux-android$API-clang
    52. CXX=$TOOLCHAIN/bin/aarch64-linux-android$API-clang++
    53. SYSROOT=$NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot
    54. CROSS_PREFIX=$TOOLCHAIN/bin/aarch64-linux-android-
    55. PREFIX=$(pwd)/android/$CPU
    56. OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU "
    57. BASE_PATH=/home/t/third_parts
    58. LIB_TARGET_ABI=arm64-v8a
    59. #指定 fdk-aac 的头文件和静态库目录
    60. FDK_INCLUDE=$BASE_PATH/fdk-aac-0.1.5/android/$LIB_TARGET_ABI/include
    61. FDK_LIB=$BASE_PATH/fdk-aac-0.1.5/android/$LIB_TARGET_ABI/lib
    62. #指定 x264 的头文件和静态库目录
    63. X264_INCLUDE=$BASE_PATH/x264-master/android/$LIB_TARGET_ABI/include
    64. X264_LIB=$BASE_PATH/x264-master/android/$LIB_TARGET_ABI/lib
    65. build_android
    66. #armv7-a
    67. ARCH=arm
    68. CPU=armv7-a
    69. API=21
    70. CC=$TOOLCHAIN/bin/armv7a-linux-androideabi$API-clang
    71. CXX=$TOOLCHAIN/bin/armv7a-linux-androideabi$API-clang++
    72. SYSROOT=$NDK/toolchains/llvm/prebuilt/linux-x86_64/sysroot
    73. CROSS_PREFIX=$TOOLCHAIN/bin/arm-linux-androideabi-
    74. PREFIX=$(pwd)/android/$CPU
    75. OPTIMIZE_CFLAGS="-mfloat-abi=softfp -mfpu=vfp -marm -march=$CPU "
    76. BASE_PATH=/home/t/third_parts
    77. LIB_TARGET_ABI=armeabi-v7a
    78. FDK_INCLUDE=$BASE_PATH/fdk-aac-0.1.5/android/$LIB_TARGET_ABI/include
    79. FDK_LIB=$BASE_PATH/fdk-aac-0.1.5/android/$LIB_TARGET_ABI/lib
    80. X264_INCLUDE=$BASE_PATH/x264/android/$LIB_TARGET_ABI/include
    81. X264_LIB=$BASE_PATH/x264/android/$LIB_TARGET_ABI/lib
    82. build_android

    可以静态库动态库同时编译 

     关于 pkg-config 

    1.4 x265

    FFmpeg 集成 x265 编译及解码_ffmpeg x265-CSDN博客

    ffmpeg 5.0后内部 mediaocodec 已支持硬编 h264

  • 相关阅读:
    【算法优选】双指针专题——贰
    碳监测能源消耗监测管理系统_碳排放在线监测管理系统_碳管理平台
    Windows服务器怎么才能长时间保持远程桌面不自动断开
    Sui基金会举办了仪式并于9月底成功启动zkLogin
    手拉手带你用 Vue3 + VantUI 写一个移动端脚手架 系列二 (页面布局与兼容)
    GPT做SQL查询引擎的自然语言
    瞪羚优化算法(Gazelle Optimization Algorithm,GOA)
    Focal and Global Knowledge Distillation for Detectors
    【附源码】计算机毕业设计SSM社区服务系统
    Rocky Linux 8.9 一键安装 Oracle 11GR2(231017)单机 ASM
  • 原文地址:https://blog.csdn.net/TyearLin/article/details/134078388