编译opencore-amr for iOS

来源:互联网 发布:已备案的域名 编辑:程序博客网 时间:2024/05/17 06:29

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/