FFmpeg 遇到的一些坑

环境

  • Ubuntu 16.04 LTS
  • NDK 16.1.4479499

Ref

各种报错

  • No such file or directory
Unknown option "".
See ./configure --help for available options.
./build_android.sh: 22: ./build_android.sh: --cross-prefix=/home/maple/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-: not found
CC  libavfilter/aeval.o
In file included from libavfilter/aeval.c:26:0:
./libavutil/avassert.h:30:20: fatal error: stdlib.h: No such file or directory
 #include <stdlib.h>
                    ^
compilation terminated.
common.mak:60: recipe for target 'libavfilter/aeval.o' failed
make: *** [libavfilter/aeval.o] Error 1
CC  libavfilter/aeval.o
In file included from libavfilter/aeval.c:26:0:
./libavutil/avassert.h:30:20: fatal error: stdlib.h: No such file or directory
 #include <stdlib.h>
                    ^
compilation terminated.
common.mak:60: recipe for target 'libavfilter/aeval.o' failed
make: *** [libavfilter/aeval.o] Error 1
 

看着很多,很虎人,其实关键字就 No such file or directory。一般都是从博客copy的看不见的字符(eg:空格,回车)引起的,因为大家的OS都不一样,系统对这些字符的编码也可能不一,所以建议在纯文本编辑软件中打开显示各种空格,这样能少不少莫名其妙的坑。
以逆流的鱼yuiop博客为例,他系统为mac,编译 FFmpeg 脚本 shell 为:

#!/bin/sh
NDK=/home/maple/Android/Sdk/ndk-bundle
SYSROOT=$NDK/platforms/android-18/arch-arm
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
CPU=arm
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS="-marm"

build_one() {
./configure \
--prefix=$PREFIX \
--enable-shared \
--disable-static \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-avdevice \
--disable-doc \
--disable-symver \
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
--target-os=linux \
--arch=arm \
--enable-cross-compile \
--sysroot=$SYSROOT \
--extra-cflags="-Os -fpic $ADDI_CFLAGS" \
--extra-ldflags="$ADDI_LDFLAGS" \
$ADDITIONAL_CONFIGURE_FLAG
make clean
make
make install
}

build_one

在Ubuntu下编辑就会报上面的错。解决方法:在build_one函数中给每行敲个空行,like:

#!/bin/sh
NDK=/home/maple/Android/Sdk/ndk-bundle
SYSROOT=$NDK/platforms/android-18/arch-arm
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
CPU=arm
PREFIX=$(pwd)/android/$CPU
ADDI_CFLAGS="-marm"

build_one() {

./configure \

--prefix=$PREFIX \

--enable-shared \

--disable-static \

--disable-doc \

--disable-ffmpeg \

--disable-ffplay \

--disable-ffprobe \

--disable-ffserver \

--disable-avdevice \

--disable-doc \

--disable-symver \

--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \

--target-os=linux \

--arch=arm \

--enable-cross-compile \

--sysroot=$SYSROOT \

--extra-cflags="-Os -fpic $ADDI_CFLAGS" \

--extra-ldflags="$ADDI_LDFLAGS" \

$ADDITIONAL_CONFIGURE_FLAG

make clean

make

make install

}

build_one
  • NDK编译报 ‘File format not recognized’
maple@maple-All-Series:~/AndroidStudioProjects/FFmpegDemo/app/src/main/jni$ /home/maple/Android/Sdk/ndk-bundle/ndk-build APP_ALLOW_MISSING_DEPS=true
Android NDK: APP_PLATFORM not set. Defaulting to minimum supported version android-14.    
Android NDK: WARNING: APP_PLATFORM android-14 is higher than android:minSdkVersion 1 in /home/maple/AndroidStudioProjects/FFmpegDemo/app/src/main/AndroidManifest.xml. NDK binaries will *not* be comptible with devices older than android-14. See https://android.googlesource.com/platform/ndk/+/master/docs/user/common_problems.md for more information.    
/home/maple/Android/Sdk/ndk-bundle/build/core/setup-app.mk:81: Android NDK: Application targets deprecated ABI(s): armeabi    
/home/maple/Android/Sdk/ndk-bundle/build/core/setup-app.mk:82: Android NDK: Support for these ABIs will be removed in a future NDK release.    
/home/maple/Android/Sdk/ndk-bundle/build/core/build-binary.mk:693: Android NDK: Module sffhelloworld depends on undefined modules: avdevice postproc    
[armeabi] Install        : libavcodec-57.so => libs/armeabi/libavcodec-57.so
/home/maple/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-strip:/home/maple/AndroidStudioProjects/FFmpegDemo/app/src/main/libs/armeabi/libavcodec-57.so: File format not recognized
make: *** [/home/maple/AndroidStudioProjects/FFmpegDemo/app/src/main/libs/armeabi/libavcodec-57.so] Error 1
make: *** Deleting file `/home/maple/AndroidStudioProjects/FFmpegDemo/app/src/main/libs/armeabi/libavcodec-57.so'

老样子,Dont Panic。 ‘File format not recognized’ 文件格式不能识别,那我们就去看看这是个什么格式,这就需要个 file 命令。

file命令用来探测给定文件的类型。file命令对文件的检查分为文件系统、魔法幻数检查和语言检查3个过程。

maple@maple-All-Series:~/AndroidStudioProjects/FFmpegDemo/app/src/main/jni$ file libavcodec-57.so 
libavcodec-57.so: ELF 64-bit LSB shared object, x86-64, version 1 (SYSV), dynamically linked, BuildID[sha1]=8de4e7be651e4db057b11d72e33fffd8d19d40dd, stripped

可知这个so是x86-64类型,所以Application.mk中应该这样:

APP_ABI :=x86

先写这些,遇到新坑我再来补充。有帮助的话点下赞咯 :)

    原文作者:然而喵星人早已看穿了一切
    原文地址: https://www.jianshu.com/p/da5d55b59f4b
    本文转自网络文章,转载此文章仅为分享知识,如有侵权,请联系博主进行删除。
点赞