Skip to content

fix: do not subtract presentationTimeOffset from @duration segment times - #198

Open
bardrop wants to merge 1 commit into
videojs:mainfrom
bardrop-oss:fix-duration-presentation-time-offset
Open

bardrop wants to merge 1 commit into
videojs:mainfrom
bardrop-oss:fix-duration-presentation-time-offset

Conversation

@bardrop

@bardrop bardrop commented Nov 12, 2026 •

Copy link
Copy Markdown

Fixes #197

Problem

segment.time means two different things depending on how segments are addressed:

  • With a SegmentTimeline, it comes from S@t. That is media time, so it already includes @presentationTimeOffset.
  • With @duration (in both SegmentTemplate and SegmentList), and in the single-segment case, durationTimeParser / parseTemplateInfo set it to number * duration (or 0). That time starts at 0 at the Period start.

segmentTemplate.js and segmentList.js subtracted @presentationTimeOffset in every case. So @duration segments came out with negative presentationTime values. For the MPD in the issue that gave -100, -95 where it should be 0, 5.

Fix

Subtract @presentationTimeOffset only when the times come from a SegmentTimeline. Segment URLs ($Number$ / $Time$), durations and timelines don't change.

Tests

  • New tests for SegmentTemplate@duration, the single SegmentTemplate segment, and SegmentList@duration with a PTO. All three fail on main.
  • New guard tests showing that SegmentTimeline times still subtract the PTO (template and list).
  • toPlaylists > presentationTime accounts for presentationTimeOffset covered the single-segment case and expected the old value (periodStart 25, PTO 100 / timescale 4 → 0). That segment starts at the Period start, so I changed the expected value to 25 and renamed the test.
  • npm run build-test && npm run test:node: 201 pass. npm run lint: same 11 existing warnings as main, 0 errors. I did not run the karma browser suite locally.
  • The issue's repro on the built dist/mpd-parser.cjs.js now prints [["f-1.m4s",0],["f-2.m4s",5]].

Autofix with [code]smith
Open in [code]smith · Need help on this PR? Tag @codesmith-bot with what you need.

segment.time is a media time (it includes @presentationTimeOffset) only when
it comes from SegmentTimeline S@t. For SegmentTemplate@duration, SegmentList
@duration and the single segment case it starts at 0 at the Period start, so
subtracting the offset gave negative presentationTime values.

Fixes videojs#197
@bardrop

bardrop commented Nov 20, 2026

Copy link
Copy Markdown
Author

Friendly ping when you have time. Is there anything you'd like changed here?

This branch has not been deployed

No deployments
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.

Negative presentationTime for SegmentTemplate@duration and SegmentList segments with @presentationTimeOffset

1 participant