[flac-dev] FLAC metadata blocks and seeking

Martijn van Beurden mvanb1 at gmail.com
Mon Dec 15 15:38:22 PST 2014

Op 16-12-14 om 00:00 schreef Neil Hinnant:
> 1. Is it possible to know the total size of FLAC metadata 
> blocks in advance? Do I really need to parse all metadata 
> blocks until I see the METADATA_BLOCK_HEADER with 
> last-metadata-block == 1?

No and yes. You need to parse all

> 2. Is there a generally accepted best-practice for seeking if 
> there is no seektable present in the file? The format states 
> /"It is possible to seek to any given sample in a FLAC stream 
> without a seek table, but the delay can be unpredictable since 
> the bitrate may vary widely within a stream." /Is this delay 
> just a fact of life, or is there any way to mitigate?

If you have a stream (without a seektable) of 30MB which encodes 
music 4:00 long, and you want to seek to 2:00, the best guess is 
to seek halfway the file. However, if the first part is silence 
and the second part is noise, the 2:00 mark won't be halfway, 
but at the beginning (because silence takes up much less space). 
This is what is meant by the comment 'because the bitrate may 
vary wildly'

So, the usual way is to take a reasonable guess, look for a 
frame, read it's header and look for the framenumber. With the 
framenumber known, it is clear where in the stream this first 
seek has gotten you, and once more you can take a reasonable 
guess at where the seekpoint should be, narrowing down the 
search range until you find the frame with the sample that the 
seek was looking for.

Seektables make this narrowing down much faster, but they aren't 
strictly necessary.
-------------- next part --------------
An HTML attachment was scrubbed...
URL: http://lists.xiph.org/pipermail/flac-dev/attachments/20141216/4d444182/attachment.htm 

More information about the flac-dev mailing list