Search code examples
objective-ccocoamultimediaspotlight

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


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?


Solution

  • 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.