Using the Media Detector
Microsoft DirectShow 9.0 |
Using the Media Detector
The media detector is a helper object that can retrieve information about a file, such as the number of streams, their type, and their duration. It also contains methods for retrieving poster frames from a video stream. It exposes the IMediaDet interface.
The media detector operates in one of two modes. When you create an instance of the media detector, it is not attached to a particular source file. In this mode, you can retrieve stream information from multiple source files. However, once you use the media detector to obtain a poster frame, it switches to bitmap grab mode. In bitmap grab mode, the media detector is attached to a specific video stream, and the stream information methods no longer work. Moreover, there is no way to switch the media detector back to its starting mode. Therefore, obtain any stream information you need before retrieving poster frames, or else create new instances of the media detector for each stream.
To obtain stream information, do the following:
- Call IMediaDet::put_Filename with the name of the source file.
- Call IMediaDet::get_OutputStreams to obtain the number of streams in the source.
- Specify a stream number with IMediaDet::put_CurrentStream. Then call one or more of the following methods:
- IMediaDet::get_StreamType: Retrieves the stream's media type.
- IMediaDet::get_StreamLength: Retrieves the duration of the stream.
- IMediaDet::get_FrameRate: Retrieves a video stream's frame rate.
To obtain a poster frame, specify the stream number, as in the previous step. Then call either IMediaDet::GetBitmapBits, which copies a poster frame into a buffer, or IMediaDet::WriteBitmapBits, which saves a poster frame to a file.