主要用于rtmp推流,这段时间在做直播功能
2016.05.27 出坑
关于rtmpdump编译总结
今日由于工作需要了解并编译rtmpdump,由于本人linux基础薄弱对makefile不是很了解,昨晚恶补了一下基础。
见帖子链接:
http://blog.csdn.net/ruglcc/article/details/7814546/
有压力才有动力,那么开始愉快的编译之旅吧~
Mac交叉编译有两种
ps:什么是交叉编译,对于iOS程序员还是比较陌生的,交叉编译就是
1、用Xcode自带的编译工具,存放目录
/Applications/Xcode.app/Contents/Developer/usr/bin
2、用Mac编译器进行混编,存放目录
/usr/bin
解决方案:
见博客,这篇博客的demo修改一下就可以编译通过了,非常完美
http://blog.csdn.net/cjj198561/article/details/28955461
这个博客也有借鉴价值:
http://www.cnblogs.com/fpzeng/p/3202344.html
下面是我的完整步骤
一、在iOS平台上编译Openssl
librtmp link时需要openssl,在iOS上编译openssl请参考以下脚本:
build-libssl.sh
Openssl完整代码下载地址
https://github.com/x2on/OpenSSL-for-iPhone
1.1、下载编译Openssl
下载过后执行master/build-libssl.sh脚本,该脚本已经将i386 x86_64 armv7 armv7s arm64 tv_x86_64 tv_arm64版本整合在了一起
1.2、新建目录rtmp
将编译的OpenSSL-for-iPhone-master目录下lib与include考入
二、在iOS平台上编译rtmp
2.1、首先获取librtmp代码:
git clone git://git.ffmpeg.org/rtmpdump
将代码放到rtmp文件夹
2.2、编译libtmp脚本
#!/bin/sh
SDKVERSION="9.1" #这里sdk版本
CURRENTPATH=`pwd`
ARCHS="armv7 armv7s arm64"
LIBPATH="${CURRENTPATH}/lib" #这里是openssl 生成的lib
INCLUDEPATH="${CURRENTPATH}/include" #这里是openssl 生成的头文件
# LIBRTMPREPO="Git://git.ffmpeg.org/rtmpdump" 该变量没用上
BUILDPATH="${CURRENTPATH}/build"
SRCPATH="${CURRENTPATH}/src"
LIBRTMP="librtmp.a"
# 默认Xcode在计算机中的路径
DEVELOPER=`xcode-select -print-path`
if [ ! -d "$DEVELOPER" ]; then
echo "xcode path is not set correctly $DEVELOPER does not exist (most likely because of xcode > 4.3)"
echo "run"
echo "sudo xcode-select -switch <xcode path>"
echo "for default installation:"
echo "sudo xcode-select -switch /Applications/Xcode.app/Contents/Developer"
exit 1
fi
# Check whether openssl has already installed on the machine or not.
# libcrypt.a / libssl.a
set -e
echo 'Check openssl installation'
if [ -f "${LIBPATH}/libcrypto.a" ] && [ -f "${LIBPATH}/libssl.a" ] && [ -d "${INCLUDEPATH}/openssl" ]; then
echo 'Openssl for iOS has already installed, no need to install openssl'
else
echo 'Openssl for iOS not found, will install openssl for iOS'
./build-libssl.sh
echo 'Succeeded to install openssl'
fi
# Download librtmp source code from git repository
# We assuem the user already installed git client.
echo 'Clone librtmp git repository'
# Remove the directory if already exist
rm -rf "${SRCPATH}/rtmpdump"
# git clone ${LIBRTMPREPO} src/rtmpdump
# cd "${SRCPATH}/rtmpdump/librtmp"
cd "${CURRENTPATH}/rtmpdump/librtmp"
LIBRTMP_REPO=""
for ARCH in ${ARCHS}
do
if [ "${ARCH}" == "i386" ];
then
PLATFORM="iPhoneSimulator"
else
PLATFORM="iPhoneOS"
fi
export CROSS_TOP="${DEVELOPER}/Platforms/${PLATFORM}.platform/Developer"
export CROSS_SDK="${PLATFORM}${SDKVERSION}.sdk"
export BUILD_TOOLS="${DEVELOPER}"
echo "Building librtmp for ${PLATFORM} ${SDKVERSION} ${ARCH}"
echo "Please wait..."
# add arch to CC=
# 这里是将librtmp中脚本用到Xcode编译器ar,转用为Mac中ar
sed -ie "s!AR=\$(CROSS_COMPILE)ar!AR=/usr/bin/ar!" "Makefile"
sed -ie "/CC=\$(CROSS_COMPILE)gcc/d" "Makefile"
echo "CC=\$(CROSS_COMPILE)gcc -arch ${ARCH}" >> "Makefile"
export CROSS_COMPILE="${DEVELOPER}/usr/bin/"
export XCFLAGS="-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} -miphoneos-version-min=7.0 -I${INCLUDEPATH} -arch ${ARCH}"
if [ "${ARCH}" == "i386" ];
then
export XLDFLAGS="-L${LIBPATH} -arch ${ARCH}"
else
export XLDFLAGS="-isysroot ${CROSS_TOP}/SDKs/${CROSS_SDK} -miphoneos-version-min=7.0 -L${LIBPATH} -arch ${ARCH}"
fi
OUTPATH="${BUILDPATH}/librtmp-${PLATFORM}${SDKVERSION}-${ARCH}.sdk"
mkdir -p "${OUTPATH}"
LOG="${OUTPATH}/build-librtmp.log"
make SYS=darwin >> "${LOG}" 2>&1
make SYS=darwin prefix="${OUTPATH}" install >> "${LOG}" 2>&1
make clean >> "${LOG}" 2>&1
LIBRTMP_REPO+="${OUTPATH}/lib/${LIBRTMP} "
done
echo "Build universal library..."
lipo -create ${LIBRTMP_REPO}-output ${LIBPATH}/${LIBRTMP}
echo "Building done."
echo "Cleaning up..."
rm -rf ${SRCPATH}/rtmpdump
echo "Done."
在rtmp目录下新建脚本并运行就可以了。