-
Notifications
You must be signed in to change notification settings - Fork 9
Expand file tree
/
Copy pathVideoFrame.cs
More file actions
83 lines (72 loc) · 2.74 KB
/
VideoFrame.cs
File metadata and controls
83 lines (72 loc) · 2.74 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
// Copyright (c) TensorStack. All rights reserved.
// Licensed under the Apache 2.0 License.
using System;
using TensorStack.Common.Tensor;
namespace TensorStack.Common.Video
{
/// <summary>
/// VideoFrame for streaming functions.
/// </summary>
public class VideoFrame
{
/// <summary>
/// Initializes a new instance of the <see cref="VideoFrame"/> class.
/// </summary>
/// <param name="frame">The frame.</param>
/// <param name="sourceFrameRate">The source frame rate.</param>
public VideoFrame(int index,ImageTensor frame, float sourceFrameRate, ImageTensor auxFrame = default)
{
Index = index;
Frame = frame;
AuxFrame = auxFrame;
SourceFrameRate = sourceFrameRate;
ThrowIfInvalid();
}
/// <summary>
/// Initializes a new instance of the <see cref="VideoFrame"/> class.
/// </summary>
/// <param name="frame">The frame.</param>
/// <param name="sourceFrameRate">The source frame rate.</param>
public VideoFrame(int index, Tensor<float> frame, float sourceFrameRate)
: this(index, new ImageTensor(frame), sourceFrameRate) { }
/// <summary>
/// Gets the index.
/// </summary>
public int Index { get; }
/// <summary>
/// Gets the frame.
/// </summary>
public ImageTensor Frame { get; }
/// <summary>
/// Gets the source frame rate.
/// </summary>
public float SourceFrameRate { get; }
/// <summary>
/// Gets the channel count.
/// </summary>
public int Channels => Frame.Dimensions[1];
/// <summary>
/// Gets the frame height.
/// </summary>
public int Height => Frame.Dimensions[2];
/// <summary>
/// Gets the frame width.
/// </summary>
public int Width => Frame.Dimensions[3];
/// <summary>
/// Gets or sets the control frame.
/// </summary>
public ImageTensor AuxFrame { get; set; }
/// <summary>
/// Throws if VideoFrame is invalid.
/// </summary>
/// <exception cref="System.ArgumentNullException">Frame</exception>
protected void ThrowIfInvalid()
{
ArgumentNullException.ThrowIfNull(Frame, nameof(Frame));
ArgumentOutOfRangeException.ThrowIfLessThanOrEqual(SourceFrameRate, 0, nameof(SourceFrameRate));
if (AuxFrame != null && (Frame.Width != AuxFrame.Width || Frame.Height != AuxFrame.Height))
throw new ArgumentException($"Frame({Frame.Width}x{Frame.Height}) and AuxFrame({AuxFrame.Width}x{AuxFrame.Height}) must have same Width/Height");
}
}
}