最新消息:雨落星辰是一个专注网站SEO优化、网站SEO诊断、搜索引擎研究、网络营销推广、网站策划运营及站长类的自媒体原创博客

How to get USB WebCam to play in Vlc.DotNet.Forms.VlcControl in WinForms C# - Stack Overflow

programmeradmin6浏览0评论

I'm trying to play usb webcam video in Vlc.DotNet.Forms.VlcControl in winforms and i think there are two ways of doing that:

  1. get some path or mrl and play it
  2. get stream and play it

I dont know hot to get stream of webcam but vlc can use dshow and by using vlc.exe dshow:// :dshow-vdev="USB2.0 PC CAMERA" in cmd i'm getting vlc playing what is need but i need it in VlcControl.

Getting camera name via DirectShowLib and

DsDevice[] cams = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
string webcam = "";

DsDevice[] cams = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
foreach  (DsDevice cam in cams)
{
    if (cam.Name.ToLower().Contains("camera"))
        webcam = $"dshow:// :dshow-vdev=\"{cam.Name}\"";
    Console.WriteLine($"\n{cam.Name}");
}
Console.WriteLine('\n' + webcam + '\n');

The webcam path is exactly the same and if i do vlcControl.Play(webcam); it shows only black screen.
By doing vlcControl.Log += (sender, args) => Console.WriteLine(args.Message); i get some logs

Creating an input for 'dshow://'
using timeshift granularity of 50 MiB
using timeshift path: C:\Users\user\AppData\Local\Temp
`dshow:// :dshow-vdev="USB2.0 PC CAMERA"' gives access `dshow' demux `any' path ` :dshow-vdev="USB2.0 PC CAMERA"'
creating demux: access='dshow' demux='any' location=' :dshow-vdev="USB2.0 PC CAMERA"' file='(null)'
looking for access_demux module matching "dshow": 11 candidates
creating access: dshow:// :dshow-vdev="USB2.0 PC CAMERA"
looking for access module matching "dshow": 25 candidates
no access_demux modules matched
no access modules matched
VLC is unable to open the MRL 'dshow:// :dshow-vdev="USB2.0 PC CAMERA"'. Check the log for details.
Your input can't be opened

vlcControl dir path is correct and can play videos but how it can webcam?

I'm trying to play usb webcam video in Vlc.DotNet.Forms.VlcControl in winforms and i think there are two ways of doing that:

  1. get some path or mrl and play it
  2. get stream and play it

I dont know hot to get stream of webcam but vlc can use dshow and by using vlc.exe dshow:// :dshow-vdev="USB2.0 PC CAMERA" in cmd i'm getting vlc playing what is need but i need it in VlcControl.

Getting camera name via DirectShowLib and

DsDevice[] cams = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
string webcam = "";

DsDevice[] cams = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
foreach  (DsDevice cam in cams)
{
    if (cam.Name.ToLower().Contains("camera"))
        webcam = $"dshow:// :dshow-vdev=\"{cam.Name}\"";
    Console.WriteLine($"\n{cam.Name}");
}
Console.WriteLine('\n' + webcam + '\n');

The webcam path is exactly the same and if i do vlcControl.Play(webcam); it shows only black screen.
By doing vlcControl.Log += (sender, args) => Console.WriteLine(args.Message); i get some logs

Creating an input for 'dshow://'
using timeshift granularity of 50 MiB
using timeshift path: C:\Users\user\AppData\Local\Temp
`dshow:// :dshow-vdev="USB2.0 PC CAMERA"' gives access `dshow' demux `any' path ` :dshow-vdev="USB2.0 PC CAMERA"'
creating demux: access='dshow' demux='any' location=' :dshow-vdev="USB2.0 PC CAMERA"' file='(null)'
looking for access_demux module matching "dshow": 11 candidates
creating access: dshow:// :dshow-vdev="USB2.0 PC CAMERA"
looking for access module matching "dshow": 25 candidates
no access_demux modules matched
no access modules matched
VLC is unable to open the MRL 'dshow:// :dshow-vdev="USB2.0 PC CAMERA"'. Check the log for details.
Your input can't be opened

vlcControl dir path is correct and can play videos but how it can webcam?

Share Improve this question asked Jan 18 at 8:31 AlexandrAlexandr 294 bronze badges
Add a comment  | 

1 Answer 1

Reset to default 0

To capture from a DirectShow webcam with Vlc.DotNet, you generally need to pass "dshow://" as the media location and then provide the device name as an extra VLC option—not jam them all into a single MRL. In other words, don’t do:

vlcControl.Play("dshow:// :dshow-vdev=\"USB2.0 PC CAMERA\""); ❌

Instead Try this :

 // Query all camera devices with DirectShowLib, pick one:
var deviceName = "USB2.0 PC CAMERA";

// Build your Vlc options array
var options = new[]
{
    $":dshow-vdev={deviceName}",
    ":dshow-adev=none",         // choose your mic name if you have audio "Microphone (USB2.0 PC CAMERA)"
    ":live-caching=0"
};

// Then play:
vlcControl.MediaPlayer.Play("dshow://", options);

Also Please check that your bitness (x86 vs. x64) of VLC, Vlc.DotNet, and your .NET project all match.

I think if you did this approach VLC should open the webcam feed in VlcControl.

发布评论

评论列表(0)

  1. 暂无评论