Skip to main content

MP2 encoder

MP2 (MPEG-1 Audio Layer II): An older, lossy audio compression format that is less complex than MP3, commonly used in broadcasting and digital radio due to its robustness.

An MP2 encoder can be used to encode audio streams in formats like MPEG-TS or VOB.

Use the MP2EncoderSettings class to set the parameters.

Block info

Name: MP2EncoderBlock.

Pin directionMedia typePins count
InputS16LE1
Outputaudio/mpeg1

The sample pipeline

Sample code

var pipeline = new MediaBlocksPipeline();

var filename = "test.mp4";
var fileSource = new UniversalSourceBlock(await UniversalSourceSettings.CreateAsync(new Uri(filename)));

var audioEncoderBlock = new MP2EncoderBlock(new MP2EncoderSettings());
pipeline.Connect(fileSource.AudioOutput, audioEncoderBlock.Input);

var h264EncoderBlock = new H264EncoderBlock(new MFH264EncoderSettings());
pipeline.Connect(fileSource.VideoOutput, h264EncoderBlock.Input);

var tsSinkBlock = new MPEGTSSinkBlock(new MPEGTSSinkSettings(@"output.ts"));
pipeline.Connect(h264EncoderBlock.Output, tsSinkBlock.CreateNewInput(MediaBlockPadMediaType.Video));
pipeline.Connect(audioEncoderBlock.Output, tsSinkBlock.CreateNewInput(MediaBlockPadMediaType.Audio));

await pipeline.StartAsync();

Platforms

Windows, macOS, Linux, iOS, Android