Skip to content

nativeRemoteHLS: sourceTime is AVPlayer item time, which runs ahead of the displayed frame after a seek on a server transcode #616

Closed
imbenjamin/dionysus-player
#247

Description

@imbenjamin

Summary

On the nativeRemoteHLS bypass, clock.sourceTime is documented as "Source PTS of the currently displayed frame". What it actually tracks is AVPlayer's item (playlist) time. On a Jellyfin HLS transcode, after a seek, item time runs ahead of the displayed frame by between 1.1s and 8.3s. The amount changes with every seek. A host driving a subtitle renderer from sourceTime (libass, in our case) draws every line early.

The WebVTT renditions injected by #316 are not affected. AVPlayer times those against the media timestamps, so they stay in sync.

AetherEngine 7.15.0, Jellyfin 10.11.11, fMP4 HLS transcode (H.264/HEVC), iOS 26.6 device.

Mechanism (measured)

  1. On a seek, Jellyfin restarts the transcode with -ss <slot start> -noaccurate_seek -copyts. ffmpeg therefore starts at the source keyframe at or before the slot. The first segment's tfdt carries the real (earlier) PTS, while the playlist places that segment at its slot start. Our transcoding URL gives EXTINF 3.003 segments.
  2. AVPlayer anchors its item timeline to the first segment it loads after the seek: item = pts + (slot_first − tfdt_first).
  3. It keeps that anchor when Jellyfin restarts the job again underneath it. Requesting the init segment always restarts the job at 0, and later segments can carry a different slot−keyframe gap.

Measured with a bare AVPlayer on macOS against the real transcoding URL, comparing presented frames with a reference decode:

First segment loaded after seek slot − keyframe Measured item − frame offset
seg 494: slot 1483.482, keyframe 1482.272 1.210 1.209
slot 1786.785, keyframe 1783.699 3.086 3.086

In the first case, a later job restart at seg 500 had slot − tfdt = 2.252. AVPlayer ignored it and kept 1.209. So probing the tfdt of the currently playing segment is not a reliable way to recover the offset.

On device, across repeated scrubs of one film, the offset varied between 1.1s and 8.3s. sourceTime − AVPlayer item time read ≈ 0.000 throughout, so sourceTime carries the offset unchanged.

Repro

  1. Load a Jellyfin HLS transcode URL with nativeRemoteHLS: true.
  2. Seek to a mid-film position that isn't keyframe-aligned (almost any).
  3. Compare clock.sourceTime with the PTS of the frame on screen, or with when an injected nativeRemoteHLS: external subtitles can never become renditions (load-time dropped, post-load overlay-only) #316 WebVTT cue appears. sourceTime leads by the first post-seek segment's slot − keyframe gap.

Expected

Either sourceTime reflects the displayed frame's PTS on this route, or its docs note that on nativeRemoteHLS it is item time, which can lead the picture after a seek on origins that restart at keyframes. The exposed offset would be enough for hosts.

Host workaround, in case it helps

The host keeps the injected WebVTT rendition selected. An AVPlayerItemLegibleOutput with suppressesPlayerRendering = true reports each cue with the item time AVPlayer presents it at. Matching the cue text to the script event then gives offset = itemTime − event.start. That self-corrects on every line.

One trap worth knowing: if the output starts suppressing while AVPlayer is already drawing a line, that line stays frozen on screen for good, and a deselect afterwards doesn't clear it. Deselecting the rendition, letting a frame or two pass, then attaching the output and reselecting avoids it.

If the engine could publish the item-to-media offset it already sees (e.g. from the first post-seek segment's tfdt, or from its own legible pipeline), hosts wouldn't need this.

Activity

  1. superuser404notfound commented on Sep 24, 2026

    @superuser404notfound
    Owner

    Thanks for the thorough report. The table and the frozen-line trap saved a lot of time.

    Confirmed in the code: on the nativeRemoteHLS bypass sourceTime was wired straight to AVPlayer's rendered item time, so the documented contract did not hold on that route.

    The fix is in #617, taking the route suggested at the end of the report: the engine measures the offset on its own #316 renditions.

    • A legible output on the bypass item with suppressesPlayerRendering = false. It changes nothing about what AVPlayer draws, and it cannot trigger the frozen-line trap, because it never suppresses.
    • Each newly presented line is matched back to the cue the engine wrote, and offset = itemTime - cue.start. The delivery at a seek landing is skipped, because a line active there carries the landing time rather than its own start. Lines that end teach nothing.
    • clock.sourceTime then publishes item time minus that offset. currentTime, seek(to:) and the scrubber stay on item time, so seeking round-trips unchanged. The log line to look for is AE#616: item time leads the presented frame by ....

    Limit, also written into the docs: it measures only while one of the injected renditions is selected and presenting. So the setup from the report (rendition selected, a host output with suppressesPlayerRendering = true in front of it) is exactly the case it covers, and the host-side itemTime - event.start matching should no longer be needed. Without an injected rendition sourceTime stays item time.

    Verified locally with a fMP4 HLS fixture whose playlist puts every segment 1.5 s after its tfdt. sourceTime led the decoded picture by 1.46 s before the first line and sat within one frame after it, including across a seek. One difference from your measurements: on that local origin, which never restarts anything, AVPlayer kept its first anchor across a seek rather than re-anchoring. So the per-seek variation you saw needs Jellyfin's restart pattern, which I cannot reproduce here. A run of the branch against your Jellyfin transcode (repeated scrubs, comparing sourceTime with the frame on screen) would be the real test. I'll leave the issue open until then.

  2. superuser404notfound commented on Sep 24, 2026

    @superuser404notfound
    Owner

    Released in 7.15.2 (19a222fe, merged in #617). On the nativeRemoteHLS bypass, sourceTime now follows the presented frame, measured off the injected WebVTT renditions. currentTime and seek(to:) stay on item time. With no injected rendition selected, sourceTime stays item time, as the API docs now say. A retest on the transcode from the report would confirm the lead is gone. I will leave the issue open until then.

  3. imbenjamin commented on Sep 24, 2026

    @imbenjamin
    Author

    Verified on 7.15.2 against the same setup as the report: Jellyfin 10.11.11 fMP4 HLS transcode of Deadpool (2016), nativeRemoteHLS, iPhone 16 Pro on iOS 26.6. The injected WebVTT rendition was selected, with a host AVPlayerItemLegibleOutput (suppressesPlayerRendering = true) in front of it. For this run the host calibration was switched off, so libass was driven by clock.sourceTime alone. Seven scrubs, forward and back.

    For each line AVPlayer presented, we logged sourceTime minus that event's Start in the script:

    Scrub landing (item) Lead removed (item − sourceTime) sourceTime − Start on the lines after it
    ~571 2.85–2.91 s −0.066, −0.016, −0.076
    ~2685 1.15–1.16 s −0.036, −0.026, −0.026
    ~1629 0.79–0.92 s −0.166, −0.041, −0.060
    ~4609 3.84–3.92 s −0.057, −0.087, −0.077, −0.007
    ~5153 2.06–2.12 s −0.074, −0.044, −0.013
    ~2813 1.38 s −0.129

    The lead varied between 0.8 s and 3.9 s from scrub to scrub, which is the Jellyfin re-anchoring pattern from the report, and sourceTime removed it every time. After the first measured line, sourceTime sat 7–90 ms behind the event start. That is within one tick of the 100 ms observer we sample it from. Styled subtitles looked in sync on screen throughout. From our side this fixes the issue, and we'll drop our host-side itemTime − event.start matching when we bump.

    One observation, not a blocker: between a seek landing and the first line the engine measures, sourceTime still carries the previous seek's offset. In the log, the one or two lines right after a landing read −1.50 s, −1.77 s (previous lead 2.9 s, new 1.15 s) and −1.79 s (previous 3.8 s, new 2.1 s), and then fell into line. So for those first seconds a host renders late when the new lead is smaller, and early when it is larger. That matches the limit you described. We'll keep a short hold after a seek on our side. If the engine could say whether the offset has been measured since the last time jump (a flag, or an optional offset that resets on timeJumped), hosts could gate on that instead of re-detecting seeks themselves. That would be nice to have, not something this issue needs.

    Thanks for the quick turnaround. Fine to close from our end.

  4. superuser404notfound commented on Sep 24, 2026

    @superuser404notfound
    Owner

    Thanks for the careful retest, and for sampling it per line across seven scrubs. Good to see the lead removed on every landing.

    The flag you suggested is in #624, merged to main and part of the next release: clock.sourceTimeFollowsPicture (plus the one-shot mirror sourceTimeFollowsPicture on the engine).

    • On every route except nativeRemoteHLS it is always true.
    • On the bypass it turns false at load and at every AVPlayerItem.timeJumpedNotification, and true once a presented line of an injected rendition has re-measured the lead. Without an injected rendition selected it stays false, since sourceTime is plain item time there.
    • During the false window sourceTime still applies the previous lead, as before. The flag only says it is a guess, so the −1.5 to −1.8 s lines from your log fall exactly inside it and can be held on that instead of on your own seek detection.

    Closing this one as confirmed. If anything about the flag doesn't fit how libass is driven on your side, a new issue is welcome.

  5. superuser404notfound commented on Sep 24, 2026

    @superuser404notfound
    Owner

    Released in 7.16.0 (eb172571): clock.sourceTimeFollowsPicture and the sourceTimeFollowsPicture mirror from #624 are in it.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions