RTSP播放方案
ffmpeg + nginx + video.js,rtsp转rtmp播放
- 优点:延迟一般(1秒以上)
- 缺点:依赖flash,但现代浏览器大多禁用或不能使用flash
- 参考方案
ffmpeg + video.js,rtsp转hls播放
- 优点:不同码率无缝切换
- 缺点1:延迟较高
- 缺点2:切片文件碎片化
- 参考方案
ffmpeg + websocket + flv.js,rtsp转flv播放
- 优点1:延迟较低(1秒左右)
- 优点2:无需安装插件
- 缺点:额外的ws支持
- 参考方案
VLC插件播放
- 优点:延迟低(毫秒级别)
- 缺点1:需要安装VLC插件
- 缺点2:不支持H265编码
- 缺点3:仅支持IE浏览器或低版本Chrome
- 参考方案
SmartPlayer插件播放
- 优点1:延迟低(毫秒级别)
- 优点2:支持H265、MJPEG编码
- 缺点:需要商用授权
rtsp转webrtc播放
- 优点1:延迟低(毫秒级别)
- 优点2:无需安装插件
- 缺点1:linux下webrtc-streamer依赖的glibc版本较高,升级困难
- 缺点2:不支持H265编码
- 参考方案
综合以上方案,最终选择使用webrtc播放,使用webrtc-streamer将rtsp转为webrtc播放。
webrtc-streamer
在github的发布记录中找到合适的版本,下载相应操作系统的可执行文件,本文使用的版本为v0.8.0。
window下安装
1. 下载windows版本的webrtc-streamer
点击下载v0.6.5, 其他版本下载启动后转流就自动停止,暂时未做问题分析。
2. 启动服务
bash
# 默认监听0.0.0.0:8000
.\webrtc-streamer.exe -o -s-
1
2
2
centos下安装
1. 下载linux版本的webrtc-streamer
bash
wget https://github.com/mpromonet/webrtc-streamer/releases/download/v0.8.0/webrtc-streamer-v0.8.0-Linux-x86_64-Release.tar.gz
tar -zxvf webrtc-streamer-v0.8.0-Linux-x86_64-Release.tar.gz
cd webrtc-streamer-v0.8.0-Linux-x86_64-Release
./webrtc-streamer
1
2
3
4
2
3
4
2. 缺少库
bash
# ./webrtc-streamer: error while loading shared libraries: libXcomposite.so.1: cannot open shared object file: No such file or directory
yum install -y libXcomposite
# ./webrtc-streamer: error while loading shared libraries: libXrandr.so.2: cannot open shared object file: No such file or directory
yum install -y libXrandr.x86_64
# ./webrtc-streamer: error while loading shared libraries: libXtst.so.6: cannot open shared object file: No such file or directory
yum install -y libXtst
# ./webrtc-streamer: error while loading shared libraries: libX11.so.6: cannot open shared object file: No such file or directory
yum install -y libX11
# ./webrtc-streamer: error while loading shared libraries: libXext.so.6: cannot open shared object file: No such file or directory
yum install -y libXext
# ./webrtc-streamer: error while loading shared libraries: libXdamage.so.1: cannot open shared object file: No such file or directory
yum install -y libXdamage
# ./webrtc-streamer: error while loading shared libraries: libXcomposite.so.1: cannot open shared object file: No such file or directory
yum install -y libXcomposite
# ./webrtc-streamer: error while loading shared libraries: libXrandr.so.2: cannot open shared object file: No such file or directory
yum install -y libXrandr
# ./webrtc-streamer: error while loading shared libraries: libXtst.so.6: cannot open shared object file: No such file or directory
yum install -y libXtst
# 汇总
yum install -y libXcomposite libXrandr.x86_64 libXtst libX11 libXext libXdamage libXcomposite libXrandr libXtst
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
3.glibc版本过低升级
需要升级glibc至少2.35
及以上版本
bash
# glibc版本过低提示信息
# ./webrtc-streamer: /lib64/libm.so.6: version `GLIBC_2.27' not found (required by ./webrtc-streamer)
# ./webrtc-streamer: /lib64/libm.so.6: version `GLIBC_2.29' not found (required by ./webrtc-streamer)
# ./webrtc-streamer: /lib64/libm.so.6: version `GLIBC_2.35' not found (required by ./webrtc-streamer)
# ./webrtc-streamer: /lib64/libc.so.6: version `GLIBC_2.25' not found (required by ./webrtc-streamer)
# ./webrtc-streamer: /lib64/libc.so.6: version `GLIBC_2.32' not found (required by ./webrtc-streamer)
# ./webrtc-streamer: /lib64/libc.so.6: version `GLIBC_2.35' not found (required by ./webrtc-streamer)
# ./webrtc-streamer: /lib64/libc.so.6: version `GLIBC_2.34' not found (required by ./webrtc-streamer)
# ./webrtc-streamer: /lib64/libc.so.6: version `GLIBC_2.28' not found (required by ./webrtc-streamer)
# ./webrtc-streamer: /lib64/libc.so.6: version `GLIBC_2.33' not found (required by ./webrtc-streamer)
# 查看glibc版本
ldd --version
1
2
3
4
5
6
7
8
9
10
11
12
13
2
3
4
5
6
7
8
9
10
11
12
13
参考CentOs升级gcc及glibc,升级过程会比较漫长。
4.启动服务
bash
# 默认监听0.0.0.0:8000
./webrtc-streamer -o -s-
1
2
2
遇到的问题
1. 视频不能播放
检查视频编码是否是H264
,webrtc当前不支持H265编码,大多数摄像机默认编码均是H265。
2. 同屏多个视频播放CPU占用率高
参考,启动参数添加-o
即可。
3. 视频出现绿屏、花屏
禁用浏览器硬件加速,以google为例。
4. 公网播放问题
参考,使用webrtc-streamer内嵌的TURN
server
bash
# 本机存在公网地址
./webrtc-streamer -o -s- -T0.0.0.0:3478 -tturn:turn@$(curl ifconfig.me -s):3478
# 使用公网映射需要TCP和UDP协议都支持 假如将本机3478端口映射到公网turn.abc.com:13478端口
./webrtc-streamer -o -s- -T0.0.0.0:3478 -tturn:turn@turn.abc.com:13478
1
2
3
4
5
2
3
4
5
demo
配置webrtc-streamer的Http服务地址即可,参考Github