Skip to content

fix(moq-mux): author DTS for B-frame MPEG-TS export (decode timeline not emitted) #1836

Description

@t0ms

Problem

moq-cli TS export emits PTS only (no DTS), so B-frame streams carry no decode
timeline. Players see out-of-order DTS and need ffplay -fflags +igndts. Validated on a
real CNN 1080i contribution feed through moq pub | relay | moq sub. Follow-up to #1798
(multi-PPS, fixed); part of #1799.

Evidence (real feed)

  • Source has 12480 B-frames (ffprobe -select_streams v -show_frames -show_entries frame=pict_type ... | grep -c ',B$'), so decode order != presentation order.
  • Subscriber output: first packet dts=N/A, then ffmpeg's reconstructed DTS is
    non-monotonic and repeats (many frames share one DTS):
    pts, dts 25.277000, N/A 25.557000, 25.297000 25.437000, 25.557000 25.357000, 25.557000 (DTS 25.557 repeated ~12x)
  • ffplay logs DTS 2289330 < 2301930 out of order; plays only with -fflags +igndts.

Root cause

rs/moq-mux/src/container/ts/export.rs write_pes sets dts: None (~line 652).
container::Frame carries a single timestamp (PTS); frames are delivered in decode
order with valid PTS, but no decode time is authored on export.

Recommended fix (exporter-side, non-breaking, main)

Frames already arrive in decode order, so the exporter can author a valid DTS with a
bounded reorder buffer (depth = max consecutive B-frames): within the window, assign DTS
= the PTS values in sorted order (exact for CFR broadcast). Emit dts: Some(..) when it
differs from PTS. No wire/format change; cost is a few frames of added latency. Removes
the out-of-order DTS and the +igndts requirement.

Optional follow-up (faithful, dev)

For byte-exact DTS (strict TR 101 290 / contribution), carry the original composition
offset (PTS-DTS) end to end: capture on TS import, add a field to container::Frame + the
hang container frame format, emit on TS/fMP4/FLV export. Breaking wire/format change ->
dev; mirror js/hang + doc/concept. Related: #1828's review found moq_mux::Export
send-timestamps use wall-clock, not PTS, and "needs a PTS-exposing API change" - the same
Export timing surface, worth solving together.

Branch

Exporter-side fix: main (additive). Faithful composition-offset carriage: dev.
(Written by Claude)

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Fields

    No fields configured for issues without a type.

    Projects

    No projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions