Repository navigation
libobs: Start the output interleaver on the first video encoder's track - #1612
Merged
Merged
Conversation
…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
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
force-pushed
the
fix/interleave-video-slot0
branch
from
October 21, 2026 09:17
54ec665 to
394fa0b
Compare
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
This file contains hidden or bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment
Add this suggestion to a batch that can be applied as a single commit.This suggestion is invalid because no changes were made to the code.Suggestions cannot be applied while the pull request is closed.Suggestions cannot be applied while viewing a subset of changes.Only one suggestion per line can be applied in a batch.Add this suggestion to a batch that can be applied as a single commit.Applying suggestions on deleted lines is not supported.You must change the existing code in this line in order to create a valid suggestion.Outdated suggestions cannot be applied.This suggestion has been applied or marked resolved.Suggestions cannot be applied from pending reviews.Suggestions cannot be applied on multi-line comments.Suggestions cannot be applied while the pull request is queued to merge.Suggestion cannot be applied right now. Please check back later.
Fixes #1611
Also fills in the PR links of the #1509 line in
docs/features.md, which is still a literal#PRplaceholder 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, andobs_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()andget_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-timedts_usec, sorted after everything later, and stayed queued until the stop.obs_output_interleave_first_video_encoder_index()), asinitialize_interleaved_packets()already does. With slot 0 set, that is still track 0, so nothing changes for outputs the frontend creates.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 functionsinterleaved_start_idx()andpremature_prune()take the track as a new argument.Changes an existing test.
test_output_interleave_e2eregisters its output withOBS_OUTPUT_MULTI_TRACK_AVinstead ofOBS_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 ofinterleaved_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:RED → GREEN
test: Start the output interleaver with slot 0 of the video encoders empty.test_output_interleave_e2eruns 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_encoderandlate_audio_drops_the_first_keyframe_of_the_first_video_encoder, fail on master (nothing sent at the start; the late-audio prune drops nothing).test_output_interleave_e2e8/8, 3 of 3 runs, against libobs and libobs-with-rust in the C and Rust lanes. Full cmockactestin 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 testof the output tests (Tiers 1 and 3, the C oracle included): 100/100.ci/local_gate.py: lint, cross and rust-test pass.Checklist
masterdocs/features.mdis added (Fixed upstream bugs, Encoding, streaming and recording)-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