On Sunday, March 31, 2002, at 10:23 PM, Haig C Didizian wrote:
Anyway, I was looking at the mp3 headers from a file, and my calculation of the frame length appears to be wrong, but I can't figure out why. The first frame of the file looks like this:
ff f3 68 64
which tells me that this is a 48kbps MPEG2 Layer-3 file at 16000Hz in joint-stereo, which is true based on what madplay says. I'd like to calculate the frame size based on this info, and using this equation for Layer-III files from http://www.dv.co.yu/mpgscript/mpeghdr.htm -
FrameLengthInBytes = 144 * BitRate / SampleRate + Padding
I calculate that the frame size is 432 bytes. When I scan through the file given this information, I find a total of 1924 frames. When madplay scans through the file, though, it finds twice as many, 3848 frames. So it seems that my frame length is 2x too big. Why does this equation hold for my 128kbps version of the same file, but not for this version (or am I missing something obvious)?
The formula you cite is only correct for MPEG-1 Layer II or Layer III. For MPEG-2 Layer III, the constant 144 should be changed to 72 -- so your frame size is really 216 bytes. This is because MPEG-2 (and MPEG 2.5) Layer III has only one granule per frame, instead of two as in MPEG-1.
On that note, does anyone have any suggestions for an mp3 frame-related resource? The one I mentioned above seems decent, but if there are any better ones, I'd love to know...
I think mp3-tech.org may have some useful resources.
-- Rob Leslie rob@mars.org