我有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不存在。
我失去了什麼?
羅馬GetPin方法怎麼樣?我是否需要這個腐爛變量? rot = new DsROTEntry(graph);我稍後在代碼中看不到任何用法。腐也不存在。 –
@BoutMan:見上面更新。 –
試過了。上面的更新。在你給的鏈接中,我嘗試了GetPin方法,所以在我的代碼中,我改變了所有地方,我得到了錯誤GetPin不存在:GetPin(elgatoFilter,「Video」);但現在我在GetPin方法中從鏈接中獲取兩個錯誤:checkHR方法不存在。 –