问题描述:
在布置好SRS+ffmpeg+flv系统后,分别使用vlc连接原始RTSP流和用flv.js播放srs出来的流,发现两者之间有多大10秒左右的延迟。示意图如下:
image.png
查找了网上的相关资料,排除网络问题,就是缓存开销等原因,通过对SRS系统进行配置优化。
参考地址
https://github.com/ossrs/srs/wiki/v2_CN_LowLatency
listen 1935;
max_connections 1000;
srs_log_tank file;
srs_log_file ./objs/srs.log;
http_api {
enabled on;
listen 1985;
}
http_server {
enabled on;
listen 80;
dir ./objs/nginx/html;
}
stats {
network 0;
disk sda sdb xvda xvdb;
}
vhost __defaultVhost__ {
#最小延迟打开,默认是打开的,该选项打开的时候,mr默认关闭。
min_latency on;
#Merged-Read,针对RTMP协议,为了提高性能,SRS对于上行的read使用merged-read,即SRS在读写时一次读取N毫秒的数据
mr {
enabled off;
#默认350ms,范围[300-2000]
#latency 350;
}
#Merged-Write,SRS永远使用Merged-Write,即一次发送N毫秒的包给客户端。这个算法可以将RTMP下行的效率提升5倍左右,范围[350-1800]
mw_latency 100;
#enabled on;
#https://github.com/simple-rtmp-server/srs/wiki/v2_CN_LowLatency#gop-cache
gop_cache off;
#配置直播队列的长度,服务器会将数据放在直播队列中,如果超过这个长度就清空到最后一个I帧
#https://github.com/simple-rtmp-server/srs/wiki/v2_CN_LowLatency#%E7%B4%AF%E7%A7%AF%E5%BB%B6%E8%BF%9F
queue_length 10;
#http_flv配置
http_remux {
enabled on;
mount [vhost]/[app]/[stream].flv;
hstrs on;
}
}
在调整参数后,系统现在的延时如下:
image.png