您的位置:首页 > 移动开发 > IOS开发

倾情奉献ios5.0编译ffmpeg,真机ok!

2012-12-24 11:01 302 查看
我不是蛋疼弄这个哈~搞这个是因为之前我的264视频是baseline的,效果不是特别好,现在要升到main profile。

申明一下,我用的是xcode4.2/.4.3.2,ios sdk5.0/5.1,是在真机上运行ok,越狱的ios5.0 和ios5.1的iphone都可以播示例视频。我选择target是ios4.3也可以的。不过如果是4.1我就不清楚了,应为貌似ffmpeg不支持编译成armv6,有这么个说法:The armv6 arch doesn't seem to be working properly so you can force building via armv7 on your 3GS until we figure
that out.

1. 到https://github.com/gabriel/ffmpeg-iphone-build下载ffmpeg-iphone-build

2.先将gas-preprocessor.pl拷贝到/usr/sbin/目录中。

3.到这里下载最新的ffmpeg:http://ffmpeg.org/download.html 或者命令行安装:git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg

下载一个事例工程:git clone git://github.com/lajos/iFrameExtractor.git

然后到命令行下到ffmpeg的目录下,执行:

./configure \

--cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc \

--as='gas-preprocessor.pl /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc' \

--sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk \

--extra-ldflags=-L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/lib/system \

--target-os=darwin \

--arch=arm \

--cpu=cortex-a8 \

--extra-cflags='-arch armv7' \

--extra-ldflags='-arch armv7' \

--enable-pic \

--enable-cross-compile \

--enable-ffmpeg \

--disable-ffplay \

--disable-ffserver \

--disable-asm \

--disable-encoders \

--disable-decoders \

--enable-decoder=h264 \

--disable-doc

也可以用下面这个配置,优化一下,我都是真机器测试ok,有问题发出来生儿子没*****,好吧。:

./configure \

--cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc \

--as='gas-preprocessor.pl /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc' \

--sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk \

--extra-ldflags=-L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/lib/system \

--target-os=darwin \

--arch=arm \

--cpu=cortex-a8 \

--extra-cflags='-arch armv7' \

--extra-ldflags='-arch armv7' \

--extra-cflags='-mfpu=neon' \

--extra-cflags='-mfloat-abi=softfp' \

--enable-pic \

--enable-cross-compile \

--enable-ffmpeg \

--disable-ffplay \

--disable-ffserver \

--disable-asm \

--disable-encoders \

--disable-decoders \

--enable-decoder=h264 \

--disable-doc

注意了,上面有--disable-asm \,这是没办法的,禁用了汇编,这样应该是会影响效率的,如果不禁用就编译不通过。谁有更好的办法不禁用,麻烦分享一下。

一般是ok的,如果提示permission deny,那就chmod 777 configure(这个情况是我同事在windows上改了这个文件)

然后就make,完了再make install一下

如果给代码做了修改,就先make clean,然后make一下

编译完了后在/usr/local/lib就是一些你用得上的.a文件,先拷贝到别的地方,比如:cp -rf lib* /src

编译完了后在/usr/local/include就是一些你用得上的.h头文件,先拷贝到别的地方,比如:cp -rf include* /src

然后把lib和include放到你的工程中,你可以在你的工程根目录下创建一个叫ffmpeg的文件夹,把lib和linclude里面的东西放进去

工程中制定head file path :"$(SRCROOT)/ffmpeg" 这样编译就可以通过了


然后,打开iFrameExtractor这个工程,在ffmpeg这个文件夹建一个lib文件夹,把之前拷贝(就这个cp -rf lib* /src)出来的.a文件全部丢进去。为什么要这么做呢?应为iFrameExtractor里面的ffmpeg版本比较老,所以我没有编译它,没有编译,就不会产生一个lib文件夹。至于这个老的ffmpeg怎么编译,下面我贴的帖子里面会有介绍。运行下面的命令可以编译通过:

./configure --disable-doc --disable-ffmpeg --disable-ffplay --disable-ffserver \

--enable-cross-compile --arch=arm --target-os=darwin \

--cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc \

--as='gas-preprocessor/gas-preprocessor.pl /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc' \

--sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk \

--cpu=cortex-a8 --extra-cflags='-arch armv7' \

--extra-ldflags='-arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk' \

--enable-pic

然后在link binary with library中导入这些.a文件和libbz.2.1.0.dylib。

然后插上真机,运行工程,ok,成功啦!!!看下面的图片。

最后分享几个帖子:

模拟器与真机下ffmpeg的编译方法(总结版):http://www.cocoachina.com/bbs/read.php?tid=79169&page=1

这个里面的ffmepg模拟器版本用的ios4.3,我这只有ios5.0和ios5.1,很遗憾,都编译不成功,想想我们就是要真机跑,模拟器意义不大,就没继续研究了。

Building FFmpeg for iPhone:http://blog.sina.com.cn/s/blog_51396f890102dyde.html 或者:http://blog.sina.com.cn/s/blog_4b8ba47f0100ve2j.html

[ 此帖被xiaochengfei在2012-04-09 18:21重新编辑 ]

图片:1.png



图片:pic.jpg

内容来自用户分享和网络整理,不保证内容的准确性,如有侵权内容,可联系管理员处理 点击这里给我发消息
标签: