IOS 编译ffmpeg For SDK6.1,模拟器、armv7、armv7s均可使用

最近在研究IOS视频播放器,需要使用到ffmpeg4ios,所以整理编译过程。

需要使用到Git,Linux Shell脚本执行install-ffmpeg.sh即可。

下述Linux Shell脚本下载地址:http://ishare.iask.sina.com.cn/f/37135883.html

install-ffmpeg.sh

SRCDIR=`pwd`
VERSION="1.2.1"

echo "install gas-* perl script"
./install-gas.sh

echo "download ffmpeg"
set -e
if [ ! -e ffmpeg-${VERSION}.tar.bz2 ]; then
    echo "Downloading ffmpeg-${VERSION}.tar.bz2"
    curl -O  http://ffmpeg.org/releases/ffmpeg-${VERSION}.tar.bz2
else
    echo "Using ffmpeg-${VERSION}.tar.bz2"
fi

tar jxvf ffmpeg-${VERSION}.tar.bz2


echo "copy install shell script to ffmpeg"
cp ./compile-*.sh "ffmpeg-${VERSION}"
cd "ffmpeg-${VERSION}"

if [ -d x264 ]
    then
        (cd $SRCDIR/ffmpeg-${VERSION}/x264; git pull)
    else
        git clone git://git.videolan.org/x264.git x264
fi

echo "compile armv7s ..."
./compile-armv7s.sh

echo "compile armv7 ..."
./compile-armv7.sh

echo "compile i386 for Simulator ..."
./compile-i386.sh

echo "packaging universal version ..."
./compile-universal.sh

 

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 +x /usr/sbin/gas-preprocessor.pl

echo "install finished."

 

compile-armv7s.sh

SRCDIR=`pwd`
SDKVERSION="6.1"

cd $SRCDIR/x264

make clean

CC=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc \
    ./configure \
        --host=arm-apple-darwin \
        --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDKVERSION}.sdk \
        --prefix=build/armv7s \
        --extra-cflags='-arch armv7s' \
        --extra-ldflags="-L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDKVERSION}.sdk/usr/lib/system -arch armv7s" \
        --enable-pic --disable-shared --enable-static

make && make install

cd $SRCDIR

make clean

./configure \
    --prefix=armv7s \
    --cc=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc \
    --as='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/iPhoneOS${SDKVERSION}.sdk \
    --extra-ldflags=-L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDKVERSION}.sdk/usr/lib/system \
    --target-os=darwin \
    --arch=arm \
    --cpu=cortex-a9 \
    --extra-cflags='-I./x264/build/armv7s/include -arch armv7s' \
    --extra-ldflags='-L./x264/build/armv7s/lib -arch armv7s' \
    --enable-pic \
    --enable-cross-compile \
    --enable-gpl \
    --enable-libx264 \
    --disable-ffmpeg  \
    --disable-ffplay \
    --disable-ffserver \
    --disable-doc
        



# build for armv7s
make clean
make

# copy out the armv7s libs
mkdir -p ./build/armv7s
cp -f ./libavcodec/libavcodec.a ./build/armv7s/libavcodec.a
cp -f ./libavdevice/libavdevice.a ./build/armv7s/libavdevice.a
cp -f ./libavfilter/libavfilter.a ./build/armv7s/libavfilter.a
cp -f ./libavformat/libavformat.a ./build/armv7s/libavformat.a
cp -f ./libavutil/libavutil.a ./build/armv7s/libavutil.a
cp -f ./libswscale/libswscale.a ./build/armv7s/libswscale.a

 

compile-armv7.sh

SRCDIR=`pwd`
SDKVERSION="6.1"

cd $SRCDIR/x264

make clean

CC=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc \
    ./configure \
        --host=arm-apple-darwin \
        --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDKVERSION}.sdk \
        --prefix=build/armv7 \
        --extra-cflags='-arch armv7' \
        --extra-ldflags="-L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDKVERSION}.sdk/usr/lib/system -arch armv7" \
        --enable-pic --disable-shared --enable-static

make && make install

cd $SRCDIR

make clean

./configure \
    --cc=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc \
    --as='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/iPhoneOS${SDKVERSION}.sdk \
    --extra-ldflags=-L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDKVERSION}.sdk/usr/lib/system \
    --target-os=darwin \
    --arch=arm \
    --cpu=cortex-a8 \
    --extra-cflags='-I./x264/build/armv7/include -arch armv7' \
    --extra-ldflags='-L./x264/build/armv7/lib -arch armv7' \
    --enable-pic \
    --enable-cross-compile \
    --enable-gpl \
    --enable-libx264 \
    --disable-ffmpeg  \
    --disable-ffplay \
    --disable-ffserver \
    --disable-doc
        



# build for armv7
make clean
make

# copy out the armv7 libs
mkdir -p ./build/armv7
cp -f ./libavcodec/libavcodec.a ./build/armv7/libavcodec.a
cp -f ./libavdevice/libavdevice.a ./build/armv7/libavdevice.a
cp -f ./libavfilter/libavfilter.a ./build/armv7/libavfilter.a
cp -f ./libavformat/libavformat.a ./build/armv7/libavformat.a
cp -f ./libavutil/libavutil.a ./build/armv7/libavutil.a
cp -f ./libswscale/libswscale.a ./build/armv7/libswscale.a

 

compile-i386.sh

SRCDIR=`pwd`
SDKVERSION="6.1"

cd $SRCDIR/x264

echo "compile x264 i386 ..."

make clean

CC=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc \
    ./configure \
        --host=i386-apple-darwin \
        --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator${SDKVERSION}.sdk \
        --prefix=build/i386 \
        --extra-cflags='-arch i386' \
        --extra-ldflags="-L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator${SDKVERSION}.sdk/usr/lib/system -arch i386" \
        --enable-pic --disable-shared --enable-static --disable-asm

make && make install

cd $SRCDIR

echo "compile ffmpeg i386 ..."

make clean

./configure \
    --cc=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc \
    --as='gas-preprocessor.pl /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc' \
    --sysroot=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator${SDKVERSION}.sdk \
    --extra-ldflags=-L/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator${SDKVERSION}.sdk/usr/lib/system \
    --target-os=darwin \
    --arch=i386 \
    --cpu=i386 \
    --extra-cflags='-I./x264/build/i386/include -arch i386' \
    --extra-ldflags='-L./x264/build/i386/lib -arch i386' \
    --enable-pic \
    --enable-cross-compile \
    --enable-gpl \
    --enable-libx264 \
    --disable-ffmpeg  \
    --disable-ffplay \
    --disable-ffserver \
    --disable-doc \
    --disable-asm


# build for i386
make clean
make

# copy out the i386 libs
mkdir -p ./build/i386

cp -f ./libavcodec/libavcodec.a ./build/i386/libavcodec.a
cp -f ./libavdevice/libavdevice.a ./build/i386/libavdevice.a
cp -f ./libavfilter/libavfilter.a ./build/i386/libavfilter.a
cp -f ./libavformat/libavformat.a ./build/i386/libavformat.a
cp -f ./libavutil/libavutil.a ./build/i386/libavutil.a
cp -f ./libswscale/libswscale.a ./build/i386/libswscale.a

 

compile-universal.sh

# make fat (universal) libs
xcrun -sdk iphoneos lipo -output ./build/libavcodec.a  \
    -create \
        -arch armv7s ./build/armv7s/libavcodec.a \
        -arch armv7 ./build/armv7/libavcodec.a \
        -arch i386 ./build/i386/libavcodec.a

xcrun -sdk iphoneos lipo -output ./build/libavdevice.a  \
    -create \
        -arch armv7s ./build/armv7s/libavdevice.a \
        -arch armv7 ./build/armv7/libavdevice.a \
        -arch i386 ./build/i386/libavdevice.a

xcrun -sdk iphoneos lipo -output ./build/libavfilter.a  \
    -create \
        -arch armv7s ./build/armv7s/libavfilter.a \
        -arch armv7 ./build/armv7/libavfilter.a \
        -arch i386 ./build/i386/libavfilter.a

xcrun -sdk iphoneos lipo -output ./build/libavformat.a  \
    -create \
        -arch armv7s ./build/armv7s/libavformat.a \
        -arch armv7 ./build/armv7/libavformat.a \
        -arch i386 ./build/i386/libavformat.a

xcrun -sdk iphoneos lipo -output ./build/libavutil.a  \
    -create \
        -arch armv7s ./build/armv7s/libavutil.a \
        -arch armv7 ./build/armv7/libavutil.a \
        -arch i386 ./build/i386/libavutil.a

xcrun -sdk iphoneos lipo -output ./build/libswscale.a  \
    -create \
        -arch armv7s ./build/armv7s/libswscale.a \
        -arch armv7 ./build/armv7/libswscale.a \
        -arch i386 ./build/i386/libswscale.a

xcrun -sdk iphoneos lipo -output ./x264/build/libx264.a  \
    -create \
        -arch armv7s ./x264/build/armv7s/lib/libx264.a \
        -arch armv7 ./x264/build/armv7/lib/libx264.a \
        -arch i386 ./x264/build/i386/lib/libx264.a

 

编译出来的文件为:

libavcodec.a

用于各种类型声音/图像编解码;

libavdevice.a

libavfilter.a

libavformat.a  

用于各种音视频封装格式的生成和解析,包括获取解码所需信息以生成解码上下文结构
和读取音视频帧等功能;

libavutil.a

包含一些公共的工具函数;

libswscale.a

用于视频场景比例缩放、色彩映射转换;

libx264.a

 

开源示例iFrameExtractor

git clone git://github.com/lajos/iFrameExtractor.git

这是一个iOS下利用ffmpeg解码播放的例子。不过这个例子是利用贴图的方式来显示,效果不是很好,而且没有加入声音解码。

 

要想项目顺利运行需要添加支持库

Project References -> Targets -> Build Phases -> Link Binary With Librarys

  • libbz.dylib
  • libz.dylib
  • libiconv.2.4.0.dylib

 

修改头文件搜索路径(头文件下载地址:http://www.ffmpeg4ios.org/releases/ffmpeg4ios-1.0-include.zip)

Project References -> Targets -> Build Settings -> Header Search Paths

 

修改库文件搜索路径(编译出来.a文件的路径)

Project References -> Targets -> Build Settings -> Library Search Paths  

 

有疑问者可以留言

posted @ 2013-05-28 12:54  wangzhipeng  阅读(7142)  评论(2编辑  收藏  举报