mp3x is a lightweight command-line scanner for MP3 files, which reports length and other metadata in an easily parsed way. In addition, it provides basic support for displaying and setting ID3 tags (all of id3v1, id3v2, id3v2.4). mp3x is not an MPEG decoder, and cannot be used to play MP3 files.
The program is intended to be similar in style to the wc(1) program, in that it displays information about the input file in a format which is intended to be stable and parseable.
For example:
$ mp3x test01-1-3.mp3 TRCK=1 TALB=Whistling TYER=2010 TIT2=Whistle 1 TPE1=Norman Gray 20 522 test01-1-3.mp3 $
or
$ mp3x -ntT test01-1-3.mp3 20 522 0:00.522 $
or (from v0.4)
$ mp3x -Fjson test01-1-3.mp3
{ "nframes": 20,
"duration": 522,
"filename": "test01-1-3.mp3",
"duration-hms": "0:00.522",
"id3": {
"TRCK": "1",
"TALB": "Whistling",
"TYER": "2010",
"TIT2": "Whistle 1",
"TPE1": "Norman Gray"
}}
$or (from v0.5)
$ mp3x -Fsexp test01-1-3.mp3 ((nframes . 20) (duration . 522) (filename . "test/other/test01-1-3.mp3") (duration-hms . "0:00.522") (id3 (TCON . "Speech") (TRCK . "1") (TALB . "Whistling") (TYER . "2010") (TDRC . "2010") (TIT2 . "Whistle 1") (TPE1 . "Norman Gray"))) $
The principal goals of this program are:
The program is intended to remain lightweight, and no major changes are planned. The program can help with basic editing of ID3 information: that turns out to be handy, but it's not regarded as core.
The program does not rely on any external library. The functions in the included modules are not intended to be thread-safe (ie, they use some static storage), but it would not be a huge project to make them so.
The antecedents of this program are that I wanted the length-of-an-MP3 functionality as part of a larger project, couldn't find it, quickly wrote it, and thought it might be more generally useful.
There are (of course) many other MP3 and ID3 programs available, some of them very reliable, others less so. Surprisingly, however, it's hard to find any which can report an MP3 file's duration, on the command-line, in a script-friendly way.
The program overlaps in functionality with mp3info. Differences: mp3info can report a broader range of information, in arbitrary formats, but is restricted to ID3v1; mp3x aims to produce easily parseable output, and supports ID3v2. It would be reasonably straightforward to adapt mp3x to extract and report further technical information, if there were any call for it.
THe distribution includes a Python module mp3x.py, which illustrates how one might wrap the JSON output of the program in a useful way.
https://purl.org/nxg/dist/mp3x (please quote this, rather than whatever page it redirects to)$ ./configure $ make $ make check $ make install
Use 'man mp3x' (or 'man ./mp3x.1') to look at the documentation.
To build from a checkout, ensure that autoconf is installed, and prefix the above with ./bootstrap.
PORTABILITY: The program is intended, and expected, to be portable to any C compiler or POSIX system.
The program is expected to be robust and correct, and to cope with any valid MPEG2 file. It is distributed with almost 2MB of test files, including a suite of ISO/MPEG layer 2 test files. Any failures to parse MPEG2 files are bugs: do let me know about these.
MPEG-1 is described in ISO/IEC 11172-3. MPEG-2 is described in ISO/IEC 13818-3. MPEG-2.5 is a common extension, but isn't formally standardised. The Wikipedia overview is useful. There is a very practical discussion of the header format at mpgedit.org.
The ID3 ‘standard’ (scare-quotes very much required) is nominally at http://www.id3.org/id3v2.3.0, but the site seems to have disappeared (as of mid-2023). The content is archived at archive.org.
The program is distributed under the terms of the 2-clause BSD licence. See the file LICENCE.txt for details.
Norman Gray https://nxg.me.uk