ffmpeg-0.10.2 xcode4.3 IOS5.1 真机调试编译过程

折腾了一下午总算把这个搞定了,之前在模拟器上运行iFrameExtractor怎么样都可以,但是在真机上总报错。到处查文章,找到的资料大多的ios4.x系列的,ffmpeg的版本也不太一样,因此折腾出来后把详细过程记录在这里,一来方便自己下次什么还需要再玩一遍,二来供有需要的人查找,不用绕我当初走的一些弯路。

首先下载以下工程代码:iFrameExtractor(https://github.com/lajos/iFrameExtractor), gas-preprocessor(https://github.com/yuvi/gas-preprocessor), ffmpeg(http://ffmpeg.org/download.html)。

 

把iFrameExtractor工程目录下的那个ffmpeg删掉,里面的ffmpeg版本实在太老。将自己下载的ffmpeg代码解压拷贝到iFrameExtractor目录下。 把gas-preprocessor.pl放到工程目录,或者干脆直接丢到/usr/bin下也成。 使用ffmpeg下面的configure来进行编译设置。

 

编译成真机调试还是模拟器调试的关键在于CC的类型,是用于编译macos程序的gcc还是供iPhone platform程序使用的gcc,以及config参数中arch是指定成x86还是armv7。 Xcode4.3中iPhone platform编译的gcc路径如下:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/llvm-gcc IOS5.1的SDK目录为:/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk 用于真机调试的configure运行参数如下:

export DEVRoot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer
export SDKRoot=$DEVRoot/SDKs/iPhoneOS5.1.sdk
export CC=$DEVRoot/usr/bin/llvm-gcc
 
./configure \
--cc=${CC} \
--as="gas-preprocessor.pl ${CC}" \
--sysroot=${SDKRoot} \
--enable-cross-compile \
--target-os=darwin \
--arch=arm \
--cpu=cortex-a8 \
--extra-cflags="-arch armv7" \
--extra-ldflags="-arch armv7 -isysroot ${SDKRoot}" \
--enable-pic \
--disable-doc \
--disable-ffplay \
--disable-ffserver \
--disable-gpl \
--disable-shared \
--enable-static \
--disable-mmx \
--disable-debug \
--enable-decoder=h264  \
--disable-asm

脚本中使用了“--disable-asm”来禁用了汇编生成。这条会严重影响视频播放的效率。以iFrameExtractor为例,在iPhone4S上运行还成,在iPod touch上就显得有些慢动作了。但是不这么干,configure和make过程中会出错。使用IOS4.3 SDK编译的话,则不会出现此问题。stackoverflow上有人曾经提过,可以通过禁用不需要的解码器及修改源代码来避免,可惜我还没试成功过。大家有什么好办法,请千万留言。 整个脚本,可以在此下载。 设置编译成功后,将dist目录下的五个.a文件拖到Xcode中iFrameExtractor项目中去,替换掉原来那5个,再链上libbz2.1.0.dylib就可以在Xcode中进行真机调试了。

 

configure过程如果出现错误,可以查看生成的config.log,根据具体的错误信息来调整configure的参数。

祝大家好运吧,折腾这东西可真累且无聊。

 

同事因为需要在旧iOS设备上进行调试,这是他折腾出来的armv6的版本,适用于iPhone及iPhone3G系统:

#!/bin/sh
 
 export FFMPEG_DIR=ffmpeg
 
 export DEVRoot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer
 export SDKRoot=$DEVRoot/SDKs/iPhoneOS5.1.sdk
 export CC=$DEVRoot/usr/bin/llvm-gcc
 export LD=$DEVRoot/usr/bin/ld
 
 cd $FFMPEG_DIR
 mkdir -p lib
 
 make clean
 
 ./configure \
 --cc=${CC} \
 --as="gas-preprocessor.pl ${CC}" \
 --sysroot=${SDKRoot} \
 --enable-cross-compile \
 --target-os=darwin \
 --arch=arm \
 --cpu=arm1176jzf-s \
 --extra-cflags="-arch armv6" \
 --extra-ldflags="-arch armv6 -isysroot ${SDKRoot}" \
 --disable-doc \
 --disable-ffplay \
 --disable-ffserver \
 --disable-gpl \
 --disable-shared \
 --enable-static \
 --disable-mmx \
 --disable-debug \
 --enable-decoder=h264  \
 --disable-asm
 
 echo "ready to make "
 
 make 
 
 mv libavcodec/libavcodec.a lib/
 mv libavdevice/libavdevice.a lib/
 mv libavformat/libavformat.a lib/
 mv libavutil/libavutil.a lib/
 mv libswscale/libswscale.a lib/

转帖:http://www.cnblogs.com/wupher/articles/2456421.html

/

首先确保mac下的终端能执行make这样的命令,不行的话需要单独安装.
安装办法参考:安装命令行工具

( 菜单Xcode >> Open Developer Tool >>More Developer Tools)

接下来可以尝试编译一个本机使用的ffmpeg库来使用.
针对xcode4.3.2+ios5.1的环境,网上找到的办法

http://www.cnblogs.com/wupher/articles/2456421.html

http://blog.fuckbugs.me/%E5%B0%86-ffmpeg-%E7%A7%BB%E6%A4%8D%E5%88%B0-ios5-0/

http://blog.sina.com.cn/s/blog_4431c76101013ywx.html


实际操作中,

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的目录下,在终端中执行这样的代码.最后是生成config.h的文件.

export DEVRoot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer
export SDKRoot=$DEVRoot/SDKs/iPhoneOS5.1.sdk
export CC=$DEVRoot/usr/bin/llvm-gcc
 
./configure \
--cc=${CC} \
--as="gas-preprocessor.pl ${CC}" \
--sysroot=${SDKRoot} \
--enable-cross-compile \
--target-os=darwin \
--arch=arm \
--cpu=cortex-a8 \
--extra-cflags="-arch armv7" \
--extra-ldflags="-arch armv7 -isysroot ${SDKRoot}" \
--enable-pic \
--disable-doc \
--disable-ffplay \
--disable-ffserver \
--disable-gpl \
--disable-shared \
--enable-static \
--disable-mmx \
--disable-debug \
--enable-decoder=h264  \
--disable-asm


然后执行make的命令.make clean用来清理

make结束后,执行sudo make install,就会在/usr/local下生成相应的文件.


然后把lib下的.o文件可以直接复制到工程中,进行使用,头文件可以不用了.在工程的target中指定header search path为/usr/local/include就行了.

添加libbz2.1.0.dylib系统库文件


最后注意:上面的方式都是指定编译的o文件为device的,不是模拟器的.


选择模拟器生成adhoc的ipa,结果编译还是失败,出现的两个问题:

错误:

        
        
1
2
3
        
        
Undefined   symbols   for   architecture   i386 :
   "_av_open_input_file" ,   referenced   from :
       - [ VideoFrameExtractor   initWithVideo : ]   in   VideoFrameExtractor . o

应该把

        
        
1
        
        
av_open_input_file ( & pFormatCtx ,   [ moviePath   cStringUsingEncoding : NSASCIIStringEncoding ] , NULL ,   0 , NULL ) ! = 0   

修改为

        
        
1
        
        
  avformat_open_input ( & pFormatCtx ,   [ moviePath   cStringUsingEncoding : NSASCIIStringEncoding ] , NULL ,   NULL ) ! = 0
iFrameExtractor中的codec_type需要将CODEC_TYPE_VIDEO修改为AVMEDIA_TYPE_VIDEO

转帖:http://blog.csdn.net/yuri99/article/details/7751673

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值