1

我有简单的代码来捕获网络摄像头视频并将其存储在文件中,但它什么也不做,也没有给我任何错误我使用 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();

当我启动应用程序时,它应该开始录制,但我什么也没得到我的代码有什么问题以及如何解决它谢谢

4

0 回答 0