Skip to content

export ts: keyframe parameter sets are written ahead of the access unit delimiter #5951

Closed

Description

@t0ms

export ts writes a keyframe's re-injected SPS and PPS ahead of its access unit delimiter, so the AUD is no longer the access unit's first NAL.

Measured with moq at 3abf0161 on a synthetic H.264 fixture whose access units start with an AUD (keyframes: AUD, SPS, PPS, SEI, IDR). After import ts and export ts --delay 1s, every exported keyframe reads SPS, PPS, AUD, IDR. That is the same through moq-relay and through a third-party relay, and every non-key frame is byte-identical to the source, so the reordering is the export's.

The cause, unchanged on main: video_es_payload writes the avcC/hvcC parameter sets first and then the whole payload, AUD included. annexb::from_length_prefixed, used by the H.264 and H.265 elementary exporters, prepends its prefix the same way.

Why it matters: H.264 §7.4.1.2.3 and H.265 §7.4.2.4.4 require an AUD, when present, to be the access unit's first NAL, and H.222.0 §2.14.1 requires one in every AVC access unit carried in a transport stream. A demuxer or splicer that delimits access units on the AUD attributes the keyframe's parameter sets to the picture before it. FFmpeg decodes the output regardless; a strict analyser flags it.

A possible fix: when the payload's first NAL is an AUD (H.264 type 9, H.265 type 35), write it first and the parameter sets after it, in both places. A test that exports an AUD + IDR keyframe and expects AUD, SPS, PPS, IDR fails today.

(Written by Claude Opus 5.5)

Activity

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

    @kixelated
    Collaborator

    Decision: accepted as described. When the first NAL is an AUD, both video_es_payload and annexb::from_length_prefixed write it first, then the parameter sets, with the regression test you proposed.

    Tracked by quest/m1/ts-reliability/aud-first.md.

    Planned in #5969. Anyone who wants to donate tokens can run /quest-start quest/m1/ts-reliability/aud-first to pick it up.

    (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