Q How do I get the pixel depth of the QuickTime video media for a
given track?
A To find the video media pixel depth, retrieve the media's image
description handle. You can use GetMediaSampleDescription to get it, but this routine needs
both the video media and the track's index number. It's not obvious, but a media's type is
identified by its media handler's type. Thus, you can walk through a movie's tracks by using
its indexes until you find video media, at which point you have both the track index and
video media.
The following sample code does the trick:
Media GetFirstVideoMedia(Movie coolMovie, long *trackIndex)
{
Track coolTrack = nil;
Media coolMedia = nil;
long numTracks;
OSType mediaType;
numTracks = GetMovieTrackCount(coolMovie);
for (*trackIndex=1; *trackIndex<=numTracks; (*trackIndex)++) {
coolTrack = GetMovieIndTrack(coolMovie, *trackIndex);
if (coolTrack) coolMedia = GetTrackMedia(coolTrack);
if (coolMedia) GetMediaHandlerDescription(coolMedia,
&mediaType, nil, nil);
if (mediaType = VideoMediaType) return coolMedia;
}
*trackIndex = 0; // trackIndex can't be 0
return nil; // went through all tracks and no video
}
short GetFirstVideoTrackPixelDepth(Movie coolMovie)
{
SampleDescriptionHandle imageDescH =
(SampleDescriptionHandle)NewHandle(sizeof(Handle));
long trackIndex = 0;
Media coolMedia = nil;
coolMedia = GetFirstVideoMedia(coolMovie, &trackIndex);
if (!trackIndex || !coolMedia) return -1; // we need both
GetMediaSampleDescription(coolMedia, trackIndex, imageDescH);
return (*(ImageDescriptionHandle)imageDescH)->depth;
}
Note that QuickTime 2.0 has a new function called GetMovieIndTrackType that
does most of the work described in the sample. GetMovieIndTrackType lets you
search for all of a movie's tracks that share a given media type or media
characteristic. See the QuickTime 2.0 SDK documentation for more details.
[May 01 1995]
|