Former-commit-id: 0a4dd455dd0f8caf6db38a346bdd45c17e0b55d7
TangShanKaiPing
wanggang 6 years ago
parent 2b24c738c1
commit 8eb761500a

@ -122,20 +122,19 @@ namespace IoT.Shared.DeviceServices.Onvif
InfoId = deviceInfo.Id,
NodeId = node.Id
};
var fileName = $"ffmpeg-{Helper.Instance.GetRunTime()}{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : "")}";
var file = Path.Combine(this._env.WebRootPath, fileName);
device.AddorUpdateData("ffmpeg.file", file, DeviceDataType.String, "ffmpeg路径", hidden: true);
device.AddorUpdateData("ffmpeg.args", this._configuration["ffmpeg.args"], DeviceDataType.String, "ffmpeg.args", hidden: true);
device.AddorUpdateData("mainrtmp", $"rtmp://{this._configuration["stream.rtmp"]}/live/main{ipCamera.Id}", DeviceDataType.String, "主码流rtmp");
device.AddorUpdateData("mainflv", $"http://{this._configuration["stream.flv"]}/live/main{ipCamera.Id}.flv", DeviceDataType.String, "主码流flv");
device.AddorUpdateData("mainhls", $"http://{this._configuration["stream.hls"]}/live/main{ipCamera.Id}.m3u8", DeviceDataType.String, "主码流hls");
device.AddorUpdateData("subrtmp", $"rtmp://{this._configuration["stream.rtmp"]}/live/sub{ipCamera.Id}", DeviceDataType.String, "子码流rtmp");
device.AddorUpdateData("subflv", $"http://{this._configuration["stream.flv"]}/live/sub{ipCamera.Id}.flv", DeviceDataType.String, "子码流flv");
device.AddorUpdateData("subhls", $"http://{this._configuration["stream.hls"]}/live/sub{ipCamera.Id}.m3u8", DeviceDataType.String, "子码流hls");
device.AddorUpdateData("ffmpeg.file", this._configuration["ffmpeg.file"], DeviceDataType.String, "ffmpeg.file", hidden: true);
device.AddorUpdateData("ffmpeg.args", this._configuration["ffmpeg.args"], DeviceDataType.String, "ffmpeg.args", hidden: true);
device.AddorUpdateData("CustomFile", "", DeviceDataType.String, "自定义ffmpeg路径", hidden: true);
device.ConnectId = this._configuration["connectId"];
device.NodeNumber = this._configuration["node.number"];
deviceRepo.Add(device);
deviceRepo.SaveChanges();
this.SendDevice(device);
}
var profiles = this._onvifDeviceManagement.GetProfiles(ipCamera.DeviceUrl, ipCamera.MediaUrl);
var needAuth = false;
@ -189,8 +188,8 @@ namespace IoT.Shared.DeviceServices.Onvif
device.AddorUpdateData("MainSnapshotUri", ipCamera.MainSnapshotUri, DeviceDataType.String, "主码流截图地址");
device.AddorUpdateData("SubStreamUri", ipCamera.SubStreamUri, DeviceDataType.String, "子码流地址");
device.AddorUpdateData("SubSnapshotUri", ipCamera.SubSnapshotUri, DeviceDataType.String, "子码流截图地址");
var jpgBytes = SubScreenShot(device.Number);
using (var stream = new MemoryStream(SubScreenShot(device.Number)))
var jpgBytes = ScreenShot(device);
using (var stream = new MemoryStream(jpgBytes))
{
using (var bigImage = Image.FromStream(stream))
{
@ -304,14 +303,9 @@ namespace IoT.Shared.DeviceServices.Onvif
var subStreamUri = camera.Data.FirstOrDefault(o => o.Key == "SubStreamUri").Value;
var subRtspUrl = $"rtsp://{(needAuth ? $"{camera.UserName}:{camera.Password}@" : "")}{subStreamUri.Substring(7)}";
var fileName = $"ffmpeg-{Helper.Instance.GetRunTime()}{(RuntimeInformation.IsOSPlatform(OSPlatform.Windows) ? ".exe" : "")}";
var file = Path.Combine(this._env.WebRootPath, fileName);
var file = camera.GetData("ffmpeg.file")?.Value;
var mainRtmp = camera.Data.FirstOrDefault(o => o.Key == "mainrtmp").Value;
var subRtmp = camera.Data.FirstOrDefault(o => o.Key == "subrtmp").Value;
var customFile = camera.GetData("CustomFile")?.Value;
if (!string.IsNullOrEmpty(customFile))
{
file = customFile;
}
Console.WriteLine(file);
var arguments = camera.Data.FirstOrDefault(o => o.Key == "ffmpeg.args").Value;
Process main = null, sub = null;
@ -544,6 +538,21 @@ namespace IoT.Shared.DeviceServices.Onvif
return hc.GetByteDigest(url, camera.UserName, camera.Password);
}
private byte[] ScreenShot(Device camera)
{
var url = camera.GetDataValue("SubSnapshotUri");
if (string.IsNullOrEmpty(url))
{
return new byte[] { };
}
var hc = this._httpClientFactory.CreateClient();
if (camera.GetDataValue("NeedAuth") == "否")
{
return hc.GetByteArrayAsync(url).Result;
}
return hc.GetByteDigest(url, camera.UserName, camera.Password);
}
private Device GetCamera(string number)
{
using (var scope = _applicationServices.CreateScope())

@ -45,7 +45,6 @@ namespace IoTNode
new EFConfigurationValue { Id = "stream.flv", Value=$"{stream}:8080"},
new EFConfigurationValue { Id = "stream.hls", Value=$"{stream}:8080"},
new EFConfigurationValue { Id = "ffmpeg.args", Value=" -y -threads {0} -rtsp_transport tcp -use_wallclock_as_timestamps 1 -stimeout 3000000 -i \"{1}\" -fflags +genpts -c copy -f flv \"{2}\""},
new EFConfigurationValue { Id = "ffmpeg.file", Value="/usr/ffmpeg-rkmp/bin/ffmpeg"},
//
new EFConfigurationValue { Id = "name", Value= "物联网节点"},
new EFConfigurationValue { Id = "logo", Value= "/images/logo.png",Type= InputType.ImageUrl},

@ -1,4 +1,4 @@
using IoT.UI.Shard;
using IoT.Shard;
using Microsoft.AspNetCore.Builder;
using Microsoft.AspNetCore.Hosting;
using Microsoft.Extensions.Configuration;

@ -26,6 +26,10 @@ http {
listen 80;
server_name localhost;
location ^~ /srs/ {
proxy_pass http://localhost:8080/;
}
location ^~ /UserCenter/ {
proxy_pass http://localhost:8000/;
}

Loading…
Cancel
Save