编译最新ffmpeg2.0.1到iOS设备

www.mingjianhua.com 

转载请注明出处。

上一篇文章讲了用NDKr9编译最新ffmpeg2.0.1到android平台,一般做了Android平台的编解码就免不了要做iOS,这次一起把iOS的ffmpeg编译也一起写一篇吧。


一、首先准备开发环境

1、XCode大家都有了吧,就不说了。

2、Command line tools,得装个。

3、gas-preprocessor,

安装方式是直接copy文件 gas-preprocessor.pl 到 /usr/bin ,记得修改权限可执行.

因为在编译ffmpeg的时候,gas-preprocessor版本必须和ffmpeg配合,所以如果你下载的ffmpeg源码是最新的,那么建议去 libav网站 下载最新的 gas-preprocessor.

如果之后在编译时候遇到类似这样的错误

unknown register alias 'TCOS_D0_HEAD'

那么可以尝试更换 gas-preprocessor版本来解决.

4、

然后 pkg-config, 可以直接通过MacPorts来安装

sudo port install pkgconfig

其实没有也行,装macports各种蛋疼。


2. 下载ffmpeg的源码

下载地址:http://ffmpeg.org/download.html


3. 编译armv7的支持

建一个build_armv7.sh文件,把下面内容拷进去。

#!/bin/sh


#armv7

./configure \

--disable-shared \

--enable-static \

--prefix=armv7 \

--enable-small \

--disable-ffmpeg \

--disable-ffplay \

--disable-ffprobe \

--disable-ffserver \

--disable-avdevice \

--disable-avformat \

--disable-swresample \

--disable-swscale \

--disable-postproc \

--disable-avfilter \

--disable-everything \

--disable-encoders \

--disable-decoders \

--enable-decoder=h264 \#要开什么编解码器自己看着办

--disable-muxers \

--disable-devices \

--disable-protocols \

--disable-network \

--disable-avdevice \

--enable-cross-compile \

--sysroot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk" \

--target-os=darwin \

--cc="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc" \

--extra-cflags="-arch armv7 -mfpu=neon -miphoneos-version-min=5.1" \

--extra-ldflags="-arch armv7 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk -miphoneos-version-min=5.1" \

--arch=arm \

--cpu=cortex-a9 \

--enable-pic \

--enable-neon 


make clean 

make 

make install


然后在命令行里输入

./build_armv7.sh

然后就可以等结果了


完了后可以看到在ffmpeg路径下有个armv7路径下有了你要的include 和lib文件了。


3. 编译armv7s,i386的支持

跟上面差不多。就不多说了,就只贴configure文件了

#armv7s

./configure \

--prefix=armv7s \

--disable-ffmpeg \

--disable-ffplay \

--disable-ffprobe \

--disable-ffserver \

--disable-encoders \

--disable-muxers \

--disable-devices \

--disable-protocols \

--disable-network \

--disable-avdevice \

--enable-avresample \

--enable-cross-compile \

--sysroot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk" \

--target-os=darwin \

--cc="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc" \

--extra-cflags="-arch armv7s -mfpu=neon -miphoneos-version-min=5.1" \

--extra-ldflags="-arch armv7s -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk -miphoneos-version-min=5.1" \

--arch=arm \

--cpu=cortex-a9 \

--enable-pic \

--enable-neon 


make clean 

make 

make install


#i386

./configure \

--prefix=i386 \

--disable-ffmpeg \

--disable-ffplay \

--disable-ffprobe \

--disable-ffserver \

--disable-encoders \

--disable-muxers \

--disable-devices \

--disable-protocols \

--disable-network \

--disable-avdevice \

--enable-avresample \

--enable-cross-compile \

--sysroot="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk" \

--target-os=darwin \

--cc="/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc" \

--extra-cflags="-arch i386" \

--extra-ldflags="-arch i386 -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk" \

--arch=i386 \

--cpu=i386 \

--enable-pic \

--disable-asm


make clean 

make 

make install


6. 最后,我们合并armv7、armv7s、i386

建立merge.sh文件并运行


#merge

cd armv7/lib


for file in *.a

do

cd ../..

xcrun -sdk iphoneos lipo -output universal/lib/$file  -create -arch armv7 armv7/lib/$file -arch armv7s armv7s/lib/$file -arch i386 i386/lib/$file

echo "Universal $file created."

cd -

done

cd ../..

完成后在universal/lib/下就是我们需要的静态库了。



 

www.mingjianhua.com


 

posted on 2013-09-17 23:02  you Richer  阅读(247)  评论(0编辑  收藏  举报