通过网盘分享的文件:srs 当前版本为 develop 建议使用 v5release 稳定版
链接: https://pan.baidu.com/s/1tdnxxUWh8edcSnXrQD1uLQ?pwd=0000 提取码: 0000
官网地址:Build | SRS
将百度网盘提供的srs 和 conf 下载或上传到指定服务器
# 安装需要的依赖包
sudo apt install -y cmake tclsh unzip gcc g++ make libpcre3-dev zlib1g-dev libssl-dev pkg-config nasm
# 解压srs.zip 包
unzip srs.zip
mv srs.conf srs/trunk/conf/
# 端口如果有冲突请使用自定义端口即可
cd srs/trunk
# 配置srs
./configure --sanitizer=off
#编译
make
# 启动服务
./objs/srs -c conf/srs.conf
# 查看服务启动状态
./etc/init.d/srs status
# 查看日志
tail -n 30 -f ./objs/srs.log
# 查看进程号
ps -ef | grep srs
kill -9 PID
# 设置开机自启动 和 崩溃重启
sudo vim /etc/systemd/system/srs.service
# 填入以下内容 位置记得改对了
[Unit]
Description=SRS (Simple Realtime Server)
After=network.target
[Service]
Type=simple
User=root
WorkingDirectory=/root/srs/trunk
ExecStart=/root/srs/trunk/objs/srs -c /root/srs/trunk/conf/srs.conf
Restart=always
RestartSec=5s
StartLimitInterval=0
StandardOutput=syslog
StandardError=syslog
SyslogIdentifier=srs
[Install]
WantedBy=multi-user.target
# 特别注意 srs.conf 中 daemon 要设置为 off ,防止与系统重启冲突
sudo systemctl daemon-reload
sudo systemctl start srs
sudo systemctl enable srs
sudo systemctl status srs
使用OBS或者FFmpeg进行测试
访问地址:播放地址要改为自己的 app 和 streamKey
8080:http_server listen 端口
http://你的服务器IP:8080/players/srs_player.html?autostart=true&stream=aaa.flv&port=8080&schema=http
详细功能可参考官方文档
使用webrtc低延迟实时直播配置
OBS推流地址:服务:WHIP http://你的IP:16001/rtc/v1/whip/?app=live&stream=livestream
播放地址:SRS 播放地址:http://你的IP:16001/rtc/v1/whip/?app=live&stream=livestream
# main config for srs.
# @see full.conf for detail config.
listen 16000;
max_connections 1000;
#srs_log_tank file;
#srs_log_file ./objs/srs.log;
daemon off;
http_api {
enabled on;
listen 16001;
https {
enabled on;
listen 17001;
key /opt/ssl/test.key;
cert /opt/ssl/test.crt;
}
}
http_server {
enabled on;
listen 16002;
dir ./objs/nginx/html;
https {
enabled on;
listen 17000;
key /opt/ssl/test.key;
cert /opt/ssl/test.crt;
}
}
rtc_server {
enabled on;
listen 16003; # UDP port
tcp {
enabled on;
listen 16003;
}
# @see https://ossrs.net/lts/zh-cn/docs/v4/doc/webrtc#config-candidate
candidate *;
protocol all;
}
vhost __defaultVhost__ {
#http_hooks {
# enabled on;
# on_publish http://192.168.0.100/api/srs/on_publish; # 替换成你的回调接口
#}
hls {
enabled off;
hls_fragment 5; # 切片时长 100ms(默认 2s)
hls_td_ratio 1.0; # 减少 GOP 缓存
hls_acodec aac; # 强制音频编码为AAC
hls_vcodec h264; # 强制视频编码为H264
hls_aof_ratio 1.0; # 禁用音频单独切片
hls_cleanup off;
#hls_m3u8_cache off; # 禁用 M3U8 缓存
}
# FLV 录制配置
dvr {
enabled on;
#dvr_path ./objs/nginx/html/[app]/[stream].[timestamp].flv;
dvr_path ./objs/nginx/html/[app]/[stream]/[2006]/[01]/[02]/[15].[04].[05].[999].flv;
dvr_plan segment;
dvr_duration 30; # 每30分钟分片
dvr_wait_keyframe on;
}
http_remux {
enabled on;
mount [vhost]/[app]/[stream].flv;
hstrs on; # 启用 HTTP Streaming
}
rtc {
enabled on;
# @see https://ossrs.net/lts/zh-cn/docs/v4/doc/webrtc#rtmp-to-rtc
rtmp_to_rtc on;
# @see https://ossrs.net/lts/zh-cn/docs/v4/doc/webrtc#rtc-to-rtmp
rtc_to_rtmp on;
# 会话超时时间,单位秒
stun_timeout 30;
# 是否开启NACK的支持,即丢包重传,默认on。
nack off;
# 是否开启TWCC的支持,即拥塞控制的反馈机制,默认on
twcc off;
dtls_role passive;
}
play{
gop_cache off;
queue_length 5; # 减少播放队列包数
mw_latency 300; # 媒体流处理延迟(ms)
}
# 推流端优化
publish {
mr off; # 禁用合并写入(减少缓冲)
mr_latency 100;
}
# 最小化传输延迟
tcp_nodelay on; # 禁用 Nagle 算法
min_latency on; # 启用 SRS 低延迟模式
}