2013年1月27日 星期日

轉載 -- Building FFmpeg for iPhone

轉載 http://blog.sina.com.cn/s/blog_51396f890102dyde.html,作者:观自己

事先申明,此文涉及所有代码、文档均为网上搜集整理,本人只做整合修改。目前我写的代码就归公司所有吧,不贴出来了。所有遇到问题,均从google上获得答案。可能需要翻*墙。
http://www.iphonedevsdk.com/forum/iphone-sdk-development/51697-rtsp-streaming-iphone-works-great.html该网页上下载iXen上传的rtspclient rtspsample代码。这两个代码都不能运行。稍作修改。把rtspclient中的RTSPClientSession.h RTSPClientSession.m添加到rtspsample中去。
参照http://www.cocoachina.com/bbs/read.php?tid-8466-page-1.html这里面制作静态库的方法,把live555的静态库加入进去。编译的时候会有一些小问题,稍加修改即可。这个时候,一个完整的rtsp客户端就ok了。
参考http://www.codza.com/extracting-frames-from-movies-on-iphone这个网页上的iFrameExtractor软件,在这个软件的压缩包中,有ffmpeg的文件夹。注意看ffmpeg中的readme,可以编译出模拟器版本、真机版本的静态库。添加一下就好了。连接ffmpeg库,会有很多问题,比如记得加入 library search path,加入libz.dylib。可以看这里http://www.logresource.com/Question/2872145/showall/http://stackoverflow.com/questions/2380397/error-while-compiling-the-xcode-project-iphone这里。
在模拟器上,贴图方式和iFrameExtractor一样,速度很好。但是在真机上,进过测试,很卡。需要用别的方法。
目前能想到的是使用sdlhttp://immersedcode.org/2011/4/25/sdl-on-ios/参考这个帖子。目前xcodesdk都达不到要求。没有进一步的进展。

iphone+ios编译ffmpeg+for+ios(转载加修改)

分类: iphone iphone+视频开发 2011-09-14 10:13 277人阅读 评论(4) 收藏 举报
1.mov格式解析
http://blog.csdn.net/sunshine1314/article/details/2547275
2。mov解析的开源工程:bento4和ffmpeg,其中bento4直接有xcode的工程文件,和比较详细的test代码
3。ffmpeg如何解析帧图像,可以看看extracting-frames-from-movies-on-iphone
http://www.codza.com/extracting-frames-from-movies-on-iphone
4。ffmpeg iphone编译
http://www.cnblogs.com/wwwkhd/archive/2011/08/09/2131780.html
5.图解autoscan、aclocal、autoheader、automake、autoconf、configure、make
http://jaguar13.iteye.com/blog/614427
6第十五章 make的常见错误信息
http://www.linuxsir.org/main/doc/gnumake/GNUmake_v3.80-zh_CN_html/make-15.html


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(我的是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即可),重新编译即可.

经过验证:需要同时覆盖2个文件。这一步我没按照原文的弄,我是按照错误提示,修改了ffmpeg中的代码(改了上面提到的2个文件,还有其他一些错误),才编译通过的。改起来应该不难。

原文:http://blog.csdn.net/tsingien/article/details/6457246
分享到:
查看评论
2楼 ios_long 2011-09-22 10:05发表 [回复]
Building <wbr>FFmpeg <wbr>for <wbr>iPhone
楼主能不能详细解释一下第七步?没怎么看懂



Building FFmpeg for iPhone
2011年08月31日 星期三 下午 03:21
原此出处:http://lists.mplayerhq.hu/pipermail/ffmpeg-devel/2009-October/076618.html
I am pleased to announce that FFmpeg can now be built unpatched for
the iPhone. The process is still not entirely without pain, however.
Here’s how it’s done:
1. Download and install the iPhone SDK 3.1.
2. Get the latest gas-preprocessor and install it in /usr/local/bin
or some other directory in your $PATH.
http://github.com/yuvi/gas-preprocessor/
3. Get the latest FFmpeg from SVN (minimum r20151).
4. Configure FFmpeg with one of the following commands. These give a
clean build with a default installation of iPhone SDK 3.1 on OSX Leopard.
Other versions may vary.
4a. For iPhone 3GS or iPod Touch 3G 32GB/64GB, use this command:
./configure –cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin9-gcc-4.2.1 –as=’gas-preprocessor.pl /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin9-gcc-4.2.1′ –sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.sdk –enable-cross-compile –target-os=darwin –arch=arm –cpu=cortex-a8 –enable-pic
4b. For other iPhone or iPod Touch models, use this command:
./configure –cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin9-gcc-4.2.1 –as=’gas-preprocessor.pl /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin9-gcc-4.2.1′ –sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS3.1.sdk –enable-cross-compile –target-os=darwin –arch=arm –cpu=arm1176jzf-s
5. Run make.
It is important to specify a correct –cpu option, and not merely an
architecture version. Failure to specify the exact CPU will give a
broken build.
For the iPhone 3GS and compatible iPods, –enable-pic is required to
avoid some nasty-looking linker warnings about relocations.
I have not tested the builds on an iPhone/iPod, so there may still be
remaining issues. Please report any problems you encounter.
Many thanks to David Conrad for the gas-preprocessor script, without
which this would not be possible.

编译iPhone下的FFmpeg

mkdir ./build
# configure for armv7 build
./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=cortex-a8 \
--extra-cflags='-arch armv7' \
--extra-ldflags='-arch armv7' \
--enable-pic \
--enable-cross-compile \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffserver \
--disable-doc
# build for armv7
make clean
make
# copy out the armv7 libs
mkdir ./build/armv7
cp -./libavcodec/libavcodec../build/armv7/libavcodec.a
cp -./libavdevice/libavdevice../build/armv7/libavdevice.a
cp -./libavfilter/libavfilter../build/armv7/libavfilter.a
cp -./libavformat/libavformat../build/armv7/libavformat.a
cp -./libavutil/libavutil../build/armv7/libavutil.a
cp -./libswscale/libswscale../build/armv7/libswscale.a
# configure for armv6 build
./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-\
--extra-cflags='-arch armv6' \
--extra-ldflags='-arch armv6' \
--enable-cross-compile \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffserver \
--disable-doc
# build for armv6
make clean
make
# copy out the armv6 libs
mkdir ./build/armv6
cp -./libavcodec/libavcodec../build/armv6/libavcodec.a
cp -./libavdevice/libavdevice../build/armv6/libavdevice.a
cp -./libavfilter/libavfilter../build/armv6/libavfilter.a
cp -./libavformat/libavformat../build/armv6/libavformat.a
cp -./libavutil/libavutil../build/armv6/libavutil.a
cp -./libswscale/libswscale../build/armv6/libswscale.a
# configure for i386 build
./configure \
--cc=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc \
--as='gas-preprocessor.pl /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc' \
--sysroot=/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk\
--extra-ldflags=-L/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.3.sdk/usr/lib/system\
--target-os=darwin \
--arch=i386 \
--cpu=i386 \
--extra-cflags='-arch i386' \
--extra-ldflags='-arch i386' \
--enable-cross-compile \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffserver \
--disable-doc
# build for i386
make clean
make
# copy out the i386 libs
mkdir ./build/i386
cp -./libavcodec/libavcodec../build/i386/libavcodec.a
cp -./libavdevice/libavdevice../build/i386/libavdevice.a
cp -./libavfilter/libavfilter../build/i386/libavfilter.a
cp -./libavformat/libavformat../build/i386/libavformat.a
cp -./libavutil/libavutil../build/i386/libavutil.a
cp -./libswscale/libswscale../build/i386/libswscale.a
# make fat (universal) libs
lipo -output ./build/libavcodec.a  -create \
-arch armv6 ./build/armv6/libavcodec.\
-arch armv7 ./build/armv7/libavcodec.\
-arch i386 ./build/i386/libavcodec.a

lipo -output ./build/libavdevice.a  -create \
-arch armv6 ./build/armv6/libavdevice.\
-arch armv7 ./build/armv7/libavdevice.\
-arch i386 ./build/i386/libavdevice.a

lipo -output ./build/libavfilter.a  -create \
-arch armv6 ./build/armv6/libavfilter.\
-arch armv7 ./build/armv7/libavfilter.\
-arch i386 ./build/i386/libavfilter.a

lipo -output ./build/libavformat.a  -create \
-arch armv6 ./build/armv6/libavformat.\
-arch armv7 ./build/armv7/libavformat.\
-arch i386 ./build/i386/libavformat.a

lipo -output ./build/libavutil.a  -create \
-arch armv6 ./build/armv6/libavutil.\
-arch armv7 ./build/armv7/libavutil.\
-arch i386 ./build/i386/libavutil.a

lipo -output ./build/libswscale.a  -create \
-arch armv6 ./build/armv6/libswscale.\
-arch armv7 ./build/armv7/libswscale.\
-arch i386 ./build/i386/libswscale.a

上面针对i386,也就是模拟器的编译配置不一定,下面有另一种配置方式:
./configure \
--disable-bzlib \
--disable-mmx \
--disable-doc \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffserver \
--cc=/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/i686-apple-darwin10-gcc-4.2.1 \
--as='gas-preprocessor/gas-preprocessor.pl /Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/i686-apple-darwin10-gcc-4.2.1' \
--sysroot=/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk \
--extra-cflags='-fmessage-length=0 -pipe -Wno-trigraphs -fpascal-strings -O0 -fasm-blocks -Wreturn-type -Wunused-variable -D__IPHONE_OS_VERSION_MIN_REQUIRED=30000 -isysroot /Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator4.0.sdk -fvisibility=hidden -mmacosx-version-min=10.5 -gdwarf-2'


另外一篇文章
移值FFMPEG到iPhone或Mac OS/X
有关FFMPEG的详细说明可以参考网上相关文档;在这里我们只讲述FFMPEG移到iPhone或Mac OS/X的过程及相关注意事项。
FFMPEG功能相当强大,在完整的FFMPEG包中就包含了ffserver, ffplay, ffmpeg, avcodec, avdevice, avformat, avutil, swscale等;其中ffserver, ffplay, ffmpeg为应该程序,对与我们这些从事软件开发的人来说基本上没什么用;而avcodec为加解码库、avformat为格式库,avutil则为基 础库(但平常我们很少用到), swscale则为图象处理库;所以我们所要的就是移值avcodec, avformat, avutil, swscale这四个库。
移值到Mac OS/X下过程:
一、   配置
./configure --prefix=/Developer/usr --cc=/Developer/usr/bin/gcc-4.0 --enable-gpl --enable-shared --disable-ipv6 --enable-swscale --enable-zlib --enable-bzlib --disable-ffmpeg --disable-ffplay --disable-ffserver --disable-vhook
二、   编译
make
三、   安装
make install
说明:上面的/Developer/usr为目标目录,如果你的Xcode为默认安装,则这样安装后既可以在Xcode中编译及调式你的代码了;
移值到Mac OS/X下的模拟iPhone平台下过程:
一、   配置
./configure --prefix=/Developer/usr --disable-debug --cc=/Developer/usr/bin/i686-apple-darwin9-gcc-4.0.1 --enable-gpl --enable-static --disable-shared --disable-ipv6 --enable-swscale --enable-zlib --enable-bzlib --disable-ffmpeg --disable-ffplay --disable-ffserver --disable-vhook --enable-pthreads
其中:也可以加入--enable-shared,这个选项是允许其编译产生动态库,在以后的编程中要用到这个几个动态库。--prefix设置的安装目录。如 果在configure的时候不加上--enable-shared的,则采用静态链接的方式,不会生成那三个动态库。同时生成的ffplay、 ffmpeg的执行文件也比较的大,因为他们不需要动态库的支持,就可以执行。但是不利于再次开发,所以我也可以考虑采用动态链接的方式。
二、   编译
make
三、   安装
make install
安装之后在/usr/local/ffmpeg会看到有三个目录
  lib 动态链接库位置
  include 编程要用到头文件
  bin 执行文件所在的目录
为了以后方便编程,我们把lib中的三个链接库libavcodec.so libavformat.so libavutil.so复制到/usr/lib下。把include目录下的ffmpeg目录复制到/usr/include下。 执行bin目录下的 ffplay,可以去播放音频或者视频文件。例如播放1.mp3
  ./ffplay 1.mp3
  另外,bin目录下还有两个文件:ffmpeg和ffserver
  ffmpeg是一个很好的视频和音频的格式转化工具。网上有很多它的说明文档。如果不想生成ffserver,只要在./configure的时候加--disable-ffserver即可。
说明:上面的/Developer/usr为目标目录,如果你的Xcode为默认安装,则这样安装后既可以在Xcode中编译及在模拟器下调式你的代码了;
移值到iPhone平台下过程:
一、   配置
./configure --enable-cross-compile --cross-prefix=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ --cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/arm-apple-darwin9-gcc-4.0.1 --prefix=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk/usr --extra-cflags="-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk" --extra-ldflags="-isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk -Wl,-syslibroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS2.0.sdk" --arch=armv6 --enable-armv6 --enable-gpl --enable-shared --disable-ipv6 --enable-swscale --enable-zlib --enable-bzlib --disable-ffmpeg --disable-ffplay --disable-ffserver --disable-vhook
二、   编译
make
三、   安装
make install
说明:上面的/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/为目标目录,如果你的Xcode为默认安装,则这样安装后既可以在Xcode中编译及在模拟器下调式你的代码了。
相关说明:
    在ffmpeg中如果使用静态库则会出现一些连接错;所以在安装ffmpeg库时请选中动态库。
OK,到现在我们就你已经知道了如何把ffmpeg移到到iPhone下并把ffmpeg库和Xcode结合起来了吧;当然如果你的Xcode工具非默认安装,请更上相关目录选项.