quoth the John Joyce:
> On Aug 15, 2007, at 7:23 PM, Adam Shelly wrote:
> > On 8/15/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 know for sure that:
> > = wave files start with the characters 'RIFF' followed by 4 bytes
> > (filesize-8) followed by 'WAVE'.
> > = ogg vorbis files start with 'oggS' followed by 24 bytes then 0x01
> > and the string 'vorbis'
> > = MIDI files start with 'MThd'
> >
> > and according to wikipedia (and verified with one file on my system)
> > = MP3 files should start with 0xFF FB or 0xFF FA.
> >
> > -Adam
>
> Thanks Adam, that's the kind of thing I'm looking for exactly.
> If anyone can contribute more audio file magic numbers, please do!

The first 4 bytes of a Flac file must be 0x66, 0x4C, 0x61, and 0x43, 
ie: 'fLaC'.

> I guess video/AV files should be next as well, primarily things
> like .mov, .wmv, etc...

.wma/.wmv are a bit trickier. You can do:

-----------------------------
def byteStringToGUID(byteString)
  guidString  = sprintf("%02X", byteString[3])
  guidString += sprintf("%02X", byteString[2])
  guidString += sprintf("%02X", byteString[1])
  guidString += sprintf("%02X", byteString[0])
  guidString += '-'
  guidString += sprintf("%02X", byteString[5])
  guidString += sprintf("%02X", byteString[4])
  guidString += '-'
  guidString += sprintf("%02X", byteString[7])
  guidString += sprintf("%02X", byteString[6])
  guidString += '-'
  guidString += sprintf("%02X", byteString[8])
  guidString += sprintf("%02X", byteString[9])
  guidString += '-'
  guidString += sprintf("%02X", byteString[10])
  guidString += sprintf("%02X", byteString[11])
  guidString += sprintf("%02X", byteString[12])
  guidString += sprintf("%02X", byteString[13])
  guidString += sprintf("%02X", byteString[14])
  guidString += sprintf("%02X", byteString[15])
end

fh = File.new("example.wma", "rb")
id = byteStringToGUID(fh.read(16))
if id == '75B22630-668E-11CF-A6D9-00AA0062CE6C'
  puts "Valid wma/wmv file"
else
  "Not a wma/wmv"
end
--------------------------

This will work for anything in an ASF wrapper.

Your best bet to find this info for other files is to find and read the 
respective specs. These should be easy to track down using Wikipedia's audio 
and video codec categories. Usually there is a direct link to the spec, or at 
least the official site for the codec.

HTH

-d
-- 
darren kirby :: Part of the problem since 1976 :: http://badcomputer.org
"...the number of UNIX installations has grown to 10, with more expected..."
- Dennis Ritchie and Ken Thompson, June 1972