Hi,
On 8/16/07, John Joyce <dangerwillrobinsondanger / gmail.com> wrote:
> Does anybody know how to identify (validate) mp3 files (other audio
> files would be interesting as well) by 'magic number'?
> I never trust file extensions to be correct. It's to easy for users
> to accidentally munge file names in a GUI or even for malicious users
> to try bad things by simply changing file names.
>
> Any library or code is welcome!
> Daniel Berger said he'd even add it to Ptools or a similar library if
> it gets posted on Ruby-Talk.
>
> I did find this online as a purported mp3 magic number (in hex of
> course),
> 49 44 33
> but I'm not even going to bother using it since I don't know
> definitively that all mp3's will have it, and I don't know where to
> expect it in the file.http://en.wikipedia.org/wiki/MP3
This explains it all:
http://upload.wikimedia.org/wikipedia/commons/0/01/Mp3filestructure.svg
So first byte should be 0xFF, second byte & 0xFE should equal 0xFA.
that is only for layer-3.
However if the MP3 has ID3v1 tags then it will start with "ID3".
Best regards.
--
Felipe Contreras