Table of Contents

Class YouTubeSinkBlock

Namespace
VisioForge.Core.MediaBlocks.Sinks
Assembly
VisioForge.Core.dll

YouTube sink block for live streaming directly to YouTube Live platform.

public class YouTubeSinkBlock : MediaBlock, IMediaBlock, IDisposable, IMediaBlockInternals, IMediaBlockDynamicInputs

Inheritance

Implements

Inherited Members

Extension Methods

Remarks

The YouTube sink block provides specialized streaming capabilities optimized for YouTube's live streaming service. It handles the specific requirements of YouTube Live, including proper RTMP formatting, recommended encoding settings, and stream key management. This sink simplifies the process of broadcasting to YouTube without manually configuring generic RTMP parameters.

Key Features:

  • Direct integration with YouTube Live streaming
  • Automatic RTMP URL construction from stream key
  • Pre-configured for YouTube's recommended settings
  • Support for scheduled live events and instant streaming
  • Compatible with YouTube's Content ID system
  • Automatic reconnection on network interruptions

Typical Use Cases:

  • Live streaming gaming sessions
  • Broadcasting webinars and online events
  • 24/7 continuous streaming channels
  • Live podcasts and talk shows
  • Educational content and tutorials
  • Live product demonstrations

Technical Requirements:

  • Video codec: H.264 (required by YouTube)
  • Audio codec: AAC or MP3
  • Recommended bitrates: 2.5-4 Mbps for 720p, 4.5-9 Mbps for 1080p
  • Maximum resolution: 4K (3840x2160) at 60 fps
  • Keyframe interval: 2 seconds (required)
  • Valid YouTube stream key from YouTube Studio

Setup Requirements: To use this sink, you need to enable live streaming in your YouTube account and obtain a stream key from YouTube Studio. The sink will automatically construct the proper RTMP URL using YouTube's primary ingestion endpoint.

Constructors

YouTubeSinkBlock(YouTubeSinkSettings)

Initializes a new instance of the VisioForge.Core.MediaBlocks.Sinks.YouTubeSinkBlock class with the specified settings.

public YouTubeSinkBlock(YouTubeSinkSettings settings)

Parameters

settings YouTubeSinkSettings

The VisioForge.Core.Types.X.Sinks.YouTubeSinkSettings object containing the YouTube stream key and any additional streaming parameters. The stream key must be valid and obtained from YouTube Studio's live streaming section.

Properties

Input

Gets the first input pad from the collection of available inputs.

public override MediaBlockPad Input { get; }

Property Value

MediaBlockPad

Inputs

Gets all available input pads for connecting media streams.

public override MediaBlockPad[] Inputs { get; }

Property Value

MediaBlockPad[]

Output

Gets the output pad for this sink block.

public override MediaBlockPad Output { get; }

Property Value

MediaBlockPad

Outputs

Gets all output pads for this sink block.

public override MediaBlockPad[] Outputs { get; }

Property Value

MediaBlockPad[]

Settings

Gets or sets the YouTube sink configuration settings.

public YouTubeSinkSettings Settings { get; set; }

Property Value

YouTubeSinkSettings

Type

Gets the media block type identifier for the YouTube sink.

public override MediaBlockType Type { get; }

Property Value

MediaBlockType

Methods

Build()

Builds and initializes the YouTube sink pipeline components.

public override bool Build()

Returns

bool

true if the sink was successfully built and configured for YouTube streaming; false if initialization failed or the stream key is invalid.

Remarks

This method creates the underlying YouTube RTMP sink and configures it with YouTube's primary ingestion server. It sets up input pads for H.264 video and AAC audio streams according to YouTube's requirements.

CleanUp()

Cleans up resources and disconnects from YouTube Live servers.

public void CleanUp()

Remarks

This method properly terminates the stream to YouTube, disposes of the underlying RTMP connection, and resets the build state. YouTube will mark the stream as ended after disconnection.

CreateNewInput(MediaBlockPadMediaType)

Creates a new input pad for connecting a media stream of the specified type.

public MediaBlockPad CreateNewInput(MediaBlockPadMediaType mediaType)

Parameters

mediaType MediaBlockPadMediaType

The type of media stream to accept. YouTube Live requires: VisioForge.Core.MediaBlocks.MediaBlockPadMediaType.Video for H.264 encoded video and VisioForge.Core.MediaBlocks.MediaBlockPadMediaType.Audio for AAC or MP3 encoded audio.

Returns

MediaBlockPad

A new VisioForge.Core.MediaBlocks.MediaBlockPad configured for the specified media type. Ensure streams meet YouTube's encoding requirements before connecting.

Remarks

YouTube has strict requirements: H.264 video with 2-second keyframe interval, and AAC audio at 128 kbps or higher. Non-compliant streams may be rejected.

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 GStreamer wrapper element for advanced pipeline integration.

public BaseElement GetCore()

Returns

BaseElement

The VisioForge.Core.GStreamer.Base.BaseElement wrapper providing access to the underlying YouTube-optimized RTMP sink for advanced configuration.

GetElement()

Gets the native GStreamer element for direct GStreamer API access.

public Element GetElement()

Returns

Element

The underlying Gst.Element representing the YouTube RTMP sink, configured with YouTube's specific server endpoints and parameters.

GetFilenameOrURL()

Gets the YouTube stream key used for authentication.

public string GetFilenameOrURL()

Returns

string

The stream key configured in the settings. This is not a URL but rather the unique key provided by YouTube Studio for your live stream.

GetInput(MediaBlockPadMediaType)

Gets an existing input pad that matches the specified media type.

public MediaBlockPad GetInput(MediaBlockPadMediaType mediaType)

Parameters

mediaType MediaBlockPadMediaType

The media type to search for among existing input pads.

Returns

MediaBlockPad

The first VisioForge.Core.MediaBlocks.MediaBlockPad that matches the specified media type, or null if no matching input pad exists.

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.

SetFilenameOrURL(string)

Sets the YouTube stream key (not implemented).

public void SetFilenameOrURL(string value)

Parameters

value string

The stream key value (not used).

Exceptions

NotImplementedException

This method is not implemented. Configure the stream key through the settings object passed to the constructor instead.

IMediaBlockInternals.SetContext(MediaBlocksPipeline)

Sets the pipeline context for this media block.

void IMediaBlockInternals.SetContext(MediaBlocksPipeline pipeline)

Parameters

pipeline MediaBlocksPipeline

The VisioForge.Core.MediaBlocks.MediaBlocksPipeline that owns this sink block, providing access to the pipeline context and logging facilities.

Remarks

This method is called internally by the pipeline during initialization and should not be called directly by user code.

See Also