C# 如何使用DirectShowLib捕获elgato视频流窗口?
我将elgato捕获设备连接到我的电脑,我正在尝试捕获并观看elgato捕获设备的窗口 我在谷歌搜索,找到了这个答案: 代码如下:C# 如何使用DirectShowLib捕获elgato视频流窗口?,c#,.net,winforms,directshow,C#,.net,Winforms,Directshow,我将elgato捕获设备连接到我的电脑,我正在尝试捕获并观看elgato捕获设备的窗口 我在谷歌搜索,找到了这个答案: 代码如下: IFilterGraph2 graph; ICaptureGraphBuilder2 captureGraph; IBaseFilter elgatoFilter; IBaseFilter smartTeeFilter; IBaseFilter videoRendererFilter; Size videoSize; //Set the video size t
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);
IPin outPin = GetPin(PinDirection.Output, "Video", elgatoFilter);
IPin inPin = GetPin(PinDirection.Input, smartTeeFilter);
outPin = GetPin(PinDirection.Output, "Preview", smartTeeFilter);
inPin = GetPin(PinDirection.Input, videoRendererFilter);
在使用方法GetPin的四行中,因此方法GetPin不存在:
rot = new DsROTEntry(graph);
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不存在
我缺少什么?
videoFeed
是您的控件,用于承载您正在嵌入的视频
mediaControl
将是IMediaControl
类型的变量:
IMediaControl mediaControl = graph as IMediaControl;
mediaControl.Run();
GetPin
是或类似DsROTEntry
不是强制性的,但使用GraphEdit或类似工具。Roman GetPin方法如何?我需要这个rot变量吗?rot=新数据录入(图表);我在代码后面没有看到它的任何用途。腐烂也不存在。试过了。上面的更新。在您提供的链接中,我尝试了GetPin方法,因此在我的代码中,我在所有地方都将错误GetPin not exist改为:GetPin(elgatoFilter,“Video”);但是现在我从链接中获取的GetPin方法中出现了两个错误:checkHR方法不存在。Ok设法修复了运行中的错误,但什么都没有。我的elgato软件我可以看到ps4窗口,但我的程序使用的是一个图片框,什么也看不见。Roman你能不能连接到我,或者在我的新表单中看到我的全部代码?Roman这是我的新表单中的代码:在表单1中,我刚刚添加了一个按钮,点击并制作实例,然后在新表单中显示:elgato_Video_Capture evc=newElgato_视频_捕获();evc.Show();