ios8.1下編譯ffmpeg

郝萌主傾心貢獻,尊重作者的勞動成果,請勿轉(zhuǎn)載。

武陟網(wǎng)站制作公司哪家好,找創(chuàng)新互聯(lián)!從網(wǎng)頁設(shè)計、網(wǎng)站建設(shè)、微信開發(fā)、APP開發(fā)、自適應網(wǎng)站建設(shè)等網(wǎng)站項目制作,到程序開發(fā),運營維護。創(chuàng)新互聯(lián)公司2013年成立到現(xiàn)在10年的時間,我們擁有了豐富的建站經(jīng)驗和運維經(jīng)驗,來保證我們的工作的順利進行。專注于網(wǎng)站建設(shè)就選創(chuàng)新互聯(lián)。

如果文章對您有所幫助,歡迎給作者捐贈,支持郝萌主,捐贈數(shù)額隨意,重在心意^_^ 

我要捐贈: 點擊捐贈

Cocos2d-X×××:點我傳送


先說步驟吧。

一:下載gas-preprocessor.pl.并把它粘貼到usr/bin或者usr/sbin都可以。
     
      有同學是不是發(fā)現(xiàn)沒有usr這個文件夾?
       mac os x隱藏文件夾 自己去搜索怎么找出來。

       然后有個權(quán)限 cd到usr/bin下 chmod +x gas-preprocessor.pl.

二:shell 命令符進行編譯

      ios8及其更高系統(tǒng)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系統(tǒng)腳本如下:

#!/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權(quán)限

生成最終庫。

三:你以為這就會一帆風順?
       N多錯誤要跟著來。

      1:pkg-config not found.媽媽桑的,pkg-config是什么東西啊。
            一查,沒這個根本不會編譯成功。
           去安裝這個玩意再說:http://blog.csdn.net/chenhezhuyan/article/details/9455625。

       2:肯定會有這樣的錯誤:compile c test failed。這是configure的編譯器路徑出現(xiàn)了錯誤。
             XCODE6以下的系統(tǒng)貌似都是gcc+,而以上都是clang。
             打印編譯器路徑,把上面對應腳本改一改,就好了。

       3:armv7,armv7s,i386前面兩個對應真機,后面一個對應模擬器。
             編譯環(huán)境都不一樣的,所以記住真機和模擬器兩種編譯環(huán)境的路徑記得換成對應的sdk,不然又報錯沒找著。

四:編譯成功后,會有個build文件夾,在子層里邊有個built文件夾,里邊就是我們要的庫了。
       里邊include和lib復制到demo工程iframeextractor里邊。iframeextractor自己去github下載。
       當然這個demo很坑爹,我后邊再說。改一改lib search path,header search path。run,可以了。

       但是你會發(fā)現(xiàn)運行成功的是個mov文件,尼瑪,ios本來就支持mov文件好吧,那老子怎么知道ffmpeg庫有沒有對視頻解碼成功。
       然后勢必要去找個源生框架不支持的格式,例如,.wmv。你把.wmv拷進工程,發(fā)現(xiàn)運行不了。

       這下讓我很疑惑了,尼瑪用的是ffmpeg的函數(shù)啊。我一度以為是不是我編譯出了錯,編譯好的庫有問題。

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

       當然這個demo并不支持對聲音的解碼,做的這么坑爹不知道為什么網(wǎng)上那么多人傳。


五:大功告成之后,在你要使用這些庫的時候,你會發(fā)現(xiàn)這些庫很大,universal版的起碼有200多M。這尼瑪比幾行代碼的工程文件大多了,安裝文件豈不會很大。事實上,根據(jù)工程需求,在編譯的時候,很多功能我們是不需要編譯的,但上面的腳本里,很多都沒有被禁止,都加了進來。在本工程中只需要decoders和encoders就可以了,其他的可以一律disable掉。這樣編譯起來比較快一點,庫文件也小很多。

六:總結(jié)一下:以后做工程選平臺的時候,不要選太新的平臺,太新的平臺上出了什么幺蛾子,網(wǎng)上都搜不到資料,還是用稍微舊一點的編譯環(huán)境和sdk,出什么事都有前人告訴你解決辦法。我比較懶,如此坑爹的事情還是少干些比較好。
       
最后吐個嘈。微軟和蘋果兩家公司能不能好好的,系統(tǒng)格式不支持沒辦法,視頻格式也TM不支持。蓋茨那小氣樣,以為微軟員工不用蘋果別個就會倒閉。蘋果那小氣樣,你自己就不會主動去支持這么流行的格式嗎,生生把ffmpeg逼了出來。哦,還有VLC.
不過VLC不怎么受蘋果待見,經(jīng)常被蘋果下架。用了它怕不怕哪天蘋果不爽了把你的app下架。

網(wǎng)站名稱:ios8.1下編譯ffmpeg
當前鏈接:http://bm7419.com/article24/ipdoce.html

成都網(wǎng)站建設(shè)公司_創(chuàng)新互聯(lián),為您提供手機網(wǎng)站建設(shè)、Google服務器托管、網(wǎng)站改版做網(wǎng)站、域名注冊

廣告

聲明:本網(wǎng)站發(fā)布的內(nèi)容(圖片、視頻和文字)以用戶投稿、用戶轉(zhuǎn)載內(nèi)容為主,如果涉及侵權(quán)請盡快告知,我們將會在第一時間刪除。文章觀點不代表本網(wǎng)站立場,如需處理請聯(lián)系客服。電話:028-86922220;郵箱:631063699@qq.com。內(nèi)容未經(jīng)允許不得轉(zhuǎn)載,或轉(zhuǎn)載時需注明來源: 創(chuàng)新互聯(lián)

外貿(mào)網(wǎng)站制作