如何获取有关媒体文件的特定信息(持续时间、比特率、FPS 等)

发布于 2024-08-19 17:19:13 字数 375 浏览 6 评论 0原文

我需要获取与使用 Finder 时通过“获取信息”获取的信息相同的信息;更具体地说,我需要“更多信息”部分中存在的相同信息,例如持续时间、比特率、尺寸、编解码器、音频通道等。

要获取大小、类型等基本信息,我有:

// Getting the file's attributes
NSError *error;
NSFileManager *fm = [NSFileManager defaultManager];
NSDictionary *fileInfo = [fm attributesOfItemAtPath:fileName error:&error];

是否有任何原生 Cocoa图书馆获取此信息?

I need to get the same kind of info that you can get on "Get Info" when using Finder; more specifically I need the same info that is present in the "More Info" section, like Duration, Bitrate, Dimension, Codecs, Audio channels, etc.

To get the basic info like size, type, I have:

// Getting the file's attributes
NSError *error;
NSFileManager *fm = [NSFileManager defaultManager];
NSDictionary *fileInfo = [fm attributesOfItemAtPath:fileName error:&error];

Is there any native Cocoa library to get this info?

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

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

发布评论

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

评论(2

混吃等死 2024-08-26 17:19:13

我需要获得与使用 Finder 时“获取信息”相同的信息,更具体地说,我需要与“更多信息”部分中存在的相同信息,例如持续时间、比特率、维度、编解码器、音频通道等

按照 Finder 的方式进行操作:Spotlight。 (不要让路径中的“Carbon”一词吓跑您:它是核心服务的一部分,因此可以 64 位使用。)只需为您感兴趣的文件实例化一个 MDItem。

另一种方法是使用 Foundation 自己的该框架的包装器(包含在该页面上),但是您需要执行一个 NSMetadataQuery 来搜索 kMDItemPath 是您感兴趣的文件的路径的项目。很多不必要的麻烦——直接使用 MDItem 会让你更快地到达目的地。

一个不错的好处是,它不仅仅适用于视频和音频文件。图像文件还具有 Finder 和您的应用程序可以显示的元数据。

I need to get the same kind of info that you can get on "get info" when using Finder, more specifically I need the same info that is present on "more info" section, like Duration, Bitrate, Dimension, Codecs, Audio channels, etc.

Do it the same way the Finder does: Spotlight. (Don't let the word “Carbon” in the path scare you off: It's part of Core Services, so it is available in 64-bit.) Just instantiate an MDItem for the file you're interested in.

Another way would be to use Foundation's own wrapper of that framework (which is included on that page), but then you need to do an NSMetadataQuery that searches for items whose kMDItemPath is the path to the file you're interested in. A lot of needless hassle—using MDItem directly will get you there faster.

A nice bonus is that this works for more than just video and audio files. Image files also have metadata that Finder and your app can show.

澜川若宁 2024-08-26 17:19:13

创建一个 QTMovie 实例,然后使用 -movieAttributes 消息查询其属性。

Create a QTMovie instance, and then query its properties with a -movieAttributes message.

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