【问题标题】:How can i use DirectShowLib to capture the elgato video stream window?如何使用 DirectShowLib 捕获 elgato 视频流窗口?
【发布时间】:2015-06-20 12:39:19
【问题描述】:

我将 elgato 捕获设备连接到我的电脑,我正在尝试捕获并实时观看 elgato 捕获设备的窗口。

我在谷歌搜索并找到了这个答案:

Can you use Elgato's HDMIComponent Game Capture HD as a video-in device in C#?

这是代码:

IFilterGraph2 graph;
ICaptureGraphBuilder2 captureGraph;
IBaseFilter elgatoFilter;
IBaseFilter smartTeeFilter;
IBaseFilter videoRendererFilter;
Size videoSize;

//Set the video size to use for capture and recording
videoSize = new Size(1280, 720);

//Initialize filter graph and capture graph
graph = (IFilterGraph2)new FilterGraph();
captureGraph = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
captureGraph.SetFiltergraph(graph);
rot = new DsROTEntry(graph);

//Create filter for Elgato
Guid elgatoGuid = new Guid("39F50F4C-99E1-464A-B6F9-D605B4FB5918");
Type comType = Type.GetTypeFromCLSID(elgatoGuid);
elgatoFilter = (IBaseFilter)Activator.CreateInstance(comType);
graph.AddFilter(elgatoFilter, "Elgato Video Capture Filter");

//Create smart tee filter, add to graph, connect Elgato's video out to smart tee in
smartTeeFilter = (IBaseFilter)new SmartTee();
graph.AddFilter(smartTeeFilter, "Smart Tee");
IPin outPin = GetPin(PinDirection.Output, "Video", elgatoFilter);
IPin inPin = GetPin(PinDirection.Input, smartTeeFilter);
graph.Connect(outPin, inPin);

//Create video renderer filter, add it to graph, connect smartTee Preview pin to video renderer's input pin
videoRendererFilter = (IBaseFilter)new VideoRenderer();
graph.AddFilter(videoRendererFilter, "Video Renderer");
outPin = GetPin(PinDirection.Output, "Preview", smartTeeFilter);
inPin = GetPin(PinDirection.Input, videoRendererFilter);
graph.Connect(outPin, inPin);

//Render stream from video renderer
captureGraph.RenderStream(PinCategory.Preview, MediaType.Video, videoRendererFilter, null, null);

//Set the video preview to be the videoFeed panel
IVideoWindow vw = (IVideoWindow)graph;
vw.put_Owner(videoFeed.Handle);
vw.put_MessageDrain(this.Handle);
vw.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipSiblings | WindowStyle.ClipChildren);
vw.SetWindowPosition(0, 0, 1280, 720);

//Start the preview
mediaControl = graph as IMediaControl;
mediaControl.Run();

我在我的项目中创建了一个新表单并添加了 DirectShowLib-2005 dll 然后我在新表单的顶部添加:

using DirectShowLib;

在构造函数添加全局变量之前:

IFilterGraph2 graph;
ICaptureGraphBuilder2 captureGraph;
IBaseFilter elgatoFilter;
IBaseFilter smartTeeFilter;
IBaseFilter videoRendererFilter;
Size videoSize;

然后在构造函数中我添加了其余代码。 而且我现在遇到了一些错误:

在这一行中,变量 rot 不存在:

rot = new DsROTEntry(graph);

在使用GetPin方法的四行中,因此GetPin方法不存在:

IPin outPin = GetPin(PinDirection.Output, "Video", elgatoFilter);
IPin inPin = GetPin(PinDirection.Input, smartTeeFilter);
outPin = GetPin(PinDirection.Output, "Preview", smartTeeFilter);
inPin = GetPin(PinDirection.Input, videoRendererFilter);

在这一行:

vw.put_Owner(videoFeed.Handle);

变量 videoFeed 不存在。

最后这两行:

mediaControl = graph as IMediaControl;
mediaControl.Run();

mediaControl 不存在。

我错过了什么?

【问题讨论】:

    标签: c# .net winforms directshow


    【解决方案1】:

    videoFeed 是您的控件,用于托管您正在嵌入的视频。

    mediaControl 将是IMediaControl 类型的变量:

    IMediaControl mediaControl = graph as IMediaControl;
    mediaControl.Run();
    

    GetPinthis 或类似的; DsROTEntry 不是强制性的,但 helps inspect filter graph externally 使用 GraphEdit 或类似工具。

    【讨论】:

    • Roman 方法 GetPin 怎么样?我需要这个 rot 变量吗? rot = new DsROTEntry(graph);我在后面的代码中看不到它的任何用途。 rot 也不存在。
    • 试过了。上面的更新。在您提供的链接中,我尝试了 GetPin 方法,因此在我的代码中,我在所有地方都发生了错误 GetPin not exist to: GetPin(elgatoFilter, "Video");但现在我从链接中获取的 GetPin 方法中出现两个错误:checkHR 方法不存在。
    • Ok 设法修复了运行中的错误,但什么也没有。我的 elgato 软件我可以看到 ps4 窗口,但在我的程序中,我使用的是图片框,什么也看不到。
    • Roman,你能不能以某种方式连接到我或以我所做的新形式查看我的整个代码?
    • Roman 这是我的新表单中的代码:pastebin.com/YiwaWaMA,在 form1 中我只是添加了一个按钮单击并创建实例并显示到新表单:Elgato_Video_Capture evc = new Elgato_Video_Capture(); evc.Show();
    猜你喜欢
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 1970-01-01
    • 2013-03-02
    • 1970-01-01
    • 2014-01-29
    相关资源
    最近更新 更多