如何取得摄像头视频数据流?不要保存,我需要使用socket发送到目标服务端。高手请帮帮忙!

解决方案 »

  1.   

    参考DirectShow.NET:http://directshownet.sourceforge.net/
      

  2.   

    基本的思路是用DirectShow,枚举硬件,得到摄像头的句柄,从摄像头的上下文设备中获取数据流,这个数据流你可以通过网络传输出去,也可以解码后送显。
      

  3.   

    DirectShow.NET中有例子,你可以看一下
      

  4.   

    private void SetupGraph(DsDevice dev, string szOutputFileName)
    {
                int hr;            IBaseFilter capFilter = null;
                IBaseFilter asfWriter = null;
        ICaptureGraphBuilder2 capGraph = null;            // Get the graphbuilder object
                m_graphBuilder = (IFilterGraph2)new FilterGraph();#if DEBUG
                m_rot = new DsROTEntry( m_graphBuilder );
    #endif            try
                {
                    // Get the ICaptureGraphBuilder2
                    capGraph = (ICaptureGraphBuilder2) new CaptureGraphBuilder2();                // Start building the graph
                    hr = capGraph.SetFiltergraph( m_graphBuilder );
                    Marshal.ThrowExceptionForHR( hr );                // Add the capture device to the graph
                    hr = m_graphBuilder.AddSourceFilterForMoniker(dev.Mon, null, dev.Name, out capFilter);
                    Marshal.ThrowExceptionForHR( hr );                asfWriter = ConfigAsf(capGraph, szOutputFileName);                hr = capGraph.RenderStream(null, null, capFilter, null, asfWriter);
                    Marshal.ThrowExceptionForHR( hr );                m_mediaCtrl = m_graphBuilder as IMediaControl;
                }
                finally
                {
                    if (capFilter != null)
                    {
                        Marshal.ReleaseComObject(capFilter);
                        capFilter = null;
                    }
                    if (asfWriter != null)
                    {
                        Marshal.ReleaseComObject(asfWriter);
                        asfWriter = null;
                    }
                    if (capGraph != null)
                    {
                        Marshal.ReleaseComObject(capGraph);
                        capGraph = null;
                    }
                }
            }哪里是取流的地方?
      

  5.   

    主要是这三句
    hr = m_graphBuilder.AddSourceFilterForMoniker(dev.Mon, null, dev.Name, out capFilter);
    asfWriter = ConfigAsf(capGraph, szOutputFileName);
    hr = capGraph.RenderStream(null, null, capFilter, null, asfWriter);
      

  6.   

    hr = capGraph.RenderStream(null, null, capFilter, null, asfWriter);
      

  7.   

    看看http://blog.csdn.net/libiegoupan/archive/2004/09/02/92547.aspx可能对你有用
      

  8.   

    hr就其本质来说,的确就是int。看来lz对DirectShow知之甚少啊,还是先补补这方面的课吧,否则越朝后就越困难了。
      

  9.   

    在DirextShow中hr定义成HRESULT,是一个长整刑的,他的返回值代表一个接口的。返回值为0则代表成功,非零代表错误或者一个状态号。真正得到流且送显的是capGraph.RenderStream(null, null, capFilter, null, asfWriter);跟进去看看。
      

  10.   

    跟进去就出不来了。呵呵。越来越看不懂。哪位给指点一下?        [PreserveSig]
            int RenderStream(
                [In, MarshalAs(UnmanagedType.LPStruct)] DsGuid PinCategory,
                [In, MarshalAs(UnmanagedType.LPStruct)] DsGuid MediaType,
                [In, MarshalAs(UnmanagedType.IUnknown)] object pSource,
                [In] IBaseFilter pfCompressor,
                [In] IBaseFilter pfRenderer
                );
      

  11.   

    DirectShow在.NET上用的人还是少,要讨论到流媒体专题去吧。
    最好自己看看这方面的书,因为别人能给你的帮助毕竟是有限的。
      

  12.   

    yespie,能否把你的成果共享一下,非常不好意思,取得摄像头视频数据流显示在什么控件中
      

  13.   

    yespie,能发给我看看吗?[email protected]向你学习!
      

  14.   

    yespie..能否把代码也发给我看一下..
    谢谢..我