简体   繁体   English

如何使用DirectShowLib捕获elgato视频流窗口?

[英]How can i use DirectShowLib to capture the elgato video stream window?

I have elgato capture device connected to my pc and i'm trying to capture and watch live the window of the elgato capture device. 我有连接到我的PC的elgato捕获设备,我正在尝试捕获和实时观看elgato捕获设备的窗口。

I searched in google and found this answer: 我在google中搜索并找到以下答案:

Can you use Elgato's HDMIComponent Game Capture HD as a video-in device in C#? 您可以将Elgato的HDMIComponent Game Capture HD用作C#中的视频输入设备吗?

This is the code: 这是代码:

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();

I created a new form in my project and added the DirectShowLib-2005 dll Then i added in the top of the new form: 我在项目中创建了一个新表单,并添加了DirectShowLib-2005 dll,然后在新表单的顶部添加了:

using DirectShowLib;

Before the constructor added the global vars: 在构造函数添加全局变量之前:

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

Then in the constructor i added the rest of the code. 然后在构造函数中,我添加了其余代码。 And i'm getting now few errors: 而且我现在得到一些错误:

On this line the variable rot is not exist: 在这一行上,变量rot不存在:

rot = new DsROTEntry(graph);

In the four lines that use the method GetPin so the method GetPin not exist: 在使用方法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);

On this line: 在这行上:

vw.put_Owner(videoFeed.Handle);

The variable videoFeed not exist. 变量videoFeed不存在。

And in the end this two lines: 最后这两行:

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

mediaControl not exist. mediaControl不存在。

What am i missing ? 我想念什么?

videoFeed is your control which is to host video you are embedding. videoFeed是您的控件,用于托管您要嵌入的视频。

mediaControl would be a variable of type IMediaControl : mediaControl将是IMediaControl类型的变量:

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

GetPin is this or similar; GetPin这个或类似的东西; DsROTEntry is not mandatory but helps inspect filter graph externally using GraphEdit or similar tool. DsROTEntry不是强制性的,但可以使用GraphEdit或类似工具帮助从外部检查过滤器图形

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

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