12682

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

Question:

I need to get the same kind of info that you can get on <strong>"Get Info"</strong> 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?

Answer1:

<blockquote>

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.

</blockquote>

Do it the same way the Finder does: <a href="http://developer.apple.com/mac/library/documentation/Carbon/Reference/SpotlightReference_Collection/" rel="nofollow">Spotlight</a>. (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.

Answer2:

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

Recommend

  • NSFileManager URL vs Path
  • Are there any cases where it's better to use [NSFileManager defaultManager] rather than [[NSFil
  • Audio file doesn't play in iPhone 5
  • How to refresh a QFileSystemModel in a QTreeView after files change through another process?
  • Sorting an array of files for rename
  • DocumentsDirectory in UITableView Array for Xcode 7 and Swift 2.0
  • How to remove end of string (fileName) using substring?
  • how to get all installed applications with Objective C in OSX
  • Special Characters on Console
  • maven-cobertura-plugion does not show the sources [closed]
  • how to implement `Jackson AnnotationIntrospector`?
  • UICollectionview scroll horizontal and vertical
  • Encoding issue with ASIHttpRequest
  • Error: java.util.Arrays$ArrayList cannot be cast to java.util.ArrayList
  • Simple script doesn't show anything on the Output in LuaEdit
  • Passing and ArrayList through intent
  • C#, “Object reference not set to an instance of an object.” error
  • CSS table cell alignment and ellipsis not working
  • Use neo4j server instead of embedded mode
  • Automapper missing type map configuration or unsupported mapping
  • Are there any libraries for Python to simulate keyboard action?
  • didUpdatePushCredentials not get called
  • Pass Dictionary to Javascript array
  • Build Successful but not running on simulator
  • List images(01.png) and descriptions(01.txt) from directory
  • how to upload multiple files in c# windows application
  • How to change the font size of a single index for UISegmentedControl?
  • How to install a .deb file on a jailbroken iphone programmatically?
  • Handling un-mapped Rest path
  • Can I have the cursor start on a particular column by default in jqgrid's edit mode?
  • Google cloud sdk not working when python points python3
  • Rearranging Cells in UITableView Bug & Saving Changes
  • Circular dependency while pushing http interceptor
  • Is there a mandatory requirement to switch app.yaml?
  • Linker errors when using intrinsic function via function pointer
  • Hits per day in Google Big Query
  • FormattedException instead of throw new Exception(string.Format(…)) in .NET
  • Linking SubReports Without LinkChild/LinkMaster
  • XCode 8, some methods disappeared ? ex: layoutAttributesClass() -> AnyClass
  • reshape alternating columns in less time and using less memory