iOS下ffmpeg编译播放网络视频

本文档详细介绍了如何在iOS环境中使用Xcode 4.6.2编译FFmpeg的过程,包括环境搭建、代码下载及配置等关键步骤,并提供了一个实际的示例项目。

一、   调试环境准备

        Xcode版本:Xcode 4.6.2 

        确保xcode的Command Line Tools已安装, Command Line Tools位于Xcode->Perference->Downloads目录下

        确保git工作正常, 安装xcode后,在Terminal里git应该就可以正常工作了, 如果工作不正常,可以到下面的链接下载gitfor mac:http://code.google.com/p/git-osx-installer/

二、   下载代码

.下载ffmpeg源代码

git clone git://source.ffmpeg.org/ffmpeg.git ffmpeg

参考:http://ffmpeg.org/download.html

下载ffmpeg-iphone-build

git clone https://github.com/gabriel/ffmpeg-iphone-build.git

参考:https://github.com/gabriel/ffmpeg-iphone-build

三、  编译

拷贝ffmpeg-iphone-build/gas-preprocessor.pl到 /usr/sbin目录下

/usr/sbin目录在文件夹为当前窗口,上方工具栏选择前往-》前往文件夹输入路径即可。

编译ffmpeg for armv7

 

(1)      将新下载的ffmpeg拷贝到ffmpeg-iphone-build目录下,改名为ffmpeg-armv7

 

(2)      用TextEdit打开build-armv7文件

 

(3)      将build-armv7修改成

 

#!/bin/sh

trap exit ERR

FFMPEG_DIR=ffmpeg-armv7
SCRIPT_DIR=$( (cd -P $(dirname $0) && pwd) )

echo "Pulling r22403..."
# svn co -r22403 svn://svn.ffmpeg.org/ffmpeg/trunk $FFMPEG_DIR

cd $FFMPEG_DIR
mkdir -p dist

# Default configure options
CONFIGURE_OPTIONS="--enable-gpl --enable-postproc --enable-swscale --enable-avfilter --enable-cross-compile --enable-nonfree --disable-armv5te --disable-swscale-alpha --disable-doc --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --disable-asm --disable-debug"

# Add x264 if exists
X264_DIST="$SCRIPT_DIR/x264-armv7/dist"
if [ -d "$X264_DIST" ]; then
CONFIGURE_OPTIONS="$CONFIGURE_OPTIONS --enable-libx264 --extra-ldflags=-L$X264_DIST/lib --extra-cflags=-I$X264_DIST/include"
fi

# Add xvid if exists
XVID_DIST="$SCRIPT_DIR/xvid-armv7"
if [ -d "$XVID_DIST" ]; then
CONFIGURE_OPTIONS="$CONFIGURE_OPTIONS --enable-libxvid --extra-ldflags=-L$XVID_DIST/lib --extra-cflags=-I$XVID_DIST/include"
fi

echo "Configure options: $CONFIGURE_OPTIONS"

./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' \
--sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk \
--extra-ldflags='-arch armv7 -isysroot/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk' \
--prefix=compiled/armv7 \
--target-os=darwin \
--arch=arm \
--cpu=cortex-a8 \
--extra-cflags='-arch armv7' $CONFIGURE_OPTIONS

make && make install

echo "Installed: $FFMPEG_DIR/dist"

   5)在Terminal里运行  ./build-armv7

把省城的lib**.a和头文件拷贝到示例工程,示例工程源码iFrameExtractor (git clone git://github.com/lajos/iFrameExtractor.git)

添加libbz2.1.0.dylib,libiconv.dylib,libz.dylib,

添加Header Search Paths:"$(SRCROOT)/lib/libavcodec"

添加Library Search Oaths :"$(SRCROOT)"

如果得不到视频源分辨率pCodecCtx->height;改成pCodecCtx->coded_width;

测试地址@"rtsp://184.72.239.149/vod/mp4:BigBuckBunny_175k.mov?tcp"

网络地址最后添加?tcp.

工程需要修改

左边选中工程,中间选中target,右面选中Build settings,在Architectures选项卡里面选择

Architetures为Optimized(armv7),Base SDK为Latest iOS(iOS 4.3) Valid Architectures填写armv7.

OK,播放成功。有点卡。

评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值