How to get specific information about media files (Duration, Bitrate, FPS, etc.)

点点圈 提交于 2019-12-12 04:35:38

问题


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?


回答1:


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.




回答2:


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



来源:https://stackoverflow.com/questions/2159663/how-to-get-specific-information-about-media-files-duration-bitrate-fps-etc

易学教程内所有资源均来自网络或用户发布的内容,如有违反法律规定的内容欢迎反馈
该文章没有解决你所遇到的问题?点击提问,说说你的问题,让更多的人一起探讨吧!