Skip to main content

MKV output

The MKV format can be used as an alternative to the MP4 format, which has more options for supporting video and audio codecs.

Use the MKVSinkSettings class to set the parameters.

Block info

Name: MKVSinkBlock.

Pin directionMedia typePins count
Input audioaudio/mpegone or more
audio/x-ac3
audio/x-eac3
audio/x-dts
audio/x-vorbis
audio/x-flac
audio/x-opus
audio/x-speex
U8, S16BE, S16LE
S24BE, S24LE
S32BE, S32LE
F32LE, F64LE
audio/x-wma
audio/x-alaw
audio/x-mulaw
audio/x-adpcm
audio/G722
audio/G726
Input videoYUY2, I420, YV12, UYVY, AYUV, GRAY8, BGR, RGBone or more
video/mpeg
video/x-h264
video/x-h265
video/x-divx
video/x-huffyuv
video/x-dv
video/x-h263
video/x-msmpeg
image/jpeg:
video/x-theora
video/x-dirac
video/x-vp8
video/x-vp9
video/x-prores
video/x-wmv
video/x-av1
video/x-ffv
Input subtitletext/utf8one or more
subtitle/x-kate
application/x-ssa
application/x-ass
application/x-usf
subpicture/x-dvd

The sample pipeline

Sample code

var pipeline = new MediaBlocksPipeline();

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 mkvSinkBlock = new MKVSinkBlock(new MKVSinkSettings(@"output.mkv"));
pipeline.Connect(h264EncoderBlock.Output, mkvSinkBlock.CreateNewInput(MediaBlockPadMediaType.Video));
pipeline.Connect(aacEncoderBlock.Output, mkvSinkBlock.CreateNewInput(MediaBlockPadMediaType.Audio));

await pipeline.StartAsync();

Platforms

Windows, macOS, Linux, iOS, Android.