簡體   English   中英

DirectShow.Net播放帶音​​頻的視頻

[英]DirectShow.Net play video with audio

DirectShow.Net包含示例項目DxPlay,該項目播放無音頻的視頻。 我需要修改此項目以使其播放音頻。 我已經讀過我需要添加一個音頻濾波器並連接到引腳,但是我沒有找到一種方法。

這是樣本中設置過濾器的代碼:

// Add the filters necessary to render the file.  This function will
// work with a number of different file types.
IBaseFilter sourceFilter = null;
hr = m_FilterGraph.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 = m_FilterGraph.AddFilter(baseGrabFlt, "Ds.NET Grabber");
DsError.ThrowExceptionForHR(hr);

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

您能提示我如何使它播放音頻嗎?

如果您的視頻被渲染而音頻未被渲染,則附加

icgb2.RenderStream(null, MediaType.Audio, sourceFilter, null, null)

將渲染音頻部分。

只需添加

icgb2.RenderStream(null, null, lavSplitter, null, null);

如果同時存在視頻和音頻,則在構建視頻部分之后,分離器中仍存在音頻輸出引腳。 RenderStream將找到它並進行渲染,並自動插入音頻解碼器和渲染器。

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM