ubuntu14.04系统Android NDK编译ffmpeg遇到的问题

1 参考以下两篇博客中的build.sh,编译ffmpeg 4.1、4.1.1、以及旧版本2.7.7都存在问题
FFmpeg编译成Android动态库
Linux下使用android ndk编译FFmpeg(最新版FFmpeg 4.4.1)

1.1 编译脚本如下:

# build.sh
# 在Linux下编译FFmpeg成功的脚本
# 注意Linux和windows的换行符\r\n不太一样,要转换(dos2unix)
#!/bin/bash
make clean
#export NDK=/home/ame/bin/android-ndk-r10e
export NDK=/home/ame/bin/android-ndk-r14b
export PREBUILT=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt
export PLATFORM=$NDK/platforms/android-9/arch-arm
export PREFIX=../fflib
build_one(){
./configure --target-os=linux --prefix=$PREFIX \
--enable-cross-compile \
--enable-runtime-cpudetect \
--disable-asm \
--arch=arm \
--cc=$PREBUILT/linux-x86_64/bin/arm-linux-androideabi-gcc \
--cross-prefix=$PREBUILT/linux-x86_64/bin/arm-linux-androideabi- \
--disable-stripping \
--nm=$PREBUILT/linux-x86_64/bin/arm-linux-androideabi-nm \
--sysroot=$PLATFORM \
--enable-gpl --enable-shared --disable-static --enable-small \
--disable-ffprobe --disable-ffplay --disable-ffmpeg --disable-ffserver --disable-debug \
--extra-cflags="-fPIC -DANDROID -D__thumb__ -mthumb -Wfatal-errors -Wno-deprecated -mfloat-abi=softfp -marm -march=armv7-a"
}
build_one
make
make install
cd ..

1.2 编译4.X版本,报错如下:
1.2.1 使用Android Studio默认下载的ndk编译ffmpeg4.1
export NDK=/home/hi/Android/Sdk/ndk-bundle
不执行make就通不过,提示错误如下
hi@hi:~/3tb_volume/ffmpeg/ffmpeg-4.1$ ./build2.sh 
/home/hi/Android/Sdk/ndk-bundle/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc is unable to create an executable file.
C compiler test failed.

If you think configure made a mistake, make sure you are using the latest
version from Git.  If the latest version fails, report the problem to the
ffmpeg-user@ffmpeg.org mailing list or IRC #ffmpeg on irc.freenode.net.
Include the log file "ffbuild/config.log" produced by configure as this will help
solve the problem.

注:使用android-ndk-r16b也报同样的错误,也就是说新版本会报这个错误

1.2.2 ndk替换为android-ndk-r10e版本和android-ndk-r14b
export NDK=/home/hi/bin/android-ndk-r10e
(1)不执行make不再报错:
hi@hi:~/3tb_volume/ffmpeg/ffmpeg-4.1$ ./build2.sh 
install prefix            ../fflib
source path               .
C compiler                /home/hi/bin/android-ndk-r10e/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-gcc
C library                 bionic
host C compiler           gcc
host C library            glibc
ARCH                      c (armv7-a)
big-endian                no
runtime cpu detection     yes
debug symbols             no
strip symbols             no
optimize for size         yes
...
Enabled outdevs:
fbdev              v4l2

License: GPL version 2 or later

WARNING: /home/hi/bin/android-ndk-r10e/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64/bin/arm-linux-androideabi-pkg-config not found, library detection may fail.
libavutil/avconfig.h is unchanged
libavcodec/codec_list.c is unchanged
libavcodec/parser_list.c is unchanged
libavcodec/bsf_list.c is unchanged
libavformat/demuxer_list.c is unchanged
libavformat/muxer_list.c is unchanged
libavformat/protocol_list.c is unchanged
hi@hi:~/3tb_volume/ffmpeg/ffmpeg-4.1$

(2)执行make,还是会报错:
CC    libavformat/udp.o
libavformat/udp.c: In function 'udp_set_multicast_sources':
libavformat/udp.c:290:28: error: request for member 's_addr' in something not a structure or union
         mreqs.imr_multiaddr.s_addr = ((struct sockaddr_in *)addr)->sin_addr.s_addr;
                            ^
compilation terminated due to -Wfatal-errors.
make: *** [libavformat/udp.o] 错误 1

1.3 编译2.7.7版本,make可以通过;但执行make install失败,报错如下:
ame@ame:~/3tb_volume/ffmpeg/ffmpeg-2.7.7$ make install
INSTALL    libavdevice/libavdevice.so
STRIP    install-libavdevice-shared
skipping strip ../fflib/lib/libavdevice-56.so
/bin/sh: 1: Syntax error: "(" unexpected (expecting ")")
make: *** [install-libavdevice-shared] 错误 2

把build.sh的#!/bin/sh修改为#!/bin/bash也不起作用

2 参考以下博客的编译脚本,编译ffmpeg 4.1、4.1.1、以及旧版本2.7.7都没有问题,make和make install都能成功执行
Android使用FFmpeg(一)--编译ffmpeg

2.1 编译脚本如下:

#!/bin/bash
make clean
export NDK=/home/ndk_build/android-ndk-r14b
export SYSROOT=$NDK/platforms/android-9/arch-arm/
export TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
export CPU=arm
export PREFIX=$(pwd)/android/$CPU
export ADDI_CFLAGS="-marm"
./configure --target-os=linux \
--prefix=$PREFIX --arch=arm \
--disable-doc \
--enable-shared \
--disable-static \
--disable-yasm \
--disable-symver \
--enable-gpl \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-doc \
--disable-symver \
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
--enable-cross-compile \
--sysroot=$SYSROOT \
--extra-cflags="-Os -fpic $ADDI_CFLAGS" \
--extra-ldflags="$ADDI_LDFLAGS" \
$ADDITIONAL_CONFIGURE_FLAG
make clean
make
make install

如果make install时提示没有权限,用sudo make install即可。

INSTALL    doc/libavdevice.3
INSTALL    doc/libavfilter.3
install: 无法删除"/usr/local/share/man/man1/ffmpeg.1": 权限不够
install: 无法删除"/usr/local/share/man/man1/ffprobe.1": 权限不够
install: 无法删除"/usr/local/share/man/man1/ffmpeg-all.1": 权限不够
install: 无法删除"/usr/local/share/man/man1/ffprobe-all.1": 权限不够

2.2 执行编译结果
2.2.1 先修改configure文件
不修改的话编译出来的.so文件后面会有一串数字,无法使用,所以得修改命名规则,使编译出来的so后缀不带数字,可以被Android识别。

#AMEYUME START {@
#SLIBNAME_WITH_MAJOR='$(SLIBNAME).$(LIBMAJOR)'
#LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"'
#SLIB_INSTALL_NAME='$(SLIBNAME_WITH_VERSION)'
#SLIB_INSTALL_LINKS='$(SLIBNAME_WITH_MAJOR) $(SLIBNAME)'
SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
LIB_INSTALL_EXTRA_CMD='$$(RANLIB)"$(LIBDIR)/$(LIBNAME)"'
SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
SLIB_INSTALL_LINKS='$(SLIBNAME)'
#AMEYUME END @}

2.2.2 再执行脚本,编译结果如下:
ffmpeg-2.7.7$ ./build3.sh
...
CC    libswresample/dither.o
CC    libswresample/log2_tab.o
CC    libswresample/options.o
CC    libswresample/rematrix.o
CC    libswresample/resample.o
CC    libswresample/resample_dsp.o
CC    libswresample/swresample.o
CC    libswresample/swresample_frame.o
LD    libswresample/libswresample-1.so
LD    libavcodec/libavcodec-56.so
LD    libavformat/libavformat-56.so
LD    libavfilter/libavfilter-5.so
LD    libavdevice/libavdevice-56.so
INSTALL    libavdevice/libavdevice.so
STRIP    install-libavdevice-shared
INSTALL    libavfilter/libavfilter.so
STRIP    install-libavfilter-shared
INSTALL    libavformat/libavformat.so
STRIP    install-libavformat-shared
INSTALL    libavcodec/libavcodec.so
STRIP    install-libavcodec-shared
INSTALL    libpostproc/libpostproc.so
STRIP    install-libpostproc-shared
INSTALL    libswresample/libswresample.so
STRIP    install-libswresample-shared
INSTALL    libswscale/libswscale.so
STRIP    install-libswscale-shared
INSTALL    libavutil/libavutil.so
STRIP    install-libavutil-shared
INSTALL    libavdevice/avdevice.h
...
INSTALL    libavutil/avconfig.h
INSTALL    libavutil/ffversion.h
INSTALL    libavutil/libavutil.pc

2.2.3 编译出的so文件在子目录android/arm/lib中
ffmpeg-2.7.7/android/arm/lib$ ls
libavcodec-56.so  libavdevice-56.so  libavfilter-5.so  libavformat-56.so  libavutil-54.so  libpostproc-53.so  libswresample-1.so  libswscale-3.so  pkgconfig
libavcodec.so     libavdevice.so     libavfilter.so    libavformat.so     libavutil.so     libpostproc.so     libswresample.so    libswscale.so

注:同一个脚本文件在编译ffmpeg 4.1/4.1.1时,可以make和sudo make install成功,但并没有在当成目录下生成子目录android文件夹

3 参考以下博客编译 ffmpeg-3.2.1 和 3.2分支最新版本 ffmpeg-3.2.13 都成功
Android FFmpeg 编译.so库
编译脚本与2.1 中基本相同,编译后结果:
ame@ame:~/3tb_volume/ffmpeg/ffmpeg-3.2.13/android/arm$ ls
include  lib
ame@ame:~/3tb_volume/ffmpeg/ffmpeg-3.2.13/android/arm/include$ ls
libavcodec  libavdevice  libavfilter  libavformat  libavutil  libpostproc  libswresample  libswscale
ame@ame:~/3tb_volume/ffmpeg/ffmpeg-3.2.13/android/arm/lib$ ls
libavcodec-57.so   libavdevice.so    libavformat-57.so  libavutil.so       libswresample-2.so  libswscale.so
libavcodec.so      libavfilter-6.so  libavformat.so     libpostproc-54.so  libswresample.so    pkgconfig
libavdevice-57.so  libavfilter.so    libavutil-55.so    libpostproc.so     libswscale-4.so

相关阅读:ubuntu14.04编译ffmpeg的过程

发布了270 篇原创文章 · 获赞 273 · 访问量 377万+
展开阅读全文

没有更多推荐了,返回首页

©️2019 CSDN 皮肤主题: 大白 设计师: CSDN官方博客

分享到微信朋友圈

×

扫一扫,手机浏览