An Ogg Opus stream can finish between codec-frame boundaries. Its final page’s granule position tells the reader how many decoded samples to retain, allowing the remaining tail to be discarded. A complete final packet can therefore produce more decoded samples than the intended audible ending without indicating that the stream contains unwanted extra programme material.
Calculate the retained tail
Use an illustrative previous completed-page granule of 48,000 and a final granule of 48,500. Their difference says to retain 500 samples from the packets completed on the final page. If the simplified final page has one packet decoding to 960 samples, the other 460 samples are excluded. Preserve both granule positions when checking this calculation.
Apply the final-page context
RFC 7845 ties this treatment to the page carrying the end-of-stream flag and defines restrictions on valid boundaries. The discarded amount should not exceed the final packet’s decoded samples. It is not a general rule allowing arbitrary short granules on every page. A parser needs the page flags and surrounding completed-packet history, rather than a final integer detached from the stream.
Distinguish sample trimming from byte truncation
A deliberately trimmed audible tail can still come from a complete coded packet. A file cut off in the middle of its packet or page is a different structural failure. A maintainer should check complete packet delivery before comparing the signaled retained samples with decoder output. File size alone cannot say which of those two conditions occurred.
Report the ending as a boundary problem
For a repeatable tail discrepancy, preserve the final page metadata, calculated retained count and actual output interval from an appropriate authorized comparison. A viewer can note whether the final spoken word is missing, extra silence appears or playback ends cleanly at an unexpected displayed time. The arithmetic explains the format’s intended ending; it is not a hands-on test of a specific app. Avoid changing every track’s delay to compensate for a final-page handling error confined to one representation.

