在C#中使用GMFPreview添加ISampleGrabber过滤器 [英] Add ISampleGrabber filter using GMFPreview in C#

查看:60
本文介绍了在C#中使用GMFPreview添加ISampleGrabber过滤器的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!

问题描述





我有以下代码使用GMFPreview桥捕获和预览。它的工作正常。现在我需要添加样本Grabber过滤器,以便我可以使用SetMode函数捕获图像并行而不会出现任何故障。请告诉我如何在此块中添加样本抓取器过滤器。



我尝试了很多但无法实现。请帮忙,因为我是新手。



Hi,

I have below code to capture and preview using GMFPreview bridge. Its working fine. Now i need to add sample Grabber filter so that i can capture image parallel without any glitch using SetMode function. Please let me know how to add sample grabber filter in this block.

I tried a lot but not able to achieve. Please help as i am new to this.

// Specify a device, and a window to draw the preview in
   public void
   SelectDevice(DsDevice dev, IntPtr hwnd)
   {
       int hr;
       IBaseFilter pfDevice = null;
       ICaptureGraphBuilder2 pBuilder = null;

       try
       {
           // create source graph and add sink filter
           m_pSourceGraph = (IGraphBuilder)new FilterGraph();
           m_rot1 = new DsROTEntry(m_pSourceGraph);

           m_pBridge = (IGMFBridgeController)new GMFBridgeController();

           // init to video-only, in discard mode (ie when source graph
           // is running but not connected, buffers are discarded at the bridge)
           hr = m_pBridge.AddStream(true, eFormatType.MuxInputs, true);
           DsError.ThrowExceptionForHR(hr);

           // Add the requested device
           hr = ((IFilterGraph2)m_pSourceGraph).AddSourceFilterForMoniker(dev.Mon, null, dev.Name, out pfDevice);
           DsError.ThrowExceptionForHR(hr);


           // Add the sink filter to the source graph
           hr = m_pBridge.InsertSinkFilter(m_pSourceGraph, out m_pSourceGraphSinkFilter);
           DsError.ThrowExceptionForHR(hr);

           // use capture graph builder to render preview
           pBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();

           // Init the CaptureGraphBuilder2
           hr = pBuilder.SetFiltergraph(m_pSourceGraph);
           DsError.ThrowExceptionForHR(hr);

           // Connect the filters together to allow preview
           hr = pBuilder.RenderStream(PinCategory.Preview, MediaType.Video, pfDevice, null, null);
           DsError.ThrowExceptionForHR(hr);

           // connect capture output to the pseudo-sink filter,
           // where it will be discarded until required
           hr = pBuilder.RenderStream(PinCategory.Capture, MediaType.Video, pfDevice, null, m_pSourceGraphSinkFilter);
           DsError.ThrowExceptionForHR(hr);


           // turn off capture stream if possible except when capturing
           hr = pBuilder.FindPin(pfDevice, PinDirection.Output, PinCategory.Capture, MediaType.Video, false, 0, out m_pCapOutput);
           if (hr >= 0)
           {
               IAMStreamControl pSC = (IAMStreamControl)m_pCapOutput;
               pSC.StartAt(NEVER, 0);  // Ignore any error
           }


           ConfigureVideo(hwnd);

           IMediaControl pMC = (IMediaControl)m_pSourceGraph;

           hr = pMC.Run();
           DsError.ThrowExceptionForHR(hr);

           // If we made it here, the device is selected
           m_DeviceSelected = true;
       }
       catch
       {
           ReleaseSelectMembers();
           throw;
       }
       finally
       {
           if (pBuilder != null)
           {
               Marshal.ReleaseComObject(pBuilder);
           }

           if (pfDevice != null)
           {
               Marshal.ReleaseComObject(pfDevice);
           }

           Saved_m_pSourceGraph = m_pSourceGraph;
       }
   }

推荐答案

m_sampleGrabber = (ISampleGrabber)new SampleGrabber();                   
SetupSampleGrabber(m_sampleGrabber);
hr = m_pSourceGraph.AddFilter(m_sampleGrabber as IBaseFilter, "SampleGrabber");
DsError.ThrowExceptionForHR(hr);





类似的东西



Something like that


这篇关于在C#中使用GMFPreview添加ISampleGrabber过滤器的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!

查看全文
登录 关闭
扫码关注1秒登录
发送“验证码”获取 | 15天全站免登陆