Applies to: Protocol and format interpretation for developers inspecting authorized media delivery.

The useful distinctions

  • STREAMINFO is the first FLAC metadata block.
  • It contains sample rate, channel count, depth, and total samples.
  • A zero total-samples value means the count is unknown.

Divide the right count by the right rate

The synthetic metadata declares 480000 interchannel samples at 48000 samples per second. Dividing those values produces ten seconds. Do not multiply the duration by the two-channel count: the stream-level sample count already has the meaning defined for this field. Keep block sizes and compressed frame sizes out of the duration calculation because they describe different structural properties.

Preserve unknown information honestly

A zero count in a real header would require an unknown-duration result at this stage, rather than a claim that the audio lasts zero seconds. Likewise, a zero checksum field can mean that the checksum is not supplied, so it should not be reported as a successful integrity check. The Python example constructs a legal metadata-block excerpt from explicit values and does not create audio frames. Its byte serialization can be checked locally without claiming a complete valid audio file. A full stream review would compare the metadata with the actual frames and handle inconsistencies according to the decoder and format requirements. The packed field combines several widths, making a decode-back check valuable: recover the original sample rate, channel count, bit depth, and total samples from the bytes, then compare them with the construction inputs.

Worked example · synthetic

The code constructs a final STREAMINFO metadata block: 34-byte payload plus a four-byte block header. Unknown frame sizes and checksum are zero. It omits the fLaC marker and all audio frames.

Valid STREAMINFO block construction only; not a complete FLAC stream.

sample_rate = 48000
channels = 2
bits_per_sample = 16
total_samples = 480000
packed = ((sample_rate << 44) | ((channels - 1) << 41)
          | ((bits_per_sample - 1) << 36) | total_samples)
streaminfo = (4096).to_bytes(2, "big") * 2 + bytes(6)
streaminfo += packed.to_bytes(8, "big") + bytes(16)
metadata_block = bytes([0x80, 0, 0, 34]) + streaminfo
assert len(streaminfo) == 34

Check the interpretation

  • Check the 34-byte payload length.
  • Compute 480000 ÷ 48000 = 10 seconds.
  • Treat zero count or checksum according to their unknown semantics.