Сохранение изображения из Elgato Game Capture с помощью DirectShow

Я использую Elgato Game Capture HD60 для предварительного просмотра GoPro Hero 5 в своем приложении. Теперь я хочу сохранить поток в формате JPG в своей папке. Но я не могу узнать, как.

Чтобы привязать булавку

    DsROTEntry rot; //Used for remotely connecting to graph
    IFilterGraph2 graph;
    ICaptureGraphBuilder2 captureGraph;
    IBaseFilter elgatoFilter;
    IBaseFilter smartTeeFilter;
    IBaseFilter videoRendererFilter;
    Size videoSize;

    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;
    }

И запустить стрим

private void button1_Click (отправитель объекта, EventArgs e) {

//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(pictureBox1.Handle);
vw.put_MessageDrain(this.Handle);
vw.put_WindowStyle(WindowStyle.Child | WindowStyle.ClipSiblings | WindowStyle.ClipChildren);
vw.SetWindowPosition(0, 0, 1280, 720);

//Start the preview
IMediaControl mediaControl = graph as IMediaControl;
mediaControl.Run();

}


person Christian Bouvin    schedule 20.04.2017    source источник


Ответы (1)


Можете ли вы успешно запустить граф фильтра и на каком шаге вы получили информацию об ошибке?
Вы можете получить пример кода \Samples\Capture\PlayCap, чтобы увидеть, как построить график фильтра захвата видео.
Если вы хотите получить снимок видео, вы можете получить пример кода по адресу \Samples\Capture\DxSnap.
Вы можете изменить индекс источника видео и размер видеофрагмента, чтобы получить то, что вы хотите.
const int VIDEODEVICE = 0; // zero based index of video capture device to use const int VIDEOWIDTH = 2048; // Depends on video device caps const int VIDEOHEIGHT = 1536; // Depends on video device caps const int VIDEOBITSPERPIXEL = 24; // BitsPerPixel values determined by device

person xiaox2y2    schedule 27.06.2017