Skip to content

Native DV Profile 8.1 (HEVC) shows transient video glitches on the loopback-HLS path; not reproducible on replay #92

Closed

Description

@rrgomes

Symptom. Playing native Dolby Vision Profile 8.1 HEVC (single-layer, dv_bl_signal_compatibility_id=1, RPU present, no EL) on a DV display, brief blocky video distortion appears intermittently during normal playback:

  • Not reproducible on replay -- seeking back to the same section does not reproduce it; glitch positions vary per play.
  • Absent in players that direct-decode without remuxing (e.g. Infuse / VT+Metal) on the same file.
  • DV-P7 is clean (libdovi RPU canonicalization + dvcC rewrite) and non-DV 4K HEVC is clean -- only native P8.1 glitches.

Localization. In resolveCodecRoute, native P8.1 on a DV panel is a pure passthrough (convertP7ToProfile81=false, rewriteDoviConfigTo81=false, stripDolbyVisionMetadata=false): the source RPU NALs (unspec62) + dvcC reach the mp4 muxer untouched, written as dvvC + SUPPLEMENTAL dvh1.08.XX/db1p. P7, by contrast, rewrites every RPU (convertPacketToProfile81, libdovi mode 2) and rewrites the dvcC.

Negative result (useful). I tried routing P8.1 RPUs through the same convertPacketToProfile81 canonicalization P7 uses (set convertP7ToProfile81 = effectiveDvMode for .profile81). The conversions ran with zero failures but the glitch persisted unchanged -- so the raw RPU passthrough is not the cause. (It also added per-frame producer latency that made the seek wedge in the companion report more frequent, so I reverted it.) The differentiator is therefore something other than RPU content -- possibly the dvcC/dvvC signaling, or AVPlayer's handling of P8.1 DV over fragmented HLS at segment boundaries.

Asset. 4K (3840x1634) HEVC, DV Profile 8.1, E-AC3 5.1, MKV container, ~25 Mbps, ~54 min. The engine classifies it correctly:

[HLSVideoEngine] DV source: profile=8 compat=1 level=6 rpu=1 el=0 bl=1 color_primaries=9 color_trc=16 color_space=9

Happy to test patches or capture additional traces.

Activity

  1. superuser404notfound commented on Jun 30, 2026

    @superuser404notfound
    Owner

    Fixed on main (489e38c).

    Root cause. It was not the RPU passthrough or the dvvC/db1p signaling; your negative result on RPU canonicalization was the right read. The VOD segmenter routed each packet to a segment by its DTS against PTS-valued plan boundaries. Under B-frame reorder a keyframe's DTS sits below its PTS, so the boundary IRAP fell into the previous segment and the next segment started mid-GOP, decode-dependent on its predecessor. Sequential playback decodes that fine, but when AVPlayer does a fresh decode at such a boundary (rebuffer/underrun recovery) the leading samples reference pictures that are not in the segment, which is the transient blocky corruption. It is intermittent and not reproducible on replay because it only surfaces on those fresh-decode events, whose timing varies per session.

    Scope. The defect is general to reordered (B-frame) content, not specific to open-GOP CRA or to DV P8.1. The native P8.1 asset just happened to be the one that reliably hit the fresh-decode condition in your setup. That also explains why it was absent in players that direct-decode without remuxing: they decode continuously and never start fresh at a mid-GOP boundary.

    Fix. The VOD cut is now keyframe-gated in decode order (VODSegmentCutter), the same way the live path and FFmpeg's hls muxer cut: a segment opens at the IRAP that reaches its plan boundary, so the IRAP is the segment's first sample and its open-GOP RASL leading pictures stay with it. A fresh decode then starts cleanly at the IRAP and discards RASL via NoRaslOutputFlag. Audio routing is unchanged and EXTINF still derives from the plan boundaries.

    Verification. Added aetherctl segverify, which fetches each segment from the loopback server and SW-decodes it in isolation (init.mp4 plus that one segment, fresh decoder). On synthetic open-GOP and closed-GOP HEVC it reported 1/8 segments independently decodable before the fix (only the first) and 8/8 after, matching FFmpeg's own hls fMP4 segmenter on the same source. Device-verified.

    Thanks for the unusually thorough report, and for ruling out the RPU path up front; it saved a lot of time.

  2. added a commit that references this issue on Jun 30, 2026
  3. rrgomes commented on Jun 30, 2026

    @rrgomes
    ContributorAuthor

    Retested on 4.8.0 (with the keyframe-gated segment-cut fix in place) — the transient DV-P8 glitch unfortunately still reproduces on the same content (native DV Profile 8.1, 4K HEVC Main 10 / HDR10, ~25 Mbps, MKV). Still intermittent / not at the same spot on replay.

    While capturing #93 on the same asset I noticed the mp4 muxer emits negative packet durations during normal playback (not just around seeks):

    [mp4] Packet duration: -656 / dts: ... out of range
    [mp4] Packet duration: -672 / dts: ... out of range
    

    Bad frame durations like these could plausibly cause both the transient visual glitch here (wrong presentation timing) and the #93 post-seek wedge — possibly a shared root cause on DV-P8 content, which would also explain why the segment-cut fix didn't touch the glitch. Flagging in case it helps; happy to attach a full session log.

  4. superuser404notfound commented on Jul 1, 2026

    @superuser404notfound
    Owner

    Reopening. Thanks for the 4.8.0 retest and, especially, the negative-duration observation. That is a strong lead.

    Confirmed on the code side already: the fMP4 muxer's input guard (OutputTimestampSanitizer) only enforces DTS monotonicity and pts >= dts. It does not touch packet duration. MP4SegmentMuxer.writePacket then passes the packet's duration straight into av_interleaved_write_frame, and the existing duration repair only fills zero/missing values, not negative ones. So a negative source duration reaches the muxer unrepaired, which matches the Packet duration: -656 ... out of range you are seeing and would land as a wrong trun sample duration, i.e. exactly the kind of transient presentation-timing artifact the keyframe-gated segment cut could not address.

    To be clear about 4.8.0: the segment-cut fix was still correct (it made mid-stream segments independently decodable, verified with aetherctl segverify), but it was evidently not the glitch's root cause on its own.

    A full session log would help a lot, ideally the muxer lines around the negative durations together with the surrounding DTS/PTS values, so I can pin down where the negative duration originates (the source packet itself vs. our rescale/repair). With that in hand I will chase the fix at the muxer input.

  5. rrgomes commented on Jul 1, 2026

    @rrgomes
    ContributorAuthor

    Retested on main @ 8e4ed87 (PR #94 merged). Two findings:

    1. PR fix(hls): prime mp4 moov with a parsed audio packet on backward-seek muxer restart (#92) #94 (moov priming) confirmed working: the mov_write_moov -22 "Cannot write moov before EAC3 packets parsed" wedge is gone (0 across 137 muxer cuts and several backward-seek muxer restarts on E-AC3 5.1 + Atmos content).

    2. The transient glitches still reproduce, and are reproducible on replay (contrary to the title): repeated ~10s backward seeks around a fixed point reproduced the blocky corruption several times at the same spot. They correlate with persistent negative packet durations and missing PTS on stream 0:

    [mp4] [warning] Packet duration: -656 / dts: 2312304 in stream 0 is out of range
    [mp4] [warning] pts has no value
    

    Counts this session: 422x negative Packet duration (317x -656, 105x -672), 422x pts has no value.

    So PR #94 fixed the moov wedge but not the glitch root; suggest #92 stays open for the negative-duration source. Asset: native Dolby Vision Profile 8.1, 4K HEVC Main 10 (HDR10 / SMPTE 2084), ~25 Mbps, MKV, E-AC3 5.1 + Atmos. The same root also feeds the terminal wedge filed on #93.

  6. superuser404notfound commented on Jul 2, 2026

    @superuser404notfound
    Owner

    Update after tracing the muxer side against the vendored FFmpeg source, because that Packet duration: -656 line is misleading.

    It is not a negative pkt->duration. It is check_pkt in movenc.c, specifically the pkt->dts < ref branch: it computes pkt->dts - ref (how far the DTS regressed), prints that value formatted as signed, then sets pkt->dts = ref + 1 and pkt->pts = AV_NOPTS_VALUE. That is why each Packet duration: -N is paired one-to-one with a pts has no value on the same stream: the pts warning is a direct consequence of check_pkt nulling the pts, not a second independent problem.

    A genuinely negative pkt->duration takes the other branch in the same function (Application provided duration: N in stream %d is invalid, logged at error level and returning EINVAL). That line does not appear in the session, so the duration field itself is not negative. The defect is the video DTS regressing relative to movenc's running reference.

    Where the reference comes from matters here. At a fragment boundary (trk->entry == 0) movenc derives ref = start_dts + track_duration, i.e. from the accumulated sample durations, not from the last written DTS. The muxer-input guard (OutputTimestampSanitizer) enforces per-stream DTS monotonicity and pts >= dts, but it does not touch track_duration. So a small, systematic per-frame duration error that accumulates ahead of the real DTS can make the reference overshoot the next real DTS and trip check_pkt at the boundary, even though the DTS stream itself is monotonic.

    The two discrete magnitudes (656 and 672) point at a fixed, small regression on a coarsely quantized source grid, which fits matroska millisecond timecodes, but I would rather confirm that from the log than assert it.

    To separate "constant per-frame duration drifting ahead of the real DTS" from "a real source DTS regression," the session log would settle it. For the video stream around a few of the -656 / -672 lines, the most useful fields are the packet's source dts, pts, and duration as demuxed (before any rescale), and whether the source is handing us a constant per-frame duration (a matroska DefaultDuration) rather than a per-block one. If it is a constant duration while the DTS advances at the true average frame interval, the fix is to make the video sample durations telescope to the real DTS deltas at the muxer input instead of trusting the constant.

    Thanks again for the exact counts, the replay repro, and for confirming PR #94 on the E-AC-3 path.

  7. superuser404notfound commented on Jul 2, 2026

    @superuser404notfound
    Owner

    The video sample-duration telescoping fix for this is now merged to main (1d57721): the look-behind muxer path always telescopes each video sample's duration to the true forward DTS delta instead of trusting matroska's constant DefaultDuration, so movenc's track_duration can no longer drift ahead and trip check_pkt. That should clear the Packet duration: -N out of range + pts has no value stream at its source.

    I have asked you to retest this together with #93 against main @ 1d57721, since the same negative-duration stream is now the leading suspect for the #93 backward-seek timeline decoupling. Details in #93 (comment).

  8. superuser404notfound commented on Jul 2, 2026

    @superuser404notfound
    Owner

    4.9.1 shipped and includes the duration telescoping from the earlier retest request, plus the restart timeline-continuity work described in #93. Retesting against 4.9.1 covers both issues in one run.

  9. rrgomes commented on Jul 2, 2026

    @rrgomes
    ContributorAuthor

    Confirmed fixed on 4.9.1 — thank you. Retested the native DV Profile 8.1 4K HEVC (Main 10 / HDR10, ~25 Mbps, E-AC3) source on a 3rd-gen Apple TV 4K: several minutes from the top plus repeated forward/backward seeks, no transient blocky glitches at any point. The video-sample-duration telescoping cleared it. Closing on our end.

  10. superuser404notfound commented on Jul 2, 2026

    @superuser404notfound
    Owner

    Thanks for confirming on 4.9.1 and for the retest turnaround. The -656/-672 duration lines you captured were exactly what pinned the matroska DefaultDuration drift as the root cause; the sample-duration telescoping would not have been found this quickly without them.

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