MKV Output
The VisioForge SDKs provides functionality for configuring and generating MKV (Matroska Video) files with various video and audio encoding options. This guide explains how to use the MKVOutput class effectively.
Matroska output is available for cross-platform X-engines: VideoCaptureCoreX, VideoEditCoreX, and Media Blocks SDK.
Basic Usage
To create a basic MKV output configuration:
// Create with default encoders
var mkvOutput = new MKVOutput("output.mkv");
You can also specify video and audio encoders during initialization:
// Create with specific encoders
var videoEncoder = new NVENCH264EncoderSettings();
var audioEncoder = new MFAACEncoderSettings();
var mkvOutput = new MKVOutput("output.mkv", videoEncoder, audioEncoder);
Video Encoding Options
The MKVOutput class supports multiple video encoders, including:
H.264 Encoders
- OpenH264 (default if no hardware encoder available)
- NVENC H.264 (NVIDIA GPU acceleration)
- QSV H.264 (Intel Quick Sync)
- AMF H.264 (AMD GPU acceleration)
HEVC (H.265) Encoders
- MF HEVC (Windows Media Foundation, Windows only)
- NVENC HEVC (NVIDIA GPU acceleration)
- QSV HEVC (Intel Quick Sync)
- AMF HEVC (AMD GPU acceleration)
Example of setting a specific video encoder:
mkvOutput.Video = new NVENCH264EncoderSettings();
Audio Encoding Options
Supported audio encoders include:
- VO AAC (default for non-Windows platforms)
- AVENC AAC (FFMPEG AAC)
- MF AAC (default for Windows, based on Media Foundation)
- MP3
- Vorbis
- OPUS
Example of setting an audio encoder:
mkvOutput.Audio = new OPUSEncoderSettings();
Custom Processing
The MKVOutput class allows for custom video and audio processing through MediaBlock processors:
// Add custom video processing
mkvOutput.CustomVideoProcessor = someProcessingVideoBlock;
// Add custom audio processing
mkvOutput.CustomAudioProcessor = someProcessingAudioBlock;
Sink Settings
The MKV sink settings can be configured to control the output file:
// Access sink settings
mkvOutput.Sink.Filename = "new_output.mkv";
// Get current filename
string currentFile = mkvOutput.GetFilename();
// Set new filename
mkvOutput.SetFilename("another_output.mkv");
Sample code
Add the MKV output to the Video Capture SDK core instance:
var core = new VideoCaptureCoreX();
core.Outputs_Add(mkvOutput, true);
Set the output format for the Video Edit SDK core instance:
var core = new VideoEditCoreX();
core.Output_Format = mkvOutput;
Create a Media Blocks MKV output instance:
var aac = new VOAACEncoderSettings();
var h264 = new OpenH264EncoderSettings();
var mkvSinkSettings = new MKVSinkSettings("output.mkv");
var mkvOutput = new MKVOutputBlock(mkvSinkSettings, h264, aac);
Hardware Acceleration
The class automatically selects the best available encoder based on hardware:
- If NVIDIA GPU is available, it will prefer NVENC
- Otherwise, it falls back to OpenH264 for video
- For audio, it uses MF AAC on Windows and VO AAC on other platforms
Getting Available Encoders
You can query the available encoders:
// Get list of supported video encoders
var videoEncoders = mkvOutput.GetVideoEncoders();
// Get list of supported audio encoders
var audioEncoders = mkvOutput.GetAudioEncoders();
Interface Implementation
The MKVOutput class implements several interfaces:
- IVideoEditXBaseOutput
- IVideoCaptureXBaseOutput
- IOutputVideoProcessor
- IOutputAudioProcessor
This makes it suitable for use in video editing and capture scenarios.
Best Practices
- Check hardware encoder availability before using:
if (NVENCH264EncoderSettings.IsAvailable())
{
mkvOutput.Video = new NVENCH264EncoderSettings();
}
- Consider platform-specific encoders:
#if NET_WINDOWS
mkvOutput.Audio = new MFAACEncoderSettings();
#else
mkvOutput.Audio = new VOAACEncoderSettings();
#endif
Notes
- The MKV format supports multiple video and audio streams
- Hardware encoders generally provide better performance but may not be available on all systems
- Custom processors should be used cautiously as they can impact performance