系统环境
MAC OS X 10.9、 XCode 6.1
所以iPhone SDK是8.1~这个请大家一定要注意。
准备工作
你需要编译好x264库
简单来说,x264库是h264的软编码的一个非常优秀的实现(不仅仅能支持h264转换,还有其他各种格式的转化,但是我这里只是用到了转化成h264格式图片),而FFmpeg必须要有x264库做基础才能编译成功。
所以第一步,就是编译x264库,请参照这个链接x264编译
这里就不作赘述。
编译FFmpeg
1、下载ffmpeg2.2.5版本代码,并解压。
2、下载并解压gas-preprocessor.pl,这个自己找吧,我把网址忘记了。
在终端中使用cp命令将它复制到 /usr/sbin/目录,并赋予可执行权限。哦,对了,这个文件是你编译好x264后,里面文件里就有。
sudo cp -f gas-preprocessor/gas-preprocessor.pl /usr/sbin/
chmod +x /usr/sbin/gas-preprocessor.pl
3、在ffmpeg目录下创建一个config.sh脚本,脚本内容如下。
#!/bin/bash
SDKVERSION="8.1"
ARCHS="armv7 armv7s i386"
DEVELOPER=`xcode-select -print-path`
cd "`dirname \"$0\"`"
REPOROOT=$(pwd)
# where we will store intermediary builds
INTERDIR="${REPOROOT}/built"
mkdir -p $INTERDIR
########################################
# Exit the script if an error happens
for ARCH in ${ARCHS}
do
if [ "${ARCH}" == "i386" ];
then
PLATFORM="iPhoneSimulator"
EXTRA_CONFIG="--arch=i386 --disable-asm --enable-cross-compile --target-os=darwin --cpu=i386"
EXTRA_CFLAGS="-arch i386"
EXTRA_LDFLAGS="-I${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDKVERSION}.sdk/usr/lib"
else
PLATFORM="iPhoneOS"
EXTRA_CONFIG="--arch=arm --target-os=darwin --enable-cross-compile --cpu=cortex-a9 --disable-armv5te"
EXTRA_CFLAGS="-w -arch ${ARCH}"
fi
mkdir -p "${INTERDIR}/${ARCH}"
./configure --prefix="${INTERDIR}/${ARCH}" \
--disable-neon \
--disable-armv6 \
--disable-armv6t2 \
--disable-ffmpeg \
--disable-ffplay \
--disable-ffprobe \
--disable-ffserver \
--disable-iconv \
--disable-bzlib \
--enable-avresample \
--sysroot="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDKVERSION}.sdk" \
--cc="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" \
--as='/usr/local/bin/gas-preprocessor.pl' \
--extra-cflags="${EXTRA_CFLAGS} -miphoneos-version-min=${SDKVERSION}" \
--extra-ldflags="-arch ${ARCH} ${EXTRA_LDFLAGS} -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDKVERSION}.sdk -miphoneos-version-min=${SDKVERSION}" ${EXTRA_CONFIG} \
--enable-pic \
--extra-cxxflags="$CPPFLAGS -isysroot ${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDKVERSION}.sdk"
make && make install && make clean
done
mkdir -p "${INTERDIR}/universal/lib"
cd "${INTERDIR}/armv7/lib"
for file in *.a
do
cd ${INTERDIR}
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."
done
cp -r ${INTERDIR}/armv7/include ${INTERDIR}/universal/
echo "Done."
SDKVERSION 是XCode的版本,通过xcode-select -print-path
来获取XCode的安装路径,ARCHS是编译的三种模式,接下来在终端中cd到ffmpeg目录,./config.sh执行就可以编译了。等到编译完成后,在ffmpeg目录下会多出一个built目录,里面分别是armv7 armv7s i386及三个合并的universal版本了。
这个里面的因为编译选项加了很多,而且有armv7 7s i386版本,故文件比较大。如果iphone调试的话个人推荐用armv7版本,i386版用来模拟器调试。
借用一下别人的成功的图像,这个就是编译成功的结果,那么编译成功之后,这个静态库就可以加入相应需要FFmpeg的项目里面了,先加入framework,后在search header path这里加入对头文件地址的包含,这样就可以使用了。(link的时候还是有问题的,这个因为时间比较晚了,等以后想起来再补充)
这个文章参照的这位大神的,多谢他的博客,我成功编译的ffmpeg,希望大家少走弯路。参考博客