简体   繁体   English

DirectShow.Net播放带音​​频的视频

[英]DirectShow.Net play video with audio

DirectShow.Net contains sample project DxPlay which plays video without audio. DirectShow.Net包含示例项目DxPlay,该项目播放无音频的视频。 I need to modify this project to make it play audio. 我需要修改此项目以使其播放音频。 I have read I need to add an audio filter and connect to pin but I didn't find a way to do it. 我已经读过我需要添加一个音频滤波器并连接到引脚,但是我没有找到一种方法。

Here is the code from the sample that sets filters up: 这是样本中设置过滤器的代码:

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

Could you please hint me how I can make it play audio? 您能提示我如何使它播放音频吗?

If your video is rendered and audio is not, then additional 如果您的视频被渲染而音频未被渲染,则附加

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

will render the audio part. 将渲染音频部分。

Just add 只需添加

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

If there are both video and audio then after building the video part there is still an audio output pin in the splitter. 如果同时存在视频和音频,则在构建视频部分之后,分离器中仍存在音频输出引脚。 RenderStream will find it and render, inserting audio decoder and renderer automatically. RenderStream将找到它并进行渲染,并自动插入音频解码器和渲染器。

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM