目录
- 配置SRS 视频录制
- 配置SRS 开启HTTP API
- 配置SRS HTTP回调
一、配置SRS 视频录制
本示例采用segment(按照时间分段录制)方式,SRS还提供了append、session等方式,session计划按照session来关闭flv文件,即编码器停止推流时关闭flv,整个session录制为一个flv。
vhost your_vhost {
dvr {
enabled on;
#all表示录制所有视频流,也可以按频道录制
#规则为<app>/<stream>,例:live/stream1 live/stream2
dvr_apply all;
#dvr计划
dvr_plan segment;
#录制的路径,详细配置规则见附录三
dvr_path ./objs/nginx/html/[app]/[stream].[timestamp].flv;
#segment方式录制时间设置,单位:分钟
dvr_duration 30;
#开启按关键帧且flv
dvr_wait_keyframe on;
#时间戳抖动算法。full使用完全的时间戳矫正;
#zero只是保证从0开始;off不矫正时间戳。
time_jitter full;
}
}
二、配置SRS 开启HTTP API
修改conf目录下的srs.conf文件,增加如下配置
stats {
network 0;
disk sda sdb xvda xvdb;
}
http_api {
enabled on;
listen 1985;
crossdomain on;
raw_api {
enabled off;
allow_reload off;
allow_query off;
allow_update off;
}
}
其中,http_api开启了HTTP API,stats配置了SRS后台统计的信息,包括:
- network: 这个配置了heartbeat使用的网卡ip,即SRS主动汇报的网卡信息。参考Heartbeat
- disk: 这个配置了需要统计的磁盘的IOPS,可以通过
cat /proc/diskstats命令获得名称,譬如阿里云的磁盘名称叫xvda.
Start
启动服务器:./objs/srs -c http-api.conf
访问api:浏览器打开地址http://192.168.1.170:1985/api/v1
请注意:请将192.168.1.170或者下面提到的任何服务器IP,换成您的服务器的IP。
PS:云服务器记得开启端口号1985
三、SRS配置HTTP回调
vhost your_vhost {
http_hooks {
enabled on;
on_dvr http://127.0.0.1:8085/onDvr; #http回调接口地址
}
}
附录一 数据库表结构
CREATE TABLE `video_file_info` (
`id` int(11) NOT NULL AUTO_INCREMENT,
`ip` varchar(40) DEFAULT NULL,
`vhost` varchar(20) DEFAULT NULL,
`app` varchar(20) DEFAULT NULL,
`stream` varchar(20) DEFAULT NULL,
`param` varchar(60) DEFAULT NULL,
`cwd` varchar(30) DEFAULT NULL,
`file` varchar(60) DEFAULT NULL,
PRIMARY KEY (`id`)
) ENGINE=InnoDB AUTO_INCREMENT=4 DEFAULT CHARSET=utf8
附录二 SRS服务器回调事件:

image.png

image.png
附录三 SRS视频录制路径配置说明:
# the dvr output path, *.flv or *.mp4.
# we supports some variables to generate the filename.
# [vhost], the vhost of stream.
# [app], the app of stream.
# [stream], the stream name of stream.
# [2006], replace this const to current year.
# [01], replace this const to current month.
# [02], replace this const to current date.
# [15], replace this const to current hour.
# [04], replace this const to current minute.
# [05], replace this const to current second.
# [999], replace this const to current millisecond.
# [timestamp],replace this const to current UNIX timestamp in ms.
# @remark we use golang time format "2006-01-02 15:04:05.999" as "[2006]-[01]-[02]_[15].[04].[05]_[999]"
# for example, for url rtmp://ossrs.net/live/livestream and time 2015-01-03 10:57:30.776
# 1. No variables, the rule of SRS1.0(auto add [stream].[timestamp].flv as filename):
# dvr_path ./objs/nginx/html;
# =>
# dvr_path ./objs/nginx/html/live/livestream.1420254068776.flv;
# 2. Use stream and date as dir name, time as filename:
# dvr_path /data/[vhost]/[app]/[stream]/[2006]/[01]/[02]/[15].[04].[05].[999].flv;
# =>
# dvr_path /data/ossrs.net/live/livestream/2015/01/03/10.57.30.776.flv;
# 3. Use stream and year/month as dir name, date and time as filename:
# dvr_path /data/[vhost]/[app]/[stream]/[2006]/[01]/[02]-[15].[04].[05].[999].flv;
# =>
# dvr_path /data/ossrs.net/live/livestream/2015/01/03-10.57.30.776.flv;
# 4. Use vhost/app and year/month as dir name, stream/date/time as filename:
# dvr_path /data/[vhost]/[app]/[2006]/[01]/[stream]-[02]-[15].[04].[05].[999].flv;
# =>
# dvr_path /data/ossrs.net/live/2015/01/livestream-03-10.57.30.776.flv;
# 5. DVR to mp4:
# dvr_path ./objs/nginx/html/[app]/[stream].[timestamp].mp4;
# =>
# dvr_path ./objs/nginx/html/live/livestream.1420254068776.mp4;
# @see https://github.com/ossrs/srs/wiki/v3_CN_DVR#custom-path
# @see https://github.com/ossrs/srs/wiki/v3_CN_DVR#custom-path
# segment,session apply it.
# default: ./objs/nginx/html/[app]/[stream].[timestamp].flv