Objective
DirectShow is a Microsoft-provided development package for streaming media processing on Windows platforms, published with the DirectX development package. DirectShow provides a powerful support for capturing and playback of multimedia streaming. Using DirectShow to develop the application, we can easily capture data from the acquisition card that supports the WDM drive model, and do the corresponding post-processing and even store it in the file.
DirectShow is COM based, and in order to write a DirectShow application, you need to understand the basics of COM client programming. DirectShow provides a large number of interfaces, but it is not easy to find in the programming, if you can build a video capture class to encapsulate some of the commonly used actions, then it is more convenient.
Programming Ideas
To make it easier to build a video capture application, DirectShow provides an object called Capture Graph builder, Capture graph Builder provides the IcaptureGraphBuilder2 interface, The interface can establish and control capture Graph.
To establish a video capture program, you must first obtain and initialize the IcaptureGraphBuilder2 interface, and then select an appropriate video capture device. After selecting a good device, create capture filter for the device, and then call AddFilter to add capture filter to filter Graph.
If you just want to use the camera for real-time monitoring, just call Icapturegraphbuilder2::renderstream on the above basis:
ICaptureGraphBuilder2 *pBuild; // Capture Graph Builder
//省略初始化部分代码
IBaseFilter *pCap; // Video capture filter.
//省略初始化和添加到Filter Graph部分代码
pBuild-> RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video, pCap, NULL, NULL);
DirectShow provides a way to capture a static image: Using the sample grabber filter. Follow these three steps in turn:
The first step is to define a class that implements the callback interface for sample grabber ISAMPLEGRABBERCB:
class CSampleGrabberCB : public ISampleGrabberCB
{
//在后面提供的类中具体完成
}
CSampleGrabberCB mCB;
The second step, call Renderstream, in turn, still pin, Sample grabber and system default renderer filter are connected.