【Android音视频】自编译FFMpeg-kit添加硬件编码支持并升级FFMpeg版本

前言

上次解决了FFMpeg-kit编译的问题,但直接编译出来是没有硬件编码支持的,只有软件编解码,软编特别特别慢。所以这次还得继续改代码,让它支持在安卓上使用硬件编码。
如果你没有自己编译过FFMpeg-kit,建议先看看这篇编译教程:
【Android音视频】自编译FFMepg-Kit疑难杂症解决

目录结构

先简单了解一下这个项目,目录结构如下:

~/ffmpeg-kit$ tree -L 2
.
├── android  <------安卓aar库项目,用于打包成aar
│   ├── build
│   ├── build.gradle
│   ├── ffmpeg-kit-android-lib
│   ├── gradle
│   ├── gradle.properties
│   ├── gradlew
│   ├── gradlew.bat
│   ├── jni
│   ├── libs
│   ├── obj
│   ├── README.md
│   └── settings.gradle
├── android.sh  <------安卓一键编译打包脚本
├── apple  <------苹果的库项目
│   ├── aclocal.m4
│   ├── ar-lib
│   ├── autogen.sh
│   ├── compile
│   ├── config.guess
│   ├── config.sub
│   ├── configure.ac
│   ├── depcomp
│   ├── Doxyfile
│   ├── install-sh
│   ├── Makefile.am
│   ├── missing
│   ├── README.md
│   └── src
├── apple.sh  <------苹果的一键编译打包脚本
├── build.log  <------编译日志,多次编译会把log追加在后面,按时间排列
├── CODE_OF_CONDUCT.md
├── CONTRIBUTING.md
├── docs   <------离线文档
│   ├── android
│   ├── apple
│   ├── assets
│   ├── _config.yml
│   ├── index.md
│   └── linux
├── flutter   <------Flutter的库项目
│   ├── flutter
│   └── flutter_platform_interface
├── ios.sh   <------ios的一键打包编译脚本
├── LICENSE
├── linux  <------Linux的库项目
│   ├── aclocal.m4
│   ├── ar-lib
│   ├── autogen.sh
│   ├── compile
│   ├── config.guess
│   ├── config.sub
│   ├── configure.ac
│   ├── depcomp
│   ├── Doxyfile
│   ├── install-sh
│   ├── m4
│   ├── Makefile.am
│   ├── missing
│   ├── README.md
│   └── src
├── linux.sh  <------Linux的一键打包编译脚本
├── macos.sh  <------MacOS的一键打包编译脚本
├── prebuilt  <------已经编译好的组件
│   ├── android-arm
│   ├── android-arm64
│   ├── android-arm-neon
│   ├── android-x86
│   ├── android-x86_64
│   └── bundle-android-aar
├── react-native  <------RN的库项目
│   ├── android
│   ├── babel.config.js
│   ├── ffmpeg-kit-react-native.podspec
│   ├── ios
│   ├── package.json
│   ├── README.md
│   └── src
├── README.md
├── scripts  <------每个组件的编译脚本
│   ├── android
│   ├── apple
│   ├── function-android.sh
│   ├── function-apple.sh
│   ├── function-ios.sh
│   ├── function-linux.sh
│   ├── function-macos.sh
│   ├── function.sh
│   ├── function-tvos.sh
│   ├── linux
│   ├── main-android.sh
│   ├── main-ios.sh
│   ├── main-linux.sh
│   ├── main-macos.sh
│   ├── main-tvos.sh
│   ├── run-android.sh
│   ├── run-apple.sh
│   ├── run-linux.sh
│   ├── source.sh  <------版本控制,里面有每个组件的版本和仓库路径
│   └── variable.sh
├── src   <------源码,第三方库的源码也放在这里
│   ├── chromaprint
│   ├── cpu-features
│   ├── dav1d
│   ├── expat
│   ├── ffmpeg
│   ├── fontconfig
│   ├── freetype
│   ├── fribidi
│   ├── giflib
│   ├── gmp
│   ├── gnutls
│   ├── harfbuzz
│   ├── jpeg
│   ├── kvazaar
│   ├── lame
│   ├── leptonica
│   ├── libaom
│   ├── libass
│   ├── libiconv
│   ├── libilbc
│   ├── libogg
│   ├── libpng
│   ├── libsamplerate
│   ├── libsndfile
│   ├── libtheora
│   ├── libuuid
│   ├── libvidstab
│   ├── libvorbis
│   ├── libvpx
│   ├── libwebp
│   ├── libxml2
│   ├── nettle
│   ├── opencore-amr
│   ├── openh264
│   ├── openssl
│   ├── opus
│   ├── rubberband
│   ├── sdl
│   ├── shine
│   ├── snappy
│   ├── soxr
│   ├── speex
│   ├── srt
│   ├── tesseract
│   ├── tiff
│   ├── twolame
│   ├── vo-amrwbenc
│   ├── x264
│   ├── x265
│   ├── xvidcore
│   └── zimg
├── tools   <------编译工具
│   ├── android
│   ├── apple
│   ├── clean.sh
│   ├── docs
│   ├── license
│   ├── patch
│   ├── protocols
│   └── source
└── tvos.sh   <------tvos的一键打包编译脚本

95 directories, 67 files

这玩意支持多个平台的编译,我们只关心安卓平台。重点关注以下文件:
android.sh
scripts/android/ffmpeg.sh
source.sh

读参数

先看看编译的参数选项,安卓平台编译使用目录下的android.sh这个脚本进行,先看看--help

./android.sh --help

'android.sh' builds FFmpegKit for Android platform. By default five Android architectures
(armeabi-v7a, armeabi-v7a-neon, arm64-v8a, x86 and x86_64) are built without any external 
libraries enabled. Options can be used to disable architectures and/or enable external 
libraries. Please note that GPL libraries (external libraries with GPL license) need --enable-
gpl flag to be set explicitly. When compilation ends an Android Archive (AAR) file is created 
under the prebuilt folder.

这里可以看到一共支持5个架构:armeabi-v7a, armeabi-v7a-neon, arm64-v8a, x86, x86_64

Usage: ./android.sh [OPTION]... [VAR=VALUE]...

Specify environment variables as VARIABLE=VALUE to override default build options.

Options:
  -h, --help            display this help and exit
  -v, --version         display version information and exit
  -d, --debug           build with debug information
  -s, --speed           optimize for speed instead of size
  -f, --force           ignore warnings
  -l, --lts         build lts packages to support API 16+ devices
      --api-level=api       override Android api level
      --no-ffmpeg-kit-protocols disable custom ffmpeg-kit protocols (saf)

加这个参数可以引用其他GPL第三方库
Licensing options:
  --enable-gpl          allow building GPL libraries, created libs will be licensed 
  under the GPLv3.0 [no]

加一条就会ban掉一个架构,每个架构都需要单独编译,所以不需要的就尽情地ban掉
虽然这里括号写的是yes,但实际上你不加参数的话它会编译全部的5个架构。
Architectures:
  --disable-arm-v7a     do not build arm-v7a architecture [yes]
  --disable-arm-v7a-neon    do not build arm-v7a-neon architecture [yes]
  --disable-arm64-v8a       do not build arm64-v8a architecture [yes]
  --disable-x86         do not build x86 architecture [yes]
  --disable-x86-64      do not build x86-64 architecture [yes]

这里是第三方库相关的支持,加一个就会单独加入一个库,full就是全加。
Libraries:
  --full            enables all external libraries
  --enable-android-media-codec  build with built-in Android MediaCodec support [no]
  --enable-android-zlib     build with built-in zlib support [no]
  --enable-chromaprint      build with chromaprint [no]
  --enable-dav1d        build with dav1d [no]
  --enable-fontconfig       build with fontconfig [no]
  --enable-freetype     build with freetype [no]
  --enable-fribidi      build with fribidi [no]
  --enable-gmp          build with gmp [no]
  --enable-gnutls       build with gnutls [no]
  --enable-kvazaar      build with kvazaar [no]
  --enable-lame         build with lame [no]
  --enable-libaom       build with libaom [no]
  --enable-libass       build with libass [no]
  --enable-libiconv     build with libiconv [no]
  --enable-libilbc      build with libilbc [no]
  --enable-libtheora        build with libtheora [no]
  --enable-libvorbis        build with libvorbis [no]
  --enable-libvpx       build with libvpx [no]
  --enable-libwebp      build with libwebp [no]
  --enable-libxml2      build with libxml2 [no]
  --enable-opencore-amr     build with opencore-amr [no]
  --enable-openh264     build with openh264 [no]
  --enable-openssl      build with openssl [no]
  --enable-opus         build with opus [no]
  --enable-sdl          build with sdl [no]
  --enable-shine        build with shine [no]
  --enable-snappy       build with snappy [no]
  --enable-soxr         build with soxr [no]
  --enable-speex        build with speex [no]
  --enable-srt          build with srt [no]
  --enable-tesseract        build with tesseract [no]
  --enable-twolame      build with twolame [no]
  --enable-vo-amrwbenc      build with vo-amrwbenc [no]
  --enable-zimg         build with zimg [no]

GPL库,加一个就是单独引入一个,必须和--enable-gpl一起使用
GPL libraries:
  --enable-libvidstab       build with libvidstab [no]
  --enable-rubberband       build with rubber band [no]
  --enable-x264         build with x264 [no]
  --enable-x265         build with x265 [no]
  --enable-xvidcore     build with xvidcore [no]

Custom libraries:
  --enable-custom-library-[n]-name=value            name of the custom library []
  --enable-custom-library-[n]-repo=value            git repository of the source code []
  --enable-custom-library-[n]-repo-commit=value         git commit to download the source code from []
  --enable-custom-library-[n]-repo-tag=value            git tag to download the source code from []
  --enable-custom-library-[n]-package-config-file-name=value    package config file installed by the build script []
  --enable-custom-library-[n]-ffmpeg-enable-flag=value  library name used in ffmpeg configure script to enable the library []
  --enable-custom-library-[n]-license-file=value        licence file path relative to the library source folder []
  --enable-custom-library-[n]-uses-cpp              flag to specify that the library uses libc++ []

Advanced options:
  --reconf-LIBRARY      run autoreconf before building LIBRARY [no]
  --redownload-LIBRARY      download LIBRARY even if it is detected as already downloaded [no]
  --rebuild-LIBRARY     build LIBRARY even if it is detected as already built [no]
  
  这条表示编译之后不打包为aar
  --no-archive          do not build Android archive [no]

添加硬件编码支持

简单分析一下,我们需要支持安卓的硬件编码器,所以需要mediacodec相关的库,以及名字带安卓的库,其他相关的库看心情加。
这里以arm64-v8a平台为例,添加大多数常见的库,指令如下:

./android.sh --enable-gpl --enable-libvidstab --enable-rubberband --enable-x264 --enable-x265 --enable-xvidcore --disable-arm-v7a --disable-arm-v7a-neon --disable-x86 --disable-x86-64 --enable-android-media-codec --enable-android-zlib --enable-kvazaar --enable-lame --enable-libaom --enable-libtheora --enable-libvorbis --enable-libvpx --enable-libwebp --enable-opencore-amr --enable-openh264 --enable-opus --enable-speex --enable-twolame --enable-vo-amrwbenc --enable-shine --enable-snappy --enable-soxr --enable-sdl

这些第三方库会下载到src/[库名称]目录下,需要用到gitgradle,建议开魔法,如果gradle的插件下载不下来,可以看看开头提到的上一篇文章有写怎么处理。

升级FFMpeg版本

除了FFMepg-kit的参数以外,FFMepg自己也有编译参数。

cd src/ffmpeg
./configure --help

Usage: configure [options]
Options: [defaults in brackets after descriptions]

Help options:
  --help                   print this message
  --quiet                  Suppress showing informative output
  --list-decoders          show all available decoders  <------查看当前版本支持的解码器
  --list-encoders          show all available encoders  <------查看当前版本支持的编码器
  --list-hwaccels          show all available hardware accelerators
  --list-demuxers          show all available demuxers
  --list-muxers            show all available muxers
  --list-parsers           show all available parsers
  --list-protocols         show all available protocols
  --list-bsfs              show all available bitstream filters
  --list-indevs            show all available input devices
  --list-outdevs           show all available output devices
  --list-filters           show all available filters

Standard options:
  --logfile=FILE           log tests and output to FILE [ffbuild/config.log]
  --disable-logging        do not log configure debug information
  --fatal-warnings         fail if any configure warning is generated
  --prefix=PREFIX          install in PREFIX [/usr/local]
  --bindir=DIR             install binaries in DIR [PREFIX/bin]
  --datadir=DIR            install data files in DIR [PREFIX/share/ffmpeg]
  --docdir=DIR             install documentation in DIR [PREFIX/share/doc/ffmpeg]
  --libdir=DIR             install libs in DIR [PREFIX/lib]
  --shlibdir=DIR           install shared libs in DIR [LIBDIR]
  --incdir=DIR             install includes in DIR [PREFIX/include]
  --mandir=DIR             install man page in DIR [PREFIX/share/man]
  --pkgconfigdir=DIR       install pkg-config files in DIR [LIBDIR/pkgconfig]
  --enable-rpath           use rpath to allow installing libraries in paths
                           not part of the dynamic linker search path
                           use rpath when linking programs (USE WITH CARE)
  --install-name-dir=DIR   Darwin directory name for installed targets

Licensing options:
  --enable-gpl             allow use of GPL code, the resulting libs  <------使用第三方GPL库
                           and binaries will be under GPL [no]
  --enable-version3        upgrade (L)GPL to version 3 [no]
  --enable-nonfree         allow use of nonfree code, the resulting libs
                           and binaries will be unredistributable [no]

Configuration options:
  --disable-static         do not build static libraries [no]
  --enable-shared          build shared libraries [no]
  --enable-small           optimize for size instead of speed
  --disable-runtime-cpudetect disable detecting CPU capabilities at runtime (smaller binary)
  --enable-gray            enable full grayscale support (slower color)
  --disable-swscale-alpha  disable alpha channel support in swscale
  --disable-all            disable building components, libraries and programs
  --disable-autodetect     disable automatically detected external libraries [no]

Program options:
  --disable-programs       do not build command line programs
  --disable-ffmpeg         disable ffmpeg build
  --disable-ffplay         disable ffplay build
  --disable-ffprobe        disable ffprobe build

Documentation options:
  --disable-doc            do not build documentation
  --disable-htmlpages      do not build HTML documentation pages
  --disable-manpages       do not build man documentation pages
  --disable-podpages       do not build POD documentation pages
  --disable-txtpages       do not build text documentation pages

ban掉指定的组件
Component options:
  --disable-avdevice       disable libavdevice build
  --disable-avcodec        disable libavcodec build
  --disable-avformat       disable libavformat build
  --disable-swresample     disable libswresample build
  --disable-swscale        disable libswscale build
  --disable-postproc       disable libpostproc build
  --disable-avfilter       disable libavfilter build
  --disable-pthreads       disable pthreads [autodetect]
  --disable-w32threads     disable Win32 threads [autodetect]
  --disable-os2threads     disable OS/2 threads [autodetect]
  --disable-network        disable network support [no]
  --disable-dwt            disable DWT code
  --disable-error-resilience disable error resilience code
  --disable-lsp            disable LSP code
  --disable-faan           disable floating point AAN (I)DCT code
  --disable-iamf           disable support for Immersive Audio Model
  --disable-pixelutils     disable pixel utils in libavutil

Individual component options:
  --disable-everything     disable all components listed below
  --disable-encoder=NAME   disable encoder NAME
  --enable-encoder=NAME    enable encoder NAME
  --disable-encoders       disable all encoders
  --disable-decoder=NAME   disable decoder NAME
  --enable-decoder=NAME    enable decoder NAME
  --disable-decoders       disable all decoders
  --disable-hwaccel=NAME   disable hwaccel NAME
  --enable-hwaccel=NAME    enable hwaccel NAME
  --disable-hwaccels       disable all hwaccels
  --disable-muxer=NAME     disable muxer NAME
  --enable-muxer=NAME      enable muxer NAME
  --disable-muxers         disable all muxers
  --disable-demuxer=NAME   disable demuxer NAME
  --enable-demuxer=NAME    enable demuxer NAME
  --disable-demuxers       disable all demuxers
  --enable-parser=NAME     enable parser NAME
  --disable-parser=NAME    disable parser NAME
  --disable-parsers        disable all parsers
  --enable-bsf=NAME        enable bitstream filter NAME
  --disable-bsf=NAME       disable bitstream filter NAME
  --disable-bsfs           disable all bitstream filters
  --enable-protocol=NAME   enable protocol NAME
  --disable-protocol=NAME  disable protocol NAME
  --disable-protocols      disable all protocols
  --enable-indev=NAME      enable input device NAME
  --disable-indev=NAME     disable input device NAME
  --disable-indevs         disable input devices
  --enable-outdev=NAME     enable output device NAME
  --disable-outdev=NAME    disable output device NAME
  --disable-outdevs        disable output devices
  --disable-devices        disable all devices
  --enable-filter=NAME     enable filter NAME
  --disable-filter=NAME    disable filter NAME
  --disable-filters        disable all filters

External library support:

  Using any of the following switches will allow FFmpeg to link to the
  corresponding external library. All the components depending on that library
  will become enabled, if all their other dependencies are met and they are not
  explicitly disabled. E.g. --enable-libopus will enable linking to
  libopus and allow the libopus encoder to be built, unless it is
  specifically disabled with --disable-encoder=libopus.

  Note that only the system libraries are auto-detected. All the other external
  libraries must be explicitly enabled.

  Also note that the following help text describes the purpose of the libraries
  themselves, not all their features will necessarily be usable by FFmpeg.

  --disable-alsa           disable ALSA support [autodetect]
  --disable-appkit         disable Apple AppKit framework [autodetect]
  --disable-avfoundation   disable Apple AVFoundation framework [autodetect]
  --enable-avisynth        enable reading of AviSynth script files [no]
  --disable-bzlib          disable bzlib [autodetect]
  --disable-coreimage      disable Apple CoreImage framework [autodetect]
  --enable-chromaprint     enable audio fingerprinting with chromaprint [no]
  --enable-frei0r          enable frei0r video filtering [no]
  --enable-gcrypt          enable gcrypt, needed for rtmp(t)e support
                           if openssl, librtmp or gmp is not used [no]
  --enable-gmp             enable gmp, needed for rtmp(t)e support
                           if openssl or librtmp is not used [no]
  --enable-gnutls          enable gnutls, needed for https support
                           if openssl, libtls or mbedtls is not used [no]
  --disable-iconv          disable iconv [autodetect]
  --enable-jni             enable JNI support [no]
  --enable-ladspa          enable LADSPA audio filtering [no]
  --enable-lcms2           enable ICC profile support via LittleCMS 2 [no]
  --enable-libaom          enable AV1 video encoding/decoding via libaom [no]
  --enable-libaribb24      enable ARIB text and caption decoding via libaribb24 [no]
  --enable-libaribcaption  enable ARIB text and caption decoding via libaribcaption [no]
  --enable-libass          enable libass subtitles rendering,
                           needed for subtitles and ass filter [no]
  --enable-libbluray       enable BluRay reading using libbluray [no]
  --enable-libbs2b         enable bs2b DSP library [no]
  --enable-libcaca         enable textual display using libcaca [no]
  --enable-libcelt         enable CELT decoding via libcelt [no]
  --enable-libcdio         enable audio CD grabbing with libcdio [no]
  --enable-libcodec2       enable codec2 en/decoding using libcodec2 [no]
  --enable-libdav1d        enable AV1 decoding via libdav1d [no]
  --enable-libdavs2        enable AVS2 decoding via libdavs2 [no]
  --enable-libdc1394       enable IIDC-1394 grabbing using libdc1394
                           and libraw1394 [no]
  --enable-libdvdnav       enable libdvdnav, needed for DVD demuxing [no]
  --enable-libdvdread      enable libdvdread, needed for DVD demuxing [no]
  --enable-libfdk-aac      enable AAC de/encoding via libfdk-aac [no]
  --enable-libflite        enable flite (voice synthesis) support via libflite [no]
  --enable-libfontconfig   enable libfontconfig, useful for drawtext filter [no]
  --enable-libfreetype     enable libfreetype, needed for drawtext filter [no]
  --enable-libfribidi      enable libfribidi, improves drawtext filter [no]
  --enable-libharfbuzz     enable libharfbuzz, needed for drawtext filter [no]
  --enable-libglslang      enable GLSL->SPIRV compilation via libglslang [no]
  --enable-libgme          enable Game Music Emu via libgme [no]
  --enable-libgsm          enable GSM de/encoding via libgsm [no]
  --enable-libiec61883     enable iec61883 via libiec61883 [no]
  --enable-libilbc         enable iLBC de/encoding via libilbc [no]
  --enable-libjack         enable JACK audio sound server [no]
  --enable-libjxl          enable JPEG XL de/encoding via libjxl [no]
  --enable-libklvanc       enable Kernel Labs VANC processing [no]
  --enable-libkvazaar      enable HEVC encoding via libkvazaar [no]
  --enable-liblc3          enable LC3 de/encoding via liblc3 [no]
  --enable-liblcevc-dec    enable LCEVC decoding via liblcevc-dec [no]
  --enable-liblensfun      enable lensfun lens correction [no]
  --enable-libmodplug      enable ModPlug via libmodplug [no]
  --enable-libmp3lame      enable MP3 encoding via libmp3lame [no]
  --enable-libopencore-amrnb enable AMR-NB de/encoding via libopencore-amrnb [no]
  --enable-libopencore-amrwb enable AMR-WB decoding via libopencore-amrwb [no]
  --enable-libopencv       enable video filtering via libopencv [no]
  --enable-libopenh264     enable H.264 encoding via OpenH264 [no]
  --enable-libopenjpeg     enable JPEG 2000 encoding via OpenJPEG [no]
  --enable-libopenmpt      enable decoding tracked files via libopenmpt [no]
  --enable-libopenvino     enable OpenVINO as a DNN module backend
                           for DNN based filters like dnn_processing [no]
  --enable-libopus         enable Opus de/encoding via libopus [no]
  --enable-libplacebo      enable libplacebo library [no]
  --enable-libpulse        enable Pulseaudio input via libpulse [no]
  --enable-libqrencode     enable QR encode generation via libqrencode [no]
  --enable-libquirc        enable QR decoding via libquirc [no]
  --enable-librabbitmq     enable RabbitMQ library [no]
  --enable-librav1e        enable AV1 encoding via rav1e [no]
  --enable-librist         enable RIST via librist [no]
  --enable-librsvg         enable SVG rasterization via librsvg [no]
  --enable-librubberband   enable rubberband needed for rubberband filter [no]
  --enable-librtmp         enable RTMP[E] support via librtmp [no]
  --enable-libshaderc      enable GLSL->SPIRV compilation via libshaderc [no]
  --enable-libshine        enable fixed-point MP3 encoding via libshine [no]
  --enable-libsmbclient    enable Samba protocol via libsmbclient [no]
  --enable-libsnappy       enable Snappy compression, needed for hap encoding [no]
  --enable-libsoxr         enable Include libsoxr resampling [no]
  --enable-libspeex        enable Speex de/encoding via libspeex [no]
  --enable-libsrt          enable Haivision SRT protocol via libsrt [no]
  --enable-libssh          enable SFTP protocol via libssh [no]
  --enable-libsvtav1       enable AV1 encoding via SVT [no]
  --enable-libtensorflow   enable TensorFlow as a DNN module backend
                           for DNN based filters like sr [no]
  --enable-libtesseract    enable Tesseract, needed for ocr filter [no]
  --enable-libtheora       enable Theora encoding via libtheora [no]
  --enable-libtls          enable LibreSSL (via libtls), needed for https support
                           if openssl, gnutls or mbedtls is not used [no]
  --enable-libtorch        enable Torch as one DNN backend [no]
  --enable-libtwolame      enable MP2 encoding via libtwolame [no]
  --enable-libuavs3d       enable AVS3 decoding via libuavs3d [no]
  --enable-libv4l2         enable libv4l2/v4l-utils [no]
  --enable-libvidstab      enable video stabilization using vid.stab [no]
  --enable-libvmaf         enable vmaf filter via libvmaf [no]
  --enable-libvo-amrwbenc  enable AMR-WB encoding via libvo-amrwbenc [no]
  --enable-libvorbis       enable Vorbis en/decoding via libvorbis,
                           native implementation exists [no]
  --enable-libvpx          enable VP8 and VP9 de/encoding via libvpx [no]
  --enable-libvvenc        enable H.266/VVC encoding via vvenc [no]
  --enable-libwebp         enable WebP encoding via libwebp [no]
  --enable-libx264         enable H.264 encoding via x264 [no]
  --enable-libx265         enable HEVC encoding via x265 [no]
  --enable-libxeve         enable EVC encoding via libxeve [no]
  --enable-libxevd         enable EVC decoding via libxevd [no]
  --enable-libxavs         enable AVS encoding via xavs [no]
  --enable-libxavs2        enable AVS2 encoding via xavs2 [no]
  --enable-libxcb          enable X11 grabbing using XCB [autodetect]
  --enable-libxcb-shm      enable X11 grabbing shm communication [autodetect]
  --enable-libxcb-xfixes   enable X11 grabbing mouse rendering [autodetect]
  --enable-libxcb-shape    enable X11 grabbing shape rendering [autodetect]
  --enable-libxvid         enable Xvid encoding via xvidcore,
                           native MPEG-4/Xvid encoder exists [no]
  --enable-libxml2         enable XML parsing using the C library libxml2, needed
                           for dash and imf demuxing support [no]
  --enable-libzimg         enable z.lib, needed for zscale filter [no]
  --enable-libzmq          enable message passing via libzmq [no]
  --enable-libzvbi         enable teletext support via libzvbi [no]
  --enable-lv2             enable LV2 audio filtering [no]
  --disable-lzma           disable lzma [autodetect]
  --enable-decklink        enable Blackmagic DeckLink I/O support [no]
  --enable-mbedtls         enable mbedTLS, needed for https support
                           if openssl, gnutls or libtls is not used [no]
  --enable-mediacodec      enable Android MediaCodec support [no]
  --enable-mediafoundation enable encoding via MediaFoundation [auto]
  --disable-metal          disable Apple Metal framework [autodetect]
  --enable-libmysofa       enable libmysofa, needed for sofalizer filter [no]
  --enable-openal          enable OpenAL 1.1 capture support [no]
  --enable-opencl          enable OpenCL processing [no]
  --enable-opengl          enable OpenGL rendering [no]
  --enable-openssl         enable openssl, needed for https support
                           if gnutls, libtls or mbedtls is not used [no]
  --enable-pocketsphinx    enable PocketSphinx, needed for asr filter [no]
  --disable-sndio          disable sndio support [autodetect]
  --disable-schannel       disable SChannel SSP, needed for TLS support on
                           Windows if openssl and gnutls are not used [autodetect]
  --disable-sdl2           disable sdl2 [autodetect]
  --disable-securetransport disable Secure Transport, needed for TLS support
                           on OSX if openssl and gnutls are not used [autodetect]
  --enable-vapoursynth     enable VapourSynth demuxer [no]
  --disable-xlib           disable xlib [autodetect]
  --disable-zlib           disable zlib [autodetect]

  The following libraries provide various hardware acceleration features:
  --disable-amf            disable AMF video encoding code [autodetect]
  --disable-audiotoolbox   disable Apple AudioToolbox code [autodetect]
  --enable-cuda-nvcc       enable Nvidia CUDA compiler [no]
  --disable-cuda-llvm      disable CUDA compilation using clang [autodetect]
  --disable-cuvid          disable Nvidia CUVID support [autodetect]
  --disable-d3d11va        disable Microsoft Direct3D 11 video acceleration code [autodetect]
  --disable-d3d12va        disable Microsoft Direct3D 12 video acceleration code [autodetect]
  --disable-dxva2          disable Microsoft DirectX 9 video acceleration code [autodetect]
  --disable-ffnvcodec      disable dynamically linked Nvidia code [autodetect]
  --disable-libdrm         disable DRM code (Linux) [autodetect]
  --enable-libmfx          enable Intel MediaSDK (AKA Quick Sync Video) code via libmfx [no]
  --enable-libvpl          enable Intel oneVPL code via libvpl if libmfx is not used [no]
  --enable-libnpp          enable Nvidia Performance Primitives-based code [no]
  --enable-mmal            enable Broadcom Multi-Media Abstraction Layer (Raspberry Pi) via MMAL [no]
  --disable-nvdec          disable Nvidia video decoding acceleration (via hwaccel) [autodetect]
  --disable-nvenc          disable Nvidia video encoding code [autodetect]
  --enable-omx             enable OpenMAX IL code [no]
  --enable-omx-rpi         enable OpenMAX IL code for Raspberry Pi [no]
  --enable-rkmpp           enable Rockchip Media Process Platform code [no]
  --disable-v4l2-m2m       disable V4L2 mem2mem code [autodetect]
  --disable-vaapi          disable Video Acceleration API (mainly Unix/Intel) code [autodetect]
  --disable-vdpau          disable Nvidia Video Decode and Presentation API for Unix code [autodetect]
  --disable-videotoolbox   disable VideoToolbox code [autodetect]
  --disable-vulkan         disable Vulkan code [autodetect]

Toolchain options:
  --arch=ARCH              select architecture []
  --cpu=CPU                select the minimum required CPU (affects
                           instruction selection, may crash on older CPUs)
  --cross-prefix=PREFIX    use PREFIX for compilation tools []
  --progs-suffix=SUFFIX    program name suffix []
  --enable-cross-compile   assume a cross-compiler is used
  --sysroot=PATH           root of cross-build tree
  --sysinclude=PATH        location of cross-build system headers
  --target-os=OS           compiler targets OS []
  --target-exec=CMD        command to run executables on target
  --target-path=DIR        path to view of build directory on target
  --target-samples=DIR     path to samples directory on target
  --tempprefix=PATH        force fixed dir/prefix instead of mktemp for checks
  --toolchain=NAME         set tool defaults according to NAME
                           (gcc-asan, clang-asan, gcc-msan, clang-msan,
                           gcc-tsan, clang-tsan, gcc-usan, clang-usan,
                           valgrind-massif, valgrind-memcheck,
                           msvc, icl, gcov, llvm-cov, hardened)
  --nm=NM                  use nm tool NM [nm -g]
  --ar=AR                  use archive tool AR [ar]
  --as=AS                  use assembler AS []
  --ln_s=LN_S              use symbolic link tool LN_S [ln -s -f]
  --strip=STRIP            use strip tool STRIP [strip]
  --windres=WINDRES        use windows resource compiler WINDRES [windres]
  --x86asmexe=EXE          use nasm-compatible assembler EXE [nasm]
  --cc=CC                  use C compiler CC [gcc]
  --stdc=STDC              use C standard STDC [c17]
  --cxx=CXX                use C compiler CXX [g++]
  --stdcxx=STDCXX          use C standard STDCXX [c++11]
  --objcc=OCC              use ObjC compiler OCC [gcc]
  --dep-cc=DEPCC           use dependency generator DEPCC [gcc]
  --nvcc=NVCC              use Nvidia CUDA compiler NVCC or clang []
  --ld=LD                  use linker LD []
  --metalcc=METALCC        use metal compiler METALCC [xcrun -sdk macosx metal]
  --metallib=METALLIB      use metal linker METALLIB [xcrun -sdk macosx metallib]
  --pkg-config=PKGCONFIG   use pkg-config tool PKGCONFIG [pkg-config]
  --pkg-config-flags=FLAGS pass additional flags to pkgconf []
  --ranlib=RANLIB          use ranlib RANLIB [ranlib]
  --doxygen=DOXYGEN        use DOXYGEN to generate API doc [doxygen]
  --host-cc=HOSTCC         use host C compiler HOSTCC
  --host-cflags=HCFLAGS    use HCFLAGS when compiling for host
  --host-cppflags=HCPPFLAGS use HCPPFLAGS when compiling for host
  --host-ld=HOSTLD         use host linker HOSTLD
  --host-ldflags=HLDFLAGS  use HLDFLAGS when linking for host
  --host-extralibs=HLIBS   use libs HLIBS when linking for host
  --host-os=OS             compiler host OS []
  --extra-cflags=ECFLAGS   add ECFLAGS to CFLAGS []
  --extra-cxxflags=ECFLAGS add ECFLAGS to CXXFLAGS []
  --extra-objcflags=FLAGS  add FLAGS to OBJCFLAGS []
  --extra-ldflags=ELDFLAGS add ELDFLAGS to LDFLAGS []
  --extra-ldexeflags=ELDFLAGS add ELDFLAGS to LDEXEFLAGS []
  --extra-ldsoflags=ELDFLAGS add ELDFLAGS to LDSOFLAGS []
  --extra-libs=ELIBS       add ELIBS []
  --extra-version=STRING   version string suffix []
  --optflags=OPTFLAGS      override optimization-related compiler flags
  --nvccflags=NVCCFLAGS    override nvcc flags []
  --build-suffix=SUFFIX    library name suffix []
  --enable-pic             build position-independent code
  --enable-thumb           compile for Thumb instruction set
  --enable-lto[=arg]       use link-time optimization
  --env="ENV=override"     override the environment variables

Advanced options (experts only):
  --malloc-prefix=PREFIX   prefix malloc and related names with PREFIX
  --custom-allocator=NAME  use a supported custom allocator
  --disable-symver         disable symbol versioning
  --enable-hardcoded-tables use hardcoded tables instead of runtime generation
  --disable-safe-bitstream-reader
                           disable buffer boundary checking in bitreaders
                           (faster, but may crash)
  --sws-max-filter-size=N  the max filter size swscale uses [256]

Optimization options (experts only):
  --disable-asm            disable all assembly optimizations
  --disable-altivec        disable AltiVec optimizations
  --disable-vsx            disable VSX optimizations
  --disable-power8         disable POWER8 optimizations
  --disable-amd3dnow       disable 3DNow! optimizations
  --disable-amd3dnowext    disable 3DNow! extended optimizations
  --disable-mmx            disable MMX optimizations
  --disable-mmxext         disable MMXEXT optimizations
  --disable-sse            disable SSE optimizations
  --disable-sse2           disable SSE2 optimizations
  --disable-sse3           disable SSE3 optimizations
  --disable-ssse3          disable SSSE3 optimizations
  --disable-sse4           disable SSE4 optimizations
  --disable-sse42          disable SSE4.2 optimizations
  --disable-avx            disable AVX optimizations
  --disable-xop            disable XOP optimizations
  --disable-fma3           disable FMA3 optimizations
  --disable-fma4           disable FMA4 optimizations
  --disable-avx2           disable AVX2 optimizations
  --disable-avx512         disable AVX-512 optimizations
  --disable-avx512icl      disable AVX-512ICL optimizations
  --disable-aesni          disable AESNI optimizations
  --disable-armv5te        disable armv5te optimizations
  --disable-armv6          disable armv6 optimizations
  --disable-armv6t2        disable armv6t2 optimizations
  --disable-vfp            disable VFP optimizations
  --disable-neon           disable NEON optimizations
  --disable-dotprod        disable DOTPROD optimizations
  --disable-i8mm           disable I8MM optimizations
  --disable-inline-asm     disable use of inline assembly
  --disable-x86asm         disable use of standalone x86 assembly
  --disable-mipsdsp        disable MIPS DSP ASE R1 optimizations
  --disable-mipsdspr2      disable MIPS DSP ASE R2 optimizations
  --disable-msa            disable MSA optimizations
  --disable-mipsfpu        disable floating point MIPS optimizations
  --disable-mmi            disable Loongson MMI optimizations
  --disable-lsx            disable Loongson LSX optimizations
  --disable-lasx           disable Loongson LASX optimizations
  --disable-rvv            disable RISC-V Vector optimizations
  --disable-fast-unaligned consider unaligned accesses slow

Developer options (useful when working on FFmpeg itself):
  --disable-debug          disable debugging symbols
  --enable-debug=LEVEL     set the debug level []
  --disable-optimizations  disable compiler optimizations
  --enable-extra-warnings  enable more compiler warnings
  --disable-stripping      disable stripping of executables and shared libraries
  --assert-level=level     0(default), 1 or 2, amount of assertion testing,
                           2 causes a slowdown at runtime.
  --enable-memory-poisoning fill heap uninitialized allocated space with arbitrary data
  --valgrind=VALGRIND      run "make fate" tests through valgrind to detect memory
                           leaks and errors, using the specified valgrind binary.
                           Cannot be combined with --target-exec
  --enable-ftrapv          Trap arithmetic overflows
  --samples=PATH           location of test samples for FATE, if not set use
                           $FATE_SAMPLES at make invocation time.
  --enable-neon-clobber-test check NEON registers for clobbering (should be
                           used only for debugging purposes)
  --enable-xmm-clobber-test check XMM registers for clobbering (Win64-only;
                           should be used only for debugging purposes)
  --enable-random          randomly enable/disable components
  --disable-random
  --enable-random=LIST     randomly enable/disable specific components or
  --disable-random=LIST    component groups. LIST is a comma-separated list
                           of NAME[:PROB] entries where NAME is a component
                           (group) and PROB the probability associated with
                           NAME (default 0.5).
  --random-seed=VALUE      seed value for --enable/disable-random
  --disable-valgrind-backtrace do not print a backtrace under Valgrind
                           (only applies to --disable-optimizations builds)
  --enable-ossfuzz         Enable building fuzzer tool
  --libfuzzer=PATH         path to libfuzzer
  --ignore-tests=TESTS     comma-separated list (without "fate-" prefix
                           in the name) of tests whose result is ignored
  --enable-linux-perf      enable Linux Performance Monitor API
  --enable-macos-kperf     enable macOS kperf (private) API
  --disable-large-tests    disable tests that use a large amount of memory
  --disable-ptx-compression don't compress CUDA PTX code even when possible
  --disable-version-tracking don't include the git/release version in the build

NOTE: Object files are built at the place where configure is launched.

如果.configure --list-encoders打印出来的一长串编码器里面没有你要的,可以尝试升级FFMpeg的版本试试,新版本可能会支持新的编码器。比如我这里的目标是想要支持av1_mediacodec

现在我们改一下FFMepg的版本号,打开scripts/source.sh这个文件,找到get_library_source这个函数:

#
# 1. library name
# 2. source type 1/2/3
#
get_library_source() {
  case $1 in
  config)
    SOURCE_REPO_URL="https://github.com/arthenica/gnu-config"
    SOURCE_ID="v20210814"
    SOURCE_TYPE="TAG"
    ;;
  chromaprint)
    SOURCE_REPO_URL="https://github.com/arthenica/chromaprint"
    SOURCE_ID="v1.5.1"
    SOURCE_TYPE="TAG"
    ;;
  cpu-features)
    SOURCE_REPO_URL="https://github.com/arthenica/cpu_features"
    SOURCE_ID="v0.8.0"
    SOURCE_TYPE="TAG"
    ;;
  dav1d)
    SOURCE_REPO_URL="https://github.com/arthenica/dav1d"
    SOURCE_ID="1.2.1"
    SOURCE_TYPE="TAG"
    ;;
  expat)
    SOURCE_REPO_URL="https://github.com/arthenica/libexpat"
    SOURCE_ID="R_2_5_0"
    SOURCE_TYPE="TAG"
    ;;
  ffmpeg)
    SOURCE_REPO_URL="https://github.com/arthenica/FFmpeg"
    SOURCE_ID="n7.1"    <------改这个
    SOURCE_TYPE="TAG"
    ;;
  fontconfig)
    SOURCE_REPO_URL="https://github.com/arthenica/fontconfig"
    SOURCE_ID="2.14.2"
    SOURCE_TYPE="TAG"
    ;;
  freetype)
    SOURCE_REPO_URL="https://github.com/arthenica/freetype2"
    SOURCE_ID="VER-2-13-0"
    SOURCE_TYPE="TAG"
    ;;
  fribidi)
    SOURCE_REPO_URL="https://github.com/arthenica/fribidi"
    SOURCE_ID="v1.0.13"
    SOURCE_TYPE="TAG"
    ;;
  giflib)
    SOURCE_REPO_URL="https://github.com/arthenica/giflib"
    SOURCE_ID="5.2.1"
    SOURCE_TYPE="TAG"
    ;;
  gmp)
    SOURCE_REPO_URL="https://github.com/arthenica/gmp"
    SOURCE_ID="v6.2.1"
    SOURCE_TYPE="TAG"
    ;;
  gnutls)
    SOURCE_REPO_URL="https://github.com/arthenica/gnutls"
    SOURCE_ID="3.7.9"
    SOURCE_TYPE="TAG"
    ;;
  harfbuzz)
    SOURCE_REPO_URL="https://github.com/arthenica/harfbuzz"
    SOURCE_ID="8.0.1"
    SOURCE_TYPE="TAG"
    ;;
  jpeg)
    SOURCE_REPO_URL="https://github.com/arthenica/libjpeg-turbo"
    SOURCE_ID="3.0.0"
    SOURCE_TYPE="TAG"
    ;;
  kvazaar)
    SOURCE_REPO_URL="https://github.com/arthenica/kvazaar"
    SOURCE_ID="v2.2.0"
    SOURCE_TYPE="TAG"
    ;;
  lame)
    SOURCE_REPO_URL="https://github.com/arthenica/lame"
    SOURCE_ID="RELEASE__3_100"
    SOURCE_TYPE="TAG"
    ;;
  leptonica)
    SOURCE_REPO_URL="https://github.com/arthenica/leptonica"
    SOURCE_ID="1.83.1"
    SOURCE_TYPE="TAG"
    ;;
  libaom)
    SOURCE_REPO_URL="https://github.com/arthenica/libaom"
    SOURCE_ID="v3.6.1"
    SOURCE_TYPE="TAG"
    ;;
    ................................

SOURCE_REPO_URL是仓库地址
SOURCE_ID是TAG或分支的名字
SOURCE_TYPE是根据TAG还是根据分支确定版本
改完版本以后跑脚本的时候要加个--redownload-ffmpeg,不然版本不会变,还是旧的。
默认的ffmpeg是n6.0,我给改成n7.1了,但编译有点问题,详见后面的疑难杂症章节。

疑难杂症

dav1d库编译报错

报错如下

The Meson build system
Version: 0.53.2
Source dir: ~/ffmpeg-kit/src/dav1d
Build dir: ~/ffmpeg-kit/.tmp/cmake/build/android-arm64/dav1d
Build type: cross build
Project name: dav1d
Project version: 1.2.1
Appending CFLAGS from environment: '-march=armv8-a -DFFMPEG_KIT_ARM64_V8A -std=c99 -Wno-unused-function -fno-integrated-as -fstrict-aliasing -DANDROID_NDK -fPIC -DANDROID -D__ANDROID__ -D__ANDROID_API__=24 -Os -ffunction-sections -fdata-sections  '
Appending LDFLAGS from environment: ['-march=armv8-a', '-Wl,--gc-sections', '-Os', '-ffunction-sections', '-fdata-sections', '-lc', '-lm', '-ldl', '-llog', '-L~/Android/Sdk/ndk/22.0.6917172/toolchains/llvm/prebuilt/linux-x86_64/aarch64-linux-android/lib', '-L~/Android/Sdk/ndk/22.0.6917172/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/24', '-L~/Android/Sdk/ndk/22.0.6917172/toolchains/llvm/prebuilt/linux-x86_64/lib', '-Wl,--hash-style=both', '-Wl,--exclude-libs,libgcc.a', '-Wl,--exclude-libs,libunwind.a']

meson.build:25:0: ERROR: Could not invoke sanity test executable: [Errno 8] Exec format error: '~/ffmpeg-kit/.tmp/cmake/build/android-arm64/dav1d/meson-private/sanitycheckc.exe'.


Build started at 2024-11-19T14:13:25.654470
Main binary: /usr/bin/python3
Build Options: -Db_lto=false -Db_ndebug=false -Denable_asm=false -Denable_tools=false -Denable_examples=false -Denable_tests=false '--cross-file ~/ffmpeg-kit/src/dav1d/package/crossfiles/arm64-v8a-android.meson'
Python system: Linux
The Meson build system
Version: 0.53.2
Source dir: ~/ffmpeg-kit/src/dav1d
Build dir: ~/ffmpeg-kit/.tmp/cmake/build/android-arm64/dav1d
Build type: cross build
Project name: dav1d
Project version: 1.2.1
Appending CFLAGS from environment: '-march=armv8-a -DFFMPEG_KIT_ARM64_V8A -std=c99 -Wno-unused-function -fno-integrated-as -fstrict-aliasing -DANDROID_NDK -fPIC -DANDROID -D__ANDROID__ -D__ANDROID_API__=24 -Os -ffunction-sections -fdata-sections  '
Appending LDFLAGS from environment: ['-march=armv8-a', '-Wl,--gc-sections', '-Os', '-ffunction-sections', '-fdata-sections', '-lc', '-lm', '-ldl', '-llog', '-L~/Android/Sdk/ndk/22.0.6917172/toolchains/llvm/prebuilt/linux-x86_64/aarch64-linux-android/lib', '-L~/Android/Sdk/ndk/22.0.6917172/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/24', '-L~/Android/Sdk/ndk/22.0.6917172/toolchains/llvm/prebuilt/linux-x86_64/lib', '-Wl,--hash-style=both', '-Wl,--exclude-libs,libgcc.a', '-Wl,--exclude-libs,libunwind.a']
No CPPFLAGS in the environment, not changing global flags.
Sanity testing C compiler: aarch64-linux-android24-clang
Is cross compiler: False.
Sanity check compiler command line: aarch64-linux-android24-clang ~/ffmpeg-kit/.tmp/cmake/build/android-arm64/dav1d/meson-private/sanitycheckc.c -o ~/ffmpeg-kit/.tmp/cmake/build/android-arm64/dav1d/meson-private/sanitycheckc.exe -march=armv8-a -DFFMPEG_KIT_ARM64_V8A -std=c99 -Wno-unused-function -fno-integrated-as -fstrict-aliasing -DANDROID_NDK -fPIC -DANDROID -D__ANDROID__ -D__ANDROID_API__=24 -Os -ffunction-sections -fdata-sections -pipe -D_FILE_OFFSET_BITS=64 -Wl,--gc-sections -lc -lm -ldl -llog -L~/Android/Sdk/ndk/22.0.6917172/toolchains/llvm/prebuilt/linux-x86_64/aarch64-linux-android/lib -L~/Android/Sdk/ndk/22.0.6917172/toolchains/llvm/prebuilt/linux-x86_64/sysroot/usr/lib/aarch64-linux-android/24 -L~/Android/Sdk/ndk/22.0.6917172/toolchains/llvm/prebuilt/linux-x86_64/lib -Wl,--hash-style=both -Wl,--exclude-libs,libgcc.a -Wl,--exclude-libs,libunwind.a
Sanity check compile stdout:

-----
Sanity check compile stderr:

-----
Running test binary command: ~/ffmpeg-kit/.tmp/cmake/build/android-arm64/dav1d/meson-private/sanitycheckc.exe

meson.build:25:0: ERROR: Could not invoke sanity test executable: [Errno 8] Exec format error: '~/ffmpeg-kit/.tmp/cmake/build/android-arm64/dav1d/meson-private/sanitycheckc.exe'.

原因:大概是说尝试运行这个文件的时候报错了,暂时没找到解决办法。不过这是个软解库,直接放弃也问题不大。

ffmpeg提示缺文件

错误信息

无法获取'/home/dubhe/ffmpeg-kit/src/ffmpeg/libavutil/x86/emms.h'

它找的这个文件本来就不存在,我们编译arm64不应该去x86目录下找文件。原因是编译脚本有问题,打开scripts/android/ffmpeg.sh这个文件修改ffmpeg的编译参数,找到这坨代码

./configure \
  --cross-prefix="${HOST}-" \
  --sysroot="${ANDROID_SYSROOT}" \
  --prefix="${FFMPEG_LIBRARY_PATH}" \
  --pkg-config="${HOST_PKG_CONFIG_PATH}" \
  --enable-version3 \
  --arch="${TARGET_ARCH}" \
  --cpu="${TARGET_CPU}" \
  --target-os=android \
  ${ASM_OPTIONS} \
  --ar="${AR}" \
  --cc="${CC}" \
  --cxx="${CXX}" \
  --ranlib="${RANLIB}" \
  --strip="${STRIP}" \
  --nm="${NM}" \
  --extra-libs="$(pkg-config --libs --static cpu-features)" \
  --disable-autodetect \
  --enable-cross-compile \
  --enable-pic \
  --enable-jni \
  --enable-optimizations \
  --enable-swscale \
  ${BUILD_LIBRARY_OPTIONS} \
  --enable-pthreads \
  --enable-v4l2-m2m \
  --disable-outdev=fbdev \
  --disable-indev=fbdev \
  ${SIZE_OPTIONS} \
  --disable-xmm-clobber-test \
  ${DEBUG_OPTIONS} \
  --disable-neon-clobber-test \
  --disable-programs \
  --disable-postproc \
  --disable-doc \
  --disable-htmlpages \
  --disable-manpages \
  --disable-podpages \
  --disable-txtpages \
  --disable-sndio \
  --disable-schannel \
  --disable-securetransport \
  --disable-xlib \
  --disable-cuda \
  --disable-cuvid \
  --disable-nvenc \
  --disable-vaapi \
  --disable-vdpau \
  --disable-videotoolbox \
  --disable-audiotoolbox \
  --disable-appkit \
  --disable-alsa \
  --disable-cuda \
  --disable-cuvid \
  --disable-nvenc \
  --disable-vaapi \
  --disable-vdpau \
  --disable-x86asm \   <-----添加这两行
  --disable-runtime-cpudetect \    <-----添加这两行
  ${CONFIGURE_POSTFIX} 1>>"${BASEDIR}"/build.log 2>&1

然后往下找到# MANUALLY ADD REQUIRED HEADERS这段注释,能看到它根本没管现在到底目标是什么架构就闭着眼睛把每个架构都去build了一遍。

# MANUALLY ADD REQUIRED HEADERS mkdir -p "${FFMPEG_LIBRARY_PATH}"/include/libavutil/x86 
1>>"${BASEDIR}"/build.log 2>&1 mkdir -p "${FFMPEG_LIBRARY_PATH}"/include/libavutil/arm 
1>>"${BASEDIR}"/build.log 2>&1 mkdir -p "${FFMPEG_LIBRARY_PATH}"/include/libavutil/aarch64 
1>>"${BASEDIR}"/build.log 2>&1 mkdir -p "${FFMPEG_LIBRARY_PATH}"/include/libavcodec/x86 
1>>"${BASEDIR}"/build.log 2>&1 mkdir -p "${FFMPEG_LIBRARY_PATH}"/include/libavcodec/arm 
1>>"${BASEDIR}"/build.log 2>&1 overwrite_file "${BASEDIR}"/src/ffmpeg/config.h 
"${FFMPEG_LIBRARY_PATH}"/include/config.h 1>>"${BASEDIR}"/build.log 2>&1 overwrite_file 
"${BASEDIR}"/src/ffmpeg/libavcodec/mathops.h 
"${FFMPEG_LIBRARY_PATH}"/include/libavcodec/mathops.h 1>>"${BASEDIR}"/build.log 2>&1 
overwrite_file "${BASEDIR}"/src/ffmpeg/libavcodec/x86/mathops.h 
"${FFMPEG_LIBRARY_PATH}"/include/libavcodec/x86/mathops.h 1>>"${BASEDIR}"/build.log 2>&1 
overwrite_file "${BASEDIR}"/src/ffmpeg/libavcodec/arm/mathops.h 
"${FFMPEG_LIBRARY_PATH}"/include/libavcodec/arm/mathops.h 1>>"${BASEDIR}"/build.log 2>&1 
overwrite_file "${BASEDIR}"/src/ffmpeg/libavformat/network.h 
"${FFMPEG_LIBRARY_PATH}"/include/libavformat/network.h 1>>"${BASEDIR}"/build.log 2>&1 
overwrite_file "${BASEDIR}"/src/ffmpeg/libavformat/os_support.h 
"${FFMPEG_LIBRARY_PATH}"/include/libavformat/os_support.h 1>>"${BASEDIR}"/build.log 2>&1 
overwrite_file "${BASEDIR}"/src/ffmpeg/libavformat/url.h 
"${FFMPEG_LIBRARY_PATH}"/include/libavformat/url.h 1>>"${BASEDIR}"/build.log 2>&1 
overwrite_file "${BASEDIR}"/src/ffmpeg/libavutil/attributes_internal.h 
"${FFMPEG_LIBRARY_PATH}"/include/libavutil/attributes_internal.h 1>>"${BASEDIR}"/build.log 2>&1 
overwrite_file "${BASEDIR}"/src/ffmpeg/libavutil/bprint.h 
"${FFMPEG_LIBRARY_PATH}"/include/libavutil/bprint.h 1>>"${BASEDIR}"/build.log 2>&1 
overwrite_file "${BASEDIR}"/src/ffmpeg/libavutil/getenv_utf8.h 
"${FFMPEG_LIBRARY_PATH}"/include/libavutil/getenv_utf8.h 1>>"${BASEDIR}"/build.log 2>&1 
overwrite_file "${BASEDIR}"/src/ffmpeg/libavutil/internal.h 
"${FFMPEG_LIBRARY_PATH}"/include/libavutil/internal.h 1>>"${BASEDIR}"/build.log 2>&1 
overwrite_file "${BASEDIR}"/src/ffmpeg/libavutil/libm.h 
"${FFMPEG_LIBRARY_PATH}"/include/libavutil/libm.h 1>>"${BASEDIR}"/build.log 2>&1 overwrite_file 
"${BASEDIR}"/src/ffmpeg/libavutil/reverse.h 
"${FFMPEG_LIBRARY_PATH}"/include/libavutil/reverse.h 1>>"${BASEDIR}"/build.log 2>&1 
overwrite_file "${BASEDIR}"/src/ffmpeg/libavutil/thread.h 
"${FFMPEG_LIBRARY_PATH}"/include/libavutil/thread.h 1>>"${BASEDIR}"/build.log 2>&1 
overwrite_file "${BASEDIR}"/src/ffmpeg/libavutil/timer.h 
"${FFMPEG_LIBRARY_PATH}"/include/libavutil/timer.h 1>>"${BASEDIR}"/build.log 2>&1 
overwrite_file "${BASEDIR}"/src/ffmpeg/libavutil/x86/asm.h 
"${FFMPEG_LIBRARY_PATH}"/include/libavutil/x86/asm.h 1>>"${BASEDIR}"/build.log 2>&1 
overwrite_file "${BASEDIR}"/src/ffmpeg/libavutil/x86/timer.h 
"${FFMPEG_LIBRARY_PATH}"/include/libavutil/x86/timer.h 1>>"${BASEDIR}"/build.log 2>&1 
overwrite_file "${BASEDIR}"/src/ffmpeg/libavutil/arm/timer.h 
"${FFMPEG_LIBRARY_PATH}"/include/libavutil/arm/timer.h 1>>"${BASEDIR}"/build.log 2>&1 
overwrite_file "${BASEDIR}"/src/ffmpeg/libavutil/aarch64/timer.h 
"${FFMPEG_LIBRARY_PATH}"/include/libavutil/aarch64/timer.h 1>>"${BASEDIR}"/build.log 2>&1 
overwrite_file "${BASEDIR}"/src/ffmpeg/libavutil/x86/emms.h 
"${FFMPEG_LIBRARY_PATH}"/include/libavutil/x86/emms.h 1>>"${BASEDIR}"/build.log 2>&1

给它改成根据当前选择的架构来build

# MANUALLY ADD REQUIRED HEADERS
# 根据当前架构判断并选择性创建对应的头文件目录
if [[ "$ARCH" == "arm" ]]; then
  mkdir -p "${FFMPEG_LIBRARY_PATH}"/include/libavutil/arm 1>>"${BASEDIR}"/build.log 2>&1
  mkdir -p "${FFMPEG_LIBRARY_PATH}"/include/libavcodec/arm 1>>"${BASEDIR}"/build.log 2>&1
  overwrite_file "${BASEDIR}"/src/ffmpeg/libavcodec/arm/mathops.h "${FFMPEG_LIBRARY_PATH}"/include/libavcodec/arm/mathops.h 1>>"${BASEDIR}"/build.log 2>&1
  overwrite_file "${BASEDIR}"/src/ffmpeg/libavutil/arm/timer.h "${FFMPEG_LIBRARY_PATH}"/include/libavutil/arm/timer.h 1>>"${BASEDIR}"/build.log 2>&1
elif [[ "$ARCH" == "arm64-v8a" ]]; then
  mkdir -p "${FFMPEG_LIBRARY_PATH}"/include/libavutil/aarch64 1>>"${BASEDIR}"/build.log 2>&1
  overwrite_file "${BASEDIR}"/src/ffmpeg/libavutil/aarch64/timer.h "${FFMPEG_LIBRARY_PATH}"/include/libavutil/aarch64/timer.h 1>>"${BASEDIR}"/build.log 2>&1
elif [[ "$ARCH" == "x86" ]]; then
  mkdir -p "${FFMPEG_LIBRARY_PATH}"/include/libavutil/x86 1>>"${BASEDIR}"/build.log 2>&1
  mkdir -p "${FFMPEG_LIBRARY_PATH}"/include/libavcodec/x86 1>>"${BASEDIR}"/build.log 2>&1
  overwrite_file "${BASEDIR}"/src/ffmpeg/libavcodec/x86/mathops.h "${FFMPEG_LIBRARY_PATH}"/include/libavcodec/x86/mathops.h 1>>"${BASEDIR}"/build.log 2>&1
  overwrite_file "${BASEDIR}"/src/ffmpeg/libavutil/x86/asm.h "${FFMPEG_LIBRARY_PATH}"/include/libavutil/x86/asm.h 1>>"${BASEDIR}"/build.log 2>&1
  overwrite_file "${BASEDIR}"/src/ffmpeg/libavutil/x86/timer.h "${FFMPEG_LIBRARY_PATH}"/include/libavutil/x86/timer.h 1>>"${BASEDIR}"/build.log 2>&1
  overwrite_file "${BASEDIR}"/src/ffmpeg/libavutil/x86/emms.h "${FFMPEG_LIBRARY_PATH}"/include/libavutil/x86/emms.h 1>>"${BASEDIR}"/build.log 2>&1
else
  echo "Unsupported architecture: $ARCH" 1>>"${BASEDIR}"/build.log 2>&1
  exit 1
fi

overwrite_file "${BASEDIR}"/src/ffmpeg/config.h "${FFMPEG_LIBRARY_PATH}"/include/config.h 1>>"${BASEDIR}"/build.log 2>&1
overwrite_file "${BASEDIR}"/src/ffmpeg/libavcodec/mathops.h "${FFMPEG_LIBRARY_PATH}"/include/libavcodec/mathops.h 1>>"${BASEDIR}"/build.log 2>&1
overwrite_file "${BASEDIR}"/src/ffmpeg/libavformat/network.h "${FFMPEG_LIBRARY_PATH}"/include/libavformat/network.h 1>>"${BASEDIR}"/build.log 2>&1
overwrite_file "${BASEDIR}"/src/ffmpeg/libavformat/os_support.h "${FFMPEG_LIBRARY_PATH}"/include/libavformat/os_support.h 1>>"${BASEDIR}"/build.log 2>&1
overwrite_file "${BASEDIR}"/src/ffmpeg/libavformat/url.h "${FFMPEG_LIBRARY_PATH}"/include/libavformat/url.h 1>>"${BASEDIR}"/build.log 2>&1
overwrite_file "${BASEDIR}"/src/ffmpeg/libavutil/attributes_internal.h "${FFMPEG_LIBRARY_PATH}"/include/libavutil/attributes_internal.h 1>>"${BASEDIR}"/build.log 2>&1
overwrite_file "${BASEDIR}"/src/ffmpeg/libavutil/bprint.h "${FFMPEG_LIBRARY_PATH}"/include/libavutil/bprint.h 1>>"${BASEDIR}"/build.log 2>&1
overwrite_file "${BASEDIR}"/src/ffmpeg/libavutil/getenv_utf8.h "${FFMPEG_LIBRARY_PATH}"/include/libavutil/getenv_utf8.h 1>>"${BASEDIR}"/build.log 2>&1
overwrite_file "${BASEDIR}"/src/ffmpeg/libavutil/internal.h "${FFMPEG_LIBRARY_PATH}"/include/libavutil/internal.h 1>>"${BASEDIR}"/build.log 2>&1
overwrite_file "${BASEDIR}"/src/ffmpeg/libavutil/libm.h "${FFMPEG_LIBRARY_PATH}"/include/libavutil/libm.h 1>>"${BASEDIR}"/build.log 2>&1
overwrite_file "${BASEDIR}"/src/ffmpeg/libavutil/reverse.h "${FFMPEG_LIBRARY_PATH}"/include/libavutil/reverse.h 1>>"${BASEDIR}"/build.log 2>&1
overwrite_file "${BASEDIR}"/src/ffmpeg/libavutil/thread.h "${FFMPEG_LIBRARY_PATH}"/include/libavutil/thread.h 1>>"${BASEDIR}"/build.log 2>&1
overwrite_file "${BASEDIR}"/src/ffmpeg/libavutil/timer.h "${FFMPEG_LIBRARY_PATH}"/include/libavutil/timer.h 1>>"${BASEDIR}"/build.log 2>&1

ffmpeg-kit报找不到头文件

报错信息

[arm64-v8a] Compile        : ffmpegkit <= ffmpegkit.c
[arm64-v8a] Compile        : ffmpegkit <= ffprobekit.c
jni/../ffmpeg-kit-android-lib/src/main/cpp/ffprobekit.c:68:49: error: implicitly declaring library function 'strlen' with type 'unsigned long (const char *)' [-Werror,-Wimplicit-function-declaration]
    argv[0] = (char *)av_malloc(sizeof(char) * (strlen(LIB_NAME) + 1));
                                                ^
jni/../ffmpeg-kit-android-lib/src/main/cpp/ffprobekit.c:68:49: note: include the header <string.h> or explicitly provide a declaration for 'strlen'
jni/../ffmpeg-kit-android-lib/src/main/cpp/ffprobekit.c:69:5: error: implicitly declaring library function 'strcpy' with type 'char *(char *, const char *)' [-Werror,-Wimplicit-function-declaration]
    strcpy(argv[0], LIB_NAME);
    ^
jni/../ffmpeg-kit-android-lib/src/main/cpp/ffprobekit.c:69:5: note: include the header <string.h> or explicitly provide a declaration for 'strcpy'
2 errors generated.
make: *** [/home/dubhe/Android/Sdk/ndk/22.0.6917172/build/core/build-binary.mk:476: obj/local/arm64-v8a/objs/ffmpegkit/ffprobekit.o] Error 1

缺个头文件,手动加一下,打开android/ffmpeg-kit-android-lib/src/main/cpp/ffprobekit.c这个文件,在开头的一堆include里面加入

#include <string.h>

运行Demo

编译完成后,把aar丢到上篇文章的demo里,直接运行即可。
在Demo运行起来的Activity里输入--encoders即可看到支持的编码器。

©著作权归作者所有,转载或内容合作请联系作者
  • 序言:七十年代末,一起剥皮案震惊了整个滨河市,随后出现的几起案子,更是在滨河造成了极大的恐慌,老刑警刘岩,带你破解...
    沈念sama阅读 214,875评论 6 496
  • 序言:滨河连续发生了三起死亡事件,死亡现场离奇诡异,居然都是意外死亡,警方通过查阅死者的电脑和手机,发现死者居然都...
    沈念sama阅读 91,569评论 3 389
  • 文/潘晓璐 我一进店门,熙熙楼的掌柜王于贵愁眉苦脸地迎上来,“玉大人,你说我怎么就摊上这事。” “怎么了?”我有些...
    开封第一讲书人阅读 160,475评论 0 350
  • 文/不坏的土叔 我叫张陵,是天一观的道长。 经常有香客问我,道长,这世上最难降的妖魔是什么? 我笑而不...
    开封第一讲书人阅读 57,459评论 1 288
  • 正文 为了忘掉前任,我火速办了婚礼,结果婚礼上,老公的妹妹穿的比我还像新娘。我一直安慰自己,他们只是感情好,可当我...
    茶点故事阅读 66,537评论 6 386
  • 文/花漫 我一把揭开白布。 她就那样静静地躺着,像睡着了一般。 火红的嫁衣衬着肌肤如雪。 梳的纹丝不乱的头发上,一...
    开封第一讲书人阅读 50,563评论 1 293
  • 那天,我揣着相机与录音,去河边找鬼。 笑死,一个胖子当着我的面吹牛,可吹牛的内容都是我干的。 我是一名探鬼主播,决...
    沈念sama阅读 39,580评论 3 414
  • 文/苍兰香墨 我猛地睁开眼,长吁一口气:“原来是场噩梦啊……” “哼!你这毒妇竟也来了?” 一声冷哼从身侧响起,我...
    开封第一讲书人阅读 38,326评论 0 270
  • 序言:老挝万荣一对情侣失踪,失踪者是张志新(化名)和其女友刘颖,没想到半个月后,有当地人在树林里发现了一具尸体,经...
    沈念sama阅读 44,773评论 1 307
  • 正文 独居荒郊野岭守林人离奇死亡,尸身上长有42处带血的脓包…… 初始之章·张勋 以下内容为张勋视角 年9月15日...
    茶点故事阅读 37,086评论 2 330
  • 正文 我和宋清朗相恋三年,在试婚纱的时候发现自己被绿了。 大学时的朋友给我发了我未婚夫和他白月光在一起吃饭的照片。...
    茶点故事阅读 39,252评论 1 343
  • 序言:一个原本活蹦乱跳的男人离奇死亡,死状恐怖,灵堂内的尸体忽然破棺而出,到底是诈尸还是另有隐情,我是刑警宁泽,带...
    沈念sama阅读 34,921评论 5 338
  • 正文 年R本政府宣布,位于F岛的核电站,受9级特大地震影响,放射性物质发生泄漏。R本人自食恶果不足惜,却给世界环境...
    茶点故事阅读 40,566评论 3 322
  • 文/蒙蒙 一、第九天 我趴在偏房一处隐蔽的房顶上张望。 院中可真热闹,春花似锦、人声如沸。这庄子的主人今日做“春日...
    开封第一讲书人阅读 31,190评论 0 21
  • 文/苍兰香墨 我抬头看了看天上的太阳。三九已至,却和暖如春,着一层夹袄步出监牢的瞬间,已是汗流浃背。 一阵脚步声响...
    开封第一讲书人阅读 32,435评论 1 268
  • 我被黑心中介骗来泰国打工, 没想到刚下飞机就差点儿被人妖公主榨干…… 1. 我叫王不留,地道东北人。 一个月前我还...
    沈念sama阅读 47,129评论 2 366
  • 正文 我出身青楼,却偏偏与公主长得像,于是被迫代替她去往敌国和亲。 传闻我的和亲对象是个残疾皇子,可洞房花烛夜当晚...
    茶点故事阅读 44,125评论 2 352

推荐阅读更多精彩内容