Repository navigation
Description
Summary
On a large remote MKV whose Cues seek index can't be read, the VOD planner emits a single segment spanning the entire title, and AVPlayer then loads zero tracks and never starts (kFigAssetError_TrackNotFound, stuck in AVPlayerWaitingWithNoItemToPlayReason). This is a sibling of #64, but reached through a different path — the existing keyframeIndexIsTrustworthy guard doesn't catch it.
What I'm seeing
The source is a ~64 GB HEVC/TrueHD MKV served over HTTPS. The tail read fails, so the Cues table never loads:
[AVIOReader] Persistent conn gen=1 ended with error: cancelled
[matroska,webm] [error] Read error at pos. 64011715695
[HLSVideoEngine] cue prewarm: capped at 16204.5ms (no usable Cues index — index points past EOF or is absent)
libavformat is left with only the keyframes scanned at open — all clustered in the first few seconds. Those inter-keyframe gaps are tiny, so the index passes keyframeIndexIsTrustworthy, and the keyframe-aligned planner (finding no keyframe at/after the first segment boundary) emits one whole-file segment:
[HLSVideoEngine] segment plan: keyframe-aligned, 5 IRAPs → 1 segments
#EXT-X-TARGETDURATION:6844
#EXTINF:6843.872, seg0.mp4
AVPlayer can't start from that:
kFigAssetError_TrackNotFound (Asset has no tracks)
asset.load(tracks) ok count=0
timeControlStatus=waitingToPlay reason=AVPlayerWaitingWithNoItemToPlayReason
(The #64 muxer buffer-bound fix does prevent the disk-fill here — the 150 MB segment is served — but playback still never begins.)
Root cause (best guess)
keyframeIndexIsTrustworthy only measures gaps between consecutive indexed keyframes. When the surviving keyframes are bunched within the first few seconds, those gaps are all tiny, so a near-empty index is judged trustworthy. The #64 clustered-TS case is caught because its entries are spread far apart; this MKV case isn't, because they're close together — yet the index still spans almost none of the title.
A possible direction
Adding a minimum-coverage check before the gap loop seems to handle it without affecting the existing "dense index that stops early" behavior (the trailing-gap-not-counted case) — e.g. requiring the indexed keyframes to span at least one targetSegmentDuration, since below that the keyframe planner can't make a single cut and degenerates to one segment. Happy to open a PR with a test if that direction looks right, though you may well have a cleaner fix in mind.
Separately, the underlying trigger is that the file's tail bytes don't fetch (the Read error at pos. near EOF), which looks like a distinct AVIOReader matter — I can file that separately if useful.
AetherEngine version or commit SHA
7620aa4
Platform
macOS
Activity
fix(player): reject a keyframe index that spans under one segment (#91)
superuser404notfound commentedon Jun 30, 2026
Fixed in 8e272f6. Your diagnosis was exactly right, including the suggested direction, so this implements precisely that.
keyframeIndexIsTrustworthynow applies two witnesses instead of one:targetSegmentDuration.When the Cues tail read fails and only the open-time keyframes survive bunched in the first few seconds, their gaps are tiny so the gap check passed, but the coverage span is under one segment. Below that, the keyframe planner can't make even the first cut, so it degenerates to the single whole-file segment AVPlayer loads zero tracks from. That index now routes to the uniform-stride fallback instead.
As you anticipated, this doesn't touch the "dense index that stops early" behavior: the coverage span is measured between keyframes and never reaches EOF, so a trailing gap from the last keyframe to the end of file isn't counted, and such an index already spans well over one segment. The clustered-TS case from #64 still fails via the gap witness.
Three tests landed in
SegmentPlanSparseIndexTests.swift: the bunched index is rejected, a witness test documents the single whole-file segment the guard prevents, and a boundary test pins the threshold attargetSegmentDuration. Full suite is green (XCTest 212, Swift Testing 268).On the separate AVIOReader matter (the tail bytes near EOF not fetching,
Read error at pos.): yes, please do file that separately. It's a distinct reader-level concern, and the segment-plan fix here just makes a source with a missing seek index degrade gracefully rather than ship an unplayable plan.Thanks for the unusually precise report and the test offer.
chore(release): prep 4.8.0 - #87/#89/#90/#91/#92 fixes, unified playb…