简体   繁体   中英

LibVLCSharp how to get list of webcams

VLC GUI shows the list of available webcams, like v4l2:///dev/video0 and v4l2:///dev/video1 , I am wondering is there a way to get a list of available webcams? what about their default resolution?

在此处输入图片说明

I tried this but md.MediaList is empty.

var mds = libVlc.MediaDiscoverers(MediaDiscovererCategory.Devices);
if (mds.Any(x => x.LongName == "Video capture"))
{
    var devices = mds.First(x => x.LongName == "Video capture");
    var md = new MediaDiscoverer(libVlc, devices.Name);
    foreach (var media1 in md.MediaList)
    {
       // Nothing ...
    }
}

Your MediaDiscoverer is empty because you never call md.Start() . For more info, I found this really helpful: /LibVLCSharp/MediaDiscoverer.cs

That being said, I had no success using MediaDiscoverer to look for webcams myself.

If you don't insist on using LibVLC, you can list all camera devices without any third party software: How can I get a list of camera devices from my PC C#

from Francesco Bonizzi:

public static List<string> GetAllConnectedCameras()
{
    var cameraNames = new List<string>();
    using (var searcher = new ManagementObjectSearcher("SELECT * FROM Win32_PnPEntity WHERE (PNPClass = 'Image' OR PNPClass = 'Camera')"))
    {
        foreach (var device in searcher.Get())
        {
            cameraNames.Add(device["Caption"].ToString());
        }
    }

    return cameraNames;
}

The technical post webpages of this site follow the CC BY-SA 4.0 protocol. If you need to reprint, please indicate the site URL or the original address.Any question please contact:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM