Class MP4SinkBlock
- Namespace
- VisioForge.Core.MediaBlocks.Sinks
- Assembly
- VisioForge.Core.dll
MP4 (MPEG-4 Part 14) sink block for writing media streams to MP4 container files.
public class MP4SinkBlock : MediaBlock, IMediaBlock, IDisposable, IMediaBlockInternals, IMediaBlockDynamicInputsInheritance
Implements
Inherited Members
Extension Methods
Remarks
The MP4 sink block provides comprehensive support for creating MP4 files, the industry-standard container format for digital multimedia. MP4 files can contain video, audio, subtitles, and metadata tracks, making it ideal for a wide range of applications from video recording to streaming content preparation.
Key Features:
- Support for multiple video and audio tracks
- Compatible with H.264/AVC, H.265/HEVC, AAC, MP3, and other codecs
- Fast-start support for progressive download/streaming
- Fragmented MP4 support for live streaming scenarios
- Metadata and chapter support
- Mux-only mode for remuxing pre-encoded streams
- Split recording capability for file size management
Typical Use Cases:
- Recording camera feeds to standard video files
- Creating content for web streaming platforms
- Producing files for mobile device playback
- Archiving video content in a universally compatible format
- Preparing content for video editing workflows
Technical Specifications:
- Compliant with ISO/IEC 14496-14 standard
- Maximum file size: Limited by filesystem (typically 4GB on FAT32)
- Supports both constant and variable bitrate encoding
- Compatible with all major media players and editing software
Constructors
MP4SinkBlock(MP4SinkSettings)
Initializes a new instance of the VisioForge.Core.MediaBlocks.Sinks.MP4SinkBlock class with the specified settings.
public MP4SinkBlock(MP4SinkSettings settings)Parameters
settingsMP4SinkSettings-
The VisioForge.Core.Types.X.Sinks.MP4SinkSettings object containing configuration for the MP4 output. When MuxOnly is true in settings, an output pad will be created for passing the muxed stream to downstream elements instead of writing directly to a file.
MP4SinkBlock(string)
Initializes a new instance of the VisioForge.Core.MediaBlocks.Sinks.MP4SinkBlock class with a simple filename.
public MP4SinkBlock(string filename)Parameters
filenamestring-
The path where the MP4 file will be written. The directory must exist and be writable. This constructor uses default MP4 settings suitable for most recording scenarios.
Properties
Input
Gets the first input pad from the collection of available inputs.
public override MediaBlockPad Input { get; }Property Value
Inputs
Gets all available input pads for connecting multiple media streams.
public override MediaBlockPad[] Inputs { get; }Property Value
Output
Gets the output pad for this sink block.
public override MediaBlockPad Output { get; }Property Value
Outputs
Gets all output pads for this sink block.
public override MediaBlockPad[] Outputs { get; }Property Value
Settings
Gets or sets the MP4 sink configuration settings.
public MP4SinkSettings Settings { get; set; }Property Value
Type
Gets the media block type identifier for the MP4 sink.
public override MediaBlockType Type { get; }Property Value
Methods
Build()
Builds and initializes the MP4 sink pipeline components.
public override bool Build()Returns
- bool
-
trueif the sink was successfully built, all requested input pads were created, and output pad was configured (if in mux-only mode);falseif initialization failed or required pads couldn't be allocated.
Remarks
This method creates the underlying GStreamer MP4 muxer (qtmux) element and configures input pads for each media stream. For split sink configurations, it uses specialized pad templates. The method is idempotent and will return immediately if already built.
CleanUp()
Cleans up resources and resets the sink block to an unbuilt state.
public void CleanUp()Remarks
This method disposes of the underlying GStreamer MP4 muxer element and resets the build state. After cleanup, the block can be rebuilt with new settings if needed. Any ongoing file writing will be terminated.
CreateNewInput(MediaBlockPadMediaType)
Creates a new input pad for connecting a media stream of the specified type.
public MediaBlockPad CreateNewInput(MediaBlockPadMediaType mediaType)Parameters
mediaTypeMediaBlockPadMediaType-
The type of media stream to accept on this input pad. MP4 supports: VisioForge.Core.MediaBlocks.MediaBlockPadMediaType.Video for video streams, VisioForge.Core.MediaBlocks.MediaBlockPadMediaType.Audio for audio streams, and VisioForge.Core.MediaBlocks.MediaBlockPadMediaType.Subtitle for subtitle tracks (though GStreamer support may vary).
Returns
- MediaBlockPad
-
A new VisioForge.Core.MediaBlocks.MediaBlockPad configured for the specified media type, ready to be connected to an upstream media source or processing block.
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 GStreamer wrapper element for advanced pipeline integration.
public BaseElement GetCore()Returns
- BaseElement
-
The VisioForge.Core.GStreamer.Base.BaseElement wrapper providing access to the underlying GStreamer MP4 muxer element for advanced configuration and pipeline operations.
GetElement()
Gets the native GStreamer element for direct GStreamer API access.
public Element GetElement()Returns
- Element
-
The underlying Gst.Element representing the MP4 muxer (qtmux), allowing direct access to GStreamer properties and methods when needed.
GetFilenameOrURL()
Gets the output filename or URL where the MP4 file will be written.
public string GetFilenameOrURL()Returns
- string
-
The file path specified in the settings. For split recording scenarios, this returns the base filename template that will be used to generate individual segment filenames.
GetInput(MediaBlockPadMediaType)
Gets an existing input pad that matches the specified media type.
public MediaBlockPad GetInput(MediaBlockPadMediaType mediaType)Parameters
mediaTypeMediaBlockPadMediaType-
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
nullif no matching input pad exists. Use VisioForge.Core.MediaBlocks.Sinks.MP4SinkBlock.CreateNewInput(VisioForge.Core.MediaBlocks.MediaBlockPadMediaType) to create a new pad if needed.
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.
SetFilenameOrURL(string)
Sets the output filename or URL for the MP4 file.
public void SetFilenameOrURL(string value)Parameters
valuestring-
The file path where the MP4 file should be written. For standard recording, this should be a complete filename. For split recording, use a template with format specifiers (e.g., "video_%05d.mp4") to generate sequential filenames.
Remarks
This method updates both the settings and the underlying GStreamer element if the sink has already been built. Changing the filename during active recording is not recommended and may cause unexpected behavior.
IMediaBlockInternals.SetContext(MediaBlocksPipeline)
Sets the pipeline context for this media block.
void IMediaBlockInternals.SetContext(MediaBlocksPipeline pipeline)Parameters
pipelineMediaBlocksPipeline-
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.