Video capture to MP4 file using Video Capture SDK .Net

Related products
Video Capture SDK .Net

To capture video in MP4 format using Video Capture SDK, you need to configure video output format using one of the classes for MP4 output. You can use several available software and hardware video encoders, including Intel QuickSync, Nvidia NVENC, and AMD/ATI APU.

Use the dialog to set settings in UI or set settings in code.

Video capture to MP4 (DirectShow) - CPU encoder or Intel QuickSync GPU encoder

Create VFMP4Output object for MP4 output

VFMP4Output mp4Output = new VFMP4Output();

Set MP4 settings using the settings dialog

MP4SettingsDialog mp4SettingsDialog = new MP4SettingsDialog();

mp4SettingsDialog.ShowDialog(this);
mp4SettingsDialog.SaveSettings(ref mp4Output);

Or

Set MP4 settings without using the settings dialog

1. Set MP4 mode

mp4Output.MP4Mode = VFMP4Mode.CPU_QSV;

2. Set video settings

mp4Output.Video.Profile = VFH264Profile.ProfileMain; // H264 profile
mp4Output.Video.Level = VFH264Level.Level4; // H264 level
mp4Output.Video.Bitrate = 2000; // bitrate

// optional parameters
mp4Output.Video.MBEncoding = VFH264MBEncoding.CABAC; //CABAC / CAVLC
mp4Output.Video.BitrateAuto = false; // true to use auto bitrate
mp4Output.Video.RateControl = VFH264RateControl.VBR; // rate control - CBR or VBR

3. Set audio settings

mp4Output.Audio_AAC.Bitrate = 192;
mp4Output.Audio_AAC.Version = VFAACVersion.MPEG4; // MPEG-4 / MPEG-2
mp4Output.Audio_AAC.Output = VFAACOutput.RAW; // RAW or ADTS
mp4Output.Audio_AAC.Object = VFAACObject.Low; // type of AAC

Apply settings

1. Use MP4 format for output

VideoCapture1.Output_Format = mp4Output;

2. Set video capture mode

VideoCapture1.Mode = VFVideoCaptureMode.VideoCapture;

3. Set file name (be sure that you have write access rights)

VideoCapture1.Output_Filename = "123.mp4";

4. Start capture

await VideoCapture1.StartAsync();

Video capture to MP4 (DirectShow) - Nvidia NVENC encoder

Create VFMP4Output object for MP4 output with NVENC encoder

var mp4Output = new VFMP4Output();

Set MP4 settings using the settings dialog

var mp4SettingsDialog = new MP4SettingsDialog();

mp4SettingsDialog.ShowDialog(this);
mp4SettingsDialog.SaveSettings(ref mp4Output);

Or

Set MP4 settings without using the settings dialog

1. Set MP4 mode – NVENC

mp4Output.MP4Mode = VFMP4Mode.NVENC;

2. Set video settings

mp4Output.Video_NVENC.Profile = VFNVENCVideoEncoderProfile.H264_Main; // H264 profile
mp4Output.Video_NVENC.Level = VFNVENCEncoderLevel.H264_4; // H264 level
mp4Output.Video_NVENC.Bitrate = 2000; // bitrate

// optional parameters
mp4Output.Video_NVENC.RateControl = VFNVENCRateControlMode.VBR; // rate control - CBR or VBR

3. Set audio settings

mp4Output.Audio_AAC.Bitrate = 192;
mp4Output.Audio_AAC.Version = VFAACVersion.MPEG4; // MPEG-4 / MPEG-2
mp4Output.Audio_AAC.Output = VFAACOutput.RAW; // RAW or ADTS
mp4Output.Audio_AAC.Object = VFAACObject.Low; // type of AAC

Apply settings

1. Use MP4 format for output

VideoCapture1.Output_Format = mp4Output;

2. Set video capture mode

VideoCapture1.Mode = VFVideoCaptureMode.VideoCapture;

3. Set file name (be sure that you have write access rights)

VideoCapture1.Output_Filename = "123.mp4";

4. Start capture

await VideoCapture1.StartAsync();

Video capture to MP4 (Media Foundation) - CPU/GPU encoders

Using MP4 v11 output, you can use hardware-accelerated encoders by Intel (QuickSync), Nvidia (NVENC), and AMD/ATI.

Create VFMP4v11Output object for MP4 output v11

var mp4Output = new VFMP4v11Output();

Set MP4 settings using the settings dialog

var mp4SettingsDialog = new MFSettingsDialog();​

mp4SettingsDialog.ShowDialog(this);
mp4SettingsDialog.SaveSettings(ref mp4Output);
Or

Set MP4 settings without using the settings dialog

1. First step – get available encoders

var filtersAvailableInfo = VideoCaptureCore.MP4_v11_GetFiltersAvailable();

2. Depending on available encoders, select video codec

mp4Output.Video.Codec = VFMFVideoEncoder.MS_H264; // Microsoft H264
mp4Output.Video.Profile = VFMFH264Profile.Main; // H264 profile
mp4Output.Video.Level = VFMFH264Level.Level4; // H264 level
mp4Output.Video.AvgBitrate = 2000; // bitrate

// optional parameters
mp4Output.Video.CABAC = true; // CABAC / CAVLC
mp4Output.Video.RateControl = VFMFCommonRateControlMode.CBR; // rate control

// many other parameters available

3. Set audio settings

mp4Output.Audio.Bitrate = 192;
mp4Output.Audio.Version = VFAACVersion.MPEG4; // MPEG-4 / MPEG-2
mp4Output.Audio.Output = VFAACOutput.RAW; // RAW or ADTS
mp4Output.Audio.Object = VFAACObject.Low; // type of AAC

Apply settings

​ 1. Use MP4 format for output

VideoCapture1.Output_Format = mp4Output;

2. Set video capture mode

VideoCapture1.Mode = VFVideoCaptureMode.VideoCapture;

3. Set file name (be sure that you have write access rights)

VideoCapture1.Output_Filename = "123.mp4";

4. Start capture

await VideoCapture1.StartAsync();

Required redists

  • Video capture redist
  • MP4 redist
Please check Deployment
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