C#DirectShow RenderStream没有音频

时间:2013-04-28 20:59:23

标签: c# audio render directshow

我正在使用DirectShow.NET,我需要编写一个显示自定义字幕的视频播放器。

我的代码基于样本的Capture.cs,以下是相关部分:

private void SetupGraph(string FileName, Control hWin)
    {
        int hr;
        ISampleGrabber m_sampGrabber = null;
        IGraphBuilder gb = null;

        // Get the graphbuilder object
        m_FilterGraph = new FilterGraph() as IFilterGraph2;
        gb = m_FilterGraph as IGraphBuilder;

        // Get a ICaptureGraphBuilder2 to help build the graph
        ICaptureGraphBuilder2 icgb2 = new CaptureGraphBuilder2() as ICaptureGraphBuilder2;

        try
        {
            // Link the ICaptureGraphBuilder2 to the IFilterGraph2
            hr = icgb2.SetFiltergraph(gb);
            DsError.ThrowExceptionForHR(hr);
            // Add the filters necessary to render the file.  This function will
            // work with a number of different file types.
            IBaseFilter sourceFilter = null;
            hr = gb.AddSourceFilter(FileName, FileName, out sourceFilter);
            DsError.ThrowExceptionForHR(hr);

            // Get the SampleGrabber interface
            m_sampGrabber = (ISampleGrabber)new SampleGrabber();
            IBaseFilter baseGrabFlt = (IBaseFilter)m_sampGrabber;

            // Configure the Sample Grabber
            ConfigureSampleGrabber(m_sampGrabber);

            // Add it to the filter
            hr = gb.AddFilter(baseGrabFlt, "Ds.NET Grabber");
            DsError.ThrowExceptionForHR(hr);

            hr = gb.RenderFile(FileName, null);
            DsError.ThrowExceptionForHR(hr);

            // Configure the Video Window
            IVideoWindow videoWindow = gb as IVideoWindow;
            ConfigureVideoWindow(videoWindow, hWin);

            // Connect the pieces together, use the default renderer
            hr = icgb2.RenderStream(null, null, sourceFilter, baseGrabFlt, null);
            DsError.ThrowExceptionForHR(hr);


            // Now that the graph is built, read the dimensions of the bitmaps we'll be getting
            SaveSizeInfo(m_sampGrabber);

            // Configure the Video Window
            videoWindow = gb as IVideoWindow;
            ConfigureVideoWindow(videoWindow, hWin);
            hr = videoWindow.put_MessageDrain(hWin.FindForm().Handle);

        }
...

正如您所看到的,现在我正在播放2个视频,其中一个用RenderFile()打开以获得音频,另一个用RenderStream可以在其上放置一个字幕(因此是两个videoWindow配置)。

它显然不是最佳解决方案,但我不知道如何通过RenderStream获取音频。

0 个答案:

没有答案