`

关于ios中编译ffmpeg0.9.2库

 
阅读更多

很多朋友在问如何在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路径,注意命令中的空格。

配置成功之后将出现如下画面,如果没有成功,则仔细检查命令是否正确:

  1. Enabledfilters:
  2. abufferearwaxpad
  3. abuffersinkfadepan
  4. aconvertfieldorderpixdesctest
  5. aevalsrcfiforgbtestsrc
  6. aformatformatscale
  7. amoviegradfunselect
  8. anullhflipsetdar
  9. anullsinklifesetpts
  10. anullsrclutsetsar
  11. aresamplelutrgbsettb
  12. ashowinfolutyuvshowinfo
  13. buffermandelbrotslicify
  14. buffersinkmoviesplit
  15. cellautonegatetestsrc
  16. colornoformattranspose
  17. copynullunsharp
  18. cropnullsinkvflip
  19. deshakenullsrcvolume
  20. drawboxoverlay
  21. Enabledbsfs:
  22. aac_adtstoascmjpeg2jpegnoise
  23. chompmjpega_dump_headerremove_extradata
  24. dump_extradatamov2textsubtext2movsub
  25. h264_mp4toannexbmp3_header_compress
  26. imx_dump_headermp3_header_decompress
  27. Enabledindevs:
  28. Enabledoutdevs:
  29. License:LGPLversion2.1orlater
  30. Creatingconfig.makandconfig.h...
  31. WARNING:pkg-confignotfound,librarydetectionmayfail.
  32. WARNING:Compilerdoesnotindicatefloating-pointABI,guessingsoft.
  33. Yarin-YangmatoiMac:ffmpeg-0.9.2yarin$

5:编译,最简单了,在终端执行make命令即可,如果出现以下画面,则表示编译成功:

  1. libavutil/opt.c:Infunction‘av_opt_ptr’:
  2. libavutil/opt.c:811:warning:initializationdiscardsqualifiersfrompointertargettype
  3. CClibavutil/parseutils.o
  4. CClibavutil/pixdesc.o
  5. CClibavutil/random_seed.o
  6. CClibavutil/rational.o
  7. CClibavutil/rc4.o
  8. CClibavutil/samplefmt.o
  9. CClibavutil/sha.o
  10. CClibavutil/tree.o
  11. CClibavutil/utils.o
  12. ARlibavutil/libavutil.a
  13. CCffprobe.o
  14. ffprobe.c:Infunction‘probe_file’:
  15. ffprobe.c:1163:warning:‘av_close_input_file’isdeprecated(declaredatlibavformat/avformat.h:1652)
  16. CCcmdutils.o
  17. LDffprobe_g
  18. CPffprobe
  19. STRIPffprobe
  20. 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,如下所示:

  1. //Findthefirstvideostream
  2. videoStream=-1;
  3. for(inti=0;i<pFormatCtx->nb_streams;i++)
  4. if(pFormatCtx->streams[i]->codec->codec_type==AVMEDIA_TYPE_VIDEO)
  5. {
  6. videoStream=i;
  7. break;
  8. }

当然了,你也可以按照iFrameExtractor项目项目中的build_armv6\build_armv7\build_i386\build_universal制作成一个编译脚本,方便后期的编译,如有需要,我后期有时间了,将整理上传。

最后,本次的项目主要是想用ffmpeg进行编解码,使用opengl es进行图像视频渲染,openal进行音频播放,即这三个开源工程的整合,如果大家有很么好的建议,也欢迎交流@杨丰盛

本文出自 “yarin's blog™” 博客,请务必保留此出处http://yarin.blog.51cto.com/1130898/862591


分享到:
评论

相关推荐

Global site tag (gtag.js) - Google Analytics