模拟器与真机下ffmpeg的编译方法(总结版)

编译ffmepg模拟器版本:
1. 到https://github.com/gabriel/ffmpeg-iphone-build下载ffmpeg-iphone-build
2.先将gas-preprocessor.pl拷贝到/usr/sbin/目录中。
3.到ffmpeg官网上下载ffmpeg源码
4.在终端下定位到ffmpeg的目录运行
./configure --disable-doc --disable-ffmpeg --disable-ffplay --disable-ffserver --disable-avfilter --disable-debug --disable-encoders --enable-cross-compile --disable-decoders --disable-armv5te --enable-decoder=h264 --enable-pic --cc=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc --as='gas-preprocessor/gas-preprocessor.pl /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc' --extra-ldflags=-L/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/usr/lib/system --sysroot=/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk --target-os=darwin --arch=i386 --cpu=i386 --extra-cflags='-arch i386' --extra-ldflags='-arch i386'
5.输入make命令
6.将libavcodec.a,libavdevice.a,libavformat.a,libavutil.a,libswscale.a到对应的目录下拷贝出来
7.在项目中就可以使用了。可以参考开源示例iFrameExtractor (git clone git://github.com/lajos/iFrameExtractor.git)需要将该项目的ffmpeg文件夹库替换为你编译的ffmpeg源码文件夹,在ffmpeg目录下新建lib目录,将刚刚拷贝出来的静态库拷贝进去。打开项目,添加libbz2.1.0.dylib系统库文件。点击编译运行就可以使用了。
8.注意如果使用的是ffmpeg0.8.5的库的话iFrameExtractor中的codec_type需要修改为AVMEDIA_TYPE_VIDEO。(下同)

编译arm7版本,网上搜到的版本,完全按照以下步骤做就行了。可以编译出arm7的库。
1. 下载:
git clone git://github.com/lajos/iFrameExtractor.git
2. 编辑:
build_armv6和build_armv7,修改./configure后面的参数,主要是SDK版本.我的是4.3,修改为:
./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/iPhoneOS4.3.sdk --cpu=arm1176jzf-s --extra-cflags='-arch armv6' --extra-ldflags='-arch armv6'

3. 编译:
出错,提示:
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc is unable to create an executable file.
C compiler test failed.
查看config.err文件,最后提示:
ld: file not found: /usr/lib/system/libcache.dylib for architecture armv7
collect2: ld returned 1 exit status
4. 重新修改configure参数为:
./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/iPhoneOS4.3.sdk --cpu=cortex-a8 --extra-cflags='-arch armv7' --extra-ldflags='-arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk' --enable-pic
5. 编译:
build_armv7
最后生成静态库,在lib目录和armv7目录.
6.用xcode打开iFrameExtractor.xcodeproj,现在编译会出错,需要修改几个地方:
左边选中工程,中间选中target,右面选中Build settings,在Architectures选项卡里面选择Architetures为Optimized(armv7),Base SDK为Latest iOS(iOS 4.3) Valid Architectures填写armv7.
编译目标选择iOS Device,当然,如果有连接电脑的设备,可以选择设备.
编译,提示:


Undefined symbols for architecture armv7:
  "_BZ2_bzDecompressInit", referenced from:
      _matroska_decode_buffer in libavformat.a(matroskadec.o)
  "_BZ2_bzDecompressEnd", referenced from:
      _matroska_decode_buffer in libavformat.a(matroskadec.o)
  "_BZ2_bzDecompress", referenced from:
      _matroska_decode_buffer in libavformat.a(matroskadec.o)

添加库libbz2.1.0.dylib,再次编译,OK通过

在ios5.0中编译ffmpeg。 到官网下载ffmpeg,然后在终端进入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 --enable-decoder=rawvideo --disable-asm

make进行编译。

然后将各个.a文件拷贝出来。


 

 ===========================================

在Xcode4.3环境下有些变化,需要注意isysroot

这是我最后调通的参数。。。
./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/iPhoneOS4.3.sdk --enable-cross-compile --target-os=darwin --cpu=arm1176jzf-s --arch=arm --extra-cflags='-arch armv6 --sysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk' --extra-ldflags='-arch armv6 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk'

 

===========================================

 

1. 下载:
在终端中输入:git clone git://github.com/lajos/iFrameExtractor.git
 注:该文件包中包含ffmpeg库以及demo。
2.编辑:
打开iFrameExtractor文件夹下ffmpeg中的 build_armv6和build_armv7,修改./configure后面的参数,主要是SDK版本.我的是4.3,修改为:
./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/iPhoneOS4.3.sdk --cpu=arm1176jzf-s --extra-cflags='-arch armv6' --extra-ldflags='-arch armv6'
3. 编译:
出错,提示:
/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc is unable to create an executable file.
C compiler test failed.
查看config.err文件,最后提示:
ld: file not found: /usr/lib/system/libcache.dylib for architecture armv7
collect2: ld returned 1 exit status



4. 重新修改build_armv7中的configure参数为:
./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/iPhoneOS4.3.sdk --cpu=cortex-a8 --extra-cflags='-arch armv7' --extra-ldflags='-arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk' --enable-pic
5. 编译:
build_armv7
最后生成静态库,在lib目录和armv7目录.
注:build_armv7不能运行,则将该文件的每个命令直接在终端中运行。


6.用xcode(我的是4.0版本)打开iFrameExtractor.xcodeproj,现在编译会出错,需要修改几个地方:
左边选中工程,中间选中target,右面选中Build settings,在Architectures选项卡里面选择Architetures为Optimized(armv7),Base SDK为Latest iOS(iOS 4.3) Valid Architectures填写armv7.
编译目标选择iOS Device,当然,如果有连接电脑的设备,可以选择设备.
编译,提示:

Undefined symbols for architecture armv7:
  "_BZ2_bzDecompressInit", referenced from:
      _matroska_decode_buffer in libavformat.a(matroskadec.o)
  "_BZ2_bzDecompressEnd", referenced from:
      _matroska_decode_buffer in libavformat.a(matroskadec.o)
  "_BZ2_bzDecompress", referenced from:
      _matroska_decode_buffer in libavformat.a(matroskadec.o)

添加库libbz2.1.0.dylib,再次编译,OK通过.


以下步骤可以忽略:

7. 修改了ffmpeg版本到最新版(0.7),编译的时候需要把common.mak复制到新版本目录.
编译的时候遇到错误:
ERROR: .endm without .macro at /usr/local/bin/gas-preprocessor.pl line 83, <ASMFILE> line 55
用老版本的libavcodec/arm/asm.S和libavcoec/arm/dsputil_arm.S覆盖新版本(实际上我怀疑只覆盖asm.S即可),重新编译即可.
原文地址:http://blog.csdn.net/tsingien/article/details/6457246




ARM6如果遇到错误不如试试下面的config

./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/iPhoneOS4.3.sdk --extra-ldflags=-L/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS4.3.sdk/usr/lib/system --target-os=darwin --arch=arm --cpu=arm1176jzf-s --extra-cflags='-arch armv6' --extra-ldflags='-arch armv6' --enable-pic --enable-cross-compile --disable-ffmpeg --disable-ffplay --disable-ffserver --disable-doc --disable-ffprobe


我的FFMPeg版本:"SVN-r4"

 

===========================================

 

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

 
 
(转帖注明出处和作者-xiaochengfei,尊重我得劳动成果,谢谢!)

我不是蛋疼弄这个哈~搞这个是因为之前我的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 

 

 

//编译日志
在加个 i386的 错误

If you are encountering this problem running a simulator binary within gdb, make sure you 'set start-with-shell off' first


解决:
before this cleanAll build then

In xcode go to Project > set active executable > appname - Iphone 4.0 simulator

then open simulator then go to Hardware > version > 4.0.2

then double click urapptarget and in build tab change "ios deployment target = 4.0"

now run in simulator it will work 

 

//////////////////////////

iPhone3需要支持arm6哦,我现在也在用ffmpeg解码,支持arm6的,我把我的编译选项发来,你参考下(ffmpeg版本0.9.0)
./configure --enable-cross-compile --cross-prefix=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ --cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2 --as='gas-preprocessor/gas-preprocessor.pl  /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin10-llvm-gcc-4.2' --prefix=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr --extra-cflags="-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk" --extra-ldflags="-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk -Wl,-syslibroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk"  --target-os=darwin --arch=armv6  --enable-gpl --enable-static --disable-shared  --enable-zlib --enable-bzlib --disable-debug --disable-ffmpeg --disable-ffplay --disable-ffserver --disable-asm --disable-debug

posted @ 2012-04-01 06:40  jprothwell  阅读(5128)  评论(0编辑  收藏  举报