Class MP3EncoderBlock
- Assembly
- VisioForge.Core.dll
Audio encoder block that compresses raw audio into MP3 (MPEG-1 Audio Layer III) format. MP3 is one of the most widely supported audio formats, offering good compression ratios while maintaining acceptable audio quality. This block uses the LAME encoder for high-quality MP3 encoding with configurable bitrate settings. It supports constant bitrate (CBR) and variable bitrate (VBR) encoding modes, with bitrates ranging from 32 to 320 kbps. The encoder accepts raw PCM audio input and produces compressed MP3 audio output suitable for streaming, storage, or further processing. Common use cases include creating audio files, streaming audio content, and reducing audio bandwidth requirements. The block optionally adds an MP3 parser for streaming scenarios like RTMP to YouTube or Facebook. Implements the VisioForge.Core.MediaBlocks.MediaBlock. Implements the VisioForge.Core.MediaBlocks.IMediaBlockInternals. Implements the IDisposable.
public class MP3EncoderBlock : MediaBlock, IMediaBlock, IDisposable, IMediaBlockInternalsInheritance
Implements
Inherited Members
Extension Methods
Constructors
MP3EncoderBlock(MP3EncoderSettings, bool)
Initializes a new instance of the VisioForge.Core.MediaBlocks.AudioEncoders.MP3EncoderBlock class with specified settings. Creates an MP3 encoder that will compress audio according to the provided configuration.
public MP3EncoderBlock(MP3EncoderSettings settings, bool addParser = false)Parameters
settingsMP3EncoderSettings-
The MP3 encoder settings including bitrate and quality parameters.
addParserbool-
If set to
true, adds an MP3 parser after encoding. This is required for RTMP streaming to services like YouTube and Facebook to ensure proper stream formatting.
Properties
Input
Gets the single audio input pad for this encoder block.
public override MediaBlockPad Input { get; }Property Value
Inputs
Gets all input pads. This block has a single audio input.
public override MediaBlockPad[] Inputs { get; }Property Value
Output
Gets the single audio output pad for this encoder block.
public override MediaBlockPad Output { get; }Property Value
Outputs
Gets all output pads. This block has a single audio output.
public override MediaBlockPad[] Outputs { get; }Property Value
Settings
Gets or sets the MP3 encoder settings including bitrate, quality, and encoding mode. These settings control the compression quality and output file size.
public MP3EncoderSettings Settings { get; set; }Property Value
Type
Gets the block type identifier for this MP3 encoder.
public override MediaBlockType Type { get; }Property Value
Methods
Build()
Builds and initializes the MP3 encoder within the pipeline. Creates the LAME MP3 encoder element with the specified settings and optionally adds an MP3 parser for streaming compatibility.
public override bool Build()Returns
- bool
-
trueif the encoder was successfully built and configured;falseif an error occurred.
CleanUp()
Releases all internal resources and disposes of the MP3 encoder element. Called during disposal to ensure proper cleanup of native GStreamer resources.
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 for the MP3 encoder.
public BaseElement GetCore()Returns
- BaseElement
-
The MP3Encoder element that performs the audio compression.
GetElement()
Gets the underlying GStreamer element for this MP3 encoder.
public Element GetElement()Returns
- Element
-
The GStreamer lamemp3enc element that performs MP3 encoding.
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.
IMediaBlockInternals.SetContext(MediaBlocksPipeline)
Sets the pipeline context for this MP3 encoder, providing access to shared resources. This method is called internally during pipeline construction.
void IMediaBlockInternals.SetContext(MediaBlocksPipeline pipeline)Parameters
pipelineMediaBlocksPipeline-
The MediaBlocksPipeline that owns this encoder block.