[linux-audio-user] "file" isn't too smart about MP3 files

New Message Reply About this list Date view Thread view Subject view Author view Other groups

Subject: [linux-audio-user] "file" isn't too smart about MP3 files
From: Charles G Waldman (cgw_AT_alum.mit.edu)
Date: Mon Feb 04 2002 - 19:12:41 EET


I've noticed that the "file" command isn't often too good at
identifying MP3 files - most Linux boxes I've tried this on just
identify them as "data". If you have such a system, this may interest
you.

Digging around a bit on the 'net, I found up with the following, which
can be appended to your "magic" file (which can usually be found
somewhere under /usr/share). Also, if the following line (or similar)
is in your magic file, you should comment it out:

0 beshort&0xfff0 0xfff0 MPEG audio stream data

Once you've updated the magic file, you get this:

prompt% file 10*June*
10 - June.mp3: MPEG 1.0 Layer III, 192 kbit/s, 44100 Hz stereo

Unfortunately, the presence of ID3v2 tags at the beginning of the file
complicates things: the ID3 tag header is variable-sized, and must not
contain any FF's - so the length field is encoded as a 28-bit int,
stuffed into 4 bytes with the high bits unused. Although file(1) can
handle variable-length headers by means of "indirect offsets", this
encoding is not something that file(1) can handle. So, if you have
tagged files, you just get:

prompt% file 10*Pure*
10_Pure And Easy.mp3: mp3 file with ID3 2.0 tag

I think it would require some substantial mods to "file(1)" to handle
this. I'm going to take a crack at doing this, but don't hold your
breath.

In any case, it still an improvement over calling them "data".

References:
  http://mail-index.netbsd.org/netbsd-bugs/1998/11/24/0003.html
  ftp://ftp.astron.com/pub/file/

---------snip here--------

#------------------------
# MPEG: file(1) magic for MPEG audio.
#
# From <ckane_AT_best.com>
# Show MPEG level, layer, kbit/s, hz, stereo/mono for an MPG audio file.
# This section is lengthy because the kbit/s rate depends on the
# level and layer, and file(1) doesn't allow math on the values.
#

####### MPEG begins with three hex 'f' nibbles.
0 beshort&0xfff0 0xfff0 MPEG
####### Level 2
>1 byte&0x08 0x00 2.0
>>1 byte&0x06 0x00 Layer Unknown,
####### Level 2, Layers I, II, and III
>>1 byte&0x06 0x02 Layer III,
>>>2 byte&0xf0 0x00 0 kbit/s,
>>>2 byte&0xf0 0x10 8 kbit/s,
>>>2 byte&0xf0 0x20 16 kbit/s,
>>>2 byte&0xf0 0x30 24 kbit/s,
>>>2 byte&0xf0 0x40 32 kbit/s,
>>>2 byte&0xf0 0x50 40 kbit/s,
>>>2 byte&0xf0 0x60 48 kbit/s,
>>>2 byte&0xf0 0x70 56 kbit/s,
>>>2 byte&0xf0 0x80 64 kbit/s,
>>>2 byte&0xf0 0x90 80 kbit/s,
>>>2 byte&0xf0 0xa0 96 kbit/s,
>>>2 byte&0xf0 0xb0 112 kbit/s,
>>>2 byte&0xf0 0xc0 128 kbit/s,
>>>2 byte&0xf0 0xd0 144 kbit/s,
>>>2 byte&0xf0 0xe0 160 kbit/s,
>>>2 byte&0xf0 0xf0 ? kbit/s,
>>1 byte&0x06 0x04 Layer II,
>>>2 byte&0xf0 0x00 0 kbit/s,
>>>2 byte&0xf0 0x10 8 kbit/s,
>>>2 byte&0xf0 0x20 16 kbit/s,
>>>2 byte&0xf0 0x30 24 kbit/s,
>>>2 byte&0xf0 0x40 32 kbit/s,
>>>2 byte&0xf0 0x50 40 kbit/s,
>>>2 byte&0xf0 0x60 48 kbit/s,
>>>2 byte&0xf0 0x70 56 kbit/s,
>>>2 byte&0xf0 0x80 64 kbit/s,
>>>2 byte&0xf0 0x90 80 kbit/s,
>>>2 byte&0xf0 0xa0 96 kbit/s,
>>>2 byte&0xf0 0xb0 112 kbit/s,
>>>2 byte&0xf0 0xc0 128 kbit/s,
>>>2 byte&0xf0 0xd0 144 kbit/s,
>>>2 byte&0xf0 0xe0 160 kbit/s,
>>>2 byte&0xf0 0xf0 ? kbit/s,
>>1 byte&0x06 0x06 Layer I,
>>>2 byte&0xf0 0x00 0 kbit/s,
>>>2 byte&0xf0 0x10 32 kbit/s,
>>>2 byte&0xf0 0x20 48 kbit/s,
>>>2 byte&0xf0 0x30 56 kbit/s,
>>>2 byte&0xf0 0x40 64 kbit/s,
>>>2 byte&0xf0 0x50 80 kbit/s,
>>>2 byte&0xf0 0x60 96 kbit/s,
>>>2 byte&0xf0 0x70 112 kbit/s,
>>>2 byte&0xf0 0x80 128 kbit/s,
>>>2 byte&0xf0 0x90 144 kbit/s,
>>>2 byte&0xf0 0xa0 160 kbit/s,
>>>2 byte&0xf0 0xb0 176 kbit/s,
>>>2 byte&0xf0 0xc0 192 kbit/s,
>>>2 byte&0xf0 0xd0 224 kbit/s,
>>>2 byte&0xf0 0xe0 256 kbit/s,
>>>2 byte&0xf0 0xf0 ? kbit/s,
####### Level 2, Hz
>>2 byte&0x0c 0x00 22050 Hz
>>2 byte&0x0c 0x04 24000 Hz
>>2 byte&0x0c 0x08 16000 Hz
>>2 byte&0x0c 0x0c ? Hz
####### Level 1 decoding
>1 byte&0x08 0x08 1.0
>>1 byte&0x06 0x00 Layer Unknown.
####### Level 1, Layers I, II, and III
>>1 byte&0x06 0x02 Layer III,
>>>2 byte&0xf0 0x00 0 kbit/s,
>>>2 byte&0xf0 0x10 32 kbit/s,
>>>2 byte&0xf0 0x20 40 kbit/s,
>>>2 byte&0xf0 0x30 48 kbit/s,
>>>2 byte&0xf0 0x40 56 kbit/s,
>>>2 byte&0xf0 0x50 64 kbit/s,
>>>2 byte&0xf0 0x60 80 kbit/s,
>>>2 byte&0xf0 0x70 96 kbit/s,
>>>2 byte&0xf0 0x80 112 kbit/s,
>>>2 byte&0xf0 0x90 128 kbit/s,
>>>2 byte&0xf0 0xa0 160 kbit/s,
>>>2 byte&0xf0 0xb0 192 kbit/s,
>>>2 byte&0xf0 0xc0 224 kbit/s,
>>>2 byte&0xf0 0xd0 256 kbit/s,
>>>2 byte&0xf0 0xe0 320 kbit/s,
>>>2 byte&0xf0 0xf0 ? kbit/s,
>>1 byte&0x06 0x04 Layer II,
>>>2 byte&0xf0 0x00 0 kbit/s,
>>>2 byte&0xf0 0x10 32 kbit/s,
>>>2 byte&0xf0 0x20 48 kbit/s,
>>>2 byte&0xf0 0x30 56 kbit/s,
>>>2 byte&0xf0 0x40 64 kbit/s,
>>>2 byte&0xf0 0x50 80 kbit/s,
>>>2 byte&0xf0 0x60 96 kbit/s,
>>>2 byte&0xf0 0x70 112 kbit/s,
>>>2 byte&0xf0 0x80 128 kbit/s,
>>>2 byte&0xf0 0x90 160 kbit/s,
>>>2 byte&0xf0 0xa0 192 kbit/s,
>>>2 byte&0xf0 0xb0 224 kbit/s,
>>>2 byte&0xf0 0xc0 256 kbit/s,
>>>2 byte&0xf0 0xd0 320 kbit/s,
>>>2 byte&0xf0 0xe0 384 kbit/s,
>>>2 byte&0xf0 0xf0 ? kbit/s,
>>1 byte&0x06 0x06 Layer I,
>>>2 byte&0xf0 0x00 0 kbit/s,
>>>2 byte&0xf0 0x10 32 kbit/s,
>>>2 byte&0xf0 0x20 64 kbit/s,
>>>2 byte&0xf0 0x30 96 kbit/s,
>>>2 byte&0xf0 0x40 128 kbit/s,
>>>2 byte&0xf0 0x50 160 kbit/s,
>>>2 byte&0xf0 0x60 192 kbit/s,
>>>2 byte&0xf0 0x70 224 kbit/s,
>>>2 byte&0xf0 0x80 256 kbit/s,
>>>2 byte&0xf0 0x90 288 kbit/s,
>>>2 byte&0xf0 0xa0 320 kbit/s,
>>>2 byte&0xf0 0xb0 352 kbit/s,
>>>2 byte&0xf0 0xc0 384 kbit/s,
>>>2 byte&0xf0 0xd0 416 kbit/s,
>>>2 byte&0xf0 0xe0 448 kbit/s,
>>>2 byte&0xf0 0xf0 ? kbit/s,
####### Level 2, Hz
>>2 byte&0x0c 0x00 44100 Hz
>>2 byte&0x0c 0x04 48000 Hz
>>2 byte&0x0c 0x08 32000 Hz
>>2 byte&0x0c 0x0c ? Hz
####### Stereo or Mono
>3 byte&0xc0 0x00 stereo
>3 byte&0xc0 0x40 joint-stereo
>3 byte&0xc0 0x80 dual-channel
>3 byte&0xc0 0xc0 mono

0 string ID3 mp3 file with ID3 2.0 tag


New Message Reply About this list Date view Thread view Subject view Author view Other groups

This archive was generated by hypermail 2b28 : Mon Feb 04 2002 - 19:01:37 EET