Skip to main content

MP4 output

MP4 is the most popular video format available for all platforms. Typically, AAC is used to encode the audio stream, and H264 or HEVC codecs are used to encode the video stream.

Use MP4SinkSettings class to set the parameters.

Block info

Name: MP4SinkBlock.

Pin directionMedia typePins count
Input audioaudio/mpegone or more
audio/x-ac3
audio/x-alac
audio/x-opus
Input videovideo/mpegone or more
video/x-divx
video/x-h264
video/x-h265
video/x-av1
Input subtitletext/utf8one or more

The sample pipeline

UniversalSourceBlock:VideoOutput H264EncoderBlock MP4SinkBlock:VideoInput UniversalSourceBlock:AudioOutput AACEncoderBlock MP4SinkBlock:AudioInput

Sample code

var pipeline = new MediaBlocksPipeline(false);

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

var aacEncoderBlock = new AACEncoderBlock(new MFAACEncoderSettings() { Bitrate = 192 });
pipeline.Connect(fileSource.AudioOutput, aacEncoderBlock.Input);

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

var mp4SinkBlock = new MP4SinkBlock(new MP4SinkSettings("output.mp4"));
pipeline.Connect(h264EncoderBlock.Output, mp4SinkBlock.CreateNewInput(MediaBlockPadMediaType.Video));
pipeline.Connect(aacEncoderBlock.Output, mp4SinkBlock.CreateNewInput(MediaBlockPadMediaType.Audio));

await pipeline.StartAsync();

Platforms

Windows, macOS, Linux, iOS, Android.