|
使用NDK编译ffmpeg,x264库
发表于 2014-10-24 15:23:55
浏览:18772
|
回复:9
打印
只看该作者
[复制链接]
楼主
本帖最后由 error结构体 于 2014-10-24 15:23 编辑
1、在 http://developer.android.com/tools/sdk/ndk/index.html 下载 android-ndk-r10c-linux-x86_64.bin
然后热行如下命令安装NDK,我是在ubuntu 12.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-r10c-darwin-x86_64.bin
ndk$ ./android-ndk-r10c-darwin-x86_64.bin
2、进入X264的官网下载最新版本,http://www.videolan.org/developers/x264.html
我下载的是x264-snapshot-20141022-2245,更新比较快。
创建build_x264.sh
- #!/bin/bash
- NDK=/home/cxx/ndk/android-ndk-r10c
- 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-asm \
- --enable-pic \
- --enable-strip \
- --cross-prefix=$TOOLCHAIN/bin/arm-linux-androideabi- \
- --host=arm-linux-androideabi \
- --sysroot=$SYSROOT \
- --extra-cflags="-Os -fpic $ADDI_CFLAGS" \
- --extra-ldflags="$ADDI_LDFLAGS" \
- $ADDITIONAL_CONFIGURE_FLAG
- }
- CPU=arm
- PREFIX=$(pwd)/android/$CPU
- ADDI_CFLAGS=""
- build_one
复制代码 另外修改.configure中的
- echo "SOSUFFIX=so" >> config.mak
- echo "SONAME=libx264.so.$API" >> config.mak
- echo "SOFLAGS=-shared -Wl,-soname,\$(SONAME) $SOFLAGS" >> config.mak
复制代码 去掉 echo "SONAME=libx264.so.$API" >> config.mak 其中的红色部分。
然后执行:
$ chmod a+x build_x264.sh
$ ./build_x264.sh
$ make
$ make install
3、进入ffmpeg官网,http://ffmpeg.org/ 下载最新版的ffmpgeg压缩包。
我下的是 ffmpeg-2.4.2
(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)在源码目录下创建,build_ffmpeg.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
复制代码 (3)编译运行
$ ./build_ffmpeg.sh
$ make
$ make install
|
|