2015-06-20 63 views
0

我有elgato捕获设备连接到我的电脑,我试图捕捉并观看elgato捕获设备的窗口。如何使用DirectShowLib捕获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 = 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不存在。

我失去了什么?

回答

0

videoFeed是您的控件,它将托管您嵌入的视频。

mediaControlIMediaControl类型的变量:

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

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

+0

罗马GetPin方法怎么样?我是否需要这个腐烂变量? rot = new DsROTEntry(graph);我稍后在代码中看不到任何用法。腐也不存在。 –

+0

@BoutMan:见上面更新。 –

+0

试过了。上面的更新。在你给的链接中,我尝试了GetPin方法,所以在我的代码中,我改变了所有地方,我得到了错误GetPin不存在:GetPin(elgatoFilter,“Video”);但现在我在GetPin方法中从链接中获取两个错误:checkHR方法不存在。 –