編譯opencore-amr for iOS

來源:互聯網
上載者:User

amr在傳聲音中應用較多,因為十多K大小就可以長達一分鐘的內容。在ios sdk4.0以後就不再支援這種格式的檔案,只有用開源opencore-amr,今天試著編譯了一下,結果成功了。

寫了一個指令碼:

#!/bin/sh############################################################################  Change values here  ##  #VERSION="0.1.2"            #SDKVERSION="4.2"  ##  #############################################################################  ## Don't change anything under this line!  ##  #############################################################################opencore-amr-0.1.2CURRENTPATH=`pwd`mkdir -p "${CURRENTPATH}/src"tar zxf opencore-amr-${VERSION}.tar.gz -C "${CURRENTPATH}/src"cd "${CURRENTPATH}/src/opencore-amr-${VERSION}"############# iPhone Simulatorecho "Building opencore-amr for iPhoneSimulator ${SDKVERSION} i386"echo "Please stand by..."mkdir -p "${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}.sdk"LOG="${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}.sdk/build-openamr-${VERSION}.log"SDK=/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator${SDKVERSION}.sdkexport CC ="/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/gcc -arch i386"export CXX="/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/g++ -arch i386"LDFLAGS="-Wl,-syslibroot,$SDK" ./configure --disable-shared --prefix="${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}.sdk"make >> "${LOG}" 2>&1make install >> "${LOG}" 2>&1make clean >> "${LOG}" 2>&1########################### iPhoneOS armv6echo "Building opencore-amr for iPhoneOS ${SDKVERSION} armv6"echo "Please stand by..."mkdir -p "${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv6.sdk"LOG="${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv6.sdk/build-openamr-${VERSION}.log"SDK=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDKVERSION}.sdkexport CC ="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv6 --sysroot=$SDK"export CXX="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/g++ -arch armv6 --sysroot=$SDK"LDFLAGS="-Wl,-syslibroot,$SDK"./configure --host=arm-apple-darwin --target=darwin --prefix="${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv6.sdk" --disable-sharedmake >> "${LOG}" 2>&1make install >> "${LOG}" 2>&1make clean >> "${LOG}" 2>&1########################### iPhoneOS armv7echo "Building opencore-amr for iPhoneOS ${SDKVERSION} armv7"echo "Please stand by..."mkdir -p "${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk"LOG="${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/build-openamr-${VERSION}.log"SDK=/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS${SDKVERSION}.sdkexport CC ="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/gcc -arch armv7 --sysroot=$SDK"export CXX="/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/g++ -arch armv7 --sysroot=$SDK"LDFLAGS="-Wl,-syslibroot,$SDK"./configure --host=arm-apple-darwin --target=darwin --prefix="${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk" --disable-shared make >> "${LOG}" 2>&1make install >> "${LOG}" 2>&1make clean >> "${LOG}" 2>&1#############echo "Build library..."mkdir -p ${CURRENTPATH}/liblipo -create -arch i386 ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}.sdk/lib/libopencore-amrwb.a -arch armv6 ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv6.sdk/lib/libopencore-amrwb.a -arch armv7 ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/lib/libopencore-amrwb.a -output ${CURRENTPATH}/lib/libopencore-amrwb.alipo -create -arch i386 ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}.sdk/lib/libopencore-amrnb.a -arch armv6 ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv6.sdk/lib/libopencore-amrnb.a -arch armv7 ${CURRENTPATH}/bin/iPhoneOS${SDKVERSION}-armv7.sdk/lib/libopencore-amrnb.a -output ${CURRENTPATH}/lib/libopencore-amrnb.amkdir -p ${CURRENTPATH}/includecp -R ${CURRENTPATH}/bin/iPhoneSimulator${SDKVERSION}.sdk/include ${CURRENTPATH}/include/echo "Building done."echo "Cleaning up..."rm -rf ${CURRENTPATH}/srcrm -rf ${CURRENTPATH}/binecho "Done."

1.將上面指令碼內容存入一個.sh檔案, 

2. 然後修改為有可運行chmod 777 xxx.sh.  

3. 再將下載下來的opencore-amr.tar.gz與xxx.sh放同一目錄,

4. 然後在命令列運行./xxx.sh

這樣在目錄下就產生一個include與lib檔案夾,裡面就是你想要的庫了。

關於庫的使用,我另寫了一篇文章介紹,傳送門,其過程也遇到了一個小問題,不過最後還是解決了。

這兒有一個demo將amr轉成wav

由於xcode4.3以後目錄發生了變化,所以上面的script已不正確了。
看到很多人編譯都需到問題,我應又花時間研究了一下,其實我也沒有在項目中用過,只是興趣而已。

找了一個新指令碼並修改了一下,在xcode4.5.1+ios6進成功編譯。支援i386,armv7,armv7s

#!/bin/shset -xeVERSION="0.1.3"                                                           #SDKVERSION="6.0"DEVELOPER=`xcode-select -print-path`DEST=${HOME}/opencore-amr-iphoneARCHS="i386 armv7 armv7s"LIBS="libopencore-amrnb.a libopencore-amrwb.a"for arch in $ARCHS; docase $arch inarm*)        echo "Building opencore-amr for iPhone $arch ****************"        PLATFORM="iPhoneOS"        PATH="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/usr/bin:$PATH"         SDK="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDKVERSION}.sdk"CC="gcc -arch $arch --sysroot=$SDK" CXX="g++ -arch $arch --sysroot=$SDK" \LDFLAGS="-Wl,-syslibroot,$SDK" ./configure \--host=arm-apple-darwin --prefix=$DEST \--disable-shared --enable-gcc-armv5;;*)        PLATFORM="iPhoneSimulator"        PATH="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/usr/bin:$PATH"        SDK="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer/SDKs/${PLATFORM}${SDKVERSION}.sdk"        echo "Building opencore-amr for iPhoneSimulator $arch*****************"CC="gcc -arch $arch" CXX="g++ -arch $arch" \./configure \--prefix=$DEST \--disable-shared;;esacmake -j3make installmake cleanfor i in $LIBS; domv $DEST/lib/$i $DEST/lib/$i.$archdonedonefor i in $LIBS; doinput=""for arch in $ARCHS; doinput="$input $DEST/lib/$i.$arch"donelipo -create -output $DEST/lib/$i $inputdone

成生的庫與標頭檔在 ${HOME}目錄下

這兒是我編譯好的,i386,armv7, armv7s

參考資料:

http://sourceforge.net/mailarchive/forum.php?thread_name=alpine.DEB.2.00.1106152258040.2333%40cone.martin.st&forum_name=opencore-amr-devel

http://sourceforge.net/mailarchive/forum.php?thread_name=alpine.DEB.2.00.1103211053460.3794%40cone.home.martin.st&forum_name=opencore-amr-devel

http://tinsuke.wordpress.com/2011/02/17/how-to-cross-compiling-libraries-for-ios-armv6armv7i386/

http://iosdeveloperzone.com/2012/09/28/tutorial-open-source-on-ios-part-1-build-your-tools/

相關文章

聯繫我們

該頁面正文內容均來源於網絡整理,並不代表阿里雲官方的觀點,該頁面所提到的產品和服務也與阿里云無關,如果該頁面內容對您造成了困擾,歡迎寫郵件給我們,收到郵件我們將在5個工作日內處理。

如果您發現本社區中有涉嫌抄襲的內容,歡迎發送郵件至: info-contact@alibabacloud.com 進行舉報並提供相關證據,工作人員會在 5 個工作天內聯絡您,一經查實,本站將立刻刪除涉嫌侵權內容。

A Free Trial That Lets You Build Big!

Start building with 50+ products and up to 12 months usage for Elastic Compute Service

  • Sales Support

    1 on 1 presale consultation

  • After-Sales Support

    24/7 Technical Support 6 Free Tickets per Quarter Faster Response

  • Alibaba Cloud offers highly flexible support services tailored to meet your exact needs.