开发者

Get QuickTime metadata: codecs, bitrates, dimensions

I'm finding it difficult to determine how to extract the following information from a QuickTime movie, either using QTKit or the older QuickTime APIs in OS X, targeting 10.5+:

  • Video and audio codecs used (e.g. "H.264")
  • Video and audio bitrates (e.g. 64 kbps)
  • Dimensions

The specific problems I've encountered are:

1) The only means to the video and audio codec names that I've found involve the use of ImageDescriptionHandle and SoundDescriptionHandle, both of which appear to require the Carbon-only methods NewHandleClear and DisposeHandle, as well as requiring the 32-bit only Media object. Is there a more modern method that doesn't require the Carbon framework and is 64-bit compatible?

2) For the bitrate, I'm getting the GetMediaDataSizeTime64 and dividing by the track duration in seconds. However, in the case of one audio track, that method returns a value of 128 kbps, but calling QTSoundDescriptionGetProperty with the audio track media and the kQTAudioPropertyID_FormatString param returns a string of "64 kbps". Why would those two values be different? Is there a better way to calculate a track's bitrate?

3) Dimensions returned by [QTMovie movieAttributes] objectForKey:QTMovieNaturalSizeAttribute] or by [QTTrack attributeForKey:QTTrackDimensionsAttribute] are incorrect for one particular movie. The size returned is 720 x 480, but the actual view size in QuickTime Player is 640 x 480. Player's info window shows a size string of "720 x 480 (640 x 480)". Is there a better way to determine the actual movie dimensions?

Thanks in ad开发者_Go百科vance!


This metadata can be obtained from the [movie tracks] QTTrack* objects.

1) Enumerating through the tracks you can find the video and audio tracks.

QTMedia* media = [track media];

if ([media hasCharacteristic:QTMediaCharacteristicVisual])
{
    // video track
}

if ([media hasCharacteristic:QTMediaCharacteristicAudio])
{
    // audio track
}

The information about codecs:

NSString* summary = [track attributeForKey:QTTrackFormatSummaryAttribute];

2) To calculate the movie's bitrate you need to calculate the total data size of all tracks and divide it on the movie duration.

Enumerating through the tracks get the data size of each track:

QTMedia* media = [track media];
Track quicktimeTrack = [track quickTimeTrack];
TimeValue startTime = 0;
TimeValue duration = GetTrackDuration(quicktimeTrack);
long trackDataSize = GetTrackDataSize(quicktimeTrack, startTime, duration);

3) To get the movie's dimensions

NSSize movieSize = [(NSValue*)[[movie movieAttributes] objectForKey:QTMovieNaturalSizeAttribute] sizeValue];

However, the actual dimensions of the video track may be different:

Fixed width = 0;

Fixed height = 0;

GetTrackDimensions(videoTrack, &width, &height);
0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜