Get MP3 & M4A File Info with afinfo from Command Line of OS X
The fastest way to get MP3 and m4a file info out of Mac OS X is using the Terminal and afinfo command. The command line tool you’ll want to use stands for Audio File Info, rather appropriately. You can try it out yourself with any audio file, though for the purposes here we’re looking at an mp3 or m4a file.
To get started, launch the Terminal and type this at the command line, specifying the path to the audio file to retrieve meta info and file details about:
afinfo PATH/To/File.xxx
For example, let’s say there’s a document called “filename.mp3” in the iTunes folder:
afinfo ~/Music/iTunes/filename.mp3
A series of information will then be reported back, looking perhaps something like the following:
File: ~/Music/iTunes/iTunes Music/Empire of the Sun/Empire of the Sun - Girl.mp3
File type ID: MPG3
Data format: 2 ch, 144100 Hz, '.mp3' (0x00000000) 0 bits/channel, 0 bytes/packet, 1152 frames/packet, 0 bytes/frame
no channel layout.
estimated duration: 238.629 sec
audio bytes: 9545142
audio packets: 9135
bit rate: 320000 bits per second
packet size upper bound: 1052
maximum packet size: 1045
audio data file offset: 10302
optimized
This command works on with any audio file and is not limited to MP3’s. We have covered afinfo in the past when checking the bitrate of an audio file.
If you just type ‘afinfo’ you’ll get a nice list of options for the command, which there is quite a bit you can do with the afinfo tool so it should be fun for audiophiles in particular:
$ afinfo
Audio File Info
Version: 2.0
Copyright 2003-2013, Apple Inc. All Rights Reserved.
Specify -h (-help) for command options
Usage:
afinfo [option...] audio_file(s)
Options: (may appear before or after arguments)
{-h --help}
print help
{-b --brief}
print a brief (one line) description of the audio file
{-r --real}
get the estimated duration after obtaining the real packet count
{ --leaks }
run leaks at the end of the conversion
{ -i --info }
print contents of the InfoDictionary
{ -x --xml }
print output in xml format
{ --warnings }
print warnings if any (by default warnings are not printed in non-xml output mode)
This has a myriad of potential uses besides just getting file data about audio formats, have fun and let us know what you use it for.
Why no corresponding support for m4a files on Windows? I can’t find a single utility that will give this information on Windows.
Because this is about getting file info on m4a and mp4 files from the command line on a Mac.
I think you meant “afinfo” not “afplay”!
Good catch and you are right, it looks like the author didn’t have his coffee this morning!
Post has been updated accordingly, thank you.
– Manish