我是靠谱客的博主 热情刺猬,最近开发中收集的这篇文章主要介绍Ubuntu编译Android版本FFmpeg,觉得挺不错的,现在分享给大家,希望可以做个参考。

概述

环境

Ubuntu 16.04 LTS
NDK android-ndk-r17

开始

1.下载最新版本NDK
2.将NDK加入环境变量

export NDK_ROOT=/path/to/ndk/
export PATH=$PATH:$NDK_ROOT

3.git clone https://github.com/FFmpeg/FFmpeg.git

4.如网上说的修改configue生成so的命名规则:

#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)'
# For android
SLIBNAME_WITH_MAJOR='$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'
LIB_INSTALL_EXTRA_CMD='$$(RANLIB) "$(LIBDIR)/$(LIBNAME)"'
SLIB_INSTALL_NAME='$(SLIBNAME_WITH_MAJOR)'
SLIB_INSTALL_LINKS='$(SLIBNAME)'

5.创建编译脚本

# build4android.sh
#!/bin/sh
NDK=/home/ubuntu/android-tools/android-ndk-r17
SYSROOT=$NDK/sysroot
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.9/prebuilt/linux-x86_64
ARCH=arm
API=21
PREFIX=./android/$ARCH
# ARM
arm-linux-androideabi
# ARM64 aarch64-linux-android
# x86
i686-linux-android
# x86_64
x86_64-linux-android
TRIPLE=arm-linux-androideabi
ADDI_CFLAGS="--sysroot $SYSROOT -isystem $NDK/sysroot/usr/include/$TRIPLE -D__ANDROID_API__=$API"
ADDI_LDFLAGS="--sysroot $NDK/platforms/android-$API/arch-$ARCH/"
config_para()
{
./configure 
--prefix=$PREFIX 
--enable-shared 
--disable-static 
--disable-doc 
--disable-ffmpeg 
--disable-ffplay 
--disable-ffprobe 
--disable-avdevice 
--disable-doc 
--disable-symver 
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- 
--target-os=linux 
--arch=$ARCH 
--enable-cross-compile 
--extra-cflags="-Os -fpic $ADDI_CFLAGS" 
--extra-ldflags="$ADDI_LDFLAGS" 
$ADDITIONAL_CONFIGURE_FLAG
make clean
make -j8
make install
}
config_para

6.编译

$ ./build4android.sh

编译后的结果在./android/arm目录下。

遇到问题

0.错误:

C compiler test failed.

解决:查看ffbuild/config.log文件末尾,一般是类似”unrecognized argument in option xxx”的错误,按照提示修改即可。
我的错误出在“-mcpu=arm”,直接去掉,就可以了。

1.错误:

fatal error: stdlib.h: No such file or directory

按照网上的编译脚本步骤,一般会报类似如上错误。原因是新版本的ndk更改了header的组织方式,具体参考:
https://android.googlesource.com/platform/ndk/+/master/docs/UnifiedHeaders.md#supporting-unified-headers-in-your-build-system
解决办法就是参考上述链接,修改编译脚本。或直接参考上面的脚本。

2.错误:

libavcodec/aaccoder.c: In function 'search_for_ms':
libavcodec/aaccoder.c:803:25: error: expected identifier or '(' before numeric constant
int B0 = 0, B1 = 0;
^
libavcodec/aaccoder.c:865:28: error: lvalue required as left operand of assignment
B0 += b1+b2;
^
libavcodec/aaccoder.c:866:25: error: 'B1' undeclared (first use in this function)
B1 += b3+b4;

宏定义变量名与宏定义冲突
解决:
参考:http://alientechlab.com/how-to-build-ffmpeg-for-android/
将B0修改为b0,一共四处。

3.错误

libavcodec/hevc_mvs.c: In function 'derive_spatial_merge_candidates':
libavcodec/hevc_mvs.c:208:15: error: 'y0000000' undeclared (first use in this function)
((y ## v) >> s->ps.sps->log2_min_pu_size))
^
libavcodec/hevc_mvs.c:204:14: note: in definition of macro 'TAB_MVF'
tab_mvf[(y) * min_pu_width + x]
^
libavcodec/hevc_mvs.c:274:16: note: in expansion of macro 'TAB_MVF_PU'
(cand && !(TAB_MVF_PU(v).pred_flag == PF_INTRA))
^
libavcodec/hevc_mvs.c:368:23: note: in expansion of macro 'AVAILABLE'
is_available_b0 = AVAILABLE(cand_up_right, B0) &&
^
libavcodec/hevc_mvs.c:208:15: note: each undeclared identifier is reported only once for each function it appears in
((y ## v) >> s->ps.sps->log2_min_pu_size))
^
libavcodec/hevc_mvs.c:204:14: note: in definition of macro 'TAB_MVF'
tab_mvf[(y) * min_pu_width + x]
^
libavcodec/hevc_mvs.c:274:16: note: in expansion of macro 'TAB_MVF_PU'
(cand && !(TAB_MVF_PU(v).pred_flag == PF_INTRA))
^
libavcodec/hevc_mvs.c:368:23: note: in expansion of macro 'AVAILABLE'
is_available_b0 = AVAILABLE(cand_up_right, B0) &&
^
libavcodec/hevc_mvs.c:207:15: error: 'x0000000' undeclared (first use in this function)
TAB_MVF(((x ## v) >> s->ps.sps->log2_min_pu_size),

^
libavcodec/hevc_mvs.c:204:34: note: in definition of macro 'TAB_MVF'
tab_mvf[(y) * min_pu_width + x]
^
libavcodec/hevc_mvs.c:274:16: note: in expansion of macro 'TAB_MVF_PU'
(cand && !(TAB_MVF_PU(v).pred_flag == PF_INTRA))
^
libavcodec/hevc_mvs.c:368:23: note: in expansion of macro 'AVAILABLE'
is_available_b0 = AVAILABLE(cand_up_right, B0) &&
^
libavcodec/hevc_mvs.c: In function 'ff_hevc_luma_mv_mvp_mode':
libavcodec/hevc_mvs.c:208:15: error: 'y0000000' undeclared (first use in this function)
((y ## v) >> s->ps.sps->log2_min_pu_size))
^
libavcodec/hevc_mvs.c:204:14: note: in definition of macro 'TAB_MVF'
tab_mvf[(y) * min_pu_width + x]
^
libavcodec/hevc_mvs.c:274:16: note: in expansion of macro 'TAB_MVF_PU'
(cand && !(TAB_MVF_PU(v).pred_flag == PF_INTRA))
^
libavcodec/hevc_mvs.c:683:24: note: in expansion of macro 'AVAILABLE'
is_available_b0 =
AVAILABLE(cand_up_right, B0) &&
^
libavcodec/hevc_mvs.c:207:15: error: 'x0000000' undeclared (first use in this function)
TAB_MVF(((x ## v) >> s->ps.sps->log2_min_pu_size),

^
libavcodec/hevc_mvs.c:204:34: note: in definition of macro 'TAB_MVF'
tab_mvf[(y) * min_pu_width + x]
^
libavcodec/hevc_mvs.c:274:16: note: in expansion of macro 'TAB_MVF_PU'
(cand && !(TAB_MVF_PU(v).pred_flag == PF_INTRA))
^
libavcodec/hevc_mvs.c:683:24: note: in expansion of macro 'AVAILABLE'
is_available_b0 =
AVAILABLE(cand_up_right, B0) &&
^
ffbuild/common.mak:60: recipe for target 'libavcodec/hevc_mvs.o' failed
make: *** [libavcodec/hevc_mvs.o] Error 1
make: *** Waiting for unfinished jobs....

解决:同上,修改libavcodec/hevc_mvs.c中B0为b0

4.错误:

libavcodec/opus_pvq.c:498:9: error: expected identifier or '(' before numeric constant
int B0 = blocks;
^
libavcodec/opus_pvq.c:559:12: error: lvalue required as left operand of assignment
B0 = blocks;

解决:同上,修改libavcodec/opus_pvq.c中B0为b0

最后

以上就是热情刺猬为你收集整理的Ubuntu编译Android版本FFmpeg的全部内容,希望文章能够帮你解决Ubuntu编译Android版本FFmpeg所遇到的程序开发问题。

如果觉得靠谱客网站的内容还不错,欢迎将靠谱客网站推荐给程序员好友。

本图文内容来源于网友提供,作为学习参考使用,或来自网络收集整理,版权属于原作者所有。
点赞(63)

评论列表共有 0 条评论

立即
投稿
返回
顶部