Skip to main content

Topic: Frame Size (Read 8061 times) previous topic - next topic

0 Members and 1 Guest are viewing this topic.
Frame Size
Hi all (1st post;) )

My application needs to calculate

song lenght
vbr or cbr?
bitrate
samplerate

what i do is:

open mp3 and jump to first frame header
read bitrate, sampelrate, padding
calc framesize
frameCount++
jump to next frameheader

1)
i found the following formula: FrameSize = 144 * BitRate / (SampleRate + Padding)
i dont really unterstand the  /( ...+padding)
it means with padding flag, the frame size is lower. i think with padding flag set, there are 8bits more!?
isnt it like:
FrameSize = (int) ((144 * BitRate / SampleRate) + Padding)

so, for 128kb/s 44khz mp3 its 417byts without padding, and 418 with padding.

2)
what exactly means "VBR" or "CBR" ?how many frames have to differ from others bitrate, to be VBR? in my test mp3s never all the frames have the same bitrate.

3)
how can i calculate the framsize in case  bitrate bits = 0%0000 (free?) ?


thx4help!

  • pdq
  • [*][*][*][*][*]
Frame Size
Reply #1
1) The padding byte is added occasionally so that the bit rate, which can result in a non-integer number of bytes per frame, can come out even.

2) The only way a file can be CBR is if ALL of the frames have exactly the same bit rate.

  • smack
  • [*][*][*]
Frame Size
Reply #2
1)
isnt it like:
FrameSize = (int) ((144 * BitRate / SampleRate) + Padding)
so, for 128kb/s 44khz mp3 its 417byts without padding, and 418 with padding.

Yes, that's correct for MPEG-1, where each frame contains 1152 samples.
For MPEG-2 LSF (with 576 samples per frame) the factor is 72 instead of 144.

Quote
2)
what exactly means "VBR" or "CBR" ?how many frames have to differ from others bitrate, to be VBR? in my test mp3s never all the frames have the same bitrate.

The "V" is for "variable" and the "C" is for "constant". If it's not constant, then it's variable.
Therefore, an mp3 file is VBR if not all frames have the same bitrate. Or in other words, it is VBR if at least one frame has a bitrate that differs from the others.

Quote
3)
how can i calculate the framsize in case  bitrate bits = 0%0000 (free?) ?

You can't.
When you have found the first frame header which indicates "free bitrate", you have to search the file for the second frame header and use the "distance" between these two frame headers (i.e. the framesize) to calculate the bitrate.


I'd suggest you also have a look at the source code of some existing decoders to learn more about such details, for example MAD MPEG Audio Decoder

  • DualIP
  • [*][*]
Frame Size
Reply #3
For VBR files, check if the first frame has a"xing" vbr header.
From the data it contains, you can get stuff like playtime without reading the entire file

  • Firon
  • [*][*][*][*][*]
Frame Size
Reply #4
Sometimes they might have a VBRI header, but I'm not sure what encoders produce that.

  • Mangix
  • [*][*][*][*][*]
Frame Size
Reply #5
there's also ABR...

  • Firon
  • [*][*][*][*][*]
Frame Size
Reply #6
ABR is merely restricted VBR, and is treated as VBR. There is no difference to the player.

Frame Size
Reply #7
hey thx:)

1)
isnt it like:
FrameSize = (int) ((144 * BitRate / SampleRate) + Padding)
so, for 128kb/s 44khz mp3 its 417byts without padding, and 418 with padding.

Yes, that's correct for MPEG-1, where each frame contains 1152 samples.
For MPEG-2 LSF (with 576 samples per frame) the factor is 72 instead of 144.


ok, i think i keep the formula, and only change the bitrate.  i can use 144, if i take the same sample rate values.

what about the protection bit?
Protection bit
0 - Protected by CRC (16bit CRC follows header)
1 - Not protected

is framesize +2bytes if bit is 0 ?

whats that:??

ipod converter
  • Last Edit: 29 April, 2007, 08:24:37 AM by klabautermack

  • robert
  • [*][*][*][*][*]
  • Developer
Frame Size
Reply #8