无法使用WPFMediaKit捕获网络摄像头视频

时间:2012-03-16 14:02:40

标签: wpf video-capture directshow.net wpf-mediakit

我有简单的代码来捕获网络摄像头视频并将其存储在文件中 但它什么也没做,并没有给我任何错误 我使用WPFMediaKit,这是我的代码

        IFilterGraph2 filterGraph;
        ICaptureGraphBuilder2 captureGraphBuilder;
        IBaseFilter captureDeviceFilter;
        DsDevice currentDevice;

        private void InitInterfaces(DsDevice device)
        {
            int hr;
            filterGraph = new FilterGraph() as IFilterGraph2;
            captureGraphBuilder = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;
            hr = captureGraphBuilder.SetFiltergraph(filterGraph);
            DsError.ThrowExceptionForHR(hr);

            currentDevice = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice)[0];
            currentDevice = device;
            hr = filterGraph.AddSourceFilterForMoniker(currentDevice.Mon, null,       currentDevice.Name, out captureDeviceFilter);
            DsError.ThrowExceptionForHR(hr);

            IFileSinkFilter sink;
            IBaseFilter mux;
            hr = captureGraphBuilder.SetOutputFileName(MediaSubType.Avi, @"ss.avi", out mux, out sink);
            DsError.ThrowExceptionForHR(hr);

            hr = captureGraphBuilder.RenderStream(PinCategory.Capture, MediaType.Video, captureDeviceFilter, null, mux);
            DsError.ThrowExceptionForHR(hr);

            hr = captureGraphBuilder.RenderStream(PinCategory.Preview, MediaType.Video, captureDeviceFilter, null, null);
            DsError.ThrowExceptionForHR(hr);


        }

并像这样打电话

     DsDevice[] devices = DsDevice.GetDevicesOfCat(FilterCategory.VideoInputDevice);
            DsDevice device = devices[0] as DsDevice;
            videoCaptureElement.VideoCaptureDevice = device ;
            InitInterfaces(device);

            videoCaptureElement.Play();

当我开始应用它应该开始录制但我什么都没得到 我的代码中出了什么问题以及如何修复它 谢谢

0 个答案:

没有答案