基于iOS5.0的MobileVLC(vlc for iOS)编译 -- 含FFMpeg库的编译解决办法

版权声明:本文为博主原创文章,未经博主允许不得转载。 https://blog.csdn.net/madongchunqiu/article/details/7625083

今天是2013年7月20日,很高兴宣布这篇文章已经完成其历史任务,并在这段时间通过这篇文章和不少同学有了交流。因为官方不光重新在app store上架了新版的VLC,并且官网(http://www.videolan.org/vlc/download-ios.html)也更新至2.0.x。

作者暂时没有时间去研究2.0版本,希望2.0版本以及后续版本一切安好~


上篇文章:《黑苹果,iOS SDK和MobileVLC之逆旅(二) 编译MobileVLC》(http://blog.csdn.net/madongchunqiu/article/details/6707068)发出之后,陆续和不少同学们有些交流。但那毕竟只是我入门iOS平台的学习之作,故不少问题也没能帮到大家。

近来工作有了阶段性成果,可以放松一下,而且手头上面的东西也和自制VLC有那么点沾边,正巧某同学提到iOS SDK5.0上面的编译环境似乎有了不少变化,我的老文章已经无法适应新环境了,所以花了点时间,终于把这个问题搞定了。

半夜三更还在敲键盘,的确有那么点啥。不过我是怕现在不写下来明天起床就忘记了~老了就这样。

下面开始。



一。编译环境:(Development Environment)

硬件平台:MBA

软件系统:Mac OS X Lion 10.7.3

扫描二维码关注公众号,回复: 3110237 查看本文章

开发环境:Xcode 4.2, iOS SDK 5.0

【注:开发环境不是最新的,是因为我手头的项目在那,怕升级后又要花时间调,想等到项目结尾再升到最新。】

【补注:据称,升级到Xcode4.3和iOS SDK5.1之后,开发环境最大的区别是SDK的目录由

/Developer/Platform/xxx

变成了

/Applications/Xcode.app/Contents/Developer/Platform/xxx

那么对于MobileVLC1.1.0版本而言,首先要做的,就是在源代码中,全局搜索/Developer/Platform/xxx,然后对其进行替换。或者把新目录中的东西再拷贝一份到老目录也行(似乎有些帖子就这么做的),但是考虑到既然Apple下决心换目录了,死抓着老的目录结构也没有必要。】

【补注的注:在bootstrap脚本中,会去查找/Developer/SDKs这个目录,也需要相应的修改】


二。编译的整体说明:(Overview)

总体来说,编译iOS5.0和iOS4.2的区别,在于几个编译器的“名字”变了,比如gcc-4.2和g++-4.2,在新的开发环境目录下都成了llvm-gcc-4.2或llvm-g++-4.2。据称是因为iOS SDK全面放弃使用GNU GCC的缘故。具体原因我也未查找更多资料,不过想来就是因为这些改变,所以才带来了更多的未可知变化。


就细节来说:编译simulator版本的MobileVLC和iOS Target版本的MobileVLC现在不能用同一个脚本了。别问我为什么会这样,我也很迷糊。如下所述

 - Simulator版本的更改:

 --->1. SDK版本号由3.2升级至5.0 【同iOS SDK4.2的编译修改】

 --->2. 编译选项彻底区分simulator版本和iOS target版本【同iOS SDK4.2的编译修改】

 --->3. 编译器名称改成:"cpp-4.2 -> llvm-cpp-4.2", "gcc-4.2 ->clang", "g++-4.2 ->llvm-g++-4.2" 【注:这里用llvm-gcc-4.2编译失败后,再改用clang成功的。原因未深究。有人说iOS SDK5.1的Simulator版本编译器目录下没有clang,这点我不甚明了。反正我iOS SDK5.0的Simulator版本编译器目录下是有clang的】


 - iOS target版本的更改

 --->1. SDK版本号由3.2升级至5.0 【同iOS SDK4.2的编译修改】

 --->2. 编译选项彻底区分simulator版本和iOS target版本【同iOS SDK4.2的编译修改】

 --->3. 编译器名称改成:"cpp-4.2 -> llvm-cpp-4.2", "gcc-4.2 ->llvm-gcc-4.2", "g++-4.2 -> llvm-g++-4.2" 【注:这里均使用llvm版本的编译器。请比较和Simulator版本的不同,此处使用clang反而会编译错误,原因未深究】

 --->4. 链接目录参数加入:-L${IOS_SDK_ROOT}/usr/lib/system

 --->5. 更改生成ffmpeg config的makefile,加入--disable-asm参数,原因后面详述

 --->6. 为了编译libdvbpsi库,稍稍修改iOS SDK的源文件,在/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/include中拷贝入两个新文件limits.h,原因后面详述。

下面一步步演示如何完成任务。


三。调试版本的修改过程:(Step by step for simulator version)


3.1 将MobileVLC 1.1.0的源代码(http://www.videolan.org/vlc/download-ios.html)下载到本地

3.2 创建目录(比如/VLC),并将3个源代码包解压在目录内,并依次重命名为:MediaLibraryKit, MobileVLC, vlc


3.3 修改MobileVLCKit(即libVLC for iOS)的脚本文件(/VLC/vlc/extras/package/ios/build_for_iOS.sh),因为有几处改动,所以不如直接拷贝我这个版本好了。【注:2处改动,一个是iOS SDK的版本号,一个是编译器的名称】

#!/bin/sh
set -e
echo "Building libvlc for the iOS"

if [ "$1" = "Simulator" ]; then
    PLATFORM="Simulator"
    TARGET="i686-apple-darwin10"
    ARCH="i386"
else
    PLATFORM="OS"
    TARGET="arm-apple-darwin10"
    ARCH="armv7"
    OPTIM="-mno-thumb"
fi

THIS_SCRIPT_PATH=`pwd`/$0

pushd `dirname $0`/../../..
VLCROOT=`pwd` # Let's make sure VLCROOT is an absolute path
popd
DEVROOT="/Developer/Platforms/iPhone${PLATFORM}.platform/Developer"
IOS_SDK_ROOT="${DEVROOT}/SDKs/iPhone${PLATFORM}5.0.sdk"

BUILDDIR=${VLCROOT}/build-ios-${PLATFORM}

PREFIX=${VLCROOT}/install-ios-${PLATFORM}

IOS_GAS_PREPROCESSOR="${VLCROOT}/extras/package/ios/resources/gas-preprocessor.pl"

export AR="${DEVROOT}/usr/bin/ar"
export RANLIB="${DEVROOT}/usr/bin/ranlib"
export CFLAGS="-isysroot ${IOS_SDK_ROOT} -arch ${ARCH} -miphoneos-version-min=3.2 ${OPTIM}"
export OBJCFLAGS="${CFLAGS}"
if [ "$PLATFORM" = "Simulator" ]; then
    # Use the new ABI on simulator, else we can't build
    export OBJCFLAGS="-fobjc-abi-version=2 -fobjc-legacy-dispatch ${OBJCFLAGS}"
fi
export CPPFLAGS="${CFLAGS}"
export CXXFLAGS="${CFLAGS}"
export CPP="${DEVROOT}/usr/bin/llvm-cpp-4.2"
export CXXCPP="${DEVROOT}/usr/bin/llvm-cpp-4.2"

export CC="${DEVROOT}/usr/bin/clang"
export OBJC="${DEVROOT}/usr/bin/llvm-gcc-4.2"
export CXX="${DEVROOT}/usr/bin/llvm-g++-4.2"
export LD="${DEVROOT}/usr/bin/ld"
export STRIP="${DEVROOT}/usr/bin/strip"

if [ "$PLATFORM" = "OS" ]; then
  export LDFLAGS="-L${IOS_SDK_ROOT}/usr/lib -arch ${ARCH}"
else
  export LDFLAGS="-syslibroot=${IOS_SDK_ROOT}/ -arch ${ARCH}"
fi

export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:${VLCROOT}/extras/contrib/build/bin:${VLCROOT}/extras/package/ios/resources"

echo "Boostraping contribs"
pushd ${VLCROOT}/extras/contrib

# contains gas-processor.pl
export PATH=$PATH:${VLCROOT}/extras/package/ios/resources

# The contrib will read the following
export IOS_SDK_ROOT

echo "Building contrib for iOS"
./bootstrap ${TARGET} ios
make src

echo "Building contrib for current host"
./bootstrap
make

popd

if [ "$PLATFORM" = "OS" ]; then
  export AS="${IOS_GAS_PREPROCESSOR} ${CC}"
  export ASCPP="${IOS_GAS_PREPROCESSOR} ${CC}"
else
  export AS="${DEVROOT}/usr/bin/as"
  export ASCPP="${DEVROOT}/usr/bin/as"
fi


echo "Bootstraping vlc"
if ! [ -e ${VLCROOT}/configure ]; then
    ${VLCROOT}/bootstrap
fi

if [ ".$PLATFORM" != ".Simulator" ]; then
    # FIXME - Do we still need this?
    export AVCODEC_CFLAGS="-I${PREFIX}include"
    export AVCODEC_LIBS="-L${PREFIX}lib -lavcodec -lavutil -lz"
    export AVFORMAT_CFLAGS="-I${PREFIX}include"
    export AVFORMAT_LIBS="-L${PREFIX}lib -lavcodec -lz -lavutil -lavformat"
fi

mkdir -p ${BUILDDIR}
pushd ${BUILDDIR}

# Run configure only upon changes.
if [ "${VLCROOT}/configure" -nt config.log -o \
     "${THIS_SCRIPT_PATH}" -nt config.log ]; then
CONTRIB_DIR=${VLCROOT}/extras/contrib/hosts/${TARGET}/ios \
${VLCROOT}/configure \
    --prefix="$PREFIX" \
    --host="${TARGET}" \
    --enable-debug \
    --disable-shared \
    --enable-static \
    --disable-macosx \
    --disable-macosx-defaults \
    --disable-macosx-vout \
    --disable-macosx-dialog-provider \
    --disable-macosx-qtcapture \
    --disable-macosx-eyetv \
    --disable-macosx-vlc-app \
    --with-macosx-sdk=${IO_SDK_ROOT} \
    --enable-audioqueue \
    --enable-ios-vout \
    --enable-avcodec \
    --enable-avformat \
    --enable-swscale \
    --enable-faad \
    --disable-mad \
    --disable-a52 \
    --disable-fribidi \
    --disable-macosx-audio \
    --disable-qt4 --disable-skins2 \
    --disable-libgcrypt \
    --disable-remoteosd \
    --disable-vcd \
    --disable-postproc \
    --disable-vlc \
    --disable-vlm \
    --disable-httpd \
    --disable-nls \
    --disable-glx \
    --disable-visual \
    --disable-lua \
    --disable-sse \
    --disable-neon \
    --disable-mmx # MMX and SSE support requires llvm which is broken on Simulator
fi

CORE_COUNT=`sysctl -n machdep.cpu.core_count`
let MAKE_JOBS=$CORE_COUNT+1

echo "Running make -j$MAKE_JOBS"

make -j$MAKE_JOBS
make install
popd


3.4. 修改总脚本(/VLC/MobileVLC/buildMobileVLC.sh),将其替换成下面这个:【注:同iOS SDK4.2。其目的只是区分和细化了simulator版本和iOS target版本的参数】

#!/bin/bash


rm -rf ./MediaLibraryKit/External/MobileVLCKit
rm -rf ./MobileVLC/External/MobileVLCKit
rm -rf ./MobileVLC/External/MediaLibraryKit

if [ "$1" = "Simulator" ]; then
	pushd vlc
		echo "--==-- Build for vlc (simulator version) --==--"
		pushd extras/package/ios
			./build_for_iOS.sh Simulator
		popd

		echo "--==-- Build for vlc-MobileVLCKit (simulator version) --==--"
		pushd projects/macosx/framework
			xcodebuild -project MobileVLCKit.xcodeproj -target "Aggregate static plugins" -configuration "Release" -sdk iphonesimulator5.0 SDKROOT=iphonesimulator5.0 VALID_ARCHS=i386 ARCHS=i386 
			xcodebuild -project MobileVLCKit.xcodeproj -target "MobileVLCKit" -configuration "Release" -sdk iphonesimulator5.0 SDKROOT=iphonesimulator5.0 VALID_ARCHS=i386 ARCHS=i386
		popd
	popd

	echo "--==-- Build for MediaLibraryKit (simulator version) --==--"
	pushd MediaLibraryKit
		ln -s ../../vlc/projects/macosx/framework/build/Release-iphonesimulator External/MobileVLCKit
		xcodebuild -project MobileMediaLibraryKit.xcodeproj -configuration "Release" -sdk iphonesimulator5.0 SDKROOT=iphonesimulator5.0 VALID_ARCHS=i386 ARCHS=i386
	popd

	echo "--==-- Build for MobileVLC (simulator version) --==--"
	pushd MobileVLC
		ln -s ../../vlc/projects/macosx/framework/build/Release-iphonesimulator External/MobileVLCKit
		ln -s ../../MediaLibraryKit/build/Release-iphonesimulator External/MediaLibraryKit
		xcodebuild -project MobileVLC.xcodeproj -configuration "Release" -sdk iphonesimulator5.0 SDKROOT=iphonesimulator5.0 VALID_ARCHS=i386 ARCHS=i386
	popd
else
	pushd vlc
		echo "--==-- Build for vlc (os version) --==--"
		pushd extras/package/ios
			./build_for_iOS.sh
		popd

		echo "--==-- Build for vlc-MobileVLCKit (os version) --==--"
		pushd projects/macosx/framework
			xcodebuild -project MobileVLCKit.xcodeproj -target "Aggregate static plugins" -configuration "Release" -sdk iphoneos5.0 SDKROOT=iphoneos5.0 VALID_ARCHS=armv7 ARCHS=armv7
			xcodebuild -project MobileVLCKit.xcodeproj -target "MobileVLCKit" -configuration "Release"  -sdk iphoneos5.0 SDKROOT=iphoneos5.0 VALID_ARCHS=armv7 ARCHS=armv7 
		popd
	popd

	echo "--==-- Build for MediaLibraryKit (os version) --==--"
	pushd MediaLibraryKit
		ln -s ../../vlc/projects/macosx/framework/build/Release-iphoneos External/MobileVLCKit
		xcodebuild -project MobileMediaLibraryKit.xcodeproj -configuration "Release" -sdk iphoneos5.0 SDKROOT=iphoneos5.0 VALID_ARCHS=armv7 ARCHS=armv7 
	popd

	echo "--==-- Build for MobileVLC (os version) --==--"
	pushd MobileVLC
		ln -s ../../vlc/projects/macosx/framework/build/Release-iphoneos External/MobileVLCKit
		ln -s ../../MediaLibraryKit/build/Release-iphoneos External/MediaLibraryKit
		xcodebuild -project MobileVLC.xcodeproj -configuration "Release" -sdk iphoneos5.0 SDKROOT=iphoneos5.0 VALID_ARCHS=armv7 ARCHS=armv7 
	popd

fi


3.5. 运行脚本进行编译

cd /VLC
./MobileVLC/buildMobileVLC.sh Simulator


3.6. 多运行几遍保证各个编译命令都是"Build SUCCEEDED"。需要多编译几次的原因我这次看了下,好像有这几种情况

 - a) FFMPEG库打patch时出错。这个似乎不影响使用。第二次编译可以通过

 - b) faad2库下载失败。可以回看log,看下载进度是不是到了100%,如果不是,去/VLC/vlc/extras/contrib/src-i686-apple-darwin10-ios/src/目录下,将下载的faad2-x.x.tar.gz和faad2库删掉。再重新编译。别的几个库同理。下载如问题多多,有必要时请加载V-PN...

 - c) 库下载解压后再编译时环境配置不到位。这时重新编译就可以发现会新编译一些东西,然后就可以过了。应该是脚本不够完善的缘故。


然后,就应该可以在simulator下调试了。不过很雷人的是VLC在调试界面下,无法导入文件,因此也没法有效调试。不过有个同学提到过可以hardcode入流媒体的链接,这不失为一种方法。不过我没有试过。经过JianJian同学的提示,我才意识到其实很容易就可以获取VLC在Simulator环境下的工作目录,NSSearchPathForDirectoriesInDomains这个API可以获取系统目录,在VLC项目中搜索这个函数(如果没有就自己写一个),然后将输出就可以看到了。获取了Simulator环境下的App工作目录之后,将待测试的视频文件拷贝入其下的Documents目录就可以被App识别了。


四。iOS目标版本的修改过程:(Step by step for iOS device version)


4.1 将MobileVLC 1.1.0的源代码(http://www.videolan.org/vlc/download-ios.html)下载到本地

4.2 创建目录(比如/VLC),并将3个源代码包解压在目录内,并依次重命名为:MediaLibraryKit, MobileVLC, vlc


4.3 修改MobileVLCKit(即libVLC for iOS)的脚本文件(/VLC/vlc/extras/package/ios/build_for_iOS.sh),因为有几处改动,所以不如直接拷贝我这个版本好了。【注:3处改动,一是iOS SDK的版本号,二是编译器的名称,三是加入了新的链接目录】【注2:谁知道怎么改变这个code窗口内的字体颜色和样式吗?我改了之后,显示出来成了HTML源代码】

#!/bin/sh
set -e

echo "Building libvlc for the iOS"

if [ "$1" = "Simulator" ]; then
    PLATFORM="Simulator"
    TARGET="i686-apple-darwin10"
    ARCH="i386"
else
    PLATFORM="OS"
    TARGET="arm-apple-darwin10"
    ARCH="armv7"
    OPTIM="-mno-thumb"
fi

THIS_SCRIPT_PATH=`pwd`/$0

pushd `dirname $0`/../../..
VLCROOT=`pwd` # Let's make sure VLCROOT is an absolute path
popd
DEVROOT="/Developer/Platforms/iPhone${PLATFORM}.platform/Developer"
IOS_SDK_ROOT="${DEVROOT}/SDKs/iPhone${PLATFORM}5.0.sdk"

BUILDDIR=${VLCROOT}/build-ios-${PLATFORM}

PREFIX=${VLCROOT}/install-ios-${PLATFORM}

IOS_GAS_PREPROCESSOR="${VLCROOT}/extras/package/ios/resources/gas-preprocessor.pl"

export AR="${DEVROOT}/usr/bin/ar"
export RANLIB="${DEVROOT}/usr/bin/ranlib"
export CFLAGS="-isysroot ${IOS_SDK_ROOT} -arch ${ARCH} -miphoneos-version-min=5.0 ${OPTIM}"
export OBJCFLAGS="${CFLAGS}"
if [ "$PLATFORM" = "Simulator" ]; then
    # Use the new ABI on simulator, else we can't build
    export OBJCFLAGS="-fobjc-abi-version=2 -fobjc-legacy-dispatch ${OBJCFLAGS}"
fi
export CPPFLAGS="${CFLAGS}"
export CXXFLAGS="${CFLAGS}"
export CPP="${DEVROOT}/usr/bin/llvm-cpp-4.2"
export CXXCPP="${DEVROOT}/usr/bin/llvm-cpp-4.2"

export CC="${DEVROOT}/usr/bin/llvm-gcc-4.2"
export OBJC="${DEVROOT}/usr/bin/llvm-gcc-4.2"
export CXX="${DEVROOT}/usr/bin/llvm-g++-4.2"
export LD="${DEVROOT}/usr/bin/ld"
export STRIP="${DEVROOT}/usr/bin/strip"

if [ "$PLATFORM" = "OS" ]; then
  export LDFLAGS="-L${IOS_SDK_ROOT}/usr/lib -L${IOS_SDK_ROOT}/usr/lib/system -arch ${ARCH}"
else
  export LDFLAGS="-syslibroot=${IOS_SDK_ROOT}/ -arch ${ARCH}"
fi

export PATH="/usr/bin:/bin:/usr/sbin:/sbin:/usr/local/bin:/usr/X11/bin:${VLCROOT}/extras/contrib/build/bin:${VLCROOT}/extras/package/ios/resources"

echo "Boostraping contribs"
pushd ${VLCROOT}/extras/contrib

# contains gas-processor.pl
export PATH=$PATH:${VLCROOT}/extras/package/ios/resources

# The contrib will read the following
export IOS_SDK_ROOT

echo "Building contrib for iOS"
./bootstrap ${TARGET} ios
make src

echo "Building contrib for current host"
./bootstrap
make

popd

if [ "$PLATFORM" = "OS" ]; then
  export AS="${IOS_GAS_PREPROCESSOR} ${CC}"
  export ASCPP="${IOS_GAS_PREPROCESSOR} ${CC}"
else
  export AS="${DEVROOT}/usr/bin/as"
  export ASCPP="${DEVROOT}/usr/bin/as"
fi


echo "Bootstraping vlc"
if ! [ -e ${VLCROOT}/configure ]; then
    ${VLCROOT}/bootstrap
fi

if [ ".$PLATFORM" != ".Simulator" ]; then
    # FIXME - Do we still need this?
    export AVCODEC_CFLAGS="-I${PREFIX}include"
    export AVCODEC_LIBS="-L${PREFIX}lib -lavcodec -lavutil -lz"
    export AVFORMAT_CFLAGS="-I${PREFIX}include"
    export AVFORMAT_LIBS="-L${PREFIX}lib -lavcodec -lz -lavutil -lavformat"
fi

mkdir -p ${BUILDDIR}
pushd ${BUILDDIR}

# Run configure only upon changes.
if [ "${VLCROOT}/configure" -nt config.log -o \
     "${THIS_SCRIPT_PATH}" -nt config.log ]; then
CONTRIB_DIR=${VLCROOT}/extras/contrib/hosts/${TARGET}/ios \
${VLCROOT}/configure \
    --prefix="$PREFIX" \
    --host="${TARGET}" \
    --enable-debug \
    --disable-shared \
    --enable-static \
    --disable-macosx \
    --disable-macosx-defaults \
    --disable-macosx-vout \
    --disable-macosx-dialog-provider \
    --disable-macosx-qtcapture \
    --disable-macosx-eyetv \
    --disable-macosx-vlc-app \
    --with-macosx-sdk=${IO_SDK_ROOT} \
    --enable-audioqueue \
    --enable-ios-vout \
    --enable-avcodec \
    --enable-avformat \
    --enable-swscale \
    --enable-faad \
    --disable-mad \
    --disable-a52 \
    --disable-fribidi \
    --disable-macosx-audio \
    --disable-qt4 --disable-skins2 \
    --disable-libgcrypt \
    --disable-remoteosd \
    --disable-vcd \
    --disable-postproc \
    --disable-vlc \
    --disable-vlm \
    --disable-httpd \
    --disable-nls \
    --disable-glx \
    --disable-visual \
    --disable-lua \
    --disable-sse \
    --disable-neon \
    --disable-mmx # MMX and SSE support requires llvm which is broken on Simulator
fi

CORE_COUNT=`sysctl -n machdep.cpu.core_count`
let MAKE_JOBS=$CORE_COUNT+1

echo "Running make -j$MAKE_JOBS"

make -j$MAKE_JOBS
make install
popd


4.4. 修改总脚本(/VLC/MobileVLC/buildMobileVLC.sh),将其替换成下面这个:【注:同iOS SDK4.2,也同上面的Simulator版本,其目的只是区分和细化了simulator版本和iOS target版本的参数】

#!/bin/bash


rm -rf ./MediaLibraryKit/External/MobileVLCKit
rm -rf ./MobileVLC/External/MobileVLCKit
rm -rf ./MobileVLC/External/MediaLibraryKit

if [ "$1" = "Simulator" ]; then
	pushd vlc
		echo "--==-- Build for vlc (simulator version) --==--"
		pushd extras/package/ios
			./build_for_iOS.sh Simulator
		popd

		echo "--==-- Build for vlc-MobileVLCKit (simulator version) --==--"
		pushd projects/macosx/framework
			xcodebuild -project MobileVLCKit.xcodeproj -target "Aggregate static plugins" -configuration "Release" -sdk iphonesimulator5.0 SDKROOT=iphonesimulator5.0 VALID_ARCHS=i386 ARCHS=i386 
			xcodebuild -project MobileVLCKit.xcodeproj -target "MobileVLCKit" -configuration "Release" -sdk iphonesimulator5.0 SDKROOT=iphonesimulator5.0 VALID_ARCHS=i386 ARCHS=i386
		popd
	popd

	echo "--==-- Build for MediaLibraryKit (simulator version) --==--"
	pushd MediaLibraryKit
		ln -s ../../vlc/projects/macosx/framework/build/Release-iphonesimulator External/MobileVLCKit
		xcodebuild -project MobileMediaLibraryKit.xcodeproj -configuration "Release" -sdk iphonesimulator5.0 SDKROOT=iphonesimulator5.0 VALID_ARCHS=i386 ARCHS=i386
	popd

	echo "--==-- Build for MobileVLC (simulator version) --==--"
	pushd MobileVLC
		ln -s ../../vlc/projects/macosx/framework/build/Release-iphonesimulator External/MobileVLCKit
		ln -s ../../MediaLibraryKit/build/Release-iphonesimulator External/MediaLibraryKit
		xcodebuild -project MobileVLC.xcodeproj -configuration "Release" -sdk iphonesimulator5.0 SDKROOT=iphonesimulator5.0 VALID_ARCHS=i386 ARCHS=i386
	popd
else
	pushd vlc
		echo "--==-- Build for vlc (os version) --==--"
		pushd extras/package/ios
			./build_for_iOS.sh
		popd

		echo "--==-- Build for vlc-MobileVLCKit (os version) --==--"
		pushd projects/macosx/framework
			xcodebuild -project MobileVLCKit.xcodeproj -target "Aggregate static plugins" -configuration "Release" -sdk iphoneos5.0 SDKROOT=iphoneos5.0 VALID_ARCHS=armv7 ARCHS=armv7
			xcodebuild -project MobileVLCKit.xcodeproj -target "MobileVLCKit" -configuration "Release"  -sdk iphoneos5.0 SDKROOT=iphoneos5.0 VALID_ARCHS=armv7 ARCHS=armv7 
		popd
	popd

	echo "--==-- Build for MediaLibraryKit (os version) --==--"
	pushd MediaLibraryKit
		ln -s ../../vlc/projects/macosx/framework/build/Release-iphoneos External/MobileVLCKit
		xcodebuild -project MobileMediaLibraryKit.xcodeproj -configuration "Release" -sdk iphoneos5.0 SDKROOT=iphoneos5.0 VALID_ARCHS=armv7 ARCHS=armv7 
	popd

	echo "--==-- Build for MobileVLC (os version) --==--"
	pushd MobileVLC
		ln -s ../../vlc/projects/macosx/framework/build/Release-iphoneos External/MobileVLCKit
		ln -s ../../MediaLibraryKit/build/Release-iphoneos External/MediaLibraryKit
		xcodebuild -project MobileVLC.xcodeproj -configuration "Release" -sdk iphoneos5.0 SDKROOT=iphoneos5.0 VALID_ARCHS=armv7 ARCHS=armv7 
	popd

fi


4.5 修改生成FFMpeg的config.h的Makefile文件,禁用汇编。具体原因见下面的纠错Troubleshooting章节。

Makefile位于:/VLC/vlc/extras/contrib/src目录下

改动方式:搜寻关键字“FFMPEGCONF”,使其加入"--disable-asm"参数。我的方法是在搜寻到关键字"FFMPEGCONF"的第一个地方,将

FFMPEGCONF = 

改成

FFMPEGCONF = --disable-asm

【注:其实改在ffmpeg编译章节那里会更合适,不过反正作用是一样的。另:由于Makefile文件太大,就不贴原文了。】


4.6 为了编译libdvbpsi库,稍稍修改iOS SDK的源文件。这是因为编译时会报错说找不到"i386/limits.h",所以需要把这个文件拷贝到他的搜寻目录中去。具体原因见后面的纠错Troubleshotting章节。

 - a) 找到目录:/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS5.0.sdk/usr/include

 - b) 在其中新建目录:i386

 - c) 全局搜索某个i386目录下的limits.h和_limits.h文件,并将搜索到的这两个文件拷贝入刚才创建的目录中。

注:修改系统目录,有风险!请谨慎!

【注2:新建目录时会提示需要administrator授权,别怕,只是新加了两个文件进去而已】

【注3:在新加入的目录中,留下个人醒目标志,以后好搜索还原】


4.7. 运行脚本进行编译

cd /VLC
./MobileVLC/buildMobileVLC.sh


4.8. 多运行几遍保证各个编译命令都是"Build SUCCEEDED"。需要多编译几次的原因我这次看了下,好像有这几种情况

 - a) FFMPEG库打patch时出错。这个似乎不影响使用。第二次编译可以通过

 - b) faad2库下载失败。可以回看log,看下载进度是不是到了100%,如果不是,去/VLC/vlc/extras/contrib/src-arm-apple-darwin10-ios/src/目录下,将下载的faad2-x.x.tar.gz和faad2库删掉。再重新编译。别的几个库同理。下载如问题多多,有必要时请加载V-PN...

 - c) 库下载解压后再编译时环境配置不到位。这时重新编译就可以发现会新编译一些东西,然后就可以过了。应该是脚本不够完善的缘故。


然后,就可以在下载到真机进行调试了。程序下载到iOS device后,debugger会报错,然后弹窗口说调试失败,未深究原因。不过MobileVLC这时已经可以直接在iOS device里面使用了。比如我向ipad的VLC中导入了rmvb/asf/mp4/mkv类型文件各一个,均可以播放哦~如图:


【注:由于去掉了FFMpeg的汇编,据称解码效率会有比较大的牺牲】

【注2:临时找的几个视频播放都还不错,mp3放进去没反应】


五。纠错 (TroubleShooting)

1. 一些基本原因,请参考上一篇同章节:《黑苹果,iOS SDK和MobileVLC之逆旅(二) 编译MobileVLC》 (http://blog.csdn.net/madongchunqiu/article/details/6707068)

2. 关于FFMpeg基于iOS5.0的编译问题。Google上有很多相关帖子。大致有如下原因:

 - a) 链接目录不对,导致出错:“ld: in /usr/lib/system/libcache.dylib, missing required architecture armv7 in file for architecture armv7”,请参考此文:StackOverflow - building MobileVLC -> armc7 + ffmpeg issue (http://stackoverflow.com/questions/6320053/building-mobilevlc-armc7-ffmpeg-issue)

 - b) 编译器选择错误,导致出错:"ld: library not found for -lcrt1.10.6.0"。clang/gcc/llvm-gcc等等,都试了试。

 - c) 未禁用inline asm或者asm,导致gas-preprocessor.pl处理时出错。原因似乎是因为编译器和汇编的指令集32bit/64bit不一致。下面这几篇文章中有比较详细的描述:StackOverflow - FFmpeg for iOS5 (http://stackoverflow.com/questions/8323672/ffmpeg-for-ios5),yuvi / gas-preprocessor issue #16 (https://github.com/yuvi/gas-preprocessor/issues/16),倾情奉献ios5.0编译ffmpeg,真机ok! (http://www.cocoachina.com/bbs/read.php?tid=98563)

 - d) 在xcode3.2.5 / iOS SDK4.2编译环境下,FFMpeg是没有这些乱七八糟的问题的。

3. 关于libdvbpsi库的编译问题,在SDK中居然缺乏必要的文件。这个问题应该也可以通过加入新的搜索目录来实现,但是我还是野蛮了一把直接改了SDK。这篇文章里面有比较详细的说明:multiple arch flags won't work with -E (http://lists.macosforge.org/pipermail/macports-dev/2011-February/013745.html)

4. 关于编译中下载第三方库并进行编译时,容易出错的原因:可能是库文件包下载不完整。我有好几次下载到一半就中断下载了,或者下载了半个小时没反应。。。最后发现还是V-PN比较好用。这种问题的解决方法就是多编译几次,或者删了下载的东西再重新编译,甚或新建一个VLC目录重新开始。

5. 关于出现某些文件无法找到的错误,比如“error: 'MobileVLCKit/MobileVLCKit.h' file not found”,也有可能是第三方库文件的问题。比如据说现在下载“contrib-macosx-i386-34.tar.bz2”个文件,经常会出现问题,若发现下载不完整,请另觅途径。

6. 第三方库最新版本的变化:由于某些第三方库并未包含在项目中,而是直接引用的下载链接,故而若第三方库有变化,则可能会编译不通过。比如:

6.1 http://live555.com/liveMedia/public/live555-latest.tar.gz据称最新版本有所变化,会导致编译不通过。具体情况请看下面的留言;


六。遗留 (TO DO)

等我的iOS SDK升级到5.1,还需要试试上面的东西管不管用。当然,如果哪位仁兄能帮我试试,然后给我一点反馈就再好不过了。留言中,已经有人确认在iOS5.1甚至iOS6.x上编译成功,需要修改的地方和本文类似,故不作详述了。稍许不同之处,可以参看本文最开始的“橙色文字”部分

然后一直以来都是编译的MobileVLC1.1.0版本,也不清楚git上面的最新MobileVLC版本会如何。不知道VLC因为license问题无法在app store上上架,是否会影响其团队在iOS平台上继续开发。


我大概几个月后,会写一篇关于自制VLC实现个人"隐私"视频库的文章,希望到时候这些问题都能得到解决。

【注:其实自从发现truecrypt后,这个项目的意义就不大了。

传统加解密方式:优点-安全;缺点-每次回放前都需要解密;

truetype方式:优点-安全,一次性加密,实时回放;缺点-需要加载成虚拟盘;

自制VLC;优点-一次性加密,回放时实时解密;缺点-现在采用的不是常规加密方式,而只是加扰,故而几乎不可谈其安全性。不过总还是有实用价值的】


七。给读者的话 (Tips)

近来越来越多的收到读者来信,让我帮忙看看编译log找出问题。我把这些问题总结后发在下面的文章中了。如果你也在编译中有所苦恼的话,请看这里:

编译MobileVLC时,可能会用到的一些编译调试技巧集合(Mac)(http://blog.csdn.net/madongchunqiu/article/details/7931267)


八。参考文章 (References)

1. StackOverflow - building MobileVLC -> armc7 + ffmpeg issue (http://stackoverflow.com/questions/6320053/building-mobilevlc-armc7-ffmpeg-issue)

2. StackOverflow - FFmpeg for iOS5 (http://stackoverflow.com/questions/8323672/ffmpeg-for-ios5)

3. yuvi / gas-preprocessor issue #16 (https://github.com/yuvi/gas-preprocessor/issues/16)

4. 倾情奉献ios5.0编译ffmpeg,真机ok!(http://www.cocoachina.com/bbs/read.php?tid=98563)

5. multiple arch flags won't work with -E (http://lists.macosforge.org/pipermail/macports-dev/2011-February/013745.html)


九。如何寻求作者帮助 (Ask Help from the Author)

我今天(2012-12-03)才发现原来CSDN里多了好些"私信",以前都没注意到有这个功能,所以都没有查看,更遑论回复,还请见谅。不过请不要再给我发"私信"了,因为要登录查看,感觉特麻烦,我一般是不会去查看的。有问题还请直接在文章后面留言,或者发邮件到我的信箱:[email protected]这两者都有消息推送,我即使不登录CSDN也可以收到的,方便很多。来信中请确保有log,并且log产生如下:

1. 将干净的源代码拷贝至“新建的目录”中

2. 运行编译命令“两遍”,注意生成目标为Simulator版本

3. 将“所有”的终端显示保存后,作为“附件”发给作者

之所以要求如此严苛,主要是因为回复了太多类似问题的邮件了,而解决方法其实就是上面三条。

a. 比如“绝大多数”发给我的log,都不是在新建目录下产生的,这样很多问题都被掩盖了。第一次编译时的信息最有用,而后面的编译,如果没有clean干净,脚本可能会忽略某些需要编译的地方,导致编译出错。【忽略率>90%】

b. 又比如Simulator版本往往更容易编译,而编译出Simulator版本后,iOS target版本的编译基本问题就不大了(一是心里有底了,二是有了参考),但是超过半数的人,总是一开始就挑战iOS target版本,然后被诸如缺乏证书之类的小问题所困住【忽略率>50%】

c. 我在文中强调了很多次,因为编译过程中会下载第三方库,而在中国或者公司网络内,往往由于各种原因下载失败或者下载不完整后解压失败,从而导致无法编译成功。这类问题也可以从log中找到端倪。如果你发现你的log中根本找不到有从网络上下载东西,那么,请还是按照上面三条红色条目重新来一遍吧。【忽略率>75%】

d. 请回看本文前面的章节:“五。纠错 (TroubleShooting)”【忽略率>?%】

e. 请回看本文前面的章节:“七。给读者的话 (Tips)”【忽略率>?%】


注:有谁知道csdn的code那个框里面的文字如何改色和高亮吗?我改了之后,出来时变成了HTML Script的文字效果了。。。


猜你喜欢

转载自blog.csdn.net/madongchunqiu/article/details/7625083