Class ChromaKeyBlock
- Assembly
- VisioForge.Core.dll
ChromaKey video effect block for professional green screen compositing and color keying. This block provides advanced chroma key functionality for removing specific colors from video content and compositing foreground subjects onto different backgrounds. Features sophisticated color selection algorithms, edge refinement, spill suppression, and alpha channel generation for seamless compositing. Supports multiple color spaces, fine-tuned sensitivity controls, noise reduction, and edge smoothing for professional-quality results. Essential for virtual production, broadcast graphics, video conferencing backgrounds, and creative content creation requiring precise color-based video compositing. Implements the VisioForge.Core.MediaBlocks.MediaBlock. Implements the VisioForge.Core.MediaBlocks.IMediaBlockInternals. Implements the IDisposable.
public class ChromaKeyBlock : MediaBlock, IMediaBlock, IDisposable, IMediaBlockInternalsInheritance
Implements
Inherited Members
Extension Methods
Constructors
ChromaKeyBlock(ChromaKeySettingsX)
Initializes a new instance of the VisioForge.Core.MediaBlocks.VideoProcessing.ChromaKeyBlock class with specified chroma key settings for color-based video compositing.
public ChromaKeyBlock(ChromaKeySettingsX settings)Parameters
settingsChromaKeySettingsX-
The chroma key configuration settings for color selection and compositing parameters.
Properties
BackgroundInput
Gets the background input pad.
public MediaBlockPad BackgroundInput { get; }Property Value
ChromaInput
Gets the chroma input pad.
public MediaBlockPad ChromaInput { get; }Property Value
Input
Gets the input (background input by default).
public override MediaBlockPad Input { get; }Property Value
Inputs
Gets the inputs.
public override MediaBlockPad[] Inputs { get; }Property Value
Output
Gets the output.
public override MediaBlockPad Output { get; }Property Value
Outputs
Gets the outputs.
public override MediaBlockPad[] Outputs { get; }Property Value
Settings
Gets or sets the chroma key settings. Contains comprehensive parameters for controlling color selection, sensitivity thresholds, edge refinement, spill suppression, and compositing quality.
public ChromaKeySettingsX Settings { get; set; }Property Value
Type
Gets the type.
public override MediaBlockType Type { get; }Property Value
Methods
Build()
Constructs and initializes the chroma key filter and its associated GStreamer elements. This method creates the filter with the specified settings, establishes background and foreground input pads, and prepares the block for professional color-based video compositing with advanced keying algorithms.
public override bool Build()Returns
- bool
-
trueif the filter was successfully built and configured;falseif initialization failed.
CleanUp()
Releases all resources and performs cleanup operations for this chroma key block. This method disposes of the GStreamer elements and resets the build state.
public void CleanUp()Dispose(bool)
Releases unmanaged and - optionally - managed resources.
protected override void Dispose(bool disposing)Parameters
disposingbool-
trueto release both managed and unmanaged resources;falseto release only unmanaged resources.
GetCore()
Gets the core BaseElement wrapper that provides additional functionality around the GStreamer chroma key filter element.
public BaseElement GetCore()Returns
- BaseElement
-
The BaseElement wrapper instance that encapsulates the GStreamer chroma key filter.
GetElement()
Gets the underlying GStreamer element that performs the chroma key compositing.
public Element GetElement()Returns
- Element
-
The GStreamer Element instance representing the chroma key filter.
IsAvailable()
Determines whether this media block is available. Correct NuGet SDK redist should be included into your project.
public static bool IsAvailable()Returns
- bool
-
trueif this media block is available; otherwise,false.
SetAlpha(double)
Sets the alpha channel transparency value for the composited result. Controls the overall opacity of the keyed foreground when composited onto the background.
public void SetAlpha(double alpha)Parameters
alphadouble-
The alpha transparency value (0.0 = fully transparent, 1.0 = fully opaque).
SetBlackSensitivity(uint)
Sets the black level sensitivity for edge refinement in chroma keying. Controls how dark pixels near the key color edges are processed, helping to remove dark fringes and improve edge quality in shadowed areas.
public void SetBlackSensitivity(uint blackSensitivity)Parameters
blackSensitivityuint-
The black sensitivity threshold (0 = no dark edge processing, 255 = maximum dark edge removal).
SetChromaColor(ChromaKeyColor)
Sets the chroma color to be removed from the foreground video. Updates the target color for the keying operation, allowing switching between common chroma colors like green, blue, or custom color selections.
public void SetChromaColor(ChromaKeyColor color)Parameters
colorChromaKeyColor-
The chroma color preset to key out from the foreground video.
SetCustomColor(SKColor)
Sets a custom color for chroma keying when using the Custom color option. Allows precise specification of any RGB color value as the key color, useful for non-standard backgrounds or specific color matching requirements.
public void SetCustomColor(SKColor customColor)Parameters
customColorSKColor-
The custom RGB color to remove from the foreground video.
SetEdgeSmoothing(double) Deprecated
Use SetBlackSensitivity and SetWhiteSensitivity instead for more precise control.
Sets the edge smoothing level for chroma keying (deprecated method). This method provides backward compatibility but offers less precise control than the separate black and white sensitivity settings.
[Obsolete("Use SetBlackSensitivity and SetWhiteSensitivity instead for more precise control.")]
public void SetEdgeSmoothing(double edgeSmoothing)Parameters
edgeSmoothingdouble-
The edge smoothing intensity (0.0 = no smoothing, 1.0 = maximum smoothing).
SetNoiseLevel(double)
Sets the noise reduction level for chroma key edge refinement. Helps clean up rough edges and reduce artifacts caused by compression or sensor noise in the source video, creating smoother keying results.
public void SetNoiseLevel(double noiseLevel)Parameters
noiseLeveldouble-
The noise reduction intensity (0.0 = no noise reduction, 64.0 = maximum smoothing).
SetPreferPassthrough(bool)
Sets the prefer passthrough optimization flag for performance enhancement. When enabled, the filter will pass video through unchanged when the effect is effectively disabled, reducing processing overhead in bypass scenarios.
public void SetPreferPassthrough(bool preferPassthrough)Parameters
preferPassthroughbool-
Whether to enable passthrough optimization for better performance.
SetSensitivity(double)
Sets the sensitivity threshold for chroma key color detection. Higher values increase the range of colors considered similar to the key color, useful for handling uneven lighting or color variations in the background.
public void SetSensitivity(double sensitivity)Parameters
sensitivitydouble-
The sensitivity value in degrees (0.0 = exact match only, 180.0 = maximum tolerance).
SetWhiteSensitivity(uint)
Sets the white level sensitivity for edge refinement in chroma keying. Controls how bright pixels near the key color edges are processed, helping to remove light halos and improve edge quality in highly lit areas.
public void SetWhiteSensitivity(uint whiteSensitivity)Parameters
whiteSensitivityuint-
The white sensitivity threshold (0 = no bright edge processing, 255 = maximum bright edge removal).
UpdateSettings(ChromaKeySettingsX)
Updates the chroma key settings dynamically during runtime. Allows real-time adjustment of all chroma key parameters including color selection, sensitivity, edge refinement, and compositing quality without rebuilding the pipeline.
public void UpdateSettings(ChromaKeySettingsX settings)Parameters
settingsChromaKeySettingsX-
The new chroma key configuration settings to apply.
IMediaBlockInternals.SetContext(MediaBlocksPipeline)
Associates this chroma key 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
pipelineMediaBlocksPipeline-
The MediaBlocksPipeline instance that will manage this block.