1

i have simple code to capture webcam video ans store it in file but it does nothing and didn't give me any error i use WPFMediaKit and this is my code

        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);


        }

and calling like this

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

            videoCaptureElement.Play();

when i start application it supposed to start recording but i get nothing what gets wrong in my code and how to fix it thanks

xmedeko
  • 7,336
  • 6
  • 55
  • 85
Ma7moud El-Naggar
  • 548
  • 1
  • 6
  • 18

0 Answers0