1.加入Sample Grabber Filter
当我们加入Sample Grabber Filter的时候,我们可以直接调用其接口(interface)ISampleGrabber。该接口可以获取经过该Filter的单独的Media Samples。详情请参见DXSDK。
1.1 派生出自己的Sample Grabber
从ISampleGrabberCB中派生出自己的类,然后实现其虚函数,详情请参见SDK中的示例程序(DXSDK ROOT/Samples/C++/DirectShow/Editing/GrabBitmaps)。
1.2 直接调用Sample Grabber Filter的接口
如果我们在播放的过程中动态的加入Filter的话,操作和效率都不乐观。所以我采用下面的方法:
该方法传递的是时间,不是在播放的时候动态加入Filter然后截图,而是另外打开源文件进行操作。
A)。申明以下接口:
#001 IGraphBuilder *pGraph = NULL; //for graph builder
#002 IMediaControl *pControl = NULL; //media control
#003 IMediaSeeking *pSeeking = NULL; //media seeking
#004 IMediaEventEx *pEvent = NULL; //media envent
#005 IBaseFilter *pNullFilter =NULL;//for holding the Sample grabber Filter
B)。初始化接口:
#001 JIF(CoCreateInstance(CLSID_FilterGraph, NULL, CLSCTX_INPROC,
#002 IID_IGraphBuilder, (void **)&pGraph));
#003
#004 JIF(CoCreateInstance(CLSID_NullRenderer, NULL, CLSCTX_INPROC,
#005 IID_IBaseFilter, (void **)&pNullFilter));
#006 JIF(pGraph->QueryInterface(IID_IMediaControl,(void **)&pControl));
#007 JIF(pGraph->QueryInterface(IID_IMediaSeeking, (void **)&pSeeking));
#008 JIF(pGraph->QueryInterface(IID_IMediaEvent, (void **)&pEvent));
C)。创建Sample Grabber
#001 // Create the Sample Grabber.
#002 IBaseFilter *pGrabberF = NULL;
#003 JIF(CoCreateInstance(CLSID_SampleGrabber,NULL, CLSCTX_INPROC_SERVER,
#004 IID_IBaseFilter, (void**)&pGrabberF));
#005
#006 JIF(pGraph->AddFilter(pGrabberF, L"Sample Grabber"));
#007 JIF(pGraph->AddFilter(pNullFilter, L"Null Render Filter"));
#008
#009 ISampleGrabber *pGrabber;
#010 JIF(pGrabberF->QueryInterface(IID_ISampleGrabber, (void**)&pGrabber));
设置Sample Grabber的媒体格式:调用SetMediaType,该函数接受一个AM_MEDIA_TYPE的结构,主要是设置该结构中的majortype,和subtype域。
D)。添加Source Filter