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...
Thanx for help.
Cheers, Sebastian
-----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.
- -- 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
The best way that I've found to attempt to find a synch pattern, decode the frame (which gives you the frame length) and see if the next frame is a valid frame (i.e. is valid synch).
This won't guarantee that the whole file is valid but it does indicate that it contains at least one (probably two) valid MP3 frames.
Erik Turner
-- Original Message ----- From: "Sebastian Trueg" sebastian@trueg.de To: mad-dev@lists.mars.org Sent: Thursday, November 07, 2002 5:35 AM Subject: [mad-dev] test if file is mp3
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...
Thanx for help.
Cheers, Sebastian
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-----
Sebastian,
Here is an example program I wrote in Delphi to scan all the MP3 frames within a file. http://www.ectsoftware.com:8000/demo.zip
Erik Turner
----- Original Message ----- From: "Sebastian Trueg" sebastian@trueg.de To: "Erik Turner" erik@turner.org Sent: Thursday, November 07, 2002 12:34 PM Subject: Re: [mad-dev] test if file is mp3
Hmm... I tried this but since I'm not that deep into mad.... how do I search for a sync? Do you have a code example? That would be great! :)
Sebastian:
On Thu, 2002-11-07 at 02:35, 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...
Check sourceforge for mp3-check. It seems to work well.
Neil