红联Linux门户
Linux帮助

Ubuntu 14.04.2移植FFmpeg 2.8.3到Android平台

发布时间:2016-08-12 15:50:17来源:jianshu作者:Andy周
笔者生产环境是ubuntu14.04.2,一直都听说FFmpeg很强大。但一直都没时间研究沉淀,今天心血来潮,决定试试看。
 
首先下载FFmpeg 2.8.3源代码
官方地址:http://www.ffmpeg.org/releases/ffmpeg-2.8.3.tar.gz
Github地址:https://github.com/FFmpeg/FFmpeg.git
 
1.首先修改configure文件
去除后缀名之后的版本号
#修改前  
#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)'  
当然了可以写成一个Shell脚本librename.sh
dot="'"
SLIBNAME_WITH_MAJOR=(LIBNAME_WITH_MAJOR=$dot'$(SLIBNAME).$(LIBMAJOR)'$dot)  
SLIBNAME_WITH_MAJOR_REP=(LIBNAME_WITH_MAJOR=$dot'$(SLIBPREF)$(FULLNAME)-$(LIBMAJOR)$(SLIBSUF)'$dot)
SLIB_INSTALL_NAME=(SLIB_INSTALL_NAME=$dot'$(SLIBNAME_WITH_VERSION)'$dot)  
SLIB_INSTALL_NAME_REP=(SLIB_INSTALL_NAME=$dot'$(SLIBNAME_WITH_MAJOR)'$dot)
SLIB_INSTALL_LINKS=(SLIB_INSTALL_LINKS=$dot'$(SLIBNAME_WITH_MAJOR)\s$(SLIBNAME)'$dot)  
SLIB_INSTALL_LINKS_REP=(SLIB_INSTALL_LINKS=$dot'$(SLIBNAME)'$dot)
sed -i 's/'$SLIBNAME_WITH_MAJOR'/'$SLIBNAME_WITH_MAJOR_REP'/g' configure  
sed -i 's/'$SLIB_INSTALL_NAME'/'$SLIB_INSTALL_NAME_REP'/g' configure  
sed -i 's/'$SLIB_INSTALL_LINKS'/'$SLIB_INSTALL_LINKS_REP'/g' configure  
 
2.编写脚本文件build.sh
NDK=/work/android-ndk-r10e  
SYSROOT=$NDK/platforms/android-9/arch-arm/
TOOLCHAIN=$NDK/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64
function build_one
{
./configure \  
--prefix=$PREFIX \  
--enable-shared \  
--disable-static \  
--disable-yasm \  
--disable-doc \  
--disable-ffserver \  
--enable-cross-compile \  
--cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \  
--target-os=linux \  
--arch=arm \  
--sysroot=$SYSROOT \  
--extra-cflags="-Os -fpic $ADDI_CFLAGS" \  
--extra-ldflags="$ADDI_LDFLAGS" \  
$ADDITIONAL_CONFIGURE_FLAG  
}
CPU=arm
PREFIX=~/ffmpeg/$CPU
ADDI_CFLAGS="-marm"
build_one
注意NDK,SYSROOT,TOOLCHAIN换成自己本机的地址
添加build.sh的权限
chmod -R 777 build.sh  
执行
./build.sh  
如果出现
WARNING: /work/android-ndk-r10e/toolchains/arm-linux-androideabi-4.8/prebuilt/linux-x86_64/bin/arm-linux-androideabi-pkg-config not found, library detection may fail.  
可以忽略
然后执行
make  
make install  
接着在目录
~/android/arm  
就有我们需要的文件
drwxrwxr-x 2 byhook byhook 4096 12月  3 23:58 bin  
drwxrwxr-x 9 byhook byhook 4096 12月  3 23:58 include  
drwxrwxr-x 3 byhook byhook 4096 12月  3 23:58 lib  
drwxrwxr-x 3 byhook byhook 4096 12月  3 23:58 share  
 
最新编译方案
FFmpeg合并为一个库:http://www.linuxdiyf.com/linux/23257.html
 
本文永久更新地址:http://www.linuxdiyf.com/linux/23258.html