关于directshow 播放视频的问题

syj8905760 2008-04-26 10:53:30
我想用ISampleGrabber来将avi视频中截图。代码如下。但现在的问题是,为什么在播放avi视频时,只有图像,没有声音出来。哪位高手指点一下啊
        
private void SetupGraph(Control hWin, string FileName)
{
int hr;

// Get the graphbuilder object
m_graphBuilder = new FilterGraph() as IFilterGraph2;

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

try
{
// Link the ICaptureGraphBuilder2 to the IFilterGraph2
hr = icgb2.SetFiltergraph(m_graphBuilder);
DsError.ThrowExceptionForHR( hr );

#if DEBUG
// Allows you to view the graph with GraphEdit File/Connect
m_DsRot = new DsROTEntry(m_graphBuilder);
#endif
// Add the filters necessary to render the file. This function will
// work with a number of different file types.
IBaseFilter sourceFilter = null;
hr = m_graphBuilder.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_graphBuilder.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 );

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

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

// Grab some other interfaces
m_mediaEvent = m_graphBuilder as IMediaEvent;
m_mediaCtrl = m_graphBuilder as IMediaControl;
}
finally
{
if (icgb2 != null)
{
Marshal.ReleaseComObject(icgb2);
icgb2 = null;
}
}
#if DEBUG
// Double check to make sure we aren't releasing something
// important.
GC.Collect();
GC.WaitForPendingFinalizers();
#endif
}
...全文
82 5 打赏 收藏 转发到动态 举报
写回复
用AI写文章
5 条回复
切换为时间正序
请发表友善的回复…
发表回复
knowledge_Is_Life 2008-05-01
  • 打赏
  • 举报
回复
支持搂主,收藏
gjh1987a 2008-05-01
  • 打赏
  • 举报
回复
c#不怎么懂,audio render没连好吧!
syj8905760 2008-04-27
  • 打赏
  • 举报
回复
rageliu,
你是用的vc吗?
vc里是怎么写的?我刚接触directshow,很多都不太懂。
rageliu 2008-04-27
  • 打赏
  • 举报
回复
C#不熟,确定audio的pin有render了吗?

2,543

社区成员

发帖
与我相关
我的任务
社区描述
专题开发/技术/项目 多媒体/流媒体开发
社区管理员
  • 多媒体/流媒体开发社区
加入社区
  • 近7日
  • 近30日
  • 至今
社区公告
暂无公告

试试用AI创作助手写篇文章吧