说在前面
上篇我们学习了编译的概念和流程,现在我们就要开始真正的编译出可以使用的FFmpeg了。
编译FFMPEG流程
- 下载FFMPEG源码
从FFMPEG官网下载编译的源码,下载最新的代码即可,现在是4.x的源码。 - 利用configure文件编写 build的脚本
我们从configure的提示一个个的来编写我们需要的脚本,输入 ./configure --help 就可以看到以下的提示内容,我们一块块的看。这里以arm平台并且静态库为详细的例子来说
- Help options
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
这个是一些帮助的命令,我们不需要写到编译的脚本里面,可以使用这些命令查看下当前ffmpeg版本支持那些编解码器,哪些协议等。
- Standard options
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
--logfile 这个是指定编译过程的日志写道哪个文件
--prefix 这个是指定我们编译完的头文件以及库文件写到哪里
其他的一般用的少,有兴趣可以看看。所以目前为止我们的编译脚本是这样的
./configure \
--prefix=./ffmpeg/android/arm \
--logfile=logfile.txt \
- Configuration options:
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]
--disable-static 是禁止使用静态库,默认是开启静调库
--enable-shared 开启动态库,默认是关闭
--enable-small 是否优化库的大小但是编译速度慢
其他的也不常用,是属于特殊需求了,我们先编译静态库,所以我们的脚本就变成了现在这样
./configure \
--prefix=./ffmpeg/android/arm \
--logfile=logfile.txt \
--enable-static \ 默认就是 写不写无所谓
--enable-small \
- Program options:
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
这个全部禁掉,这个是命令行用的,如果我们要编译出命令行就要开启这些。
当前脚本:
./configure \
--prefix=./ffmpeg/android/arm \
--logfile=logfile.txt \
--enable-static \ 默认就是 写不写无所谓
--enable-small \
--disable-programs \
--disable-ffmpeg \
--disable-fplay \
--disable-ffprobe \
- Documentation options:
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
文档我们一般也不需要,全部禁掉。
当前脚本:
./configure \
--prefix=./ffmpeg/android/arm \
--logfile=logfile.txt \
--enable-static \ 默认就是 写不写无所谓
--enable-small \
--disable-programs \
--disable-ffmpeg \
--disable-fplay \
--disable-ffprobe \
--disable-doc \
--disable-htmlpages \
--disable-manpages \
--disable-podpages \
--disable-txtpages \
- Component options:
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-dct disable DCT code
--disable-dwt disable DWT code
--disable-error-resilience disable error resilience code
--disable-lsp disable LSP code
--disable-lzo disable LZO decoder code
--disable-mdct disable MDCT code
--disable-rdft disable RDFT code
--disable-fft disable FFT code
--disable-faan disable floating point AAN (I)DCT code
--disable-pixelutils disable pixel utils in libavutil
这些就是ffmpeg的代码模块了,根据我们的需求来选择。
--disable-device 这个一般禁掉,device用不到 其他的都留着
当前脚本:
./configure \
--prefix=./ffmpeg/android/arm \
--logfile=logfile.txt \
--enable-static \ 默认就是 写不写无所谓
--enable-small \
--disable-programs \
--disable-ffmpeg \
--disable-fplay \
--disable-ffprobe \
--disable-doc \
--disable-htmlpages \
--disable-manpages \
--disable-podpages \
--disable-txtpages \
--disable-avdevice \
- Individual component options:
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
这就是更为精细的控制了,比如说我能明确的知道我只需要aac
我就可以
--disable-decoders 先禁掉所有的解码器
--enable-decoder=aac
只打开aac
这里我们不控制,所有解码器都支持,生产环境建议根据自己的需求选择编解码器,应该用不到这么多。
- External library support:
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-libaom enable AV1 video encoding/decoding via libaom [no]
--enable-libaribb24 enable ARIB text and caption decoding via libaribb24 [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-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-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-libklvanc enable Kernel Labs VANC processing [no]
--enable-libkvazaar enable HEVC encoding via libkvazaar [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 de/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-libpulse enable Pulseaudio input via libpulse [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-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-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-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-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 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]
--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]
--enable-vulkan enable Vulkan code [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-dxva2 disable Microsoft DirectX 9 video acceleration code [autodetect]
--disable-ffnvcodec disable dynamically linked Nvidia code [autodetect]
--enable-libdrm enable DRM code (Linux) [no]
--enable-libmfx enable Intel MediaSDK (AKA Quick Sync Video) code via libmfx [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]
这个就是ffmpeg能接入的第三方模块,例如我们常见要用的,打开libx264以及fdkaac
--enable-libx264
--enable-fdkaac
这里我们先不打开,等需要用到x264再来编译
- Toolchain options:
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]
--cxx=CXX use C compiler CXX [g++]
--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 []
--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 use link-time optimization
--env="ENV=override" override the environment variables
toolchains就比较重要了,他涉及到编译时的头文件和库文件的查找和选择,这也是第一篇文章写编译基础的原因,要用到了.
--arch=arm/arm64 这个是指编译什么平台
--cross-prefix=xxx 交叉编译工具链的路径,我的mac下面是这样的,注意是arm平台,结尾有个-
cross_prefix=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-
----enable-cross-compile 打开交叉编译
--sysroot这个是指定头文件和库文件的路径,上篇文章说过了,在platform对应的api下面
----target-os=android 编译的平台
这里我们使用ndkr17c作为ndk的版本,在ndk r17里面相对于r14多了一个头文件和库文件的路径,就是在ndk/sysroot下面。这里如果用NDK r14也是可以编译的,但是编译时会有错误需要处理,所以这里直接选择R17.我们需要把这个头文件和库文件也指定查找路径,在ffmpeg里面用extra-cflags 来指定
--extra-cflags = "-INDK/sysroot/usr/include/arm-linux-anroideabi -isysroot $NDK/sysroot"
这里有个-I 是指定头文件的目录,指定的是arm-linux-anroideabi 下面的头文件目录,主要是哪个asm。
-isysroot指定的头文件目录,usr/include都被指定为可查找目录。注意这个是有双引号的
这里还需要指定一个东西
--cc= cc指的就是编译的工具,第一篇文章写过了,gcc或者clang等,这里我们想用gcc来编译,如果不指定cc会有问题,问题在configure文件中可以找到答案:
set_default target_os
if test "$target_os" = android; then
cc_default="clang"
fi
如果指定target_os为android 那么默认的cc编译工具为clang,所以我们如果想使用gcc这里就需要指定cc 为gcc。所以到目前为止,我们的编译脚本变成了这个样子.
./configure \
--logfile=logfile \
--prefix=$prefix \
--disable-static \
--enable-shared \
--enable-small \
--disable-programs \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-doc \
--disable-htmlpages \
--disable-manpages \
--disable-podpages \
--disable-txtpages \
--disable-avdevice \
--disable-postproc \
--arch=arm \
--cross_prefix=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi- \
--cc=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/darwin-x86_64/bin/arm-linux-androideabi-gcc \
--enable-cross-compile \
--extra-cflags="-I$NDK/sysroot/usr/include/arm-linux-androideabi -isysroot $NDK/sysroot" \
--sysroot=$NDK/platforms/android-14/arch-arm \
--target-os=android \
prefix自己按照需求指定一个可以访问到的位置即可,NDK变量自己定义一下。
编译arm64的静态库
编译ARM64位的整体流程和ARM一样,只是头文件和库文件以及编译工具使用64位的,platforms要选择21及以上,ndk在21在开始增加arm64的头文件和库文件。
./configure \
--logfile=logfile \
--prefix=$prefix \
--disable-static \
--enable-shared \
--enable-small \
--disable-programs \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-doc \
--disable-htmlpages \
--disable-manpages \
--disable-podpages \
--disable-txtpages \
--disable-avdevice \
--disable-postproc \
//从这里开始改
--arch=aarch64 \
--cross_prefix=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android- \
--cc=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-gcc \
--sysroot=$NDK/platforms/android-21/arch-arm64 \
//到这一行为止
--extra-cflags="-I$NDK/sysroot/usr/include/arm-linux-androideabi -isysroot $NDK/sysroot" \
--enable-cross-compile \
--target-os=android \
主要是改和平台相关的内容,注意如果拷贝使用的话请把中间的注释去掉。
拿着这个脚本编译发现报了一个错误
/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-androideabi-nm: No such file or directory
这说明nm工具找不到,去指定的目录下看一下,发现nm应该是aarch64-linux-android-nm这样的,这个nm是configure默认的,去configure文件看一下
nm_default="${cross_prefix}${nm_default}"
默认的是 cross_prefix-nm所以,所以是我们指定的cross-prefrix+nm,这个nm肯定找不到的,因此我们需要指定nm的位置,跟指定cc一样
./configure \
--logfile=logfile \
--prefix=$prefix \
--disable-static \
--enable-shared \
--enable-small \
--disable-programs \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-doc \
--disable-htmlpages \
--disable-manpages \
--disable-podpages \
--disable-txtpages \
--disable-avdevice \
--disable-postproc \
--arch=aarch64 \
--cross_prefix=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android- \
--cc=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-gcc \
--sysroot=$NDK/platforms/android-21/arch-arm64 \
--extra-cflags="-I$NDK/sysroot/usr/include/arm-linux-androideabi -isysroot $NDK/sysroot" \
//加上下面一行 指定nm的位置
--nm=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-nm "
--enable-cross-compile \
--target-os=android \
继续编译,问题叒来了
aarch64-linux-androideabi-ar: No such file or directory
其实问题跟上面的是一样的,上篇文章也说了ar是打静态包的工具,我们只需要指定下ar就可以了,因为默认的ar是不对的。
./configure \
--logfile=logfile \
--prefix=$prefix \
--disable-static \
--enable-shared \
--enable-small \
--disable-programs \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-doc \
--disable-htmlpages \
--disable-manpages \
--disable-podpages \
--disable-txtpages \
--disable-avdevice \
--disable-postproc \
--arch=aarch64 \
--cross_prefix=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android- \
--cc=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-gcc \
--sysroot=$NDK/platforms/android-21/arch-arm64 \
--extra-cflags="-I$NDK/sysroot/usr/include/arm-linux-androideabi -isysroot $NDK/sysroot" \
--nm=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-nm "
//加了这行
--ar=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-ar "
--enable-cross-compile \
--target-os=android \
以为成功了但是又出错了,跟上面的错误类型是一样的
aarch64-linux-androideabi-ranlib: No such file or directory
ranlib在上篇文章中也介绍过了,这时候我们生产了最终的编译脚本。
./configure \
--logfile=logfile \
--prefix=$prefix \
--disable-static \
--enable-shared \
--enable-small \
--disable-programs \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-doc \
--disable-htmlpages \
--disable-manpages \
--disable-podpages \
--disable-txtpages \
--disable-avdevice \
--disable-postproc \
--arch=aarch64 \
--cross_prefix=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android- \
--cc=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-gcc \
--sysroot=$NDK/platforms/android-21/arch-arm64 \
--extra-cflags="-I$NDK/sysroot/usr/include/arm-linux-androideabi -isysroot $NDK/sysroot" \
--nm=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-nm "
--ar=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-ar "
--ranlib=$NDK/toolchains/aarch64-linux-android-4.9/prebuilt/darwin-x86_64/bin/aarch64-linux-android-ranlib"
--enable-cross-compile \
--target-os=android \
那这个脚本是运行时可以编译出我们需要的静态库的。
说在最后
上面我们编译出了32位和64位的arm静态库,但其实里面的很多参数我们都可以根据自己的项目的需求来进行裁剪的,这样打出来的包会小很多。然后我们现在只打出来了.a库,我们还可以通过NDK的工具把多个.a库打包成一个so库使用,这样使用也方便点。包括后期我们还会引入libx264等第三方库,到时候我们再回头来编译下。以及会拿到android项目里面用的时候还会涉及到cmakeList的使用,这都是我们后期会来慢慢说的。
下期展望
下期我们来说视频编码的一些基础知识,主要是H264的介绍。
网友评论