设为首页 收藏本站
查看: 954|回复: 0

[经验分享] ios下编译ffmpeg:Mac OS X 10.9.2 + XCode 5.1 + iOS7.1 + ffmpeg 2.1

[复制链接]

尚未签到

发表于 2015-12-30 10:03:40 | 显示全部楼层 |阅读模式
  编译环境:Mac OS X 10.9.2 + XCode 5.1 + iOS7.1
  FFmpeg版本:2.1
  测试视频地址:http://livecdn.cdbs.com.cn/fmvideo.flv
  
  参考链接:
  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.
DSC0000.png

一、安装gas-preprocessor
  Install gas-preprocessor


  • Click on the ZIP icon to download https://github.com/mansr/gas-preprocessor.
  • Copy gas-preprocessor.pl to /usr/bin directory.
  • 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
#
#
###########################################################################
#
# Don't 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 we'll 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 # don't bail out of bash script if ccache doesn't 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
DSC0001.png
  3.添加头文件搜索路径
DSC0002.png
  
  参考资料:
  
  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.iyunv.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

运维网声明 1、欢迎大家加入本站运维交流群:群②:261659950 群⑤:202807635 群⑦870801961 群⑧679858003
2、本站所有主题由该帖子作者发表,该帖子作者与运维网享有帖子相关版权
3、所有作品的著作权均归原作者享有,请您和我们一样尊重他人的著作权等合法权益。如果您对作品感到满意,请购买正版
4、禁止制作、复制、发布和传播具有反动、淫秽、色情、暴力、凶杀等内容的信息,一经发现立即删除。若您因此触犯法律,一切后果自负,我们对此不承担任何责任
5、所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其内容的准确性、可靠性、正当性、安全性、合法性等负责,亦不承担任何法律责任
6、所有作品仅供您个人学习、研究或欣赏,不得用于商业或者其他用途,否则,一切后果均由您自己承担,我们对此不承担任何法律责任
7、如涉及侵犯版权等问题,请您及时通知我们,我们将立即采取措施予以解决
8、联系人Email:admin@iyunv.com 网址:www.yunweiku.com

所有资源均系网友上传或者通过网络收集,我们仅提供一个展示、介绍、观摩学习的平台,我们不对其承担任何法律责任,如涉及侵犯版权等问题,请您及时通知我们,我们将立即处理,联系人Email:kefu@iyunv.com,QQ:1061981298 本贴地址:https://www.yunweiku.com/thread-158220-1-1.html 上篇帖子: Mac OS X Lion 配置 PHP-Xdebug 调试 下篇帖子: How to change the HostName of Mac OS/X Server
您需要登录后才可以回帖 登录 | 立即注册

本版积分规则

扫码加入运维网微信交流群X

扫码加入运维网微信交流群

扫描二维码加入运维网微信交流群,最新一手资源尽在官方微信交流群!快快加入我们吧...

扫描微信二维码查看详情

客服E-mail:kefu@iyunv.com 客服QQ:1061981298


QQ群⑦:运维网交流群⑦ QQ群⑧:运维网交流群⑧ k8s群:运维网kubernetes交流群


提醒:禁止发布任何违反国家法律、法规的言论与图片等内容;本站内容均来自个人观点与网络等信息,非本站认同之观点.


本站大部分资源是网友从网上搜集分享而来,其版权均归原作者及其网站所有,我们尊重他人的合法权益,如有内容侵犯您的合法权益,请及时与我们联系进行核实删除!



合作伙伴: 青云cloud

快速回复 返回顶部 返回列表