Commit c4be4b7c by liulongfei

裁切录制

parent 8a094dd9
......@@ -284,7 +284,6 @@ namespace VIZ.H2V.ClipTestTool
if (manager == null)
return;
log.Debug($"发送: {this.ClipX}, || {e.Frame.TimeStamp}");
ClipSender.CropRoi(manager, 0, new List<int> { this.ClipX, 0, this.ClipX + 810, e.Frame.Height }, 810, e.Frame.Height, e.Frame.TimeStamp);
}
}
......
......@@ -52,7 +52,7 @@ namespace VIZ.H2V.Module
/// <summary>
/// 裁切框X坐标
/// </summary>
double? ClipBoxX { get; }
double ClipBoxX { get; }
/// <summary>
/// 算法模式
......
......@@ -7,6 +7,7 @@ using System.Text;
using System.Threading.Tasks;
using VIZ.Framework.Core;
using VIZ.H2V.Domain;
using log4net;
namespace VIZ.H2V.Module
{
......@@ -16,6 +17,11 @@ namespace VIZ.H2V.Module
public class ManualController : IManualController
{
/// <summary>
/// 日志
/// </summary>
private static readonly ILog log = LogManager.GetLogger(typeof(ManualController));
/// <summary>
/// 手动控制器
/// </summary>
/// <param name="support">控制器支持</param>
......@@ -89,7 +95,9 @@ namespace VIZ.H2V.Module
double x = this.ClipBoxTargetX + this.GetMappingValue();
x = MathHelper.Clip(min, max, x);
this.ClipBoxTargetX = x;
return this.ClipBoxSmooth.Call(this.ClipBoxTargetX, 1);
double result = this.ClipBoxSmooth.Call(this.ClipBoxTargetX, 1);
return result;
}
/// <summary>
......
......@@ -7,6 +7,8 @@ using VIZ.Framework.Core;
using VIZ.Framework.Common;
using OpenCvSharp;
using System.Windows.Controls;
using SharpDX;
using log4net;
namespace VIZ.H2V.Module
{
......@@ -15,6 +17,11 @@ namespace VIZ.H2V.Module
/// </summary>
public class NDIViewRecording : VideoControlRecording
{
/// <summary>
/// 日志
/// </summary>
private static readonly ILog log = LogManager.GetLogger(typeof(NDIViewRecording));
public NDIViewRecording()
{
this.defaultBoxInfo = new ClipBoxInfo();
......@@ -32,32 +39,78 @@ namespace VIZ.H2V.Module
private ClipBoxInfo defaultBoxInfo;
/// <summary>
/// 保存视频
/// </summary>
/// <param name="path">源路径</param>
/// <param name="path_cut">裁切路径</param>
/// <param name="fps">FPS</param>
/// <param name="width">源视频宽度</param>
/// <param name="height">源视频高度</param>
/// <param name="width_cut">裁切视频宽度</param>
/// <param name="height_cut">裁切视频高度</param>
public void Save(string path, string path_cut, int fps, int width, int height, int width_cut, int height_cut)
{
this.IsSaving = true;
using (VideoWriter writer = new VideoWriter(path, FourCC.MJPG, fps, new Size(width, height)))
using (VideoWriter writer_cut = new VideoWriter(path_cut, FourCC.MJPG, fps, new Size(width_cut, height_cut)))
{
while (this.RecordingFrameQueue.Count > 0)
{
if (!this.RecordingFrameQueue.TryDequeue(out VideoControlRecordingFrame recording))
{
Task.Delay(10).Wait();
continue;
}
Mat[] mats = this.Packaging(recording);
writer.Write(mats[0]);
writer_cut.Write(mats[1]);
mats[0].Dispose();
mats[1].Dispose();
recording.VideoFrame.Dispose();
}
}
this.IsSaving = false;
}
/// <summary>
/// 包装
/// </summary>
/// <param name="recordingFrame">录制帧</param>
public override Mat Packaging(VideoControlRecordingFrame recordingFrame)
public Mat[] Packaging(VideoControlRecordingFrame recordingFrame)
{
ClipBoxInfo boxInfo = recordingFrame.DataFrame as ClipBoxInfo;
boxInfo = boxInfo ?? this.beforeBoxInfo ?? this.defaultBoxInfo;
Mat mat = new Mat(recordingFrame.VideoFrame.Height, recordingFrame.VideoFrame.Width, MatType.CV_8UC4, recordingFrame.VideoFrame.DataStream.DataPointer);
int x = (int)boxInfo.SrcRect.Left;
int y = (int)boxInfo.SrcRect.Top;
int w = (int)(boxInfo.SrcRect.Right - boxInfo.SrcRect.Left);
int h = (int)(boxInfo.SrcRect.Bottom - boxInfo.SrcRect.Top);
Mat cut = mat[new Rect(x, y, w, h)];
Mat dst = new Mat();
Cv2.CvtColor(cut, dst, ColorConversionCodes.BGRA2BGR);
Cv2.CvtColor(mat, dst, ColorConversionCodes.BGRA2BGR);
int x = (int)boxInfo.SrcRect.Left;
int y = 0;
int w = x + 810;
int h = 1080;
Mat cut = dst[new Rect(x, y, w, h)];
recordingFrame.VideoFrame.DataStream.Dispose();
mat.Dispose();
cut.Dispose();
this.beforeBoxInfo = boxInfo;
return dst;
#if DEBUG
log.Debug($"x: {boxInfo.SrcRect.Left} , timeCode: {recordingFrame.VideoFrame.TimeStamp}");
#endif
return new Mat[] { dst, cut };
}
}
}
......@@ -23,7 +23,7 @@ namespace VIZ.H2V.Module
{
this.Support = support;
this.Recording = new NDIViewRecording();
this.Recording.MaxFrameCount = 30 * 25;
this.Recording.MaxFrameCount = 60 * 25;
Single = this;
}
......@@ -34,7 +34,7 @@ namespace VIZ.H2V.Module
public IRecordingSupport Support { get; private set; }
/// <summary>
/// NDI视频录制
/// NDI视频录制 裁切
/// </summary>
private NDIViewRecording Recording;
......@@ -58,9 +58,10 @@ namespace VIZ.H2V.Module
{
Directory.CreateDirectory(dir);
}
string path = Path.Combine(dir, $"{DateTime.Now.ToString("yyyy_MM_dd__HH_mm_ss")}.avi");
string path = Path.Combine(dir, $"{DateTime.Now.ToString("yyyy_MM_dd__HH_mm_ss__SRC")}.avi");
string path_cut = Path.Combine(dir, $"{DateTime.Now.ToString("yyyy_MM_dd__HH_mm_ss__CUT")}.avi");
this.Recording.Save(path, 25, 810, 1080);
this.Recording.Save(path, path_cut, 25, 1920, 1080, 810, 1080);
}
}
}
......@@ -74,10 +74,10 @@ namespace VIZ.H2V.Module
#if DEBUG
// ====================================================================
// 录制测试
//if (this.ViewKey == NDIViewKeys.CAM_1)
//{
// this.ReecordingController = new RecordingController(this);
//}
if (this.ViewKey == NDIViewKeys.CAM_1)
{
this.ReecordingController = new RecordingController(this);
}
// ====================================================================
#endif
}
......
......@@ -39,8 +39,7 @@ namespace VIZ.H2V.Module
return;
}
this.ClipBoxX = this.GetClipX(renderInfo);
this.ManualController.Reset(this.ClipBoxX.Value);
this.ManualController.Reset(this.ClipBoxX);
}
/// <summary>
......@@ -85,7 +84,7 @@ namespace VIZ.H2V.Module
ClipBoxInfo clipBox = new ClipBoxInfo();
clipBox.DrawingBorderWidth = this.CLIP_BOX_BORDER_WIDTH;
clipBox.SrcRect = new RawRectangleF((float)(this.ClipBoxX ?? 0), 0, (float)(this.ClipBoxX ?? 0) + (float)this.CLIP_BOX_WIDTH, renderInfo.Frame.Height);
clipBox.SrcRect = new RawRectangleF((float)(this.ClipBoxX), 0, (float)(this.ClipBoxX) + (float)this.CLIP_BOX_WIDTH, renderInfo.Frame.Height);
clipBox.DrawingBorderColor = this.StrategyMode == AlgorithmStrategyMode.manual_mode ? this.ClipBoxStrokeColor_Manual : this.ClipBoxStrokeColor_Normal;
clipBox.MaskColor = this.CLIP_BOX_MASK_COLOR;
......@@ -111,12 +110,12 @@ namespace VIZ.H2V.Module
#if DEBUG
// ====================================================================
// 录制测试
//if (this.ReecordingController != null)
//{
// ClipBoxInfo temp = new ClipBoxInfo();
// temp.SrcRect = new RawRectangleF((float)(this.ClipBoxX ?? 555), 0, (float)((this.ClipBoxX ?? 555) + 810), 1080);
// this.ReecordingController.Append(e.Frame, temp);
//}
if (this.ReecordingController != null)
{
ClipBoxInfo temp = new ClipBoxInfo();
temp.SrcRect = new RawRectangleF((float)this.ClipBoxX, 0, (float)this.ClipBoxX + 810, 1080);
this.ReecordingController.Append(e.Frame, temp);
}
// ====================================================================
#endif
......@@ -147,21 +146,5 @@ namespace VIZ.H2V.Module
// 统计裁切FPS
this.ClipFPS.CalcFps();
}
/// <summary>
/// 获取默认的裁切坐标
/// </summary>
/// <param name="renderInfo">渲染信息</param>
/// <returns>默认裁切坐标</returns>
private double GetClipX(VideoRenderInfo renderInfo)
{
if (this.ClipBoxX != null)
return this.ClipBoxX.Value;
if (renderInfo == null || renderInfo.Frame == null)
return 0d;
return (renderInfo.Frame.Width - this.CLIP_BOX_WIDTH) / 2d;
}
}
}
......@@ -264,11 +264,11 @@ namespace VIZ.H2V.Module
#region ClipBoxX -- 裁切框X坐标
private double? clipBoxX = 555;
private double clipBoxX = 555;
/// <summary>
/// 裁切框X坐标
/// </summary>
public double? ClipBoxX
public double ClipBoxX
{
get { return clipBoxX; }
set { clipBoxX = value; this.RaisePropertyChanged(nameof(ClipBoxX)); }
......
......@@ -231,7 +231,7 @@ namespace VIZ.H2V.Module
if (renderInfo == null)
return null;
return new List<int> { (int)(this.ClipBoxX ?? 0), 0, (int)((this.ClipBoxX ?? 0) + this.CLIP_BOX_WIDTH), renderInfo.Frame.Height };
return new List<int> { (int)this.ClipBoxX, 0, (int)(this.ClipBoxX + this.CLIP_BOX_WIDTH), renderInfo.Frame.Height };
}
/// <summary>
......
......@@ -41,7 +41,7 @@ namespace VIZ.H2V
#if DEBUG
// ====================================================================
// 录制测试
//AppSetup.AppendSetup(new AppSetup_Recording());
AppSetup.AppendSetup(new AppSetup_Recording());
// ====================================================================
#endif
......
Markdown is supported
0% or
You are about to add 0 people to the discussion. Proceed with caution.
Finish editing this message first!
Please register or to comment