Skip to main content

Custom format file output using DirectShow filters

Products: Video Capture SDK .Net, Video Edit SDK .Net

Currently, there are several options for connecting third-party DirectShow filters for you to be able to get the necessary format.

The CustomOutput class is used to set custom output settings.

The same sample code can be used for Video Edit SDK .Net. Use the VideoEditCore class instead of VideoCaptureCore.

var customOutput = new CustomOutput();

Custom format output - three independent filters

There are three different filters - an audio codec, a video codec, and a multiplexer. You can use both DirectShow filters and regular codecs as codecs.

1. Get lists of audio and video codecs and fill combo boxes

foreach (string codec in VideoCapture1.Video_Codecs)
{
cbCustomVideoCodecs.Items.Add(codec);
}

foreach (string codec in VideoCapture1.Audio_Codecs)
{
cbCustomAudioCodecs.Items.Add(codec);
}

2. Get a list of DirectShow filters

foreach (string directShowFilter in VideoCapture1.DirectShow_Filters)
{
cbCustomDSFilterA.Items.Add(directShowFilter);
cbCustomDSFilterV.Items.Add(directShowFilter);
cbCustomMuxer.Items.Add(directShowFilter);
cbCustomFilewriter.Items.Add(directShowFilter);
}

3. Select filters and codecs

if (rbCustomUseVideoCodecsCat.Checked)
{
customOutput.Video_Codec = cbCustomVideoCodecs.Text;
customOutput.Video_Codec_UseFiltersCategory = false;
}
else
{
customOutput.Video_Codec = cbCustomDSFilterV.Text;
customOutput.Video_Codec_UseFiltersCategory = true;
}

if (rbCustomUseAudioCodecsCat.Checked)
{
customOutput.Audio_Codec = cbCustomAudioCodecs.Text;
customOutput.Audio_Codec_UseFiltersCategory = false;
}
else
{
customOutput.Audio_Codec = cbCustomDSFilterA.Text;
customOutput.Audio_Codec_UseFiltersCategory = true;
}

customOutput.MuxFilter_Name = cbCustomMuxer.Text;
customOutput.MuxFilter_IsEncoder = false;

4. Custom file writer filter

customOutput.SpecialFileWriter_Needed = cbUseSpecialFilewriter.Checked;
customOutput.SpecialFileWriter_FilterName = cbCustomFilewriter.Text;

Custom format output - one all-in-one filter

There is one filter that contains a multiplexer, a video codec, and an audio codec. Another difference is whether the filter can write to a file itself, whether you should use the standard File Writer filter, or whether you need another special filter. In the first two cases, VisioForge Video Capture will detect it automatically and set the necessary parameters, but you have to specify the required filter yourself in the third case. And now, let us see what the code for different options looks like.

1. Get a list of DirectShow filters

foreach (string directShowFilter in VideoCapture1.DirectShow_Filters)
{
cbCustomDSFilterA.Items.Add(directShowFilter);
cbCustomDSFilterV.Items.Add(directShowFilter);
cbCustomMuxer.Items.Add(directShowFilter);
cbCustomFilewriter.Items.Add(directShowFilter);
}

2. Select a multiplexer (mux) filter

customOutput.MuxFilter_Name = cbCustomMuxer.Text;
customOutput.MuxFilter_IsEncoder = true;

3. Custom file writer filter

customOutput.SpecialFileWriter_Needed = cbUseSpecialFilewriter.Checked;
customOutput.SpecialFileWriter_FilterName = cbCustomFilewriter.Text;

Custom format output - configure using the settings dialog

CustomFormatSettingsDialog dialog usage

CustomFormatSettingsDialog customFormatSettingsDialog = new CustomFormatSettingsDialog(
VideoCapture1.Video_Codecs.ToArray(),
VideoCapture1.Audio_Codecs.ToArray(),
VideoCapture1.DirectShow_Filters.ToArray());
customFormatSettingsDialog.SaveSettings(ref customOutput);

Apply settings

1. Set custom format output settings

VideoCapture1.Output_Format = customOutput;

2. Set video capture mode and file name (be sure that you have to write access rights)

VideoCapture1.Mode = VideoCaptureMode.VideoCapture;
VideoCapture1.Output_Filename = "output.mp4";

3. Start capture (sync or async)

await VideoCapture1.StartAsync();

Required redists

  • Video Capture SDK redist x86 x64
  • Video Edit SDK redist x86 x64

Visit our GitHub page to get more code samples.