ios下编译ffmpeg:Mac OS X 10.9.2 + XCode 5.1 + iOS7.1 + ffmpeg 2.1

编译环境:Mac OS X 10.9.2 + XCode 5.1 + iOS7.1

FFmpeg版本:2.1

 

参考链接:

iOS下完美编译ffmpeg+x264,支持armv7, armv7s, 模拟器(支持iOS7&XCode5) 

Installing ffmpeg ios libraries armv7, armv7s, i386 and universal on Mac with 10.8 

 

 

Support universal ffmpeg library for iOS7 and XCode5:

Make sure you have the latest Command Line Tools under Xcode >; Preferences >; Downloads >; Components

我的Xcode版本是5.1,Command Line Tools 位于 Xcode -> Preferences -> Locations.

 

一、安装gas-preprocessor

Install gas-preprocessor

  1. Click on the ZIP icon to download https://github.com/mansr/gas-preprocessor.
  2. Copy gas-preprocessor.pl to /usr/bin directory.
  3. Change permission of gas-preprocessor.pl by setting the privilege to Read & Write for all.

install-gas.sh:

echo "install gas-preproccesor.pr"
git clone git://github.com/mansr/gas-preprocessor.git

echo "copy gas-preprocessor.pl to /usr/sbin"
sudo cp -f gas-preprocessor/gas-preprocessor.pl /usr/sbin/

echo "set execute right"
chmod a+rwx /usr/sbin/gas-preprocessor.pl

echo "install finished."

 

二.开始编译ffmpeg

Download my shell script from: https://gist.github.com/m1entus/6983547

Run sh build-ffmpeg.sh.

改写了脚本,install-ffmpeg.sh:

注意:

1. VERSION改为ffmpeg版本,SDKVERSION改为iOS SDK版本

2. 编译针对armv7和armv7s平台要加入

--disable-armv6 \
--disable-armv6t2 \

3. gcc xcode5默认使用的是clang:

--cc="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" \

4. 最好分别针对armv7、armv7s、i386进行编译:i386代表模拟器,armv6、armv7、armv7s是arm CPU的指令集,一般是向下兼容的。

#!/bin/bash

###########################################################################
#  Choose your ffmpeg version and your currently-installed iOS SDK version:
#
VERSION="2.1"
SDKVERSION="7.1"

echo "install gas-* perl script" ./install-gas.sh # # ########################################################################### # # Dont change anything under this line! # ########################################################################### # No need to change this since xcode build will only compile in the # necessary bits from the libraries we create ARCHS="armv7 armv7s i386" #ARCHS="i386" DEVELOPER=`xcode-select -print-path` cd "`dirname \"$0\"`" REPOROOT=$(pwd) # Where well end up storing things in the end OUTPUTDIR="${REPOROOT}/dependencies" mkdir -p ${OUTPUTDIR}/include mkdir -p ${OUTPUTDIR}/lib mkdir -p ${OUTPUTDIR}/bin BUILDDIR="${REPOROOT}/build" mkdir -p $BUILDDIR # where we will keep our sources and build from. SRCDIR="${BUILDDIR}/src" mkdir -p $SRCDIR # where we will store intermediary builds INTERDIR="${BUILDDIR}/built" mkdir -p $INTERDIR ######################################## cd $SRCDIR # Exit the script if an error happens set -e if [ ! -e "${SRCDIR}/ffmpeg-${VERSION}.tar.bz2" ]; thenecho "Downloading ffmpeg-${VERSION}.tar.bz2" curl -LO http://ffmpeg.org/releases/ffmpeg-${VERSION}.tar.bz2 elseecho "Using ffmpeg-${VERSION}.tar.bz2"fi tar zxf ffmpeg-${VERSION}.tar.gz -C $SRCDIR cd "${SRCDIR}/ffmpeg-${VERSION}" set +e # dont bail out of bash script if ccache doesnt exist CCACHE=`which ccache` if [ $? == "0" ]; then echo "Building with ccache: $CCACHE" CCACHE="${CCACHE} " else echo "Building without ccache" CCACHE="" fi set -e # back to regular "bail out on error" mode 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 -mfpu=neon" else PLATFORM="iPhoneOS" EXTRA_CONFIG="--arch=arm --target-os=darwin --enable-cross-compile --cpu=cortex-a9 --disable-armv5te" EXTRA_CFLAGS="-w -arch ${ARCH} -mfpu=neon" EXTRA_LDFLAGS="-mfpu=neon" fi mkdir -p "${INTERDIR}/${ARCH}" LOG="${INTERDIR}/${ARCH}/build-ffmpeg-${VERSION}.log" export CROSS_TOP="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer" export CROSS_SDK="${PLATFORM}${SDKVERSION}.sdk" export RANLIB=${CROSS_TOP}/usr/bin/ranlib echo "Building ffmpeg-${VERSION} for ${PLATFORM} ${SDKVERSION} ${ARCH}" echo "Please stand by..." ./configure --prefix="${INTERDIR}/${ARCH}" --cc="${DEVELOPER}/Toolchains/XcodeDefault.xctoolchain/usr/bin/clang" --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --disable-iconv --disable-bzlib --enable-avresample --disable-armv6 \ --disable-armv6t2 --sysroot="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDKVERSION}.sdk" --extra-cflags="${EXTRA_CFLAGS} -miphoneos-version-min=${SDKVERSION} -I${OUTPUTDIR}/include" --extra-ldflags="-arch ${ARCH} ${EXTRA_LDFLAGS} -isysroot /Applications/Xcode.app/Contents/Developer/Platforms/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDKVERSION}.sdk -miphoneos-version-min=${SDKVERSION} -L${OUTPUTDIR}/lib" ${EXTRA_CONFIG} --enable-pic --extra-cxxflags="$CPPFLAGS -I${OUTPUTDIR}/include -isysroot ${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDKVERSION}.sdk" make -j16 && make install && make clean #make >> "${LOG}" 2>&1 #make install >> "${LOG}" 2>&1 #make clean >> "${LOG}" 2>&1 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."

三、合并armv7 armv7s i386  创建fat类型的静态库

create-universal.sh:

echo "create universal ..."

REPOROOT=$(pwd)

BUILDDIR="${REPOROOT}/build"

INTERDIR="${BUILDDIR}/built"

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 "install finished."

四、调试kxmovie和iFrameExtractor(推荐使用kxmovie,已经视频和音频同步)

kxmovie主页:https://github.com/kolyvan/kxmovie  

iFrameExtractor:https://github.com/lvjian700/ffmpegc-demo(推荐使用这个,官方的版本太老了)

iFrmaeExtractor只能播放视频,没有音频,不推荐。

使用kxmovie的方法:

1.添加依赖库文件:MediaPlayer, CoreAudio, AudioToolbox, Accelerate, QuartzCore, OpenGLES and libz.dylib,libiconv.dylib

2.添加ffmpeg lib库文件:libavcodec.a, libavformat.a, libavutil.a, libswscale.a, libswresample.a

3.添加头文件搜索路径

 

参考资料:

 

iOS下完美编译ffmpeg+x264,支持armv7, armv7s, 模拟器(支持iOS7&XCode5)   

Installing ffmpeg ios libraries armv7, armv7s, i386 and universal on Mac with 10.8 

iOS: FFmpeg编译和使用问题总结(也不错的,针对ffmpeg 2.X 和 ffmpeg 0.7编译)

http://witcheryne.iteye.com/blog/1734706

编译ffmpeg for iOS,并调试iFrameExtractor demo

iOS使用ffmpeg播放rstp实时监控视频数据流(使用kxmovie)

 

 

ffmpeg历史版本下载地址:http://ffmpeg.org/releases/

gas-preprocessor脚本地址: https://github.com/mansr/gas-preprocessor

FFmpeg 2.X 编译脚本:https://gist.github.com/m1entus/6983547

kxmovie git地址:https://github.com/kolyvan/kxmovie

iFrameExtractor:https://github.com/lvjian700/ffmpegc-demo(推荐使用这个,官方的版本太老了)

 

编译过程中碰到的问题:

1. 报错:

cputype (12) does not match previous archive members cputype (7)(all members must match)
解决方案:
http://www.xcoder.cn/html/mobile/iOS/2013/0307/1604.html

So be sure to make clean to start anew.

2.如果是针对armv7、armv7s编译,ffmpeg configure中要加入

--disable-armv6 \
--disable-armv6t2 \

3.gcc xcode5默认使用的是clang

 


ios下编译ffmpeg:Mac OS X 10.9.2 + XCode 5.1 + iOS7.1 + ffmpeg 2.1,,5-wow.com

郑重声明:本站内容如果来自互联网及其他传播媒体,其版权均属原媒体及文章作者所有。转载目的在于传递更多信息及用于网络分享,并不代表本站赞同其观点和对其真实性负责,也不构成任何其他建议。