Skip to content

fix: flac loses its tail at finalize (#497) - #499

Open
remsky wants to merge 2 commits into
masterfrom
fix/flac-ogg-wav-tail
Open

fix: flac loses its tail at finalize (#497)#499
remsky wants to merge 2 commits into
masterfrom
fix/flac-ogg-wav-tail

Conversation

@remsky

@remsky remsky commented Aug 4, 2026

Copy link
Copy Markdown
Owner

Output buffer is truncated after every chunk, so muxers that seek back to
patch a header at pos 0 on close (wav RIFF sizes, flac STREAMINFO, mp3 xing) were landing the patch on the flushed audio instead.

Finalize now reads before close for everything except ogg, which appends its last audio page during close. Drops the wav return b"" special case from #463, no longer needed with the correct order.

  • wav/flac round-trip sample-exact, streaming and non-streaming payloads byte-identical
  • mp3/aac/opus unchanged (verified byte-identical to master)
  • regression test decodes and counts samples per format
  • known limitation: streamed flac still carries total_samples=0 (inherent to streaming,
    spec-valid); libsndfile readers reject it, same as before this fix. ffmpeg/pyav decode fully.

Diagnosis by @Technologicat in #497.

@remsky remsky changed the title Fix/flac ogg wav tail fix: flac loses its tail at finalize (#497) Aug 4, 2026
@remsky remsky linked an issue Aug 4, 2026 that may be closed by this pull request
@remsky

remsky commented Aug 4, 2026

Copy link
Copy Markdown
Owner Author
Format Single chunk (non-streaming) Multi-chunk ×30 (streaming) Payloads identical PyAV libsndfile
WAV 144078 B 144078 B Yes 72000, sample-exact 72000, OK
FLAC 38009 B 38009 B Yes 72000, sample-exact Fails (pre-existing)
MP3 48812 B 48812 B Yes 73152 73152, OK (encoder pad)
Opus 54983 B 54983 B Decode-identical* 144000 @ 48 kHz = 3.000 s 72000, OK
AAC 26067 B 26067 B Yes 73728 (encoder pad) Fails (never supported)
PCM 144000 B 144000 B Yes Raw, sample-exact N/A

* Opus bytes differ only in the random Ogg serial number stamped per writer; decoded output is identical.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

FLAC loses its tail: #448 and #463 are two halves of one bug

1 participant