Video capture to custom output format using Video Capture SDK .Net

Related products
Video Capture SDK .Net

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

VFCustomOutput class is used to set custom output settings.

VFCustomOutput customOutput = new VFCustomOutput();

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 comboboxes

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

If you need a special File Writer filter, you should specify it. It is true for both options described above.
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, or you should use the standard File Writer filter, or 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 necessary 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 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 write access rights)

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

3. Start capture (sync or async)

await VideoCapture1.StartAsync();

Required redists

Please contact support to get help with this tutorial. Visit our GitHub page to get more code samples.
abstract 2abstract 1abstract 3
logo
VisioForge © 2006 - 2021