Skip to main content

Enumerate and select video capture devices

Products: Video Capture SDK .Net

Engines: VideoCaptureCore, VideoCaptureCoreX

Video Capture SDK .Net can use any video capture device supported by OS. The code sample shows you how to list available video capture devices and choose one of them.

Enumerate video capture devices

Sample code to enumerate video capture devices and add them to a combobox:

foreach (var device in VideoCapture1.Video_CaptureDevices())
{
cbVideoInputDevice.Items.Add(device.Name);
}

Enumerate available video formats and frame rates

After getting the device name, you can enumerate available video formats and frame rates:

// Find device by name
var deviceItem = VideoCapture1.Video_CaptureDevices().FirstOrDefault(device => device.Name == "Some device name");

// Enumerate video formats
foreach (var format in deviceItem.VideoFormats)
{
cbVideoInputFormat.Items.Add(format);

// Enumerate frame rates for a specified format
foreach (var frameRate in format.FrameRates)
{
cbVideoInputFrameRate.Items.Add(frameRate.ToString(CultureInfo.CurrentCulture));
}
}

Set the video capture device as a source

// Find the device by name
var deviceItem = VideoCapture1.Video_CaptureDevices().FirstOrDefault(device => device.Name == "Some device name");

// Create the video capture device
VideoCapture1.Video_CaptureDevice = new VideoCaptureSource(deviceItem.Name);

// Set the default format and frame rate
VideoCapture1.Video_CaptureDevice.Format = deviceItem.VideoFormats[0].ToString();
VideoCapture1.Video_CaptureDevice.FrameRate = deviceItem.VideoFormats[0].FrameRates[0];

Use the VideoPreview or VideoCapture mode to preview or capture video from the device.


Visit our GitHub page to get more code samples.