MP3 - VBR - Frame length in time

Erik Heneryd erik at
Sun Dec 12 22:30:05 CET 2004

Florian Schulze wrote:
> On Sat, 11 Dec 2004 20:32:30 +0100, Ivo Woltring <TheDolphin at> 
> wrote:
>> mmpython will help but not always.
>> Lets put it this way. I will ALWAYS read through the whole file. In that
>> order I don't mind evaluating each frame. The thing I don't seem to be 
>> able
>> to find is the timelength-constants for frames for the different mp3
>> versions, bitrates and layers. Can anybody help me?
>  From
> "In addition, the number of samples stored in an MP3 frame is constant, 
> at 1,152 samples per frame."
> So you only need the samplerate for each frame to calculate the duration 
> of that frame.
> 1152 samples / 44100 samples per second ~ 0.026 seconds
> I don't exactly know whether you need to include mono/stereo into the 
> calculation, you would have to test that out.
> Regards,
> Florian Schulze

This thread prompted me to dig up some old code I wrote in April 2003 
parsing MPEG audio headers.  Don't remember much about it except I had 
trouble finding reference material.

This is what I used for frame duration:

self.size = (144*self.bitrate) / self.samplerate + self.padding

if self.bitrate:
     self.duration = self.size*8.0/self.bitrate
     self.duration = 0.0

That is, using bitrate instead of samplerate.  More complicated, if you 
don't need the frame size.  However, remember there might be metaframes, 
so the naive samplerate method might be off.  I think most encoders set 
bitrate to 0 for metaframes, but you should check the Xing/Info tag to 
be sure...

Ofcourse, the right way to do it is to parse and use the VBR tag...

I'm attaching my old as-is MPEG code.  Most of that project was lost in 
a disk crash and abandoned, so I don't know what state it's in, but...

-------------- next part --------------
An embedded and charset-unspecified text was scrubbed...
URL: <>

More information about the Python-list mailing list