Microsoft DirectX 9.0

MediaDet Object

Retrieves information about a media file, such as the number of streams and the type, duration, and frame rate of each stream. This object also contains methods for retrieving poster frames from a video stream.

To obtain information about a file, perform the following steps:

  1. Create a new instance of the MediaDet object.
  2. Set the Filename property to specify the name of the source file.
  3. Retrieve the OutputStreams property to obtain the number of output streams in the source.
  4. Set the CurrentStream property to specify a particular stream.
  5. Retrieve any of the following properties: StreamType, StreamMediaType, StreamLength, or FrameRate.

To retrieve poster frames, call WriteBitmapBits. This method puts the MediaDet object into a new mode, called bitmap grab mode. The informational methods described previously do not work in this mode. Therefore, get any information you need before retrieving poster frames, or else create new instances of the MediaDet object for each stream.

The MediaDet object ignores any streams in the file that are not video or audio. For example, if the file contains an audio stream, a data stream, and a video stream, the OutputStreams property will report only two streams (the audio and video).

Code Example

Dim Det As New MediaDet
Const VideoGUID As String = "{73646976-0000-0010-8000-00AA00389B71}"
bFoundVidStream = False

Det.FileName = "C:\Media\Example.avi"

' Look for a video stream.
For i = 0 To Det.OutputStreams - 1
    Det.CurrentStream = i
    StreamType = Det.StreamTypeB
    If StrComp(StreamType, VideoGUID, vbTextCompare) = 0 Then
        bFoundVidStream = True
        Exit For
    End If
Next

If bFoundVidStream Then
    ' Update the label with the duration.
    VideoInfo.Caption = Det.FileName + ": " + Str(Det.StreamLength) + " seconds"
    
    ' Load a poster frame.
    TempFile = "C:\Temp.bmp"
    Preview.ScaleMode = vbPixels  ' Scale twips to pixels.
    Det.WriteBitmapBits 0, Preview.ScaleWidth, Preview.ScaleHeight, TempFile
    Preview.Picture = LoadPicture(TempFile)
End If

This object has the following properties and methods.

Property Description
CurrentStream Stream number currently used by the MediaDet object.
Filename Name of the source file currently used by the MediaDet object.
Filter Not supported for Visual Basic.
OutputStreams Number of audio and video streams contained in the media source.
FrameRate Frame rate of the current stream, in frames per second.
StreamLength Duration of the current stream, in seconds.
StreamMediaType Not supported for Visual Basic.
StreamType Not supported for Visual Basic.
StreamTypeB String representing the GUID of the media type for the current stream.

Method Description
EnterBitmapGrabMode Switches the MediaDet object to bitmap grab mode and seeks the filter graph to a specified time.
GetBitmapBits Not supported for Visual Basic.
GetSampleGrabber Not supported for Visual Basic.
WriteBitmapBits Retrieves a poster frame at the specified media time and writes it to a file.

Requirements

Include a reference in your project to "Dexter 1.0 Type Library" (Qedit.dll).