Blu-ray SUP export: fix invalid PTS/DTS on exported segments#12074
Merged
Conversation
The writer put decode-model values into the DTS field and zeroed the PTS of ODS/END segments, producing segments with DTS > PTS (e.g. PTS=0, DTS=13097155), violating the rule that decoding must finish before presentation. The DTS also underflowed to a huge uint for captions starting within the first ~150 ms. This broke tools that shift every segment's PTS, like SupMover with a negative delay. Write timestamps the way .sup files extracted from retail discs look and the common consumers expect: every segment of a display set carries the display set's presentation time as PTS, and DTS stays 0 (ffmpeg's sup demuxer explicitly treats 0 as unset; muxers like tsMuxeR re-derive decode timing from the PCS when authoring m2ts). Verified: segment-level invariants (DTS=0, uniform PTS per display set, monotonic), ffmpeg remux to mkv without warnings, ffmpeg PGS decode renders/clears captions at the exact times, SupMover negative delay with no spurious warnings, and SE roundtrip re-import. Fixes #10219 Co-Authored-By: Claude Fable 5 <noreply@anthropic.com>
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #10219.
What was wrong
BluRaySupPicture.CreateSupFrame(a port of BDSup2Sub's writer) mixed up the timestamp fields:PTS 0, DTS 13097155segment from the issue, violating "decoding must finish before presentation" (DTS ≤ PTS).dts = (uint)(pts - decodeTimes)underflowed to a huge value for captions starting in the first ~150 ms.Tools like SupMover shift the PTS of every segment when applying a delay, so the zeroed/garbled fields made every caption trigger "starts before the full delay amount" on negative delays (MonoS/SupMover#30).
The fix
Every segment of a display set now carries the display set's presentation time as PTS, and DTS stays 0 ("unset"). Rationale, checked against the ecosystem:
.supfiles extracted from retail discs look (per the segment traces in the SupMover issue) — uniform PTS per display set, empty DTS.supdemuxer has an explicit code path: "Many files have DTS set to 0 for all packets, so assume 0 means unset"..supDTS field is informational.ffmpeg -c copyremuxing produces no "non-monotonous DTS" warnings (staggered per-segment PTS would).Verification
Generated test sups via libse (caption at t=0, small gaps, and a 900×300 noisy bitmap forcing a 5-packet ODS chain):
PGheader): DTS=0 everywhere, DTS ≤ PTS, uniform PTS per display set, monotonic across sets, clean PCS…END structure. ✔--delay -335on a shifted file → zero warnings, all display sets moved exactly 335 ms, output still passes the validator. The only warnings left are for a caption genuinely starting at t=0, which is correct clamping. ✔BluRaySupParserre-imports all captions with correct times, sizes, and forced flags. ✔🤖 Generated with Claude Code