很多朋友在问如何在ios中编译ffmpeg库,虽说网上的教程很多,但是大部分都说按其操作,最后编译总是不成功,正好我最近的项目要用到ffmpeg,所以就再次编译了,同时在这里记下,方便需要参考的朋友。
先说一下本次编译的环境:
mac os x 10.7.4
xcode4.2.1
ios5.0
ffmpeg0.9.2(最新的为0.10.3,一般不喜欢用最新的,原因不说了,所以这里选择次新的,^_^,有兴趣的朋友可以自己去测试最新的版本)
下面直接上步骤:
1:https://github.com/yuvi/gas-preprocessor下载gas-preprocessor.pl文件并将其放置到/usr/sbin路径下,然后对其赋予权限,如下所示:
cd /usr/sbin
chmod 777 gas-preprocessor.pl
2:到ffmpeg的官网http://ffmpeg.org/download.html下载所需要版本代码,这里选择ffmpeg0.9.2,解压之后会得到一个ffmpeg-0.9.2的文件夹。
3:从终端进入到加压出来的ffmpeg-0.9.2文件夹,并执行make clean命令,清除上次生成的库文件。
4:编译配置(分为模拟器和真机两个版本)
4.1:模拟器版本编译配置,在终端执行如下命令:
./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/iPhoneSimulator5.0.sdk/usr/lib/system --sysroot=/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator5.0.sdk --target-os=darwin --arch=i386 --cpu=i386 --extra-cflags='-arch i386' --extra-ldflags='-arch i386' --disable-asm
4.2:真机版本编译配置,在终端执行如下命令:
./configure --disable-doc --disable-ffmpeg --disable-ffplay --disable-ffserver --disable-avfilter --disable-debug --disable-decoders --enable-cross-compile --disable-encoders --disable-armv5te --enable-decoder=h264 --enable-pic --cc=/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc --as='gas-preprocessor/gas-preprocessor.pl /Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc' --extra-ldflags='-arch armv7 -isysroot /Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk' --sysroot=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk --target-os=darwin --arch=arm --cpu=cortex-a8 --extra-cflags='-arch armv7' --disable-asm
注意:需要将其中的sdk路径更换为自己环境所对应的sdk路径,注意命令中的空格。
配置成功之后将出现如下画面,如果没有成功,则仔细检查命令是否正确:
- Enabledfilters:
- abufferearwaxpad
- abuffersinkfadepan
- aconvertfieldorderpixdesctest
- aevalsrcfiforgbtestsrc
- aformatformatscale
- amoviegradfunselect
- anullhflipsetdar
- anullsinklifesetpts
- anullsrclutsetsar
- aresamplelutrgbsettb
- ashowinfolutyuvshowinfo
- buffermandelbrotslicify
- buffersinkmoviesplit
- cellautonegatetestsrc
- colornoformattranspose
- copynullunsharp
- cropnullsinkvflip
- deshakenullsrcvolume
- drawboxoverlay
- Enabledbsfs:
- aac_adtstoascmjpeg2jpegnoise
- chompmjpega_dump_headerremove_extradata
- dump_extradatamov2textsubtext2movsub
- h264_mp4toannexbmp3_header_compress
- imx_dump_headermp3_header_decompress
- Enabledindevs:
- Enabledoutdevs:
- License:LGPLversion2.1orlater
- Creatingconfig.makandconfig.h...
- WARNING:pkg-confignotfound,librarydetectionmayfail.
- WARNING:Compilerdoesnotindicatefloating-pointABI,guessingsoft.
- Yarin-YangmatoiMac:ffmpeg-0.9.2yarin$
5:编译,最简单了,在终端执行make命令即可,如果出现以下画面,则表示编译成功:
- libavutil/opt.c:Infunction‘av_opt_ptr’:
- libavutil/opt.c:811:warning:initializationdiscardsqualifiersfrompointertargettype
- CClibavutil/parseutils.o
- CClibavutil/pixdesc.o
- CClibavutil/random_seed.o
- CClibavutil/rational.o
- CClibavutil/rc4.o
- CClibavutil/samplefmt.o
- CClibavutil/sha.o
- CClibavutil/tree.o
- CClibavutil/utils.o
- ARlibavutil/libavutil.a
- CCffprobe.o
- ffprobe.c:Infunction‘probe_file’:
- ffprobe.c:1163:warning:‘av_close_input_file’isdeprecated(declaredatlibavformat/avformat.h:1652)
- CCcmdutils.o
- LDffprobe_g
- CPffprobe
- STRIPffprobe
- Yarin-YangmatoiMac:ffmpeg-0.9.2yarin$
上面的代码本人亲测,能编译通过,如果不能编译成功的请仔细检查每一步是否操作正确,同时在文末我提供了一个我编译的真机版本的控制台输出信息,大家可以核对。
另外,很多朋友都在使用iFrameExtractor项目(git clone git://github.com/lajos/iFrameExtractor.git)作为测试,如果你选择的ffmpeg版本在0.8.5及其以上,那么需要将VideoFrameExtractor.m中72行的codec_type值改为AVMEDIA_TYPE_VIDEO,如下所示:
- //Findthefirstvideostream
- videoStream=-1;
- for(inti=0;i<pFormatCtx->nb_streams;i++)
- if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
- {
- videoStream=i;
- break;
- }
当然了,你也可以按照iFrameExtractor项目项目中的build_armv6\build_armv7\build_i386\build_universal制作成一个编译脚本,方便后期的编译,如有需要,我后期有时间了,将整理上传。
最后,本次的项目主要是想用ffmpeg进行编解码,使用opengl es进行图像视频渲染,openal进行音频播放,即这三个开源工程的整合,如果大家有很么好的建议,也欢迎交流@杨丰盛。
本文出自 “yarin's blog™” 博客,请务必保留此出处http://yarin.blog.51cto.com/1130898/862591