Table of Contents

Class VideoSampleGrabberBlock

Namespace
VisioForge.Core.MediaBlocks.VideoProcessing
Assembly
VisioForge.Core.dll

Video sample grabber block for frame capture and analysis during playback. This block provides real-time access to video frames as they pass through the pipeline, enabling frame extraction, analysis, processing, and snapshot capabilities. Features multiple output formats (buffer, SKBitmap, System.Drawing.Bitmap), configurable pixel formats, frame caching for snapshots, and event-based frame delivery. Essential for video analysis applications, thumbnail generation, motion detection, computer vision integration, real-time monitoring, and any scenario requiring access to raw video data. Implements the VisioForge.Core.MediaBlocks.MediaBlock. Implements the VisioForge.Core.MediaBlocks.IMediaBlockInternals. Implements the IDisposable.

public class VideoSampleGrabberBlock : MediaBlock, IMediaBlock, IDisposable, IMediaBlockInternals

Inheritance

Implements

Inherited Members

Extension Methods

Constructors

VideoSampleGrabberBlock(VideoFormatX, bool, bool)

Initializes a new instance of the VisioForge.Core.MediaBlocks.VideoProcessing.VideoSampleGrabberBlock class with specified capture format and rendering options.

public VideoSampleGrabberBlock(VideoFormatX format = VideoFormatX.RGBA, bool addNullRenderer = false, bool nullRendererSync = false)

Parameters

format VideoFormatX

The pixel format for captured frames (default: RGBA).

addNullRenderer bool

if set to true add null renderer for capture-only scenarios.

nullRendererSync bool

if set to true null renderer synchronizes to pipeline clock.

Fields

TAG

Logging tag used to identify log messages from this video sample grabber block.

protected const string TAG = "VideoSampleGrabberBlock"

Field Value

string

Properties

Input

Gets the input.

public override MediaBlockPad Input { get; }

Property Value

MediaBlockPad

Inputs

Gets the inputs.

public override MediaBlockPad[] Inputs { get; }

Property Value

MediaBlockPad[]

Output

Gets the output.

public override MediaBlockPad Output { get; }

Property Value

MediaBlockPad

Outputs

Gets the outputs.

public override MediaBlockPad[] Outputs { get; }

Property Value

MediaBlockPad[]

SaveLastFrame

Gets or sets a value indicating whether to save the last frame. You can use it to take a snapshot with GetFrame() method. When enabled, maintains a cache of the most recent frame for on-demand retrieval.

public bool SaveLastFrame { get; set; }

Property Value

bool

Type

Gets the type.

public override MediaBlockType Type { get; }

Property Value

MediaBlockType

Methods

Build()

Constructs and initializes the video sample grabber and its associated elements. This method creates the grabber with the specified format, establishes event handlers, configures pads, and prepares the block for frame capture and analysis.

public override bool Build()

Returns

bool

true if the grabber was successfully built and configured; false if initialization failed.

CleanUp()

Releases all resources and performs cleanup operations for this sample grabber block. This method disposes of the grabber elements and resets the build state.

public void CleanUp()

Dispose(bool)

Releases unmanaged and - optionally - managed resources.

protected override void Dispose(bool disposing)

Parameters

disposing bool

true to release both managed and unmanaged resources; false to release only unmanaged resources.

GetCore()

Gets the core BaseElement wrapper that provides additional functionality around the video sample grabber element.

public BaseElement GetCore()

Returns

BaseElement

The BaseElement wrapper instance that encapsulates the sample grabber.

GetElement()

Gets the underlying GStreamer element that performs the frame capture.

public Element GetElement()

Returns

Element

The GStreamer Element instance representing the sample grabber.

GetLastFrame()

Gets the last captured video frame as raw data. Requires SaveLastFrame to be enabled before capture.

public VideoFrameX GetLastFrame()

Returns

VideoFrameX

The last captured VideoFrameX object, or null if not available.

GetLastFrameAsSKBitmap()

Gets the last captured frame as a SkiaSharp.SKBitmap. Requires SaveLastFrame to be enabled and BGRA/RGBA format.

public SKBitmap GetLastFrameAsSKBitmap()

Returns

SKBitmap

The last captured frame as SKBitmap, or null if not available.

IsAvailable()

Determines whether this media block is available. Correct NuGet SDK redist should be included into your project.

public static bool IsAvailable()

Returns

bool

true if this media block is available; otherwise, false.

IMediaBlockInternals.SetContext(MediaBlocksPipeline)

Associates this sample grabber block with a pipeline and initializes its internal context. This method is called internally when the block is added to a pipeline.

void IMediaBlockInternals.SetContext(MediaBlocksPipeline pipeline)

Parameters

pipeline MediaBlocksPipeline

The MediaBlocksPipeline instance that will manage this block.

OnVideoFrameBuffer

This event occurs whenever each new video frame is received. Provides raw frame data as a buffer for custom processing.

public event EventHandler<VideoFrameXBufferEventArgs> OnVideoFrameBuffer

Event Type

EventHandler<VideoFrameXBufferEventArgs>

OnVideoFrameSKBitmap

This event occurs whenever each new video frame is received (SkiaSharp Bitmap). Provides frames as SKBitmap objects for cross-platform image processing.

public event EventHandler<VideoFrameSKBitmapEventArgs> OnVideoFrameSKBitmap

Event Type

EventHandler<VideoFrameSKBitmapEventArgs>

See Also