[FFmpeg-user] mp3 duration is not correct

Oliver Fromme oliver at fromme.com
Thu Jul 17 17:32:20 CEST 2014


Moritz Barsnick wrote:
 > On Thu, Jul 17, 2014 at 13:05:38 +0000, Carl Eugen Hoyos wrote:
 > > > http://www.maknoon.com/download/audios/quran/alafasy/114.mp3
 > > I opened ticket #3777 - thank you for the sample!
 > 
 > MP3Diags GUI (is there no command line version of this? d'uh) reports:
 > "Frame count mismatch between the Xing header and the audio stream."
 > 
 > Is ffmpeg supposed to analyze the latter?

I've had a look at this 114.mp3 file (I'm somewhat familiar
with MPEG audio, being former co-author of mpg123).

This file is the result of concatenating two distinct mp3
files with Xing/LAME headers.  This is sometimes called a
"Frankenstein" mp3.

The first section is 6.79 seconds (109086 bytes), and the
second section is 47.18 seconds (754824 bytes, starting at
offset 0x1aa1e).  I haven't looked at ffmpeg's mp3 code, but
it seems that it only looks at the Xing/LAME header of the
first section, not noticing that another file was appended
to it.

It is debatable if this really a "bug" in ffmpeg, because
the Xing header is non-standard in the first place (as are
the various variants of "id3" tags).  But I guess people
expect it to work, so ...

The solution is rather simple:  The Xing header contains a
field that holds the length of the file in bytes.  Just
seek to that position and check if there's another header
(instead of EOF that should normally be there).  If there
is, then a concatenated file follows.  This procedure has
to be repeated, in case that more than two files were
concatenated.

Best regards
   Oliver


-- 
``We are all but compressed light'' (Albert Einstein)

Donations: http://www.amazon.de/wishlist/A0LHFK68RV8S


More information about the ffmpeg-user mailing list