mpeg framesize

D Bera dbera.web at gmail.com
Fri Oct 6 05:42:48 CEST 2006


>   I was having some problem with the duration of a vbr mpeg file and
> then i ran into the problem of a faulty Xing header. That lead me to
> the source of taglib and lame (mpglib) to figure out how they compute
> framesize. Now, I dont have much expertise in these things so I
> compared the framesize calculation in lame and taglib. And I found
> some differences!!!
>
> In taglib/taglib/mpeg/mpegheader.cpp :
>
> if(d->layer == 1)
> -       d->frameLength = 24000 * 2 * d->bitrate / d->sampleRate +
> int(d->isPadded);
> +      d->frameLength = (12000 * d->bitrate / d->sampleRate +
> int(d->isPadded))*4;
> else if (d->layer == 2)
> -       d->frameLength = 72000 * d->bitrate / d->sampleRate + int(d->isPadded);
> +      d->frameLength = 144000 * d->bitrate / d->sampleRate + int(d->isPadded);
> else if (d->layer == 3)
> -       d->frameLength = 72000 * d->bitrate / d->sampleRate + int(d->isPadded);
> +      d->frameLength = 144000 * d->bitrate / d->sampleRate /
> (d->version == Version1 ? 1 : 2) + int(d->isPadded);
>
> Diff computed against the logic used in
> http://lame.cvs.sourceforge.net/lame/lame/mpglib/common.c
>
> Maybe someone here can tell me which is the correct logic ? (I couldnt
> find any 'free' reliable source of MPEG standard :P). I am writing a
> simple tool to fix faulty xing headers in some of my vbr mp3 files and
> it will be helpful to know the correct way to compute framelength.

There was also some other inconsistency in how the duration was
calculated. I am attaching a patch fixing all these. Dunno if the
calculation logic is correct; no reliable header information at hand.
I based my calculations on lame(mpglib) source code and
http://www.codeproject.com/audio/mpegaudioinfo.asp
Thanks,

- dBera

-- 
-----------------------------------------------------
Debajyoti Bera @ http://dtecht.blogspot.com
beagle / KDE fan
Mandriva / Inspiron-1100 user
-------------- next part --------------
A non-text attachment was scrubbed...
Name: taglib-mp3.patch
Type: text/x-patch
Size: 1742 bytes
Desc: not available
Url : http://mail.kde.org/pipermail/taglib-devel/attachments/20061005/3cfdfe43/attachment-0001.bin 


More information about the taglib-devel mailing list