Question

All,
I have a shell script on Mac OS X which uses the mdls command to fetch the Total bit-rate meta-attribute for all media files (mp3,mov,m4v etc.). I want to compare the output with a set threshold (XY Kbps) and raise a flag if the bit-rate exceeds XY for a media file. The issue is that the output doesn't denote if it's in Kbps or bits per second. For example I ran the mdls command on 2 audio files test1.m4a and test2.mp3 :

   mdls -name kMDItemTotalBitRate test1.m4a   
   Output -> kMDItemTotalBitRate = 249


   mdls -name kMDItemTotalBitRate test2.mp3   
   Output -> kMDItemTotalBitRate = 192000

On checking in iTunes , I saw that the number was 249 kbps for the former and 192 kbps for the latter. How can I force the mdls command to output kMDItemTotalBitRate in bits per second only so that the output is uniform for all files and removes confusion?

Was it helpful?

Solution

As Ken Thomases correctly states in his comment, you are at the mercy of the Spotlight importer that stores the value when working with Spotlight attributes. Note Apple’s MDItem documentation omits all indication of the unit in which kMDItemTotalBitRate, a raw numeric value, should be measured. One might logically expect this to be bps, what with bps being the base bit rate unit, but there is no way to normalize stored values to bps if the Importer decides otherwise.

An alternative to relying on Spotlight would be to analyze the file with a utility like MediaInfo (which can be installed using homebrew). The command

mediainfo '--Inform=General;%BitRate%' "/path/to/your/media file"

will return the bit rate of any supported media file, reliably in bps.

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top