Skip to content

fix: end a Period without @duration at the next Period start - #199

Open
bardrop wants to merge 1 commit into
videojs:mainfrom
bardrop-oss:fix-period-duration-from-next-start
Open

bardrop wants to merge 1 commit into
videojs:mainfrom
bardrop-oss:fix-period-duration-from-next-start

Conversation

@bardrop

@bardrop bardrop commented Nov 12, 2026 •

Copy link
Copy Markdown

Fixes #195

Problem

toAdaptationSets set periodDuration only from an explicit Period@duration. When a static multi-Period MPD gives only Period@start, parseByDuration fell back to sourceDuration (the full mediaPresentationDuration) for every Period. So each Period got segments for the whole presentation, running past its own end. For the MPD in the issue, Period 2 got b-1..b-4 at 10, 15, 20, 25 instead of b-1, b-2 at 10, 15.

Fix

New getPeriodDuration helper, next to getPeriodStart, following ISO/IEC 23009-1 5.3.2.1:

  1. Period@duration if present (same as before).
  2. Otherwise the next Period's start minus this Period's start.
  3. For the last Period of a static MPD that starts after 0: mediaPresentationDuration minus its start.

A last Period that starts at 0 still gets no periodDuration, so it keeps using sourceDuration like before (single-Period MPDs don't change). If the end is unknown, or not after the start, nothing is set, which is also the old behavior. periodDuration is only read on the static @duration path, so dynamic MPDs and SegmentTimeline don't change. The <S r="-1"> path still uses sourceDuration; that is #196 and I left it out of this PR.

Tests

  • Unit tests for getPeriodDuration: explicit duration, next start (static and dynamic), last static Period, and the cases that return undefined.
  • An end-to-end parse() test with the MPD from the issue. It fails on main.
  • inheritAttributes > end to end - basic multiperiod now expects periodDuration: 30 on the second Period (mediaPresentationDuration 60, start 30). It had no periodDuration before.
  • 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 a a-1.m4s@0 a-2.m4s@5 and b b-1.m4s@10 b-2.m4s@15.
  • This PR and fix: do not subtract presentationTimeOffset from @duration segment times #198 touch different files and merge cleanly together.

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

A static multi-Period MPD that only gives Period@start filled every Period
to the full mediaPresentationDuration, so segments ran past the Period
end. Per ISO/IEC 23009-1 5.3.2.1 a Period without @duration ends where
the next Period starts, and the last one ends at mediaPresentationDuration.

Fixes videojs#195
@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.

Static Period without @duration gets segments for the whole mediaPresentationDuration

1 participant