如何获取有关媒体文件的特定信息(持续时间、比特率、FPS 等)
我需要获取与使用 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 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论
评论(2)
按照 Finder 的方式进行操作:Spotlight。 (不要让路径中的“Carbon”一词吓跑您:它是核心服务的一部分,因此可以 64 位使用。)只需为您感兴趣的文件实例化一个 MDItem。
另一种方法是使用 Foundation 自己的该框架的包装器(包含在该页面上),但是您需要执行一个 NSMetadataQuery 来搜索
kMDItemPath
是您感兴趣的文件的路径的项目。很多不必要的麻烦——直接使用 MDItem 会让你更快地到达目的地。一个不错的好处是,它不仅仅适用于视频和音频文件。图像文件还具有 Finder 和您的应用程序可以显示的元数据。
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.
创建一个
QTMovie
实例,然后使用-movieAttributes
消息查询其属性。Create a
QTMovie
instance, and then query its properties with a-movieAttributes
message.