资讯

精准传达 • 有效沟通

从品牌网站建设到网络营销策划,从策略到执行的一站式服务

ios8.1下编译ffmpeg

郝萌主倾心贡献,尊重作者的劳动成果,请勿转载。

武陟网站制作公司哪家好,找创新互联!从网页设计、网站建设、微信开发、APP开发、自适应网站建设等网站项目制作,到程序开发,运营维护。创新互联公司2013年成立到现在10年的时间,我们拥有了丰富的建站经验和运维经验,来保证我们的工作的顺利进行。专注于网站建设就选创新互联

如果文章对您有所帮助,欢迎给作者捐赠,支持郝萌主,捐赠数额随意,重在心意^_^ 

我要捐赠: 点击捐赠

Cocos2d-X×××:点我传送


先说步骤吧。

一:下载gas-preprocessor.pl.并把它粘贴到usr/bin或者usr/sbin都可以。
     
      有同学是不是发现没有usr这个文件夹?
       mac os x隐藏文件夹 自己去搜索怎么找出来。

       然后有个权限 cd到usr/bin下 chmod +x gas-preprocessor.pl.

二:shell 命令符进行编译

      ios8及其更高系统shell脚本如下
 

#!/bin/bash


###########################################################################

#  Choose your ffmpeg version and your currently-installed iOS SDK version:

#

VERSION="2.0.2"

SDKVERSION="8.1"

ARCHS="armv7 armv7s i386"

#

#

###########################################################################

#

# Don't change anything under this line!

#

###########################################################################


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" ]; then

echo "Downloading ffmpeg-${VERSION}.tar.bz2"

    curl -LO http://ffmpeg.org/releases/ffmpeg-${VERSION}.tar.bz2

else

echo "Using ffmpeg-${VERSION}.tar.bz2"

fi


tar jxf ffmpeg-${VERSION}.tar.bz2 -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}"


    ./configure --prefix="${INTERDIR}/${ARCH}" --disable-ffmpeg --disable-ffplay --disable-ffprobe --disable-ffserver --disable-iconv --disable-bzlib --enable-avresample --disable-asm --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} -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 && 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."


ios7,ios6系统脚本如下:

#!/bin/bash

###########################################################################
#  Choose your ffmpeg version and your currently-installed iOS SDK version:
#
VERSION="2.0.2"
SDKVERSION="6.1"
ARCHS="armv7 armv7s i386"
#
#
###########################################################################
#
# Don't change anything under this line!
#
###########################################################################

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" ]; then
echo "Downloading ffmpeg-${VERSION}.tar.bz2"
    curl -LO http://ffmpeg.org/releases/ffmpeg-${VERSION}.tar.bz2
else
echo "Using ffmpeg-${VERSION}.tar.bz2"
fi

tar jxf ffmpeg-${VERSION}.tar.bz2 -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}"

    ./configure --prefix="${INTERDIR}/${ARCH}" --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} -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 && 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."

将其写成sh文件,放在桌面 cd 进入文件夹 同样chmod +x权限

生成最终库。

三:你以为这就会一帆风顺?
       N多错误要跟着来。

      1:pkg-config not found.妈妈桑的,pkg-config是什么东西啊。
            一查,没这个根本不会编译成功。
           去安装这个玩意再说:http://blog.csdn.net/chenhezhuyan/article/details/9455625。

       2:肯定会有这样的错误:compile c test failed。这是configure的编译器路径出现了错误。
             XCODE6以下的系统貌似都是gcc+,而以上都是clang。
             打印编译器路径,把上面对应脚本改一改,就好了。

       3:armv7,armv7s,i386前面两个对应真机,后面一个对应模拟器。
             编译环境都不一样的,所以记住真机和模拟器两种编译环境的路径记得换成对应的sdk,不然又报错没找着。

四:编译成功后,会有个build文件夹,在子层里边有个built文件夹,里边就是我们要的库了。
       里边include和lib复制到demo工程iframeextractor里边。iframeextractor自己去github下载。
       当然这个demo很坑爹,我后边再说。改一改lib search path,header search path。run,可以了。

       但是你会发现运行成功的是个mov文件,尼玛,ios本来就支持mov文件好吧,那老子怎么知道ffmpeg库有没有对视频解码成功。
       然后势必要去找个源生框架不支持的格式,例如,.wmv。你把.wmv拷进工程,发现运行不了。

       这下让我很疑惑了,尼玛用的是ffmpeg的函数啊。我一度以为是不是我编译出了错,编译好的库有问题。

       后来我把.wmv文件格式生生改成.mov。大功告成。

       当然这个demo并不支持对声音的解码,做的这么坑爹不知道为什么网上那么多人传。


五:大功告成之后,在你要使用这些库的时候,你会发现这些库很大,universal版的起码有200多M。这尼玛比几行代码的工程文件大多了,安装文件岂不会很大。事实上,根据工程需求,在编译的时候,很多功能我们是不需要编译的,但上面的脚本里,很多都没有被禁止,都加了进来。在本工程中只需要decoders和encoders就可以了,其他的可以一律disable掉。这样编译起来比较快一点,库文件也小很多。

六:总结一下:以后做工程选平台的时候,不要选太新的平台,太新的平台上出了什么幺蛾子,网上都搜不到资料,还是用稍微旧一点的编译环境和sdk,出什么事都有前人告诉你解决办法。我比较懒,如此坑爹的事情还是少干些比较好。
       
最后吐个嘈。微软和苹果两家公司能不能好好的,系统格式不支持没办法,视频格式也TM不支持。盖茨那小气样,以为微软员工不用苹果别个就会倒闭。苹果那小气样,你自己就不会主动去支持这么流行的格式吗,生生把ffmpeg逼了出来。哦,还有VLC.
不过VLC不怎么受苹果待见,经常被苹果下架。用了它怕不怕哪天苹果不爽了把你的app下架。

本文标题:ios8.1下编译ffmpeg
转载注明:http://cdkjz.cn/article/ipdoce.html
多年建站经验

多一份参考,总有益处

联系快上网,免费获得专属《策划方案》及报价

咨询相关问题或预约面谈,可以通过以下方式与我们联系

大客户专线   成都:13518219792   座机:028-86922220