NDK编译ffmpeg程序

来源:互联网 发布:联通3g网络接入点设置 编辑:程序博客网 时间:2024/05/18 05:08

参考: http://blog.csdn.net/sunwutian0325/article/details/8796772 

http://blog.csdn.net/leixiaohua1020/article/details/47008825



1. 用Android NDK自带的脚本做一个独立的工具链:

[root@localhost work]# pwd
/root/work

[root@localhost work]# ls
android-ndk-r10d  ffmpeg-2.6.2.tar.bz2

[root@localhost work]# tar xjf ffmpeg-2.6.2.tar.bz2

[root@localhost work]# ls android-ndk-r10d/
build              ndk-depends     ndk-which                  samples
docs               ndk-gdb         platforms                  sources
find-win-host.cmd  ndk-gdb-py      prebuilt                   tests
GNUmakefile        ndk-gdb.py      README.TXT                 toolchains
ndk-build          ndk-gdb-py.cmd  RELEASE.TXT
ndk-build.cmd      ndk-stack       remove-windows-symlink.sh


[root@localhost work]# android-ndk-r10d/build/tools/make-standalone-toolchain.sh  --platform=android-8 --toolchain=arm-linux-androideabi-4.9
Copying prebuilt binaries...
Copying sysroot headers and libraries...
Copying c++ runtime headers and libraries...
Creating package file: /tmp/ndk-root/arm-linux-androideabi-4.9.tar.bz2
Cleaning up...
Done.

注: --toolchain=arm-linux-androideabi-4.9 取决于NDK子目录/toolchains下提供了哪些文件夹(工具链)


2. 将工具链bin目录加到PATH环境变量

[root@localhost work]# tar xjf /tmp/ndk-root/arm-linux-androideabi-4.9.tar.bz2

[root@localhost work]# export PATH=$PATH:/root/work/arm-linux-androideabi-4.9/bin/


3. 配置ffmpeg代码

[root@localhost work]#  cd ffmpeg-2.6.2

[root@localhost ffmpeg-2.6.2]#  mkdir ../temp

[root@localhost ffmpeg-2.6.2]#  ./configure --enable-cross-compile --target-os=linux --arch=arm --cross-prefix=arm-linux-androideabi- --disable-doc --disable-debug  --prefix=/root/work/temp

这里输出一条警告,貌似不影响:WARNING: arm-linux-androideabi-pkg-config not found, library detection may fail.


4. 编译安装(安装到刚才 --perfix= 指定的目录中去)

[root@localhost ffmpeg-2.6.2]#  make; make install; 

[root@localhost ffmpeg-2.6.2]#  cd ..; ls temp

bin  include  lib  share

[root@localhost ffmpeg-2.6.2]#  ls temp/bin

ffmpeg  ffprobe  ffserver

以上是生成的arm二进制程序


5. 复制到Android上运行,添加可执行权限需要手机 root 过

将生成的ffmpeg,ffprobe复制到手机存储空间;

然后adb shell进Android系统:

$ su
# mount
......
/dev/block/mmcblk1p21 /system ext3 ro,noatime,nodiratime,barrier=1,data=ordered
0 0
......

#mount -o remount /dev/block/mmcblk1p21 /system/
将/system目录重新挂载为可读可写

# cp /sdcard/ffmpeg /system/bin/
# cp /sdcard/ffprobe /system/bin/


然后试下运行效果

# ffmpeg -version
ffmpeg -version
ffmpeg version 2.6.2 Copyright (c) 2000-2015 the FFmpeg developers
built with gcc 4.9 (GCC) 20140827 (prerelease)
configuration: --enable-cross-compile --target-os=linux --arch=arm --cross-prefi
x=arm-linux-androideabi- --disable-doc --disable-debug --prefix=/root/work/temp
libavutil      54. 20.100 / 54. 20.100
libavcodec     56. 26.100 / 56. 26.100
libavformat    56. 25.101 / 56. 25.101
libavdevice    56.  4.100 / 56.  4.100
libavfilter     5. 11.102 /  5. 11.102
libswscale      3.  1.101 /  3.  1.101
libswresample   1.  1.100 /  1.  1.100


Android上运行ffmpeg命令

0 0