On Thursday 07 November 2002 17:52, Russell O'Connor wrote:
-----BEGIN PGP SIGNED MESSAGE----- Hash: SHA1
[To: sebastian@trueg.de, mad-dev@lists.mars.org]
On Thu, 7 Nov 2002, Sebastian Trueg wrote:
Hy list, is there a good and fast way to test if a file actually is a mp3 file or not? My attempts with decoding some bytes at the beginning of the file do not work...
I was thinking about this problem recently. I was planning on implementing the following.
Read the first 4 bytes A B C D
if ABC = ID3, then it's MP3 (It might be better to skip the ID3 header and then ensure the following holds)
or if ABCD form a valid MP3 header, then it's MP3. Otherwise not MP3.
To check if it's a valid header, I'd ensure
A = FF B & 0xE0 = E0 B & 0x18 != 0x08 B & 0x06 != 0 C & 0xF0 != 0xF0 C & 0x0C != 0x0C D & 0x03 != 0x02
I'd be interested in other's opinions of this detection algorithm.
I think that's manly what the file command (mimemagic) checks. But I also found some corrupt mp3 files which mad is able to decode but which do neither start with an id3 tag nor with the specific byte pattern. One of them even had a wave header. Ok, now one could argue that files like this should not be detected as mp3 but mad is able to decode them so I intend to let it :)
Russell O'Connor http://www.math.berkeley.edu/~roconnor/ ``[Law enforcement officials] suggested that the activists were stopped not because their names are on the list, but because their names resemble those of suspected criminals or terrorists.'' -- SFGate.com -----BEGIN PGP SIGNATURE----- Version: GnuPG v1.0.6 (SunOS) Comment: For info see http://www.gnupg.org
iD8DBQE9yppTuZUa0PWVyWQRAuvcAJ42lsOMXrZZckfcYOt1RuNdaGwccQCdEqwk ByG4seF0/yIQMtLRt9Ox2Iw= =AqCB -----END PGP SIGNATURE-----