我正在使用DirectShow.NET創建攝像頭控件。我想將相機的視頻渲染到WPF窗口中。目前發生的事情是,IVMRWindowlessControl9
似乎沒有進入無窗口模式,並且沒有被指定給我的窗口,即使我正在調用適當的方法。IVMRWindowlessControl9未呈現到父級WPF窗口
爲什麼這些方法不被調用?還有什麼我不是在做什麼?
下面是相關的代碼片段:
IGraphBuilder graphBuilder = (IGraphBuilder) new FilterGraph();
ICaptureGraphBuilder2 captureGraphBuilder = (ICaptureGraphBuilder2)new CaptureGraphBuilder2();
IMediaControl mediaControl = (IMediaControl) this.graphBuilder;
IBaseFilter renderFilter = (IBaseFilter) new VideoMixingRenderer9();
hr = this.captureGraphBuilder.SetFiltergraph(this.graphBuilder);
DsError.ThrowExceptionForHR(hr);
IBaseFilter sourceFilter = FindCaptureDevice();
hr = this.graphBuilder.AddFilter(sourceFilter, "Video Capture");
DsError.ThrowExceptionForHR(hr);
SetCaptureResolution();
IVMRFilterConfig9 filterConfig = (IVMRFilterConfig9)renderFilter;
hr = filterConfig.SetNumberOfStreams(1);
DsError.ThrowExceptionForHR(hr);
hr = filterConfig.SetRenderingMode(VMR9Mode.Windowless);
DsError.ThrowExceptionForHR(hr);
windowlessControl = (IVMRWindowlessControl9)renderFilter;
hr = this.graphBuilder.AddFilter(renderFilter, "Video Capture");
DsError.ThrowExceptionForHR(hr);
Window window = Window.GetWindow(this);
var wih = new WindowInteropHelper(window);
IntPtr hWnd = wih.Handle;
hr = windowlessControl.SetVideoClippingWindow(hWnd);
DsError.ThrowExceptionForHR(hr);
hr = windowlessControl.SetAspectRatioMode(VMR9AspectRatioMode.LetterBox);
DsError.ThrowExceptionForHR(hr);
hr = this.captureGraphBuilder.RenderStream(PinCategory.Capture, MediaType.Video, sourceFilter, null, null);
DsError.ThrowExceptionForHR(hr);
Marshal.ReleaseComObject(sourceFilter);
hr = this.mediaControl.Run();
DsError.ThrowExceptionForHR(hr);
要回答潛在的問題(因爲我有這個問題p ),是的,hWnd
正在設置/有一個值 - 所以windowlessControl確實有一個指向窗口的指針。
'SetNumberOfStreams'可能爲時過早,'SetRenderingMode'應該[首先](https://msdn.microsoft.com/en-us/library/windows/desktop/dd407299)。 ActiveMovie窗口表示視頻渲染器未設置。您的有效過濾器圖表可能不是您期望的圖表。請參閱[瞭解您的DirectShow過濾器圖表](http://alax.info/blog/1678)。具體來說,你的有效圖表可能有兩個渲染器。 –
@RomanR。 http://imgur.com/a/wjjm5 - 這是我在應用程序運行時捕獲的過濾器圖形圖像的鏈接。這看起來很正常嗎? –