Xcode4.5编译ffmpeg成功,过程说明

最近项目要用音视频的通话,需要用ffmpeg来实现,但是ffmpeg在iOS平台上的编译有些问题。

1    下载代码

1.下载ffmpeg源代码

git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg

参考:http://ffmpeg.org/download.html

2.下载ffmpeg-iphone-build

git clone https://github.com/gabriel/ffmpeg-iphone-build.git

参考:https://github.com/gabriel/ffmpeg-iphone-build

1. 拷贝ffmpeg-iphone-build/gas-preprocessor.pl到 /usr/sbin目录下

2. 编译ffmpeg for iOS i386版本

(1)将新下载的ffmpeg拷贝到ffmpeg-iphone-build目录下,改名为ffmpeg-i386

(2)用TextEdit打开build-i386文件注释#svnco -r22403 svn://svn.ffmpeg.org/ffmpeg/trunk $FFMPEG_DIR这一行

(3)在CONFIGURE_OPTIONS里添加:--disable-asm --enable-cross-compile

(4)将 ./configure 所在的行修改成:

./configure --cc=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc --as="$SCRIPT_DIR/gas-preprocessor.pl/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc" --extra-ldflags=-L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk/usr/lib/system --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.1.sdk --extra-cflags="-mdynamic-no-pic" --prefix="dist"$CONFIGURE_OPTIONS --target-os=darwin --arch=i386 --cpu=i386 --extra-cflags='-arch i386' --extra-ldflags='-arch i386'

截图

  

 编译ffmpeg for iOS armv7版本

(1)      将新下载的ffmpeg拷贝到ffmpeg-iphone-build目录下,改名为ffmpeg-armv7

(2)      用TextEdit打开build-armv7文件注释#svnco -r22403 svn://svn.ffmpeg.org/ffmpeg/trunk $FFMPEG_DIR这一行

(3)      在CONFIGURE_OPTIONS里添加:--disable-asm --enable-cross-compile

(4)      将 ./configure修改成:

./configure --cc=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc --as="$SCRIPT_DIR/gas-preprocessor.pl/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc" --extra-ldflags=-L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk/usr/lib/system --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.0.sdk --extra-cflags="-mdynamic-no-pic" --prefix="dist"$CONFIGURE_OPTIONS --target-os=darwin --arch=armv7 --cpu=armv7 --extra-cflags='-arch armv7' --extra-ldflags='-arch armv7'

  

armv6的我就不再说了,iPhone3GS开始就是armv7的指令了,都已经不支持了。

特别注意的是

/iPhoneOS6.0.sdk

这个信息一定要正确,不然报错:

Pulling r22403...
Configure options: --enable-gpl --enable-postproc --enable-swscale --enable-avfilter --disable-asm --enable-cross-compile
/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc is unable to create an executable file.
C compiler test failed.

其实就是对应的iPhoneSDK不存在。

合并armv6 armv7 i386  创建fat类型的静态库

将之前的build-armv7拷贝一份,然后将内容更改为

#!/bin/tcsh -f

 

mkdir universal

mkdir lib

mkdir armv7

mkdir i386



mv ffmpeg-armv7/libavcodec/libavcodec.a armv7/

mv ffmpeg-armv7/libavdevice/libavdevice.a armv7/

mv ffmpeg-armv7/libavformat/libavformat.a armv7/

mv ffmpeg-armv7/libavutil/libavutil.a armv7/

mv ffmpeg-armv7/libswscale/libswscale.a armv7/

 

mv ffmpeg-i386/libavcodec/libavcodec.a i386/

mv ffmpeg-i386/libavdevice/libavdevice.a i386/

mv ffmpeg-i386/libavformat/libavformat.a i386/

mv ffmpeg-i386/libavutil/libavutil.a i386/

mv ffmpeg-i386/libswscale/libswscale.a i386/

 

rm universal/*.a

lipo -create -arch armv7 armv7/libavcodec.a -arch i386 i386/libavcodec.a -output universal/libavcodec.a

lipo -create -arch armv7 armv7/libavdevice.a -arch i386 i386/libavdevice.a -output universal/libavdevice.a

lipo -create -arch armv7 armv7/libavformat.a -arch i386 i386/libavformat.a -output universal/libavformat.a

lipo -create -arch armv7 armv7/libavutil.a -arch i386 i386/libavutil.a -output universal/libavutil.a

lipo -create -arch armv7 armv7/libswscale.a -arch i386 i386/libswscale.a -output universal/libswscale.a

rm lib/*.a

cp universal/*.a lib/

静态库编译成功,后面给出一个demo.  

参考链接:

http://www.cnblogs.com/ikodota/archive/2012/09/12/compile_ffmpeg_for_iOS.html

http://www.cocoachina.com/bbs/read.php?tid=98563

http://blog.csdn.net/xt_jat/article/details/7836646

posted on 2013-01-24 14:54  easonoutlook  阅读(3981)  评论(0编辑  收藏  举报