Previewing Video
Microsoft DirectShow 9.0 |
Previewing Video
To build a video preview graph, call the ICaptureGraphBuilder2::RenderStream method as follows:
ICaptureGraphBuilder2 *pBuild; // Capture Graph Builder // Initialize pBuild (not shown). IBaseFilter *pCap; // Video capture filter. /* Initialize pCap and add it to the filter graph (not shown). */ hr = pBuild->RenderStream(&PIN_CATEGORY_PREVIEW, &MEDIATYPE_Video, pCap, NULL, NULL);
This example assumes the following:
- pBuild was initialized, as described in About the Capture Graph Builder.
- pCap was initialized, by creating an instance of the capture filter and adding it to the filter graph, as described in Selecting a Capture Device.
The first parameter to the RenderStream method specifies a pin category; for a preview graph, use PIN_CATEGORY_PREVIEW. The second parameter specifies a media type, as a major type GUID. For video, use MEDIATYPE_Video. DV devices deliver interleaved audio and video, for which the media type is MEDIATYPE_Interleaved. (For more information about DV capture, see Digital Video in DirectShow.)
The third parameter is a pointer to the capture filter's IBaseFilter interface. The next two parameters are not needed in this example. They are used to specify additional filters that might be needed to render the stream. Setting the last parameter to NULL causes the Capture Graph Builder to select a default renderer for the stream, based on the media type. For video, the Capture Graph Builder always uses the Video Renderer filter as the default renderer.
- **Note **In Windows XP, although the Video Mixing Renderer (VMR) is the default video renderer for IGraphBuilder methods, it is not the default renderer for the RenderStream method. On any platform, the Capture Graph Builder always uses the old Video Renderer filter unless you specify otherwise.
Although the pin category is given as PIN_CATEGORY_PREVIEW, it does not matter whether the filter actually has a preview pin; it could have a video port pin or just a capture pin. In either case, the Capture Graph Builder automatically builds the correct graph.
The following diagram shows the simplest possible graph for previewing video.
In this diagram, the capture filter has a preview pin, which connects directly to the video renderer.
If the capture filter has only a capture pin, the Capture Graph Builder inserts a Smart Tee filter, which splits the stream into a capture stream and a preview stream. This is described in more detail in Combining Video Capture and Preview.
In some cases, the video stream must go through the Overlay Mixer filter. If so, the RenderStream method adds it to the graph automatically.
See Also