環(huán)境
ubuntu 20.04 ? gcc version 9.4.0 ? cmake version 3.16.3
部署ZLMediaKit流媒體服務(wù)器
安裝openssl
首先可以檢查一下自己的openssl的版本如果是1.1.1以上就可以忽略這一步
wget https://www.openssl.org/source/openssl-1.1.1k.tar.gz
tar -xvzf openssl-1.1.1k.tar.gz
yum install -y zlib zlib-devel perl-CPAN #這一步不是必要
cd openssl-1.1.1k/
./config shared --openssldir=/usr/local/openssl --prefix=/usr/local/openssl
make && make install
echo "/usr/local/lib64/" >> /etc/ld.so.conf
echo "/usr/local/openssl/lib" >> /etc/ld.so.conf
ldconfig
ln -s /usr/local/openssl/bin/openssl /usr/local/bin/openssl # 替換系統(tǒng)openssl,非必須
openssl version -a
安裝libsrtp
tar -xvzf libsrtp-2.3.0.tar.gz
cd libsrtp-2.3.0
./configure --enable-openssl --with-openssl-dir=/usr/local/openssl
make -j8 && make install
其中初始化配置的時(shí)候可能會(huì)報(bào)錯(cuò),如果報(bào)錯(cuò)換成./configure --enable-openssl
即可
對(duì)于一些比較新的編譯環(huán)境(如GCC 10+),編譯 libsrtp-2.3.0 可能會(huì)存在問(wèn)題,可以考慮切換到 2.5.0 版本,即
wget https://github.com/cisco/libsrtp/archive/refs/tags/v2.5.0.tar.gz
tar -xvzf libsrtp-2.5.0.tar.gz
cd libsrtp-2.5.0
另外可以安裝ffmpeg進(jìn)行推流測(cè)試
sudo apt-get install ffmpeg
編譯ZLMediaKit
#國(guó)內(nèi)用戶推薦從同步鏡像網(wǎng)站gitee下載
git clone --depth 1 https://gitee.com/xia-chu/ZLMediaKit
cd ZLMediaKit
#千萬(wàn)不要忘記執(zhí)行這句命令
git submodule update --init
編譯
$ mkdir build $ cd build $ cmake .. -DENABLE_WEBRTC=true ?-DOPENSSL_ROOT_DIR=/usr/local/openssl ?-DOPENSSL_LIBRARIES=/usr/local/openssl/lib $ cmake --build . --target MediaServer ? # 最終輸出 [ 96%] Built target test_rtcp_fci [ 96%] Building CXX object tests/CMakeFiles/test_rtp.dir/test_rtp.cpp.o [ 97%] Linking CXX executable ../../release/linux/Debug/test_rtp [ 97%] Built target test_rtp [ 97%] Building CXX object tests/CMakeFiles/test_wsServer.dir/test_wsServer.cpp.o [ 97%] Linking CXX executable ../../release/linux/Debug/test_wsServer [ 97%] Built target test_wsServer [ 97%] Building CXX object tests/CMakeFiles/test_server.dir/test_server.cpp.o [ 97%] Linking CXX executable ../../release/linux/Debug/test_server [ 97%] Built target test_server [ 98%] Built target jsoncpp [ 98%] Linking CXX executable ../../release/linux/Debug/MediaServer [100%] Built target MediaServer
使用上面命令之后就不用make && make install了,會(huì)在release/debug下生成可執(zhí)行文件
部署完成
官方文檔:
zlm啟用webrtc編譯指南 · ZLMediaKit/ZLMediaKit Wiki (github.com)
按照官方文檔走基本不會(huì)出什么問(wèn)題
修改配置文件
webrtc啟動(dòng)后,還需要修改配置文件,需要在填寫rtc.externip,webrtc協(xié)議需要告知播放器服務(wù)器的ip,不過(guò)如果是內(nèi)網(wǎng)環(huán)境的話可以不用修改此配置,因?yàn)槿绻麨榭?,?huì)自動(dòng)讀取內(nèi)網(wǎng)的網(wǎng)卡信息,這樣做的話將無(wú)法實(shí)現(xiàn)跨域NAT使用
[rtc] #rtc播放推流、播放超時(shí)時(shí)間 timeoutSec=15 #本機(jī)對(duì)rtc客戶端的可見ip,作為服務(wù)器時(shí)一般為公網(wǎng)ip,置空時(shí),會(huì)自動(dòng)獲取網(wǎng)卡ip externIP= #rtc udp服務(wù)器監(jiān)聽端口號(hào),所有rtc客戶端將通過(guò)該端口傳輸stun/dtls/srtp/srtcp數(shù)據(jù), #該端口是多線程的,同時(shí)支持客戶端網(wǎng)絡(luò)切換導(dǎo)致的連接遷移 #需要注意的是,如果服務(wù)器在nat內(nèi),需要做端口映射時(shí),必須確保外網(wǎng)映射端口跟該端口一致 port=8000 #設(shè)置remb比特率,非0時(shí)關(guān)閉twcc并開啟remb。該設(shè)置在rtc推流時(shí)有效,可以控制推流畫質(zhì) rembBitRate=1000000
至此基于ZLMediaKit的webrtc流媒體服務(wù)器搭建完成
測(cè)試
在流量器訪問(wèn)服務(wù)器的ip就可以訪問(wèn)流媒體服務(wù)器,這里直接使用https,因?yàn)閔ttp無(wú)法調(diào)用攝像頭
開兩個(gè)不同的窗口,一個(gè)選擇push推流,一個(gè)選擇play拉流,校園網(wǎng)環(huán)境下延遲在120ms左右?
通過(guò)域名訪問(wèn)
ZLMediaKit自帶有效證書,在debug目錄下的default.pem,這個(gè)證書默認(rèn)是解析到127.0.0.1的,這里我嘗試修改解析到內(nèi)網(wǎng)的服務(wù)器ip上
如果是linux機(jī)器則可以通過(guò)修改/etc/hosts文件修改地址解析
127.0.0.1 localhost 127.0.1.1 connect_class ? # The following lines are desirable for IPv6 capable hosts ::1 ? ? ip6-localhost ip6-loopback fe00::0 ip6-localnet ff00::0 ip6-mcastprefix ff02::1 ip6-allnodes ff02::2 ip6-allrouters 10.14.2.7 default.zlmediakit.com
如果是windows機(jī)器則在C:\Windows\System32\drivers\etc\hosts目錄下,修改hosts文件需要管理員權(quán)限,可以以管理員身份打開記事本修改
# Copyright (c) 1993-2009 Microsoft Corp. # # This is a sample HOSTS file used by Microsoft TCP/IP for Windows. # # This file contains the mappings of IP addresses to host names. Each # entry should be kept on an individual line. The IP address should # be placed in the first column followed by the corresponding host name. # The IP address and the host name should be separated by at least one # space. # # Additionally, comments (such as these) may be inserted on individual # lines or following the machine name denoted by a '#' symbol. # # For example: # # ? ? 102.54.94.97 ? ? rhino.acme.com ? ? ? ? # source server # ? ? ? 38.25.63.10 ? ? x.acme.com ? ? ? ? ? ? # x client host ? # localhost name resolution is handled within DNS itself. # 127.0.0.1 ? ? ? localhost # ::1 ? ? ? ? ? ? localhost 10.14.2.7 default.zlmediakit.com
修改后可以ping一下測(cè)試
接下來(lái)重啟流媒體服務(wù),使用自帶證書啟動(dòng)./MediaServer -s default.pem
在瀏覽器上輸入https://default.zlmediakit.com/
即可訪問(wèn)文章來(lái)源:http://www.zghlxwxcb.cn/news/detail-780830.html
文章來(lái)源地址http://www.zghlxwxcb.cn/news/detail-780830.html
到了這里,關(guān)于基于ZLMediaKit的webrtc實(shí)時(shí)視頻傳輸demo搭建的文章就介紹完了。如果您還想了解更多內(nèi)容,請(qǐng)?jiān)谟疑辖撬阉鱐OY模板網(wǎng)以前的文章或繼續(xù)瀏覽下面的相關(guān)文章,希望大家以后多多支持TOY模板網(wǎng)!