[MPlayer-users] wrong length and bitrate with FLAC

Ilja Sekler ilja_sekler_ at gmx.de
Sun Nov 25 21:19:00 CET 2012


Am 25.11.2012 20:56, schrieb Reimar Döffinger:

> On Sun, Nov 25, 2012 at 07:33:50PM +0100, Ilja Sekler wrote:
> 
>> Am 25.11.2012 16:41, schrieb Reimar Döffinger:
>> 
>>> On Sun, Nov 25, 2012 at 04:13:19PM +0100, Ilja Sekler wrote:
>>> 
>>> [...] the main reason is that coverity complained about the code,
>>> and using stream_read_int24 to then discard everything but the 
>>> lowest 16 bits is senseless.
>> 
>> Did it happen at libmpdemux/demux_audio.c:606
>> 
>> -	      num_samples |= stream_read_word(s);
>> 
>> prior to the present fix, where stream_read_word and
>> stream_read_int24 were defined in stream/stream.h?
> 
> No, the problem is with
> stream_read_int24(s) << 16;
> The problem is that without the cast, the left shift is done as a
> 32 bit operation.
> Shifting a 24 bit value 16 to the left thus resulted in the top 8
> "falling off the cliff".
> Which was kind of lucky since the top 4 would have caused trouble
> (in the way that happened when I added the cast, thus making the
> shift a 64 bit operation), but it would still lose 4 bits.

Thank you very much, I've got it now.

>>> So the thing is that the number of audio samples value in FLAC is
>>> 36 bits (i.e. 5 bytes but 4 bits used for something else).
>> 
>> So this is 2^36-1 = 68719476735 max and the definition comes from 
>> <http://flac.sourceforge.net/format.html#metadata_block_streaminfo>.
>> If this buffer is filled with 44100 samples per second [...] it
>> will be full if the lenght of the file is 432,8 [...] hours [...].
>> It is still at least twice as long as aforementioned 100 hours.
> 
> So your 400 hour number should be correct. But 36 bits is the _stored_,
> correct value - FLAC files longer than this will not work 100% right
> no matter what.
> But before the changes we read only 32 bit, i.e. for a sample count of
> 2^32 we would already think the file has 0 samples.
> So if like you assuming 44100 as sample-rate that would be something
> around 27 hours. The reason that it does not match my 100 hours is that
> I did not use a calculator and I ended up rounding up quite a bit.

Thank you very much for this detailed explanation (and again for the
fix, of course).

-- 
Regards

Ilja


More information about the MPlayer-users mailing list