使用NDK编译ffmpeg库

来源:互联网 发布:linux查看snmp团体名 编辑:程序博客网 时间:2024/05/29 03:16
1、在 http://developer.android.com/tools/sdk/ndk/index.html 
   下载 android-ndk-r10e-linux-x86_64.bin 
   然后热行如下命令安装NDK,我是在ubuntu 14.04下安装的,在WIN下要装cygwin,会麻烦很多,不推荐。


它官方的安装提示如下:
  On Linux and Mac OS X (Darwin):
   1. Download the appropriate package from this page.
   2. Open a terminal window.
   3. Go to the directory to which you downloaded the package.
   4. Run chmod a+x on the downloaded package.
   5. Execute the package. For example:




   ndk$ chmod a+x android-ndk-r10e-linux-x86_64.bin
   ndk$ ./android-ndk-r10e-linux-x86_64.bin


更具体的安装与配置见《Ubuntu14.04下最新Android NDK安装》


2. 进入ffmpeg官网,http://ffmpeg.org/ 下载最新版的ffmpgeg压缩包。
   我下的是 ffmpeg-2.8.1 
(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)'




(2)在源码目录下创建,ndk_build_config.sh
#!/bin/bash  
NDK=/home/cxx/ndk/android-ndk-r10c
SYSROOT=$NDK/platforms/android-19/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-doc \
    --disable-ffserver \
    --enable-gpl\
    --enable-libx264 \
    --enable-encoder=libx264 \
    --enable-decoder=h264 \
    --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=$(pwd)/android/$CPU
ADDI_CFLAGS="-marm -I../x264/android/arm/include -DANDROID "
ADDI_LDFLAGS="-L../x264/android/arm/lib"
build_one


编译运行
$ chmod a+x ndk_build_config.sh
$ ./ndk_build_config.sh
$ make 
$ make install
0 0