Skip to content

bug: libobs: an output whose video encoder is not in slot 0 drops its first keyframe and starts on a non-keyframe #1611

Closed

Description

@rdoupe

Found by reading the interleaver after its Rust port (#1603); no upstream report. OBS master has the same code (libobs/obs-output.c, prune_premature_packets() and get_interleaved_start_idx() look for video track 0 only), so this fork inherited it.

Location

  • libobs/obs-output-interleave.c.h (and its port in rust/obs-output/src/interleave.rs), prune_premature_packets() and get_interleaved_start_idx(): both look for the first video packet of track 0 only. initialize_interleaved_packets() and the rest of obs-output.c.h (pause, obs_output_get_video_encoder(), pair_encoders()) already use the first video encoder's slot (get_first_video_encoder_index()).
  • With slot 0 empty, prune_premature_packets() finds no video packet and returns -1, so interleave_packets() skips the start (prune_interleaved_packets() returns false). The received flags stay set, so the next packet is handled as if the output had started: no offsets, no premature prune, no re-sort.
  • The packets queued before that point keep the encoder's system-time dts_usec (encoder->start_ts / 1000 + ...), while every later packet gets its dts_usec recomputed from its own dts. The early packets, the first keyframe among them, sort after everything that comes later and stay queued until the output stops.

Class

Wrong output. The output starts on a frame that is not a keyframe, so a decoder shows garbage or nothing until the next keyframe. Audio queued before the start is held back the same way (in the test, the first packet of one audio track), and timestamps are not offset to 0 (with an encoder already running for another output they start wherever that encoder is). It is not a memory leak: only the packets queued before the start stay behind (a fixed handful), and they are freed when the output stops. Not reachable from untrusted input (below).

How it is reached

obs_output_set_video_encoder2(output, encoder, idx) with idx > 0 and slot 0 left empty, on an output with OBS_OUTPUT_MULTI_TRACK_VIDEO. obs_output_can_begin_data_capture() accepts it (video_valid() checks every slot), and obs_output_get_video_encoder() returns the first non-empty slot, so the API treats it as valid.

  • The frontend never does this: multitrack video (Enhanced Broadcasting) fills slots 0..n-1 in order from the service's encoder configurations, and WHIP simulcast adds slots 1+ next to the main encoder in slot 0.
  • obs-websocket has no request that sets an output's encoders.
  • A third-party plugin, or a script with the libobs bindings, can.

Reproduced in the current release

test_output_interleave_e2e (headless: private Xvfb, private D-Bus, fresh HOME): a registered encoded output with a video encoder only in slot 1 and two audio encoders, with media fed by hand.

Build Case Result
v0.1.0-beta.20261018 AppImage's libobs video encoder in slot 0 (4 cases) pass
v0.1.0-beta.20261018 AppImage's libobs video encoder in slot 1 only (4 cases) 4 fail: first packet is audio, then video frame 1 (not a keyframe); the keyframe of frame 0 is never sent
master 819a325, libobs and libobs-with-rust, C and Rust lanes video encoder in slot 1 only 4 fail, the same

Fix

prune_premature_packets() and get_interleaved_start_idx() follow the track of the first video encoder (obs_output_interleave_first_video_encoder_index()), as initialize_interleaved_packets() already does. With slot 0 set that is track 0, so nothing changes for any output the frontend creates. The same change goes into the C original and the Rust core, so the Tier 3 parity holds. PR follows.

Activity

  1. added 2 commits that reference this issue on Oct 21, 2026
    394fa0b
    5712015
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

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions