Skip to content

fix(disc): fold a DVD title by cell and seek it by its time map - #738

Merged
superuser404notfound merged 1 commit into
superuser404notfound:mainfrom
yipengfei329:fix/dvd-cell-timeline
Oct 12, 2026
Merged

superuser404notfound merged 1 commit into
superuser404notfound:mainfrom
yipengfei329:fix/dvd-cell-timeline

Conversation

@yipengfei329

Copy link
Copy Markdown
Contributor

Summary

A DVD title's VOBs are read as one MPEG-PS, and many discs restart the presentation timestamps at a cell boundary. A seek was a timestamp search over the whole title, and on real discs it read straight to the end of the title: a 2000 s seek ended the session. This folds the main PGC's cells onto one title timeline with the clip fold Blu-ray already uses (AE#105), each cell's base measured from its navigation packs, and seeks through the title's VTS time map. It is MovieClaw P13 from #703, and the limitation #737 points at.

What changed

  • DVDIFOParser: parseMainPGCCells (first / last sector, playback time, angle-block flag per cell) and parseMainTimeMap (VTS_TMAPT at VTSI 0xD4, the map at the main PGC's own index, discontinuity bit stripped). mainPGCOffset now comes from mainPGC, which also returns that index; the existing duration, chapter and language reads are unchanged.
  • DiscReader.dvdCellTimeline: for the selected title's VTS IFO, contiguous cells from the first title sector and outside any angle block become ClipSpans (byte start in the concatenated VOBs, start on the title timeline, predicted shift as if each cell restarted from cell 0's base), plus a DVDTimeMap of VOBU bytes. Anything else yields neither and the title reads as before. Both ride on DiscInfo and the recognition cache.
  • Demuxer:
    • A cell-folded title (dvdCellFold) keeps its DVD_NAV stream through discardAllStreamsExcept. readPacketLocked absorbs every navigation pack, so callers never see one. A PCI sets its cell's resolved shift to its base (VOBU start PTS less C_ELTM) minus cell 0's base and the cell's title start, before that cell's audio and video are folded. Cell 0's base is the stream's start_time, so a resume landing in a later cell can fold at once.
    • seek(to:), seekBounded and seek(to:streamIndex:) try seekByDVDTimeMapLocked first: title time from the folded source axis, the VOBU at or before it, one AVSEEK_FLAG_BYTE seek. Without a time map, or before cell 0's base is known, they search by timestamp as before.
  • docs/formats.md (Disc) and CHANGELOG.

Relation to #737: that PR moves the ISO9660 DVD branch into wrapDVD so a UDF-only image shares it. The two merge cleanly in either order (checked locally), and the cell timeline then applies to UDF-only images too, as in the second disc below.

Test plan

  • Device / OS: MacBook Pro (Mac14,5, M2 Max), macOS 27.0.1, Xcode 27.0 (27A266a).

  • Real remote images from a NAS, served by a local Range origin, aetherctl play <url> --seconds 60 --seek-every 10|12 --seek-pattern …. Software path (720x480 MPEG-2 PS) on both:

    Disc Without this With this
    He's a Woman, She's a Man (ISO9660, 6349 s, 16 cells, time map 1587 x 4 s), seeks 2000, 4000, 500 first seek ends the session at 2000.03 s, the next is rejected (noActiveSession) 3 of 3 landed, played on to 524.9 s
    same, seek to 3805 and play across cell 8 (starts at 3814.5 s) n/a playhead continuous 3813.29 -> 3814.54 -> 3815.54
    The Little Chinese Seamstress (UDF only, so with fix(disc): recognize a DVD-Video image that has no ISO9660 bridge #737 merged locally; 6364 s, 14 cells, cell 7 at 3569.1 s restarts its timestamps at ~147.5 s), seeks 2000, 3560, 4500, 300 with fix(disc): recognize a DVD-Video image that has no ISO9660 bridge #737 alone: the 2000 s seek ends the session 4 of 4 landed; from 3560 it played across cell 7 continuously (3569.25 -> 3570.50), and the landing at 4500 s inside a restarted cell played on

    The log shows DVD time map seek: title=…s -> byte … for each seek and DVD cell 7: base=147.456s cumBefore=3569.1s -> shift -3421.682s for the restarted cell. Dropped-frame counts are the same with and without this change.

  • New DVDCellTimelineTests (7): cells in playback order with their sectors and times; the time map at the main PGC's own index, and none without VTS_TMAPT; the discontinuity bit; spans and byte map from contiguous cells; one cell, a late start, a gap, or an angle block left alone (4 cases); the time map's VOBU lookup; the cell base from a 29.97 and a 25 fps PCI, a DSI ignored, and a short PCI ignored. The navigation-pack absorption and the fold through the demuxer need a real DVD program stream, so the real discs above cover them.

  • Full swift test --jobs 8: 737 XCTest cases (1 skipped) and 4,205 Swift Testing cases in 584 suites, all passing. Scripts/check-doc-links.py passes.

Checklist

  • CHANGELOG.md updated
  • Commit messages follow Conventional Commits (feat(...), fix(...), chore(...))
  • The fix lives in the engine, not in a host-side workaround
  • Public API changes are intentional and documented (none)

🤖 Generated with Claude Code

A DVD title's VOBs are read as one MPEG-PS, and many discs restart the
presentation timestamps at a cell boundary (The Little Chinese Seamstress puts
cell 7, at 3569 s of title time, at about 147 s). A seek was a timestamp search
over the whole title, which on real discs read straight to the end: a 2000 s
seek ended the session.

Recognition now reads the selected title's main PGC cells and VTS time map
(DVDIFOParser.parseMainPGCCells / parseMainTimeMap). Contiguous cells from the
first title sector, outside any angle block, become AE#105 clip spans; the
demuxer measures each cell's timestamp base from its navigation packs (PCI
VOBU start PTS less the cell's elapsed time) and absorbs them, so the Blu-ray
clip fold carries the playhead across cells. Every seek entry point goes to the
VOBU's byte through the time map. A title outside that shape, or a disc without
a time map, reads and seeks as before.

Co-Authored-By: Claude Opus 5.5 <[email protected]>
@superuser404notfound
superuser404notfound merged commit 4666e3d into superuser404notfound:main Oct 12, 2026
4 checks passed
@superuser404notfound

Copy link
Copy Markdown
Owner

Merged in 4666e3d, thank you. This closes the DVD half of what #737 left open, and the two real-disc runs in the description made it easy to trust.

It needed a manual merge: 7.35.1 added the Blu-ray EP-map seek table (AE#736) at the same places (DiscInfo, DiscRecognition, the cache, the three seek paths). Both now sit side by side; a seek tries the EP maps, then the DVD time map, then the timestamp search. The UDF-only path from #737 goes through the shared wrapDVD, so it gets the cell fold as well. Full swift test on the merged state: 747 XCTest (1 skipped) and 4,323 Swift Testing cases, all passing.

One thing I may harden later: a later cell's predictedShiftSec assumes the cell restarts at cell 0's base. That only applies to packets read before the cell's first navigation pack, which a time-map seek never produces, but a timestamp-search fallback landing mid-VOBU on a continuous disc would fold those few packets by the whole cumulative time.

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.

2 participants