Struct VideoFrame
- Namespace
- VisioForge.Core.Types
- Assembly
- VisioForge.Core.dll
Represents a single frame of video data, including its raw data, format information, and timing. This struct provides a managed way to work with video frames, abstracting some of the complexities of unmanaged memory.
public struct VideoFrameInherited Members
Extension Methods
Remarks
The VideoFrame struct holds a pointer to the raw pixel data, along with its dimensions, stride, color space, and timing information.
It includes methods for memory management (VisioForge.Core.Types.VideoFrame.Alloc, VisioForge.Core.Types.VideoFrame.Free) and conversions to other frame types like VisioForge.Core.Types.RAWVideoFrame and VisioForge.Core.Types.RAWImage.
Unlike RAWVideoFrame which uses millisecond timestamps, VideoFrame uses TimeSpan for timing, making it more convenient for C# code.
The Info field contains all format metadata including dimensions, color space, stride, and frame rate.
Memory management is manual - Alloc() allocates unmanaged memory which must be freed with Free() to prevent leaks.
The struct provides multiple conversion methods: ToRAWVideoFrame for interop, ToArray for byte array access, ToRAWImage for image processing.
IsEmpty() checks if the Data pointer is null, useful for validating frame availability.
CreateAndAlloc is a static factory method that combines construction and allocation in one call.
This type is central to video processing workflows in the framework, bridging managed and unmanaged code.
Fields
Data
A pointer to the unmanaged memory buffer containing the raw video data.
public nint DataField Value
DataSize
The total size of the video data buffer in bytes.
public int DataSizeField Value
Duration
The duration of the video frame.
public TimeSpan DurationField Value
Info
Contains detailed information about the raw video format, such as width, height, color space, and stride.
public RAWBaseVideoInfo InfoField Value
Timestamp
The presentation timestamp of the video frame.
public TimeSpan TimestampField Value
Methods
Alloc()
Allocates unmanaged memory for the video data buffer based on the VisioForge.Core.Types.RAWBaseVideoInfo.Stride and VisioForge.Core.Types.RAWBaseVideoInfo.Height. The VisioForge.Core.Types.VideoFrame.DataSize field is updated accordingly.
public void Alloc()Remarks
This method should be called before writing pixel data to the VisioForge.Core.Types.VideoFrame.Data pointer. It is crucial to call VisioForge.Core.Types.VideoFrame.Free when the allocated memory is no longer needed.
Alloc(int)
Allocates unmanaged memory for the video data buffer with a specified size.
public void Alloc(int size)Parameters
sizeint-
The number of bytes to allocate for the video data.
Remarks
This overload allows for direct control over the allocated buffer size, which can be useful for custom formats.
Clone()
Creates a deep copy of the current VisioForge.Core.Types.VideoFrame instance. This involves allocating new memory for the data and copying all frame properties.
public VideoFrame Clone()Returns
- VideoFrame
-
A new VisioForge.Core.Types.VideoFrame instance that is a clone of the current one.
CreateAndAlloc(int, int, int, RAWVideoColorSpace)
Creates a new VisioForge.Core.Types.VideoFrame instance and allocates its internal data buffer.
public static VideoFrame CreateAndAlloc(int width, int height, int stride, RAWVideoColorSpace colorspace)Parameters
widthint-
The width of the video frame.
heightint-
The height of the video frame.
strideint-
The stride (bytes per row) of the video frame.
colorspaceRAWVideoColorSpace-
The color space of the video frame.
Returns
- VideoFrame
-
A new VisioForge.Core.Types.VideoFrame instance with allocated memory.
CreateNoAlloc(int, int, int, RAWVideoColorSpace)
Creates a new VisioForge.Core.Types.VideoFrame instance without allocating its internal data buffer. The VisioForge.Core.Types.VideoFrame.Data pointer will be Zero.
public static VideoFrame CreateNoAlloc(int width, int height, int stride, RAWVideoColorSpace colorspace)Parameters
widthint-
The width of the video frame.
heightint-
The height of the video frame.
strideint-
The stride (bytes per row) of the video frame.
colorspaceRAWVideoColorSpace-
The color space of the video frame.
Returns
- VideoFrame
-
A new VisioForge.Core.Types.VideoFrame instance without allocated memory.
Free()
Frees the unmanaged memory previously allocated for the video data buffer.
public void Free()Remarks
This method should always be called to prevent memory leaks when the VideoFrame instance is no longer needed,
especially if VisioForge.Core.Types.VideoFrame.Alloc or VisioForge.Core.Types.VideoFrame.Alloc(System.Int32) was used.
IsEmpty()
Determines whether this video frame instance is empty (i.e., its VisioForge.Core.Types.VideoFrame.Data pointer is Zero).
public bool IsEmpty()Returns
- bool
-
trueif this instance is empty; otherwise,false.
ToArray()
Copies the raw video data from the unmanaged memory buffer into a new managed byte array.
public byte[] ToArray()Returns
- byte[]
-
A new byte array containing the video data.
ToRAWImage()
Converts the current VisioForge.Core.Types.VideoFrame instance into a VisioForge.Core.Types.RAWImage struct. This conversion is useful for treating the video frame as a raw image for processing or saving.
public RAWImage ToRAWImage()Returns
- RAWImage
-
A new VisioForge.Core.Types.RAWImage instance populated with data from the current frame.
ToRAWVideoFrame()
Converts the current VisioForge.Core.Types.VideoFrame instance into a VisioForge.Core.Types.RAWVideoFrame struct. This conversion is useful for passing video frame data to native components that expect the VisioForge.Core.Types.RAWVideoFrame structure.
public RAWVideoFrame ToRAWVideoFrame()Returns
- RAWVideoFrame
-
A new VisioForge.Core.Types.RAWVideoFrame instance populated with data from the current frame.
ToVideoFrameX(bool)
Converts the current VisioForge.Core.Types.VideoFrame instance into a VisioForge.Core.Types.X.VideoFrameX object. This conversion is useful for integrating with the newer MediaBlocks framework.
public VideoFrameX ToVideoFrameX(bool copyData)Parameters
copyDatabool-
If set to
true, a new memory buffer is allocated for VisioForge.Core.Types.X.VideoFrameX.Data and the data is copied; otherwise, the VisioForge.Core.Types.VideoFrame.Data pointer is directly assigned (use with caution).
Returns
- VideoFrameX
-
A new VisioForge.Core.Types.X.VideoFrameX instance populated with data from the current frame.