2

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

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

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

在此处输入图像描述

我用来更改视频源的“其他程序”(似乎可以显示图像): 在此处输入图像描述

在我使用那个“其他程序”之后,我回到源代码并运行它,这就是我得到的: 在此处输入图像描述

我在这里使用名为 dot Net Webcam Library 的 C# 代码:在此处输入链接描述

似乎使用了此处输入链接描述中的 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();
    }
}
4

1 回答 1

3

在运行文件管理器图之前,您需要获取交叉开关接口。您通常ICaptureGraphBuilder2::FindInterface用于此。这需要一个额外的过滤器,该FindInterface方法特别有用:

支持过滤器。如果捕获设备使用 Windows 驱动程序模型 (WDM) 驱动程序,则该图可能需要 WDM 视频捕获过滤器上游的某些过滤器,例如电视调谐器过滤器或模拟视频交叉开关过滤器。如果 pCategory 参数不等于 NULL,此方法会自动将任何所需的 WDM 过滤器插入到图中

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

另请参阅:Crossbar 滤波器将当前输入更改为 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);
于 2013-07-17T06:36:43.507 回答