轉載請注明出處:http://www.cnblogs.com/fpzeng/p/3202344.html
系統版本:OS X 10.8
一、在iOS平台上交叉編譯librtmp
librtmp link時需要openssl,在iOS上編譯openssl請參考以下腳本:https://github.com/x2on/OpenSSL-for-iPhone/blob/master/build-libssl.sh,假設openssl/*.h頭文件放於
/a/b/c/openssl/include路徑下,libcrypto.a和libssl.a庫文件i386版本存放於/a/b/c/openssl/ios/libs/ios_i386路徑下,libcrypto.a和libssl.a庫文件armv7版本存放於/a/b/c/openssl/ios/libs/ios_armv7路徑下。
首先獲取librtmp代碼:
git clone git://git.ffmpeg.org/rtmpdump
在rtmpdump中就有librtmp代碼了,可以看到librtmp/Makefile文件已經存在了,我們需要做的就是export相關變量就行了。其中需要處理CROSS_COMPILE、XCFLAGS、XLDFLAGS三個變量。
1.1 編譯i386版本
cd rtmpdump/librtmp export CROSS_COMPILE=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/usr/bin/ export XCFLAGS="-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk -I/a/b/c/openssl/ios/include -arch i386" export XLDFLAGS="-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneSimulator.platform/Developer/SDKs/iPhoneSimulator6.1.sdk -L/a/b/c/openssl/ios/libs/ios_i386 -arch i386 "
make SYS=darwin
1.2 編譯armv7版本
export CROSS_COMPILE=/Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/usr/bin/ export XCFLAGS='-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk -I/a/b/c/openssl/ios/include -arch armv7'
export XLDFLAGS='-isysroot /Applications/Xcode.app/Contents/Developer/Platforms/iPhoneOS.platform/Developer/SDKs/iPhoneOS6.1.sdk -L/a/b/c/openssl/ios/libs/openssl/ios_armv7 -arch armv7'
make SYS=darwin
1.3 調試
如果需要調試,請將librtmp/Makefile中設置優化選項產生debug信息。
OPT=-O0 CFLAGS=-Wall -g $(XCFLAGS) $(INC) $(DEF) $(OPT) $(SO_DEF) LDFLAGS=$(XLDFLAGS) -g
其中,-O0能減少編譯時間並產生調試信息。並且在編譯和鏈接選項中添加-g選項產生debug symbol。
二、在ffmpeg中使用librtmp
假設librtmp/*.h頭文件在/a/b/c/librtmp/include路徑下,librtmp.a在/a/b/c/librtmp/libs/路徑下。
執行配置時,添加選項開啟librtmp並且指定頭文件和鏈接庫路徑:
./configure --enable-librtmp --extra-cflags=-I/a/b/c/librtmp/include --extra-ldflags=-L/a/b/c/librtmp/libs/
此時,提示錯誤:
ERROR: librtmp not found
查看日志文件config.log:
check_pkg_config librtmp librtmp/rtmp.h RTMP_Socket
ERROR: librtmp not found
ffmpeg嘗試在檢查librtmp時運行pkg-config,請將
enabled librtmp && require_pkg_config librtmp librtmp/rtmp.h RTMP_Socket
修改為
enabled librtmp