說明:本文部分內容參考互連網,親自調整測試。
測試視頻地址:http://livecdn.cdbs.com.cn/fmvideo.flv
(MBD,cnblogs上傳圖片功能都不能用了,還去sina weibo發了張圖。)
一、 調試環境準備1. 作業系統:Mac OS 10.7.42. 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 universalmkdir libmkdir armv6mkdir armv7mkdir 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/*.alipo -create -arch armv6 armv6/libavcodec.a -arch armv7 armv7/libavcodec.a -arch i386 i386/libavcodec.a -output universal/libavcodec.alipo -create -arch armv6 armv6/libavdevice.a -arch armv7 armv7/libavdevice.a -arch i386 i386/libavdevice.a -output universal/libavdevice.alipo -create -arch armv6 armv6/libavformat.a -arch armv7 armv7/libavformat.a -arch i386 i386/libavformat.a -output universal/libavformat.alipo -create -arch armv6 armv6/libavutil.a -arch armv7 armv7/libavutil.a -arch i386 i386/libavutil.a -output universal/libavutil.alipo -create -arch armv6 armv6/libswscale.a -arch armv7 armv7/libswscale.a -arch i386 i386/libswscale.a -output universal/libswscale.arm lib/*.acp 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.old: symbol(s) not found for architecture i386clang: 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測試能解碼視頻,但是沒聲音,有時會中斷等問題,還有幾個地方 不替換會出現警告(我還不是很深入瞭解,就不寫了)。