gpt4 book ai didi

c# - DirectShow USB 网络摄像头更改视频源

转载 作者:行者123 更新时间:2023-11-30 22:16:01 33 4
gpt4 key购买 nike

嘿,我正在尝试找到将我的视频源更改为网络摄像头“复合”的设置。似乎如果我拔下 USB 然后重新插入并启动代码,它只会出现空白屏幕。但是一旦我更改视频源(在另一个程序中)然后返回并再次运行我的代码,它就会出现。

所以我需要一些可以让我改变它的东西,以便在我自己的应用程序中发生同样的事情,而不必启动另一个具有该功能的程序来设置网络摄像头。

当我拔出 USB 数据线然后重新插入并运行源代码时,应用程序的图片框是黑色的。

enter image description here

我用来更改视频源的“其他程序”(似乎可以调出图像): enter image description here

在我使用那个“其他程序”之后,我回到源代码并运行它,这就是我得到的结果: enter image description here

我正在使用来自此处的名为 dot Net Webcam Library 的 C# 代码:enter link description here

它似乎使用了 enter link description here 中的 DirectShow

我注意到源代码中列出了不同类型的视频设置(在下面的 AXExtend.cs 中找到):

public enum PhysicalConnectorType
{
Video_Tuner = 1,
Video_Composite,
Video_SVideo,
Video_RGB,
Video_YRYBY,
Video_SerialDigital,
Video_ParallelDigital,
Video_SCSI,
Video_AUX,
Video_1394,
Video_USB,
Video_VideoDecoder,
Video_VideoEncoder,
Video_SCART,
Video_Black,

Audio_Tuner = 0x1000,
Audio_Line,
Audio_Mic,
Audio_AESDigital,
Audio_SPDIFDigital,
Audio_SCSI,
Audio_AUX,
Audio_1394,
Audio_USB,
Audio_AudioDecoder,
}

但我不确定如何在此处的代码中调用它:

Device selectedDevice = device as Device;
imageCapture.Device = selectedDevice as Device;
imageCapture.PerformAutoScale();
imageCapture.Refresh();
imageCapture.Start();

所以我猜我可能需要“Video_Composite”才能做到这一点?

任何帮助都会很棒!!!谢谢!

大卫

代码更新

foreach (Device device in Device.FindDevices())
{
if (device.ToString() == "BackupCamera")
{
Device selectedDevice = device as Device;
IGraphBuilder graphBuilder = new FilterGraph() as IGraphBuilder;
DsDevice device1 = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice)[1]; // <<--- Your Device
Guid baseFilterIdentifier = typeof(IBaseFilter).GUID;
object videoSourceObject;
device1.Mon.BindToObject(null, null, ref baseFilterIdentifier, out videoSourceObject);
IBaseFilter videoSourceBaseFilter = videoSourceObject as IBaseFilter;
graphBuilder.AddFilter(videoSourceBaseFilter, "Source");
ICaptureGraphBuilder2 captureGraphBuilder = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;
captureGraphBuilder.SetFiltergraph(graphBuilder);
object crossbarObject;
captureGraphBuilder.FindInterface(FindDirection.UpstreamOnly, null, videoSourceBaseFilter, typeof(IAMCrossbar).GUID, out crossbarObject);
IAMCrossbar crossbar = crossbarObject as IAMCrossbar;
int inputPinCount, outputPinCount;
crossbar.get_PinCounts(out inputPinCount, out outputPinCount); // <<-- In/Out Pins
// Pin Selection: Physical Input 2 (e.g. Composite) to Capture Pin 0
crossbar.Route(0, 2);

imageCapture.Device = selectedDevice as Device;
imageCapture.PerformAutoScale();
imageCapture.Refresh();
imageCapture.Start();
}
}

最佳答案

运行filer graph之前,需要先获取crossbar接口(interface)。为此,您通常使用 ICaptureGraphBuilder2::FindInterface。这需要一个额外的过滤器,FindInterface 方法特别适用于此原因:

Supporting Filters. If a capture device uses a Windows Driver Model (WDM) driver, the graph may require certain filters upstream from the WDM Video Capture filter, such as a TV Tuner filter or an Analog Video Crossbar filter. If the pCategory parameter does not equal NULL, this method automatically inserts any required WDM filters into the graph.

完成此操作后,您将拥有 IAMCrossbar 界面,IAMCrossbar::Route 方法是您切换输入的方式。

另请参阅:Crossbar filter change current input to Composite

代码片段:

IGraphBuilder graphBuilder = new FilterGraph() as IGraphBuilder;
DsDevice device = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice)[1]; // <<--- Your Device
Guid baseFilterIdentifier = typeof(IBaseFilter).GUID;
object videoSourceObject;
device.Mon.BindToObject(null, null, ref baseFilterIdentifier, out videoSourceObject);
IBaseFilter videoSourceBaseFilter = videoSourceObject as IBaseFilter;
graphBuilder.AddFilter(videoSourceBaseFilter, "Source");
ICaptureGraphBuilder2 captureGraphBuilder = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;
captureGraphBuilder.SetFiltergraph(graphBuilder);
object crossbarObject;
captureGraphBuilder.FindInterface(FindDirection.UpstreamOnly, null, videoSourceBaseFilter, typeof(IAMCrossbar).GUID, out crossbarObject);
IAMCrossbar crossbar = crossbarObject as IAMCrossbar;
int inputPinCount, outputPinCount;
crossbar.get_PinCounts(out inputPinCount, out outputPinCount); // <<-- In/Out Pins
// Pin Selection: Physical Input 2 (e.g. Composite) to Capture Pin 0
crossbar.Route(0, 2);

关于c# - DirectShow USB 网络摄像头更改视频源,我们在Stack Overflow上找到一个类似的问题: https://stackoverflow.com/questions/17689763/

33 4 0
Copyright 2021 - 2024 cfsdn All Rights Reserved 蜀ICP备2022000587号
广告合作:1813099741@qq.com 6ren.com