Skip to content

libobs: Start the output interleaver on the first video encoder's track - #1612

Merged
zackees merged 3 commits into
obs-rust:masterfrom
rdoupe:fix/interleave-video-slot0
Oct 21, 2026
Merged

zackees merged 3 commits into
obs-rust:masterfrom
rdoupe:fix/interleave-video-slot0

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 21, 2026 •

Copy link
Copy Markdown
Collaborator

Fixes #1611

Also fills in the PR links of the #1509 line in docs/features.md, which is still a literal #PR placeholder on master (the earlier fix in #1572 was lost in a conflict resolution).

What and why

An encoded output whose only video encoder is not in slot 0 now starts on its first keyframe, with every track offset to 0. Before, the first keyframe was never sent: the output started on a frame that is not a keyframe, with timestamps not offset to 0. OBS master has the same code; there is no upstream report.

  • obs_output_set_video_encoder2() lets a multitrack video output leave slot 0 empty, and obs_output_can_begin_data_capture() accepts that (video_valid() checks every slot). The frontend never does it (multitrack video fills slots 0..n-1, WHIP simulcast adds slots 1+ next to slot 0), and obs-websocket can't set encoders, so this is reached from plugins through the public API.
  • prune_premature_packets() and get_interleaved_start_idx() looked for the first video packet of track 0 only. With slot 0 empty the premature prune returned -1 and the start was skipped, while the received flags stayed set. The next packet was then sent as if started, without offsets. The packets queued before it (the first keyframe among them) kept the encoder's system-time dts_usec, sorted after everything later, and stayed queued until the stop.
  • Both now 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 still track 0, so nothing changes for outputs the frontend creates.
  • The same change goes into the C original (libobs/obs-output-interleave.c.h, still built in the C lane) and the Rust core (rust/obs-output), so the Tier 3 parity holds. The Rust pure functions interleaved_start_idx() and premature_prune() take the track as a new argument.

Changes an existing test. test_output_interleave_e2e registers its output with OBS_OUTPUT_MULTI_TRACK_AV instead of OBS_OUTPUT_MULTI_TRACK, so that slot 1 can be set, and its delivery check expects the video track the case set up instead of a literal 0. Its four existing cases are unchanged and still pass; the slot 1 cases are new. In the Tier 1 port (rust/obs-output/tests/output/interleave.rs) the four direct calls of interleaved_start_idx() / premature_prune() pass track 0 for the new argument, with the same expectations. test_output_interleave (the C characterization) is unchanged.

Headless (private Xvfb, private D-Bus, fresh HOME), test_output_interleave_e2e:

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 audio, then video frame 1, not a keyframe; the keyframe of frame 0 never sent
master, C and Rust lanes, libobs and libobs-with-rust video encoder in slot 1 only 4 fail, the same
This branch, C and Rust lanes, libobs and libobs-with-rust all 8 cases 8/8 pass, 3 of 3 runs each

RED → GREEN

  • RED commit: 236747a test: Start the output interleaver with slot 0 of the video encoders empty. test_output_interleave_e2e runs its four cases again with the video encoder in slot 1 and slot 0 empty: on master 4 of 8 fail against libobs and libobs-with-rust in both lanes (the first packet is audio, not the keyframe of video frame 0 at dts 0). Two new Tier 1 cases, start_follows_the_first_video_encoder and late_audio_drops_the_first_keyframe_of_the_first_video_encoder, fail on master (nothing sent at the start; the late-audio prune drops nothing).
  • GREEN: 394fa0b. test_output_interleave_e2e 8/8, 3 of 3 runs, against libobs and libobs-with-rust in the C and Rust lanes. Full cmocka ctest in both lanes, each against libobs and libobs-with-rust: 350/350, none skipped. Exported symbols of libobs and libobs-with-rust identical in both lanes (1766). cargo test of the output tests (Tiers 1 and 3, the C oracle included): 100/100. ci/local_gate.py: lint, cross and rust-test pass.
  • Real app (UI, protocol output or logging changes): not applicable. No frontend path leaves slot 0 empty; the e2e test drives a real output through the libobs that ships.

Checklist

  • Base is master
  • I claimed the issue, or no one else has an open PR for it
  • Characterization test (if the unit had none), then RED, then GREEN commits
  • User-visible change: its line in docs/features.md is added (Fixed upstream bugs, Encoding, streaming and recording)
  • (Optional) Local gate passed and the pushed head is stamped; otherwise PR CI runs the full suite
  • Warning or flag changes (-W..., ratchets): built with scripting ON (a flag change under cmake/ or build-aux/ runs the full builds) and cross-checked with clang and MSVC
  • Intentional differences from C listed in the parity test header and rust/README.md (ports): none, the C original changes the same way

…empty

obs_output_set_video_encoder2() lets a multitrack video output leave
slot 0 empty and use slot 1 or higher, and obs_output_can_begin_data_
capture() accepts that (video_valid() checks every slot). The start of
the interleaver then never runs: prune_premature_packets() and
get_interleaved_start_idx() look for the first video packet of track 0
only, find none, and the start is skipped. The next packet sees both
received flags set and is sent as if started, with no offsets applied.
The packets queued before the start keep the encoder's system-time
dts_usec, so they sort after everything sent later and stay queued
until the output stops: the first keyframe is never sent, and the
output starts on a frame that is not a keyframe with timestamps that
are not offset to 0.

test_output_interleave_e2e runs its four cases again with the video
encoder in slot 1 and slot 0 empty (the output is registered
OBS_OUTPUT_MULTI_TRACK_AV so that slot 1 can be set; the slot 0 cases
are unchanged). All four fail on master against libobs and
libobs-with-rust: the first packet is audio, then video frame 1, not
the keyframe of frame 0 at dts 0. The Tier 1 port gets the same two
start cases on its model output.

Refs obs-rust#1611
@rdoupe
rdoupe requested a review from zackees as a code owner October 21, 2026 09:17
The interleaver's start follows the first video packet of track 0:
prune_premature_packets() and get_interleaved_start_idx() look for it,
and with slot 0 of the video encoders empty (a multitrack video output
set up with obs_output_set_video_encoder2() and an index above 0, which
obs_output_can_begin_data_capture() accepts) they never find one. The
start was then skipped, the next packet was sent as if started, without
offsets, and the packets queued before the start (the first keyframe
among them) kept their system-time dts_usec, sorted after everything
sent later, and stayed queued until the output stopped. The output
started on a frame that is not a keyframe.

Both now follow the track of the first video encoder, as
initialize_interleaved_packets() already does
(obs_output_interleave_first_video_encoder_index()). With slot 0 set,
that is track 0, so nothing changes for those outputs. The C original
and the Rust core get the same change, so the Tier 3 parity holds; the
Rust pure functions take the track as an argument (the four Tier 1
calls pass 0).

Fixes obs-rust#1611
@rdoupe
rdoupe force-pushed the fix/interleave-video-slot0 branch from 54ec665 to 394fa0b Compare October 21, 2026 09:17
It was merged with a literal #PR placeholder. The fix landed in obs-rust#1562
(zeroed video fields) and obs-rust#1565 (no crash before obs_startup).

Refs obs-rust#1611
@zackees
zackees added this pull request to the merge queue Oct 21, 2026
Merged via the queue into obs-rust:master with commit ea76164 Oct 21, 2026
25 checks passed
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

Status: Done

Development

Successfully merging this pull request may close these issues.

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

2 participants