编译ffmpeg for iOS,并调试iFrameExtractor demo

 说明:本文部分内容参考互联网,亲自调整测试。

测试视频地址:http://livecdn.cdbs.com.cn/fmvideo.flv

 编译ffmpeg for iOS,并调试iFrameExtractor demo_第1张图片

(MBD,cnblogs上传图片功能都不能用了,还去sina weibo发了张图。)

一、   调试环境准备

1.         操作系统:Mac OS 10.7.4

2.         Xcode版本:Xcode 4.4.1 

3.         确保xcode的Command Line Tools已安装, Command Line Tools位于Xcode->Perference->Downloads目录下

4.         确保git工作正常, 安装xcode后,在Terminal里git应该就可以正常工作了, 如果工作不正常,可以到下面的链接下载gitfor mac:http://code.google.com/p/git-osx-installer/

 

二、   下载代码

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'

(4) 在Terminal里运行  ./build-i386

3 编译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/iPhoneOS5.1.sdk/usr/lib/system --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.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'

 

(5)在Terminal里运行  ./build-armv7

 

4 编译ffmpeg for iOS armv6版本

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

(2)      用TextEdit打开build-armv6文件注释#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/iPhoneOS5.1.sdk/usr/lib/system --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.1.sdk --extra-cflags="-mdynamic-no-pic" --prefix="dist"$CONFIGURE_OPTIONS --target-os=darwin --arch=armv6 --cpu=armv6 --extra-cflags='-arch armv6' --extra-ldflags='-arch armv6'

 

(5)     在Terminal里运行  ./build-armv6

 

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

(1)创建build-universal文件。文件内容为

#!/bin/tcsh -f

 

mkdir universal

mkdir lib

mkdir armv6

mkdir armv7

mkdir i386

 

mv ffmpeg-armv6/libavcodec/libavcodec.a armv6/

mv ffmpeg-armv6/libavdevice/libavdevice.a armv6/

mv ffmpeg-armv6/libavformat/libavformat.a armv6/

mv ffmpeg-armv6/libavutil/libavutil.a armv6/

mv ffmpeg-armv6/libswscale/libswscale.a armv6/

 

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 armv6 armv6/libavcodec.a -arch armv7 armv7/libavcodec.a -arch i386 i386/libavcodec.a -output universal/libavcodec.a

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

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

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

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

rm lib/*.a

cp universal/*.a lib/

 

(2)运行build-universal文件./build-universal

 

此时,我们需要的都在 lib/目录下

 

 四、  调试iFrameExtractor demo

  可以参考开源示例iFrameExtractor (git clone git://github.com/lajos/iFrameExtractor.git)需要将该项目的ffmpeg文件夹库替换为你编译的ffmpeg源码文件夹,在ffmpeg目录下新建lib目录,将上一步编译在 lib/目录下的静态库拷贝进去。打开项目,点击编译运行:出现 ####/iFrameExtractor/ffmpeg/libavutil/common.h:38:10: 'libavutil/avconfig.h' file not found,可以新建 avconfig.h文件,内容如下(也可以从ffmpeg-iphone-build/ffmpeg-i386/libavutil/avconfig.h下复制过去):

/* Generated by ffconf */
#ifndef AVUTIL_AVCONFIG_H
#define AVUTIL_AVCONFIG_H
#define AV_HAVE_BIGENDIAN 0
#define AV_HAVE_FAST_UNALIGNED 0
#define AV_HAVE_INCOMPATIBLE_FORK_ABI 0
#endif /* AVUTIL_AVCONFIG_H */

 

在xcode中继续运行,出现错误:: Use of undeclared identifier 'CODEC_TYPE_VIDEO'

解决办法:把iFrameExtractor中的CODEC_TYPE_VIDEO修改为AVMEDIA_TYPE_VIDEO。(注意如果使用的是版本<=ffmpeg0.8.5的库需要修改)

 

继续运行出现了一些错误,

Undefined symbols for architecture i386:
  "_BZ2_bzDecompress", referenced from:
      _matroska_decode_buffer in libavformat.a(matroskadec.o)
  "_BZ2_bzDecompressEnd", referenced from:
      _matroska_decode_buffer in libavformat.a(matroskadec.o)
  "_BZ2_bzDecompressInit", referenced from:
      _matroska_decode_buffer in libavformat.a(matroskadec.o)
  "_av_open_input_file", referenced from:
      -[VideoFrameExtractor initWithVideo:] in VideoFrameExtractor.o
ld: symbol(s) not found for architecture i386
clang: error: linker command failed with exit code 1 (use -v to see invocation)

解决方法如下:

在项目中添加 libbz2.1.0.dylib 库。

 

继续执行,如出现如下错误:

Undefined symbols for architecture i386:
  "_av_open_input_file", referenced from:
      -[VideoFrameExtractor initWithVideo:] in VideoFrameExtractor.o

把 

av_open_input_file(&pFormatCtx, [moviePath cStringUsingEncoding:NSASCIIStringEncoding],NULL, 0,NULL)!=0 替换成
avformat_open_input(&pFormatCtx, [moviePath cStringUsingEncoding:NSASCIIStringEncoding],NULL, NULL)!=0

此时运行成功,添加了几个网络地址flv测试能解码视频,但是没声音,有时会中断等问题,还有几个地方 不替换会出现警告(我还不是很深入了解,就不写了)。
 

 

转载于:https://www.cnblogs.com/ikodota/archive/2012/09/12/compile_ffmpeg_for_iOS.html

你可能感兴趣的:(编译ffmpeg for iOS,并调试iFrameExtractor demo)