I still can't figure out why capturing the video window from the elgato usb is not working?

238 views Asked by At

In form1 i just have a simple button click event:

private void button3_Click(object sender, EventArgs e)
        {
            Elgato_Video_Capture evc = new Elgato_Video_Capture();
            evc.Show();
        }

Then in the new form in designer i added a pictureBox. And the new form code:

using System;
using System.Collections.Generic;
using System.ComponentModel;
using System.Data;
using System.Drawing;
using System.Linq;
using System.Text;
using System.Threading.Tasks;
using System.Windows.Forms;
using DirectShowLib;
using DirectShowLib.BDA;
using DirectShowLib.DES;
using DirectShowLib.DMO;
using DirectShowLib.Dvd;
using DirectShowLib.MultimediaStreaming;
using DirectShowLib.SBE;
using System.Runtime.InteropServices;

namespace Test
{

    public partial class Elgato_Video_Capture : Form
    {



        IFilterGraph2 graph;
        ICaptureGraphBuilder2 captureGraph;
        IBaseFilter elgatoFilter;
        IBaseFilter smartTeeFilter;
        IBaseFilter videoRendererFilter;
        Size videoSize;
        string error = "";

        public Elgato_Video_Capture()
        {
            InitializeComponent();
            try
            {
                //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(elgatoFilter, "Video"); //GetPin(PinDirection.Output, "Video", elgatoFilter);
                IPin inPin = GetPin(elgatoFilter, "Video");//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(elgatoFilter, "Video");//GetPin(PinDirection.Output, "Preview", smartTeeFilter);
                inPin = GetPin(elgatoFilter, "Video");//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();
            }
            catch (Exception err)
            {
                error = err.ToString();
            }
        }


        static IPin GetPin(IBaseFilter filter, string pinname)
        {
            IEnumPins epins;
            int hr = filter.EnumPins(out epins);
            checkHR(hr, "Can't enumerate pins");
            IntPtr fetched = Marshal.AllocCoTaskMem(4);
            IPin[] pins = new IPin[1];
            while (epins.Next(1, pins, fetched) == 0)
            {
                PinInfo pinfo;
                pins[0].QueryPinInfo(out pinfo);
                bool found = (pinfo.name == pinname);
                DsUtils.FreePinInfo(pinfo);
                if (found)
                    return pins[0];
            }
            checkHR(-1, "Pin not found");
            return null;
        }

        public static void checkHR(int hr, string msg)
        {
            if (hr < 0)
            {
                MessageBox.Show(msg);
                DsError.ThrowExceptionForHR(hr);
            }
        }



        private void Elgato_Video_Capture_Load(object sender, EventArgs e)
        {

        }
    }
}

When running the program and showing the form i can hear the sounds of detecting the device in the usb. But after that when the form is showing i don't see anything just the form and nothing on the pictureBox1.

I don't get any errors or exceptions.

0

There are 0 answers