[flac-dev] Two questions

Brian Willoughby brianw at audiobanshee.com
Mon Aug 2 22:30:53 UTC 2021

On Aug 2, 2021, at 08:40, Federico Miyara <fmiyara at fceia.unr.edu.ar> wrote:
> 1) Is there a way to get the audio size (number of samples) and other information, such as number of channels, from a flac file without fully decoding it?

Yes. There is a specific header with this information. Look for the documentation of the FLAC format for reference, and then look through the library for calls that might return this information.

I usually start from https://xiph.org/flac/documentation_format_overview.html for the official specification of the file format.

Note that FLAC is mostly a streaming format, where metadata is not generally used. But the file does have this information early on. See https://xiph.org/flac/format.html#def_STREAMINFO where it says that the STREAMINFO packet must be the first packet in the file.

> I've found that the WAV header is replicated after the "riffRIFF" keyword, but I don't seem to be able to predict where it is located or whether it is safe or not to asume that the first time such keyword appears is the correct one, and if there is an upper bound for its location; for instance, some text such as the name of a song or some comment could contain that keyword, even if it is unlikely. The information preceding the  "reference libFLAC 1.3.3" encoder version seems to be non-text information.

You should not use the RIFF information. It is not part of the FLAC specification. It is an optional enhancement to store information that is only about the input WAV files. It will strictly be missing from FLAC files that are recorded live, converted from AIFF, and will even be missing when WAV is the source if the option is not added.

> 2) I decode using the option --skip=0 --until=1. I would expect to get a wav file with only 1 sample, but I get 3 samples. Stictly no sample should be decoded since 0 samples should be skipped and the help says: 
> --until={#|[+|-]mm:ss.ss}  Stop at the given sample number for each input file. The given sample number is not included in the decoded output.
> so sample #1 should not be included, unless the first sample is sample #0, in which case only 1 sample, and not 3 samples, should be included in the output file.

Are you seeing 3 bytes for 1 sample? ... or are you seeing 3 samples?

Also, I recall that the FLAC library returns 32-bit numbers, so you have to convert these to 16-bit or 24-bit samples.


More information about the flac-dev mailing list