Skip to content

Loopback-HLS: a single backward seek on heavy 4K can wedge the segment producer (video stalls, audio continues -> A/V desync) #93

Closed

Description

@rrgomes

Symptom. On heavy 4K content over the loopback-HLS path, a single backward seek (not a rapid burst) can intermittently wedge playback: the video freezes while AVPlayer's already-buffered audio keeps playing, producing A/V desync, periodic audio dropouts, and dropped subtitles. The producer logs a sustained backpressure park and the re-anchor cap is hit:

[HLSSegmentProducer] #65 backpressure PARK (advance) ... parked=Ns (no playback progress)
[HLSSegmentProducer] #65 backpressure WEDGE BROKEN (advance) ... exiting pump for host re-anchor on AVPlayer position
[HLSVideoEngine] #65 backpressure wedge re-anchor cap reached (6 consecutive at pos=...); giving up (AVPlayer not resuming)
[NativeAVPlayerHost] item.status=failed err=AVFoundationErrorDomain/-11819 'Cannot Complete Action'   (in the worst case)

Around the same area the mp4 muxer logs malformed packet timing:

[mp4] [warning] Packet duration: -656 / dts: 23840480 in stream 0 is out of range

Intermittent. In the same session, earlier seeks resolved cleanly -- frameAhead / producerShift / hostShift = 0.000 throughout, the seek landed and resumed normally -- while a later, comparable moderate seek wedged. So it's timing/state-dependent, not deterministic.

Asset. 4K (3840x1634) HEVC, DV Profile 8.1, E-AC3 5.1, MKV, ~25 Mbps. The wedge is on the backpressure/loopback path, so it likely is not DV-specific -- heavy 4K is the common factor.

This is in the #65 family you've fixed iteratively (4.2.2 / 4.5.2 / 4.5.3 / 4.5.4). On heavy 4K it still bites occasionally on a single seek. Logs and asset available; happy to test patches.

Activity

  1. superuser404notfound commented on Jun 30, 2026

    @superuser404notfound
    Owner

    Thanks for the detailed report.

    Since you filed this, we shipped a fix for #92 that reworked VOD segment cutting (keyframe-gated, so the IRAP opens its own segment). It touched a related but distinct code path, so before I patch #93 I'd like to know whether it still reproduces on the current build.

    Could you retest with the #92 segment-cut fix in place, using the same asset and the same backward seek that wedged? If you consume AetherEngine directly as a package, that is current main (the fix landed in 489e38c, so anything at or after it).

    If it still wedges, the most useful thing would be the full session log around the wedge, in particular:

    • the [HLSSegmentProducer] video gate open: actual=... target=... desired=... shift=... line(s) right after the seek (this tells me whether the restart landed on the intended keyframe or overshot by a GOP),
    • the #65 backpressure PARK / WEDGE BROKEN / re-anchoring lines,
    • the [mp4] Packet duration: ... out of range line(s) with a few lines of context around them,
    • any #65 ledger seg-... lines.

    My working theory is a decode-order vs presentation-order mismatch at the restart keyframe selection (the same class of bug as #92, at a different spot), which would explain why it is intermittent and worse on heavy 4K. The gate-open line will confirm or rule that out.

  2. rrgomes commented on Jun 30, 2026

    @rrgomes
    ContributorAuthor

    Retested on 4.8.0 (so the #92 segment-cut fix 489e38c is in place). It still wedges — reproduced twice with a single backward seek, same asset (native DV Profile 8.1, 4K HEVC Main 10 / HDR10, ~25 Mbps, MKV, E-AC3 + Atmos).

    Helpfully for narrowing it: the restart keyframe selection looks correct — the gate-open lands exactly on target, no GOP overshoot:

    [HLSSegmentProducer] video gate open: actual=529904 anchorPts=529904 target=529904 desired=529904 shift=0
    [HLSSegmentProducer] video gate open: actual=436895 anchorPts=436895 target=436895 desired=436895 shift=0
    

    So the decode-vs-presentation-order-at-the-keyframe theory doesn't look like it here (actual == target == desired, shift=0 on every post-seek gate-open).

    What actually happens: the backward seek starves AVPlayer and it never resumes:

    [AetherEngine] #65 seek did not land within 8.0s and AVPlayer is starved (rendered=532.40s buffered=532.91s); reconciled clock to rendered position and re-anchored producer
    

    The re-anchor is clean (on-target, per the gate-open above), but AVPlayer stays at rate 0 / paused, so the producer parks itself and never recovers:

    [HLSSegmentProducer] #65 backpressure PARK (advance) head=122 target=112 cacheTarget=111 highStored=121 cached=13 parked=12s (consumer paused; wedge detection suspended)
    … parked=182s   (stays parked; only a manual back-out clears it)
    

    Sampling engine clock vs. AVPlayer clock through the wedge, both are frozen together at the seek target with AVPlayer fully paused (no A/V split):

    engineClock=442.40 avpClock=442.40 div=0.00 tcs=.paused rate=0.00 waitReason=nil   (stalled 80s+)
    

    The one thing that looks malformed throughout is a stream of negative packet durations out of the mp4 muxer, around and after the seek (and during normal playback too):

    [mp4] Packet duration: -656 / dts: 1663008 in stream 0 is out of range
    [mp4] Packet duration: -672 / dts: 381040 in stream 0 is out of range   (recurs every few segments)
    

    Those -656 / -672 durations feel like a likely culprit for AVPlayer choking and not resuming. Happy to attach a full session log, or run aetherctl segverify / a throttled repro — whichever helps most.

  3. DrHurt commented on Jun 30, 2026

    @DrHurt
    Contributor

    I know ffmpeg has a -avoid_negative_ts option which I think is meant to avoid negative time stamps which can cause sync issues! I cannot tell for sure if this is relevant here but worth looking into.

  4. superuser404notfound commented on Jul 1, 2026

    @superuser404notfound
    Owner

    Thanks for the retest and for pulling exactly the right lines. This changes the picture in two ways.

    First, the restart keyframe selection is clearly fine. Every post-seek video gate open you posted has actual == target == desired and shift=0, so the decode-order vs presentation-order theory from my first comment is ruled out. Good to know the #92 cutter path is not involved here.

    Second, and more importantly, the producer is not the thing that stalls. The park line is the tell:

    #65 backpressure PARK (advance) head=122 target=112 cacheTarget=111 highStored=121 cached=13 parked=12s (consumer paused; wedge detection suspended)
    

    highStored=121 means the producer had already produced the segments and then parked because the consumer (AVPlayer) stopped fetching. The clock sample confirms AVPlayer is genuinely paused rather than starved:

    engineClock=442.40 avpClock=442.40 div=0.00 tcs=.paused rate=0.00 waitReason=nil
    

    waitReason=nil with rate=0 is a real pause, not a buffer stall. So this is not the producer choking on a bad segment; it is AVPlayer sitting at .paused after the seek and nothing bringing it back to play.

    On the -656 / -672 durations and @DrHurt's -avoid_negative_ts point: those recur during normal playback too and playback is fine, and in the wedge the producer had already produced the segments, so they are not what wedges this. They do look like a separate non-monotonic-DTS issue at the muxer input that is worth fixing on its own, just not as part of this bug.

    Working theory now: the backward seek does not land within the reconcile budget on this asset (the loopback restart is legitimately slow for heavy 4K), the engine reconciles to AVPlayer's real position and re-anchors the producer, AVPlayer drops to .paused somewhere in that window, and the play intent is never re-asserted, so the producer parks on a paused consumer and the session deadlocks.

    To confirm the exact moment and reason AVPlayer goes to .paused, a full session log would help a lot, in particular every timeControlStatus= line from a few seconds before the seek through the wedge:

    [NativeAVPlayerHost] #<sid> timeControlStatus=<paused|waitingToPlay|playing> reason=<...> t+<...>s
    

    That timeline (the transition into paused and its reason) plus the surrounding #65 lines (seek-did-not-land, re-anchor, park) is what I need to lock this down before patching. A plain full log is enough, no need for the throttled or segverify repro yet, though I may ask for the throttle one later to reproduce it locally.

  5. rrgomes commented on Jul 1, 2026

    @rrgomes
    ContributorAuthor

    Retested #93 against main @ 8e4ed87 (with PR #94 moov-priming merged). #93 still reproduces on this asset, via a path distinct from the moov wedge. Details below.

    Environment: AetherEngine main @ 8e4ed87, loopback-HLS native (AVPlayer) path, tvOS 26.5, Apple TV 4K (3rd gen).

    Asset (by characteristics): native Dolby Vision Profile 8.1, 4K HEVC Main 10 (HDR10 / SMPTE 2084), ~25 Mbps, MKV, E-AC3 5.1 + Atmos, ~54 min.

    Moov path ruled out. Across 137 muxer cuts and several backward-seek muxer restarts, zero mov_write_moov "Cannot write moov atom before EAC3 packets parsed" (-22). PR #94 holds; the wedge below is a separate mechanism.

    Negative-duration root (context). The negative packet durations that #92 tracks persist on this build (422x Packet duration: -656/-672 ... out of range and 422x pts has no value on stream 0), and are the likely source of the playhead/loaded divergence below. Fuller glitch detail on #92.

    Terminal wedge. A backward seek (target 746.6s) lands the playhead at clock 765.30s, outside AVPlayer's loaded range, and the item fails:

    [NativeAVPlayerHost] #1 asset.tracks empty (item.failed)
    [NativeAVPlayerHost] #1 item.status=.failed after playback established (tcs=1 clock=765.30);
        deferring possibly-spurious failure: Cannot Complete Action
    [FreezeDiag] state=failed(...Cannot Complete Action) engineClock=765.300 frozenFor=14.3s
        lastSeekTarget=746.600 seekAge=33.5s avpClock=765.300 tcs=1 rate=1.0
        waitReason=AVPlayerWaitingToMinimizeStallsReason seekable=[0.0-3220.1] loaded=[19.2-548.0]
        frameAhead=0.000 producerShift=0.000 hostShift=0.000
    

    loaded=[19.2-548.0] vs clock=765.30: the playhead sits ~217s beyond loaded media, so AVPlayer stays WaitingToMinimizeStalls (rate=1, clock frozen) indefinitely. The #65 backpressure re-anchor then retries 6x, each re-anchoring the producer to pos 765.30 -> seg190 and producing to head=327 but parking 24s with no playback progress, before giving up:

    [HLSSegmentProducer] #65 backpressure WEDGE BROKEN parked=24s; exiting pump for host re-anchor
    [HLSVideoEngine] #65 backpressure wedge: re-anchoring producer to AVPlayer position 765.30s -> seg190 (attempt 1/5 ... 5/5)
    [HLSVideoEngine] #65 backpressure wedge re-anchor cap reached (6 consecutive at pos=765.30s); giving up (AVPlayer not resuming)
    

    Surfaces as a "Cannot Complete Action" playback error to the host.

    Telemetry note. frameAhead / producerShift / hostShift all report 0.000 throughout, so the existing divergence signals do not capture this (consistent with #38). The observable divergence is playhead (765.30) vs loaded window (up to 548.0).

    Offer. Happy to re-run with more instrumentation, or run aetherctl segverify / --throttle-kbps to help isolate whether the negative-duration packets originate at demux or at segment cutting. Pinned to 8e4ed87, quick turnaround.

  6. superuser404notfound commented on Jul 2, 2026

    @superuser404notfound
    Owner

    Thanks, this retest is very useful and it moves the diagnosis.

    Two things your log settles:

    1. Keyframe selection is fine (again). Every post-seek gate-open lands on target, so the restart is not overshooting a GOP. Not the cutter path.

    2. The real anomaly is a playhead/loaded decoupling, and the existing telemetry misses it. clock=765.30 while loaded=[19.2-548.0] means AVPlayer's currentTime() has drifted ~217s past its own buffered range, so it stays WaitingToMinimizeStalls forever waiting for media that can never be contiguous. And frameAhead=0.000 producerShift=0.000 hostShift=0.000 throughout confirms none of the current divergence signals capture this (the Expose an accurate in-flight seek signal (isSeeking / seekTarget) that spans the real loopback-HLS landing and covers native scrubs #38 gap). That is the thing to explain.

    On the negative durations: given this decoupled-timeline signature, I am walking back my earlier "red herring" call. The -656/-672 out of range plus pts has no value stream is on stream 0 (the video track), and corrupt fragment timing there is a live suspect for why currentTime() ran ahead of the loaded window. @DrHurt's instinct was pointing at the right neighborhood.

    A fix for exactly that regression just landed on main (1d57721): the look-behind muxer path now always telescopes each video sample's duration to the true forward DTS delta (next - dts) instead of trusting matroska's constant DefaultDuration. The constant was drifting movenc's track_duration about one frame ahead per segment, tripping check_pkt (the Packet duration: -N out of range clamp, which then nulls pts, which then writes wrong trun timing). That is precisely the -656/-672 + pts has no value stream you are seeing, and this should remove it.

    Could you retest both #92 and #93 against main at or after 1d57721, same asset and same backward seek? Two things to report:

    • whether the Packet duration: -N out of range and pts has no value lines are gone, and
    • whether the backward seek still wedges.

    If those lines are gone and the wedge is gone, #92 and #93 share this root and both are fixed. If the wedge still reproduces with those lines gone, then the timeline decoupling has another source, and separately I will fix a robustness gap I can already see on the reconcile side: when a seek does not land in budget, the engine re-anchors the producer to AVPlayer's reported rendered position with no clamp to the seekable/loaded window, so a decoupled renderedTime (your 765.30) re-anchors the producer to a phantom spot it can never serve. In that case the full [NativeAVPlayerHost] ... timeControlStatus=... reason=... transition timeline (a few seconds before the seek through the wedge) would be the next thing I need.

    Pinned or package, main @ 1d57721 has the fix. Thanks again for the precise numbers.

  7. superuser404notfound commented on Jul 2, 2026

    @superuser404notfound
    Owner

    4.9.1 is out and contains two changes directly relevant here, so retesting against 4.9.1 (or current main) supersedes the earlier request to test main @ 1d57721:

    • Producer restarts now continue the fMP4 media timeline. Previously every restart's fresh muxer zero-based its timeline, so a restarted segment carried tfdt=0 while the VOD playlist placed it at its real offset. Your second-retest signature (playhead decoupled from loadedTimeRanges, WaitingToMinimizeStalls forever) matches mixed-epoch timeline bookkeeping exactly. A restarted segment is now byte-identical to continuous production apart from the mfhd sequence number.
    • Byte-budgeted segment retention. A backward seek into already-watched content is now served from cache with no producer restart at all, so for that repro shape the wedge chain (slow heavy-4K restart, false-positive reconcile, spurious pause latch) is not even entered.

    The #92 duration telescoping from the earlier request is included as well, so a single run on 4.9.1 covers both issues. If the wedge still reproduces there, the remaining suspect list is short, and the same logs as before (the timeControlStatus timeline plus the #65 lines) would pin it down.

  8. rrgomes commented on Jul 2, 2026

    @rrgomes
    ContributorAuthor

    Big improvement on 4.9.1 — thank you. The hard failure is gone: on the native DV P8.1 4K HEVC (HDR10, ~25 Mbps) source, forward/backward seeks recover cleanly — no A/V desync, no AVPlayer "Cannot Complete Action". Segment retention + fMP4 timeline continuity did the heavy lifting.

    One residual, leaving open for your call: an aggressive backward seek (large jump, past the retained window) still parks on a still frame ~30 s before self-recovering — no error. Most visible on a 4K HEVC + TrueHD source with the consumer paused. Host-side diagnostic at the park:

    engineClock=314.06 avpClock=354.06 div=40.00 engineStalled=7.2s→31.2s
    (starts rate=0/nil; flips ~12s in to rate=1/AVPlayerWaitingToMinimizeStallsReason)
    

    The engine clock is frozen at the seek target while AVPlayer sits ~40 s ahead waiting to minimize stalls — the producer restart on the far-back seek takes ~30 s. Pre-4.9.0 this parked for minutes; flagging in case the restart can be shortened or the retained window extended.

  9. superuser404notfound commented on Jul 2, 2026

    @superuser404notfound
    Owner

    Thanks for the retest. The original hard failure (playhead decoupling, WaitingToMinimizeStalls forever, Cannot Complete Action) is confirmed fixed by 4.9.1's timeline continuity plus retention, matching your results.

    The residual you describe is reproducible here as well, in a harsher shape: iPhone over a WAN link, repeated 10 s backward skips past the retained window. The far-back restart's demuxer read can wedge on the dying source connection, the in-flight-read watchdog fires much later than its intended ~5 s, and pending segment fetches exhaust their retry budgets against a restart that is still making progress (one restart took ~44 s end to end; every queued fetch got a 503 by then). Your ~30 s still-frame park is the same latency cluster with a healthier link.

    Keeping this issue open to track that cluster as the next work package: watchdog timing on the wedged read, a cheaper far-back reopen (skip the head re-probe and cue prewarm on a same-source restart), letting waiting segment fetches ride out a restart that is demonstrably progressing instead of burning fixed retry budgets, and not launching subtitle side-readers while a restart is in flight (they compete for the same starved link). The retained-window budget is also worth revisiting for heavy 4K.

  10. 83 remaining items

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