获取 QuickTime 元数据:编解码器、比特率、维度

发布于 2024-12-08 11:49:08 字数 969 浏览 1 评论 0原文

我发现很难确定如何使用 QTKit 或 OS X 中较旧的 QuickTime API(针对 10.5+)从 QuickTime 影片中提取以下信息:

  • 使用的视频和音频编解码器(例如“H.264”)
  • 视频和音频比特率(例如 64 kbps)
  • 尺寸

我遇到的具体问题是:

1)我发现的视频和音频编解码器名称的唯一方法涉及使用ImageDescriptionHandleSoundDescriptionHandle,两者似乎都需要仅 Carbon 的方法 NewHandleClearDisposeHandle,以及仅需要 32 位媒体对象。是否有一种更现代的方法不需要 Carbon 框架并且兼容 64 位?

2)对于比特率,我获取 GetMediaDataSizeTime64 并除以曲目持续时间(以秒为单位)。但是,对于一个音轨,该方法返回 128 kbps 的值,但使用音轨媒体和 kQTAudioPropertyID_FormatString 参数调用 QTSoundDescriptionGetProperty 会返回一串“ 64 kbps”。为什么这两个值会不同?有没有更好的方法来计算曲目的比特率?

3) 对于某一特定电影,[QTMovie movieAttributes] objectForKey:QTMovieNaturalSizeAttribute][QTTrack attributeForKey:QTTrackDimensionsAttribute] 返回的尺寸不正确。返回的尺寸为 720 x 480,但 QuickTime Player 中的实际视图尺寸为 640 x 480。播放器的信息窗口显示尺寸字符串“720 x 480 (640 x 480)”。有没有更好的方法来确定实际的电影尺寸?

提前致谢!

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 advance!

如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。

扫码二维码加入Web技术交流群

发布评论

需要 登录 才能够评论, 你可以免费 注册 一个本站的账号。

评论(1

雪落纷纷 2024-12-15 11:49:08

此元数据可以从 [movie Track] QTTrack* 对象获取。

1)通过轨道枚举可以找到视频和音频轨道。

QTMedia* media = [track media];

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

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

有关编解码器的信息:

NSString* summary = [track attributeForKey:QTTrackFormatSummaryAttribute];

2) 要计算电影的比特率,您需要计算所有轨道的总数据大小并将其除以电影持续时间。

枚举轨道得到每个轨道的数据大小:

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

3) 获取电影的尺寸

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

但是,视频轨道的实际尺寸可能会有所不同:

Fixed width = 0;

Fixed height = 0;

GetTrackDimensions(videoTrack, &width, &height);

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);
~没有更多了~
我们使用 Cookies 和其他技术来定制您的体验包括您的登录状态等。通过阅读我们的 隐私政策 了解更多相关信息。 单击 接受 或继续使用网站,即表示您同意使用 Cookies 和您的相关数据。
原文