diff --git a/projects/Platform/Api/Api/SrsController.cs b/projects/Platform/Api/Api/SrsController.cs new file mode 100644 index 00000000..3d75508f --- /dev/null +++ b/projects/Platform/Api/Api/SrsController.cs @@ -0,0 +1,64 @@ +using Application.Domain.Entities; +using Infrastructure.Data; +using Microsoft.AspNetCore.Authorization; +using Microsoft.AspNetCore.Mvc; +using Newtonsoft.Json; +using System; +using System.Collections.Generic; +using System.Diagnostics; +using System.IO; +using System.Linq; + +namespace Platform.Apis.Controllers +{ + [Route("api/v{version:apiVersion}/[controller]/[action]")] + [ApiVersion("1.0")] + [ApiController] + public class SrsController : ControllerBase + { + private readonly IRepository _deviceRepo; + private readonly IRepository _liveRecordRepo; + + public SrsController(IRepository deviceRepo, + IRepository liveRecordRepo) + { + this._deviceRepo = deviceRepo; + this._liveRecordRepo = liveRecordRepo; + } + + /// + /// 录制完毕事件响应 + ///{"action":"on_dvr","client_id":107,"ip":"192.168.3.124","vhost":"__defaultVhost__","app":"live","stream":"main0a5d5deee43011b483884cbd8fd2b3dd","param":"","cwd":"/root/publish/apps/srs","file":"./objs/nginx/html/live.main0a5d5deee43011b483884cbd8fd2b3dd.1574832559180.mp4"} + /// + /// + [AllowAnonymous] + [HttpPost] + public string OnDvr() + { + using (var reader = new StreamReader(Request.Body)) + { + var json = reader.ReadToEndAsync().Result; + Debug.WriteLine("ondvr:"); + Debug.WriteLine(json); + var result = JsonConvert.DeserializeObject>(json); + if (result["action"] == "on_dvr") + { + var streamId = result["stream"]; + var device = this._deviceRepo.ReadOnlyTable().FirstOrDefault(o => o.Number == streamId); + if (device != null) + { + this._liveRecordRepo.Add(new LiveRecord + { + DeviceNumber = device.Number, + DeviceName = device?.DisplayName, + Name = $"回放{DateTime.Now:yyyy-MM-dd HH:mm}", + Value = $"/video{result["file"].Substring(result["file"].LastIndexOf('/'))}" + }); + this._liveRecordRepo.SaveChanges(); + } + } + } + return string.Empty; + } + } +} \ No newline at end of file diff --git a/publish/src/linux-x64/publish/docker/conf/srs/conf/srs.conf b/publish/src/linux-x64/publish/docker/conf/srs/conf/srs.conf new file mode 100644 index 00000000..ba368b5b --- /dev/null +++ b/publish/src/linux-x64/publish/docker/conf/srs/conf/srs.conf @@ -0,0 +1,74 @@ +listen 1935; +max_connections 1000; +srs_log_tank file; +srs_log_file ./objs/log/srs.log; +daemon off; +http_api { + enabled on; + listen 1985; + raw_api { + enabled on; + allow_reload on; + allow_query on; + allow_update on; + } +} +http_server { + enabled on; + listen 8080; + dir ./objs/nginx/html; +} +stats { + network 0; + disk sda sdb xvda xvdb; +} +vhost __defaultVhost__ { + tcp_nodelay on min_latency on; + play { + gop_cache off; + queue_length 10; + mw_latency 100; + } + publish { + mr off; + } + transcode live { + enabled off; + ffmpeg ./objs/ffmpeg/bin/ffmpeg; + engine snapshot { + enabled on; + iformat flv; + vfilter { + vf fps=1; + } + vcodec png; + vparams { + vframes 1; + } + acodec an; + oformat image2; + output ./objs/nginx/html/[app]/[stream].png; + } + } + http_remux { + enabled on; + mount [vhost]/[app]/[stream].flv; + } + hls { + enabled on; + hls_fragment 3; + hls_window 10; + hls_path ./objs/nginx/html; + hls_m3u8_file [app]/[stream].m3u8; + hls_ts_file [app]/[stream]-[seq].ts; + } + dvr { + enabled on; + dvr_apply none; + dvr_path ./objs/nginx/html/video/[app].[stream].[timestamp].mp4; + } + http_hooks { + enabled on; + on_dvr http://172.172.0.80/platform/api/v1/Srs/OnDvr; + } +} diff --git a/publish/src/linux-x64/publish/docker/conf/srs/dev/srs.conf b/publish/src/linux-x64/publish/docker/conf/srs/dev/srs.conf new file mode 100644 index 00000000..475bfda3 --- /dev/null +++ b/publish/src/linux-x64/publish/docker/conf/srs/dev/srs.conf @@ -0,0 +1,65 @@ +listen 1935; +max_connections 1000; +srs_log_tank file; +srs_log_file ./objs/log/srs.log; +daemon off; +http_api { + enabled on; + listen 1985; + raw_api { + enabled on; + allow_reload on; + allow_query on; + allow_update on; + } +} +http_server { + enabled on; + listen 8080; + dir ./objs/nginx/html; +} +stats { + network 0; + disk sda sdb xvda xvdb; +} +vhost __defaultVhost__ { + transcode live { + enabled off; + ffmpeg ./objs/ffmpeg/bin/ffmpeg; + engine snapshot { + enabled on; + iformat flv; + vfilter { + vf fps=1; + } + vcodec png; + vparams { + vframes 1; + } + acodec an; + oformat image2; + output ./objs/nginx/html/[app]/[stream].png; + } + } + http_remux { + enabled on; + mount [vhost]/[app]/[stream].flv; + } + hls { + enabled on; + hls_fragment 3; + hls_window 10; + hls_path ./objs/nginx/html; + hls_m3u8_file [app]/[stream].m3u8; + hls_ts_file [app]/[stream]-[seq].ts; + } + dvr { + enabled on; + dvr_apply none; + dvr_path ./objs/nginx/html/video/[app].[stream].[timestamp].mp4; + } + http_hooks { + enabled on; + on_dvr http://host.docker.internal/platform/api/v1/Srs/OnDvr; + } +}