合肥做百度网站,一般公司常用的邮箱,天津seo排名公司,学做课件的网站环境
ubuntu 20.04
gcc version 9.4.0
cmake version 3.16.3
部署ZLMediaKit流媒体服务器
安装openssl
首先可以检查一下自己的openssl的版本如果是1.1.1以上就可以忽略这一步
wget https://www.openssl.org/source/openssl-1.1.1k.tar.gz
tar -xvzf openssl-1.1.1k…环境
ubuntu 20.04
gcc version 9.4.0
cmake version 3.16.3
部署ZLMediaKit流媒体服务器
安装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
./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 # 替换系统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
其中初始化配置的时候可能会报错如果报错换成./configure --enable-openssl即可
对于一些比较新的编译环境如GCC 10编译 libsrtp-2.3.0 可能会存在问题可以考虑切换到 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进行推流测试
sudo apt-get install ffmpeg
编译ZLMediaKit
#国内用户推荐从同步镜像网站gitee下载
git clone --depth 1 https://gitee.com/xia-chu/ZLMediaKit
cd ZLMediaKit
#千万不要忘记执行这句命令
git submodule update --init
编译
$ mkdir build
$ cd build
$ cmake .. -DENABLE_WEBRTCtrue -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了会在release/debug下生成可执行文件 部署完成 官方文档
zlm启用webrtc编译指南 · ZLMediaKit/ZLMediaKit Wiki (github.com)
按照官方文档走基本不会出什么问题
修改配置文件
webrtc启动后还需要修改配置文件需要在填写rtc.externipwebrtc协议需要告知播放器服务器的ip不过如果是内网环境的话可以不用修改此配置因为如果为空会自动读取内网的网卡信息这样做的话将无法实现跨域NAT使用
[rtc]
#rtc播放推流、播放超时时间
timeoutSec15
#本机对rtc客户端的可见ip作为服务器时一般为公网ip置空时会自动获取网卡ip
externIP
#rtc udp服务器监听端口号所有rtc客户端将通过该端口传输stun/dtls/srtp/srtcp数据
#该端口是多线程的同时支持客户端网络切换导致的连接迁移
#需要注意的是如果服务器在nat内需要做端口映射时必须确保外网映射端口跟该端口一致
port8000
#设置remb比特率非0时关闭twcc并开启remb。该设置在rtc推流时有效可以控制推流画质
rembBitRate1000000
至此基于ZLMediaKit的webrtc流媒体服务器搭建完成
测试
在流量器访问服务器的ip就可以访问流媒体服务器这里直接使用https因为http无法调用摄像头
开两个不同的窗口一个选择push推流一个选择play拉流校园网环境下延迟在120ms左右✔ 通过域名访问
ZLMediaKit自带有效证书在debug目录下的default.pem这个证书默认是解析到127.0.0.1的这里我尝试修改解析到内网的服务器ip上
如果是linux机器则可以通过修改/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机器则在C:\Windows\System32\drivers\etc\hosts目录下修改hosts文件需要管理员权限可以以管理员身份打开记事本修改
# 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一下测试 接下来重启流媒体服务使用自带证书启动./MediaServer -s default.pem
在浏览器上输入https://default.zlmediakit.com/即可访问