Question

I am creating a project using DirectShow.Net that shows a preview of a webcam view within a windows form using Visual C#.

I would like to start with gaining a collection of available video devices so I can choose between either the built in webcam or the USB webcam.

I have seen several examples of this being done in C++, e.g. on the msdn "http://msdn.microsoft.com/en-us/library/windows/desktop/dd377566(v=vs.85).aspx".

However as I do not know any C++ I do not know how to convert this code into C#.

Was it helpful?

Solution

DirectShow.NET sample \Samples\Capture\DxLogo\Capture.cs shows how to do it:

// Get the collection of video devices
capDevices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);

The keyword you need is FilterCategory.VideoInputDevice.

See also:

OTHER TIPS

.netcore solution: Install the package: DirectShowLib.Standard

Then you can get the cameras list:

var devices = new List<DsDevice>(DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice));
var cameraNames = new List<string>();
foreach (var device in devices)
{
    cameraNames.Add(device.Name);
}

This is the perfect solution for getting a Camera List. An internal camera comes first then an external camera.

//.netcore solution: Install the package: DirectShowLib.Standard
//Then you can get the cameras list:
//var devices = new List<DsDevice>(DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice));
//var cameraNames = new List<string>();
//foreach (var device in devices){    cameraNames.Add(device.Name);}
Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top