Former-commit-id: 07afccc69cf903b3f04208f8c4716d17e2a409b5
Former-commit-id: 74e5a4bf3e122023cbe31562d50cdf6f75ff8c5e
1.0
wanggang 4 years ago
parent 208a89e842
commit fb53fbccff

@ -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<IoTDevice> _deviceRepo;
private readonly IRepository<LiveRecord> _liveRecordRepo;
public SrsController(IRepository<IoTDevice> deviceRepo,
IRepository<LiveRecord> liveRecordRepo)
{
this._deviceRepo = deviceRepo;
this._liveRecordRepo = liveRecordRepo;
}
/// <summary>
/// 录制完毕事件响应
///{"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"}
/// </summary>
/// <returns></returns>
[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<Dictionary<string, string>>(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;
}
}
}

@ -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;
}
}

@ -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;
}
}
Loading…
Cancel
Save