Code sample - Custom output formats
Delphi and C# (ActiveX) sample code.
Currently, there are several options for connecting third-party DirectShow filters to get the necessary format.
The first option - 3 different DirectShow filters
An audio codec, a video codec, and a multiplexer – different filter. You can use both DirectShow filters and regular codecs as codecs.
The second option - an all-in-one DirectShow filter
A multiplexer, a video codec, and an audio codec – the same filter.
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 necessary filter yourself in the third case.
Now, let us see what the code for different options looks like.
First option
Get lists of audio and video codecs
for I := 0 to VideoCapture1.Video_Codecs_GetCount - 1 do
cbCustomVideoCodec.Items.Add(VideoCapture1.Video_Codecs_GetItem(i));
for I := 0 to VideoCapture1.Audio_Codecs_GetCount - 1 do
cbCustomAudioCodec.Items.Add(VideoCapture1.Audio_Codecs_GetItem(i));
for (int i = 0; i < VideoCapture1.Video_Codecs_GetCount(); i++)
cbCustomVideoCodecs.Items.Add(VideoCapture1.Video_Codecs_GetItem(i));
for (int i = 0; i < VideoCapture1.Audio_Codecs_GetCount(); i++)
cbCustomAudioCodecs.Items.Add(VideoCapture1.Audio_Codecs_GetItem(i));
Get the list of DirectShow filters
for I := 0 to VideoCapture1.DirectShow_Filters_GetCount - 1 do
begin
cbCustomDSFilterV.Items.Add(VideoCapture1.DirectShow_Filters_GetItem(i));
cbCustomDSFilterA.Items.Add(VideoCapture1.DirectShow_Filters_GetItem(i));
cbCustomMuxer.Items.Add(VideoCapture1.DirectShow_Filters_GetItem(i));
cbCustomFilewriter.Items.Add(VideoCapture1.DirectShow_Filters_GetItem(i));
end;
for (int i = 0; i < VideoCapture1.DirectShow_Filters_GetCount(); i++)
{
cbCustomDSFilterA.Items.Add(VideoCapture1.DirectShow_Filters_GetItem(i));
cbCustomDSFilterV.Items.Add(VideoCapture1.DirectShow_Filters_GetItem(i));
cbCustomMuxer.Items.Add(VideoCapture1.DirectShow_Filters_GetItem(i));
cbCustomFilewriter.Items.Add(VideoCapture1.DirectShow_Filters_GetItem(i));
}
Select filters and codecs
if rbCustomUseVideoCodecsCat.Checked then
begin
VideoCapture1.Custom_Output_Video_Codec := cbCustomVideoCodec.Items[cbCustomVideoCodec.ItemIndex];
VideoCapture1.Custom_Output_Video_Codec_Use_Filters_Category := false;
end
else
begin
VideoCapture1.Custom_Output_Video_Codec := cbCustomDSFilterV.Items[cbCustomDSFilterV.ItemIndex];
VideoCapture1.Custom_Output_Video_Codec_Use_Filters_Category := true;
end;
if rbCustomUseAudioCodecsCat.Checked then
begin
VideoCapture1.Custom_Output_Audio_Codec := cbCustomAudioCodec.Items[cbCustomAudioCodec.ItemIndex];
VideoCapture1.Custom_Output_Audio_Codec_Use_Filters_Category := false;
end
else
begin
VideoCapture1.Custom_Output_Audio_Codec := cbCustomDSFilterA.Items[cbCustomDSFilterA.ItemIndex];
VideoCapture1.Custom_Output_Audio_Codec_Use_Filters_Category := true;
end;
VideoCapture1. Custom_Output_Mux_Filter_Name := cbCustomMuxer.Items[cbCustomMuxer.ItemIndex];
if (rbCustomUseVideoCodecsCat.Checked)
{
VideoCapture1.Custom_Output_Video_Codec = cbCustomVideoCodecs.Text;
VideoCapture1.Custom_Output_Video_Codec_Use_Filters_Category = false;
}
else
{
VideoCapture1.Custom_Output_Video_Codec = cbCustomDSFilterV.Text;
VideoCapture1.Custom_Output_Video_Codec_Use_Filters_Category = true;
};
if (rbCustomUseAudioCodecsCat.Checked)
{
VideoCapture1.Custom_Output_Audio_Codec = cbCustomAudioCodecs.Text;
VideoCapture1.Custom_Output_Audio_Codec_Use_Filters_Category = false;
}
else
{
VideoCapture1.Custom_Output_Audio_Codec = cbCustomDSFilterA.Text;
VideoCapture1.Custom_Output_Audio_Codec_Use_Filters_Category = true;
};
VideoCapture1.Custom_Output_Mux_Filter_Name = cbCustomMuxer.Text;
Second option
Get lists of DirectShow filters.
for I := 0 to VideoCapture1.DirectShow_Filters_GetCount - 1 do
begin
cbCustomDSFilterV.Items.Add(VideoCapture1.DirectShow_Filters_GetItem(i));
cbCustomDSFilterA.Items.Add(VideoCapture1.DirectShow_Filters_GetItem(i));
cbCustomMuxer.Items.Add(VideoCapture1.DirectShow_Filters_GetItem(i));
cbCustomFilewriter.Items.Add(VideoCapture1.DirectShow_Filters_GetItem(i));
end;
for (int i = 0; i < VideoCapture1.DirectShow_Filters_GetCount(); i++)
{
cbCustomDSFilterA.Items.Add(VideoCapture1.DirectShow_Filters_GetItem(i));
cbCustomDSFilterV.Items.Add(VideoCapture1.DirectShow_Filters_GetItem(i));
cbCustomMuxer.Items.Add(VideoCapture1.DirectShow_Filters_GetItem(i));
cbCustomFilewriter.Items.Add(VideoCapture1.DirectShow_Filters_GetItem(i));
}
Select multiplexer (mux) filter
VideoCapture1.Custom_Output_Mux_Filter_Name := cbCustomMuxer.Items[cbCustomMuxer.ItemIndex];
VideoCapture1.Custom_Output_Mux_Filter_Is_Encoder := cbCustomMuxFilterIsEncoder.Checked;
VideoCapture1.Custom_Output_Mux_Filter_Name = cbCustomMuxer.Text;
VideoCapture1.Custom_Output_Mux_Filter_Is_Encoder = cbCustomMuxFilterIsEncoder.Checked;
If you need a special File Writer filter, you should specify it. This is true for both options described above.
VideoCapture1.Custom_Output_Special_FileWriter_Needed := cbUseSpecialFilewriter.Checked;
VideoCapture1.Custom_Output_Special_FileWriter_Filter_Name := cbCustomFilewriter.Items[cbCustomFilewriter.ItemIndex];
VideoCapture1.Custom_Output_Special_FileWriter_Needed = cbUseSpecialFilewriter.Checked;
VideoCapture1.Custom_Output_Special_FileWriter_Filter_Name = cbCustomFilewriter.Text;
Start capture
VideoCapture1.Start;
VideoCapture1.Start();
Please get in touch with support to get help with this tutorial. Visit our GitHub page to get more code samples.