Ubuntu安装SRS流媒体服务
通过网盘分享的文件:srs
链接: 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.zipmv 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 srskill -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-reloadsudo systemctl start srssudo systemctl enable srssudo 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 porttcp {enabled on;listen 16003;}# @see https://ossrs.net/lts/zh-cn/docs/v4/doc/webrtc#config-candidatecandidate *;protocol all;
}
vhost __defaultVhost__ {#http_hooks {# enabled on;# on_publish http://192.168.0.130/api/srs/on_publish; # 替换成你的回调接口#}hls {enabled off;hls_fragment 5; # 切片时长 100ms(默认 2s)hls_td_ratio 1.0; # 减少 GOP 缓存hls_acodec aac; # 强制音频编码为AAChls_vcodec h264; # 强制视频编码为H264hls_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-rtcrtmp_to_rtc on;# @see https://ossrs.net/lts/zh-cn/docs/v4/doc/webrtc#rtc-to-rtmprtc_to_rtmp on;# 会话超时时间,单位秒stun_timeout 30;# 是否开启NACK的支持,即丢包重传,默认on。nack off;# 是否开启TWCC的支持,即拥塞控制的反馈机制,默认ontwcc 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 低延迟模式
}