You can obtain information on an audio file, such as an MP3 file on a Mac OS X system from the command line using the
afinfo
command.
$ afinfo Waterfalls.mp3 File: Waterfalls.mp3 File type ID: MPG3 Num Tracks: 1 ---- Data format: 2 ch, 44100 Hz, '.mp3' (0x00000000) 0 bits/channel, 0 bytes/packet, 1152 frames/packet, 0 bytes/frame no channel layout. estimated duration: 3642.644850 sec audio bytes: 72852897 audio packets: 139445 bit rate: 160000 bits per second packet size upper bound: 1052 maximum packet size: 523 audio data file offset: 2228 optimized audio 160637484 valid frames + 528 priming + 2628 remainder = 160640640 ----
The command will tell you the bit rate and the estimated duration if you choose to play the file. In the example above, the MP3 bitrate is 160 kbit/s, which is a mid-range bitrate quality for an MP3 file. Common bitrates for MP3 files are as follows:
- 32 kbit/s – generally acceptable only for speech
- 96 kbit/s – generally used for speech or low-quality streaming
- 128 or 160 kbit/s – mid-range bitrate quality
- 192 kbit/s – a commonly used high-quality bitrate
- 320 kbit/s – highest level supported by MP3 standard
The estimated playing time of the MP3 file in the example above is 3642.644850 sec. You can convert that to minutes from the command line by passing a command to python to convert seconds to minutes.
$ python -c "print 3642.644850 / 60" 60.7107475
If you wanted to convert that to hours, you could just divide by 60 minutes per hour by adding another "/ 60" at the end of the command.
$ python -c "print 3642.644850 / 60 / 60" 1.01184579167
If you just want to know the bit rate, you can pipe the output of afinfo through grep and awk:
$ afinfo Waterfalls.mp3 | grep "bit rate" | awk '{print $3}' 160000
If you just want to know the duration in seconds, you can use the following commands:
$ afinfo Waterfalls.mp3 | grep "estimated duration" | awk '{print $3}' 3642.644850
If you want the value in minutes you can also use awk to print that value instead.
$ afinfo Waterfalls.mp3 | grep "estimated duration" | awk '{print $3 / 60 , "minutes"}' 60.7107 minutes