Skip to content
Projects
Groups
Snippets
Help
This project
Loading...
Sign in / Register
Toggle navigation
V
VIZ.Framework
Overview
Overview
Details
Activity
Cycle Analytics
Repository
Repository
Files
Commits
Branches
Tags
Contributors
Graph
Compare
Charts
Issues
0
Issues
0
List
Board
Labels
Milestones
Merge Requests
0
Merge Requests
0
CI / CD
CI / CD
Pipelines
Jobs
Schedules
Charts
Wiki
Wiki
Snippets
Snippets
Members
Collapse sidebar
Close sidebar
Activity
Graph
Charts
Create a new issue
Jobs
Commits
Issue Boards
Open sidebar
刘龙飞
VIZ.Framework
Commits
b6d7ca1a
Commit
b6d7ca1a
authored
Sep 02, 2022
by
liulongfei
Browse files
Options
Browse Files
Download
Email Patches
Plain Diff
裁切录制
parent
19cf2a85
Hide whitespace changes
Inline
Side-by-side
Showing
4 changed files
with
153 additions
and
5 deletions
+153
-5
VIZ.Framework.Common/VIZ.Framework.Common.csproj
+2
-0
VIZ.Framework.Common/VideoControl/Recording/VideoControlRecording.cs
+121
-0
VIZ.Framework.Common/VideoControl/Recording/VideoControlRecordingFrame.cs
+24
-0
VIZ.Framework.Common/VideoControl/Stream/NDI/NDIStream.cs
+6
-5
No files found.
VIZ.Framework.Common/VIZ.Framework.Common.csproj
View file @
b6d7ca1a
...
@@ -186,6 +186,8 @@
...
@@ -186,6 +186,8 @@
<Compile Include="SharpDx\WIC\WicBitmapHelper.cs" />
<Compile Include="SharpDx\WIC\WicBitmapHelper.cs" />
<Compile Include="SharpDx\WPF\D2dControl.cs" />
<Compile Include="SharpDx\WPF\D2dControl.cs" />
<Compile Include="SharpDx\WPF\Dx11ImageSource.cs" />
<Compile Include="SharpDx\WPF\Dx11ImageSource.cs" />
<Compile Include="VideoControl\Recording\VideoControlRecordingFrame.cs" />
<Compile Include="VideoControl\Recording\VideoControlRecording.cs" />
<Compile Include="VideoControl\Sync\IVideoControlSync.cs" />
<Compile Include="VideoControl\Sync\IVideoControlSync.cs" />
<Compile Include="VideoControl\Sync\VideoControlSyncEventArgs.cs" />
<Compile Include="VideoControl\Sync\VideoControlSyncEventArgs.cs" />
<Compile Include="VideoControl\Sync\VideoControlSyncQueue.cs" />
<Compile Include="VideoControl\Sync\VideoControlSyncQueue.cs" />
...
...
VIZ.Framework.Common/VideoControl/Recording/VideoControlRecording.cs
0 → 100644
View file @
b6d7ca1a
using
OpenCvSharp
;
using
System
;
using
System.Collections.Concurrent
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
using
VIZ.Framework.Core
;
namespace
VIZ.Framework.Common
{
/// <summary>
/// 视频录制
/// </summary>
public
class
VideoControlRecording
:
ModelBase
{
#
region
MaxFrameCount
--
最大帧数
private
int
maxFrameCount
;
/// <summary>
/// 最大帧数
/// </summary>
public
int
MaxFrameCount
{
get
{
return
maxFrameCount
;
}
set
{
maxFrameCount
=
value
;
this
.
RaisePropertyChanged
(
nameof
(
MaxFrameCount
));
}
}
#
endregion
/// <summary>
/// 是否正在保存
/// </summary>
public
bool
IsSaving
{
get
;
protected
set
;
}
/// <summary>
/// 录制帧队列
/// </summary>
public
ConcurrentQueue
<
VideoControlRecordingFrame
>
RecordingFrameQueue
{
get
;
private
set
;
}
=
new
ConcurrentQueue
<
VideoControlRecordingFrame
>();
/// <summary>
/// 添加视频帧
/// </summary>
/// <param name="frame">视频帧</param>
public
void
Append
(
IVideoFrame
frame
,
object
data
)
{
if
(
this
.
IsSaving
)
return
;
VideoControlRecordingFrame
recording
=
new
VideoControlRecordingFrame
();
OpenCVStreeamVideoFrame
openCv
=
new
OpenCVStreeamVideoFrame
();
openCv
.
Width
=
frame
.
Width
;
openCv
.
Height
=
frame
.
Height
;
openCv
.
TimeStamp
=
frame
.
TimeStamp
;
openCv
.
DataStream
=
new
SharpDX
.
DataStream
(
frame
.
Length
,
true
,
true
);
unsafe
{
Buffer
.
MemoryCopy
(
frame
.
DataStream
.
DataPointer
.
ToPointer
(),
openCv
.
DataStream
.
DataPointer
.
ToPointer
(),
frame
.
Length
,
frame
.
Length
);
}
recording
.
VideoFrame
=
openCv
;
recording
.
DataFrame
=
data
;
if
(
this
.
RecordingFrameQueue
.
Count
>
this
.
maxFrameCount
)
{
this
.
RecordingFrameQueue
.
TryDequeue
(
out
VideoControlRecordingFrame
_
);
}
this
.
RecordingFrameQueue
.
Enqueue
(
recording
);
}
/// <summary>
/// 保存视频
/// </summary>
/// <param name="path">视频文件路径</param>
public
void
Save
(
string
path
,
int
fps
,
int
width
,
int
height
)
{
this
.
IsSaving
=
true
;
using
(
VideoWriter
writer
=
new
VideoWriter
(
path
,
FourCC
.
MJPG
,
fps
,
new
OpenCvSharp
.
Size
(
width
,
height
)))
{
while
(
this
.
RecordingFrameQueue
.
Count
>
0
)
{
if
(!
this
.
RecordingFrameQueue
.
TryDequeue
(
out
VideoControlRecordingFrame
recording
))
{
Task
.
Delay
(
10
).
Wait
();
continue
;
}
Mat
mat
=
this
.
Packaging
(
recording
);
writer
.
Write
(
mat
);
mat
.
Dispose
();
recording
.
VideoFrame
.
Dispose
();
}
}
this
.
IsSaving
=
false
;
}
/// <summary>
/// 录制包装
/// </summary>
/// <param name="recordingFrame">录制帧</param>
/// <returns>Mat数据</returns>
private
Mat
Packaging
(
VideoControlRecordingFrame
recordingFrame
)
{
Mat
mat
=
new
Mat
(
recordingFrame
.
VideoFrame
.
Height
,
recordingFrame
.
VideoFrame
.
Width
,
MatType
.
CV_8UC4
,
recordingFrame
.
VideoFrame
.
DataStream
.
DataPointer
);
Mat
dst
=
new
Mat
();
Cv2
.
CvtColor
(
mat
,
dst
,
ColorConversionCodes
.
BGRA2BGR
);
mat
.
Dispose
();
return
dst
;
}
}
}
VIZ.Framework.Common/VideoControl/Recording/VideoControlRecordingFrame.cs
0 → 100644
View file @
b6d7ca1a
using
System
;
using
System.Collections.Generic
;
using
System.Linq
;
using
System.Text
;
using
System.Threading.Tasks
;
namespace
VIZ.Framework.Common
{
/// <summary>
/// 视频录制帧
/// </summary>
public
class
VideoControlRecordingFrame
{
/// <summary>
/// 视频帧
/// </summary>
public
IVideoFrame
VideoFrame
{
get
;
set
;
}
/// <summary>
/// 数据帧
/// </summary>
public
object
DataFrame
{
get
;
set
;
}
}
}
VIZ.Framework.Common/VideoControl/Stream/NDI/NDIStream.cs
View file @
b6d7ca1a
...
@@ -187,11 +187,6 @@ namespace VIZ.Framework.Common
...
@@ -187,11 +187,6 @@ namespace VIZ.Framework.Common
info
=
this
.
StreamInfos
.
FirstOrDefault
(
p
=>
p
.
FullName
==
remoteSenderName
);
info
=
this
.
StreamInfos
.
FirstOrDefault
(
p
=>
p
.
FullName
==
remoteSenderName
);
}
}
if
(
info
==
null
)
{
return
false
;
}
// -------------------------------------------------------------------------------
// -------------------------------------------------------------------------------
// 释放
// 释放
...
@@ -214,6 +209,12 @@ namespace VIZ.Framework.Common
...
@@ -214,6 +209,12 @@ namespace VIZ.Framework.Common
// 设置NDI发送者名称
// 设置NDI发送者名称
this
.
RemoteSenderName
=
remoteSenderName
;
this
.
RemoteSenderName
=
remoteSenderName
;
if
(
info
==
null
)
{
this
.
CurrentRemoteSenderSource
=
null
;
return
true
;
}
// 设置当前NDI发送源
// 设置当前NDI发送源
this
.
CurrentRemoteSenderSource
=
info
.
Source
;
this
.
CurrentRemoteSenderSource
=
info
.
Source
;
...
...
Write
Preview
Markdown
is supported
0%
Try again
or
attach a new file
Attach a file
Cancel
You are about to add
0
people
to the discussion. Proceed with caution.
Finish editing this message first!
Cancel
Please
register
or
sign in
to comment