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

拜拜、爱过 提交于 2019-12-12 15:55:41

问题


We're wondering if it's possible to capture the video stream from Elgato's Game Capture HD (or something similar--the model/brand doesn't matter) and get it in a window using C#. We haven't found any information on using that product with anything but its own software, nor have we found any other hardware that can capture such a thing.

Again, our goal is simply to get a device with Component Out to appear in a window on-screen, nothing else. No recording, no screen capture, no overlays, nothing. Just pure, 'live' video.

Been looking for several months now and getting nowhere so I figured I'd throw this out to the SO community.


回答1:


Look for registered video capture DirectShow filters, you can load it by its GUID. It'll be installed when Game Capture HD 1.2.1 is installed. Contact Elgato support with questions.




回答2:


Take a look at this Github project. It seems to show how to use Elgato's Game Capture HD as a capture device in a c++ DirectShow application. The same method should apply to a c# project.




回答3:


I know this is an old question, but in case anyone else stumbles across it it is quite easy to use the video stream from an Elgato capture card in C# with DirectShow. Here is an example of creating a simple graph and previewing the Elgato's video stream.

using DirectShowLib;

DsROTEntry rot; //Used for remotely connecting to graph

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

private IPin GetPin(PinDirection pinDir, IBaseFilter filter)
{
    IEnumPins epins;
    int hr = filter.EnumPins(out epins);
    if (hr < 0)
        return null;
    IntPtr fetched = Marshal.AllocCoTaskMem(4);
    IPin[] pins = new IPin[1];
    epins.Reset();
    while (epins.Next(1, pins, fetched) == 0)
    {
        PinInfo pinfo;
        pins[0].QueryPinInfo(out pinfo);
        bool found = (pinfo.dir == pinDir);
        DsUtils.FreePinInfo(pinfo);
        if (found)
            return pins[0];
    }
    return null;
}

private IPin GetPin(PinDirection pinDir, string name, IBaseFilter filter)
{
    IEnumPins epins;
    int hr = filter.EnumPins(out epins);
    if (hr < 0)
        return null;
    IntPtr fetched = Marshal.AllocCoTaskMem(4);
    IPin[] pins = new IPin[1];
    epins.Reset();
    while (epins.Next(1, pins, fetched) == 0)
    {
        PinInfo pinfo;
        pins[0].QueryPinInfo(out pinfo);
        bool found = (pinfo.dir == pinDir && pinfo.name == name);
        DsUtils.FreePinInfo(pinfo);
        if (found)
            return pins[0];
    }
    return null;
}


来源:https://stackoverflow.com/questions/14370125/can-you-use-elgatos-hdmicomponent-game-capture-hd-as-a-video-in-device-in-c

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!