Skip to content

export ts --sync: a group that began behind the one before it lays apart on a leg that lost that earlier group #5864

Description

@t0ms

Building quest/m2/ts-hitless
(branch, not yet a PR) with the plan's
third placement rule: each PID owns a fixed lane on the rate's packet grid, and each group
re-anchors at its lane's first position from its first unit's release, derived from its timestamp.
On a 9.95 Mb/s broadcast mux (field-coded H.264, MP2, AC-3, teletext, three SCTE-35 PIDs, DVB SI)
at --mux-rate 12000000 --delay 1s, two legs that joined 20 s apart write the same packets,
continuity counters included, over 59 s.

Complementary loss breaks it wherever the first group a leg reads after its loss overran on the
other leg. There the group before it was still filling the video lane at the new group's anchor, so
the leg holding both opened the new group 14 to 19 packets late. The leg that lost the earlier group
opened it on the anchor. Payloads and DTS are the same; the positions differ for up to 0.6 s, until
a frame's own release catches the lane up. In three runs of four, the leg stopped at +35 s differs
from the other two in 2,218 to 3,821 video packets; the leg stopped at +20 s, whose first group did
not overrun, matches the unstopped leg in every packet.

The plan's "with headroom" can't be given on this content. The video lane may not exceed the
stream's Rx: it is 9.93 Mb/s at 12 Mb/s, and 10.59 Mb/s at 16 Mb/s or 24 Mb/s, for 9.0 Mb/s of
video whose four-frame mini-GOPs peak near 13 Mb/s. About one group in five overruns at every rate,
and the 16 and 24 Mb/s runs gave the same 2,218 differing packets. A leg that lacks a group cannot
know how far it spilled.

Which would you take?

  • Carry a little of a packet plan with the objects: for instance, each group's first object naming
    the previous group's unit sizes and decode times, so every leg computes the spill for its own
    lanes. That adds to what the importer publishes.
  • Scope identity to groups that do not overrun. The export already counts each one (overruns in
    its stats) and logs a warning, so a receiver's operator can see where the legs may differ.
  • A placement rule I haven't thought of.

The rest of the quest is built: the decode clock settles DTS by count at the SPS's declared reorder
depth, so a leg's DTS no longer depends on what it read before, and just check passes. Happy to
build whichever you choose.

(Written by Claude Opus 5.5)

Activity

  1. t0ms commented on Oct 19, 2026

    @t0ms
    ContributorAuthor

    A placement rule that removes the trade-off, now built and measured: open each group where the
    encoder's own HRD says the group before has arrived.

    Result. On e2cfc7e40,
    the same four complementary-loss runs (12 Mb/s twice, 16 and 24 Mb/s once) give no differing packet
    between any two legs, no overrun and no late unit on any leg, and the stopped legs' merge equals the
    unstopped leg in every packet (441,223 to 882,048 positions a run). The previous build counted about
    12 overruns a minute at 12 Mb/s.

    The rule. A unit is released as early as a full CPB would need it. A picture that opens a
    buffering period says how full the CPB really is when it decodes: initial_cpb_removal_delay at
    BitRate, which leaves room = CpbSize - BitRate * initial_cpb_removal_delay / 90000 empty. A
    group's first picture, when it carries that SEI, is released later by the time its lane takes to
    carry room, but never so late that its own packets would miss their deadline. Later units keep
    today's rule. Every group on this source opens on such a picture (102 of 102 random access points
    over two minutes;
    NAL HRD, CBR, BitRate = CpbSize = 8,797,568, a 1.0 s buffer; delays 0.51 s to 0.92 s).

    Why no group spills into the next. Take any unit of the group before, released Δ ahead of the
    next group's first picture. H.264 C.3 (C.4 in H.265) bounds initial_cpb_removal_delay by the time
    since the previous picture's final arrival, so every bit the lane still has to carry from that unit
    to the end of its group reached the HRD between that unit's first bit and the next picture's first
    bit. That is at most BitRate * (Δ + CpbSize / BitRate - delay), which is BitRate * Δ + room. A
    lane faster than BitRate carries it within Δ + room / lane rate, which is when the next group
    opens. So a leg holding the earlier group has finished it there, and a leg that lost it opens at the
    same place. The send-ahead cancels out, and the headroom that matters is over BitRate, not over the
    content's peaks, which the CPB absorbs: here the video lane is 9.93 Mb/s at 12 Mb/s for 9.0 Mb/s of
    packetized video.

    What it costs. About 120 lines in moq-mux, plus tests: the SPS walk keeps the NAL HRD's
    schedule count and delay length, a reader takes the delay from the access unit's buffering period
    SEI, and the export moves the group's first release. The importer and the objects don't change. A
    stream without a NAL HRD or a buffering period keeps today's anchor and its overruns, which the
    export still counts, and so does H.265 for now, whose buffering period SEI is laid out differently.
    Under the new anchor, an overrun means a source that breaks its own HRD.

    Tests. A parser test on a buffering period x264 wrote, a lane test of the deadline guard, and a
    mocked-time test whose source ends a group in a burst: the leg holding the burst overruns once
    without the new anchor, and with it lays the next group where the leg that lost the burst does.
    just check passes.

    If this is the placement you'd take, I'll add H.265's buffering period and open the quest's PR with
    it.

    (Written by Claude Opus 5.5)

  2. added
    questBeing tracked/planned in a quest. See `quest/`
    on Oct 19, 2026
  3. kixelated commented on Oct 19, 2026

    @kixelated
    Collaborator

    Decision: the HRD buffering-period anchor from #5949 is the placement rule, recorded in quest/m2/ts-hitless.md; #5949 closes this. Identity is promised where the stream carries a NAL HRD buffering period; others keep the plain anchor and count overruns. The packet plan was rejected because it adds to what the importer publishes.

    H.265 is its own follow-up: quest/m2/ts-hitless-h265.md.

    Planned in #5969. Anyone who wants to donate tokens can run /quest-start quest/m2/ts-hitless-h265 to pick it up.

    (Written by Claude Opus 5.5)

  4. kixelated commented on Oct 22, 2026

    @kixelated
    Collaborator

    Reopening: the planning PR #5969 auto-closed this, but the fix is #5949 (still open), which now closes it.

    (Written by Claude Opus 5.5)

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

    questBeing tracked/planned in a quest. See `quest/`

    Type

    No type

    Projects

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions