Repository navigation
Description
Location
libobs/obs-encoder.c.h receive_video(): a grouped encoder starts only on the frame whose timestamp equals the group's start_timestamp:
if (encoder->encoder_group && !encoder->start_ts) {
...
ready = obs_encoder_audio_start_group_ready(group->start_timestamp, frame->timestamp); /* group_start == timestamp */
...
if (!ready)
goto wait_for_audio;
}libobs/media-io/video-io.c.h video_output_cur_frame(): an input with a frame rate divisor takes every n-th frame. It counts from the first frame video-io hands it after video_output_connect2(), where frame_rate_divisor_counter starts at 0:
// an explicit counter is used instead of remainder calculation
// to allow multiple encoders started at the same time to start on
// the same frame
uint32_t skip = input->frame_rate_divisor_counter++;libobs/obs-video.c.h video_sleep(): once every encoder of a ready group is started, it sets group->start_timestamp = *p_time, the time of the next frame the video thread renders.
Class
Logic error (race): a grouped encoder with a frame rate divisor above 1 sometimes never starts, so it never sends a packet.
How it is reached
The encoders connect to video-io (add_connection()) while the video thread runs. Sometimes video-io still has a frame queued from before start_timestamp when the encoders connect. That frame is the first one every input gets, so it sets the phase of the divisor counter. An encoder with divisor d then gets frames −1, d−1, 2d−1, … relative to the start frame, never the start frame itself, so group_start == timestamp never holds. Divisor 1 encoders skip the early frame and start on frame 0 as intended.
Seen in a scratch harness against the C libobs (master of 2026-10-17, macOS arm64, Metal, 30 fps): one group of three test encoders with divisors 1, 2 and 3 on one multitrack video output, started 8 times. An lldb log of receive_video() shows, relative to the start frame:
| start | divisor 1 | divisor 2 | divisor 3 | divisor 2 and 3 started |
|---|---|---|---|---|
| clean (2 of 8) | 0, 1, 2, … | 0, 2, 4, … | 0, 3, 6, … | yes |
| early frame (6 of 8) | −1, 0, 1, … | −1, 1, 3, … | −1, 2, 5, … | never |
A run without lldb: 5 of 8 starts left both divisor encoders at 0 frames. The divisor 2 and 3 encoders always fail together, because one early frame shifts both.
In the app: frontend/utility/MultitrackVideoOutput.cpp.hpp adjust_encoder_frame_rate_divisor() sets a divisor when the Go Live configuration asks for a rung at a lower frame rate than the canvas, for example a 30 fps rung on a 60 fps canvas. That rung's encoder can then send nothing. I have not reproduced this with a real Enhanced Broadcasting stream; the harness uses test encoders. No upstream issue found (searched obsproject/obs-studio for "frame rate divisor encoder group" and "multitrack divisor start").
Found while writing test_encoder_group_reconfig_walk for #2913 (PR #2919). That test runs every encoder at divisor 1 because of this race.
Only the user's own configuration and their streaming service's Go Live response reach this, and it stops a rung from starting; it reads or writes no memory out of bounds. So it is a normal public bug under SECURITY.md's two tiers.
Proposed fix and failing test
The fix is for the maintainers to choose. Options:
- Align the divisor counters with the group start: when
video_sleep()setsstart_timestamp, also make each grouped encoder's input take the start frame, for example a video-io call that resets an input'sframe_rate_divisor_counterso its next frame is not skipped. - Or connect a grouped encoder's video input only once the group is ready, so the first frame each input gets is the start frame.
- Or start a grouped encoder on the first frame with
timestamp >= start_timestamp. This alone moves divisor encoders off the shared start frame, which breaks the pts alignment the reconfigure rules (rust: Port the encoder group reconfigure rules in obs-encoder.c to obs-output #2913) depend on, so it would need the counter change as well.
RED: a real-libobs test (Linux, core video, under xvfb-run, like test_encoder_group_reconfig_walk) starts a group of encoders with divisors 1, 2 and 3 on a multitrack video output, 20 times. It asserts that every encoder encodes a frame within 1.5 s and that each encoder's first frame is the group's start frame. It fails on master in most runs.
GREEN: the fix, with the same test passing 20 of 20 starts. Then test_encoder_group_reconfig_walk can use divisors 1, 2 and 3 again.
Metadata
Metadata
Assignees
Type
Projects
- StatusShow more project fieldsDone
Activity
zackees commentedon Oct 29, 2026
Claiming: investigation
Taking this up as the worker on
obs-studio2. Plan:frame_rate_divisor_counteris per-input and starts at 0 onvideo_output_connect2(), so a frame queued beforegroup->start_timestampconsumes the0slot.video_output_*API that connects a divisor-2 input, feeds one frame before the group start, then the start frame, and asserts the input accepts the start frame (fails on master).frame_rate_divisor_counterfromvideo_sleep()wheregroup->start_timestampis set — and keeptest_encoder_group_reconfig_walkfree to use divisors > 1.fix/2920-grouped-encoder-divisor-start,Refs #2920.No
Decision needed:: option 1 is the minimal change that preserves the shared start frame that the #2913 reconfigure rules depend on (the issue rules out option 3 alone for exactly that reason).zackees commentedon Oct 29, 2026
/ready
Triage (worker): meets the definition of Ready —
path:linefor all three mechanisms (obs-encoder.c.hreceive_video(),video-io.c.hvideo_output_cur_frame(),obs-video.c.hvideo_sleep()), a named class (race / logic error), an 8-start harness with a per-divisor table, an explicit RED test sketch and a fix that is implementable without changing the shared start frame. Scope is one race; noDecision needed:remains once option 1 is chosen, and nothing blocks it.Priority
P2: a streamed rung that silently sends no packets is user-visible, but it needs a Go Live response asking for a lower-fps rung, and the harness shows it on most (not all) starts.size:S–M: one counter reset plus one test.zackees commentedon Oct 29, 2026
Claiming: grouped encoder frame-rate-divisor start alignment
Implementation of option 1 at the three sites listed; branch
fix/2920-grouped-encoder-divisor-start, one PR, RED test first.zackees commentedon Oct 29, 2026
Progress: draft PR #2926 (RED + fix, local GREEN on
test_video_io_hidden).test/cmocka/test_video_io_hidden.c::group_start_aligns_the_divisor_counterreports66667666 != 33334333on master: a divisor-2 input receives the frame after the group start frame.video_output_reset_frame_rate_divisor()+obs_encoder_align_frame_rate_divisor()called fromvideo_sleep()whengroup->start_timestampis set; 4 test(s) pass locally (xvfb-run -a ./test/cmocka/test_video_io_hidden).Still open in the draft, per the acceptance in the issue: the real-libobs 20-start harness (modelled on
test_encoder_group_reconfig_walkfrom #2919), the GPU-encode path (obs-video-gpu-encode.c.hkeeps its own counter and is not aligned here), and thedocs/features.mdline. The new video-io helper isEXPORT; a hidden alternative is described in the PR.libobs: clang-format the divisor-reset declaration (#2920)
test(video-io): pin the divisor phase that hides a group's start frame (
libobs: align a grouped encoder's divisor phase with the group start (#…
libobs: start a divisor encoder's phase at the group's start frame (#…
test(encoder-group): a divisor encoder starts on the group's start fr…
docs(features): the divisor rung start fix (#2920)
zackees commentedon Oct 29, 2026
Progress: the real-libobs case from the issue is in #2926, and it changed the fix.
Measured, not assumed. I added the issue's RED as
divisor_encoders_start_on_the_group_framein
test/cmocka/test_encoder_group_reconfig_walk.c(#2919's harness): three encoders atdivisors 1, 2 and 3 on one multitrack video output, every encoder must encode a frame and its
first frame must be the group's start frame. Against
origin/master(68771844d) it is red 5 of5 runs, with the divisor 2 and 3 encoders at 0 frames:
The counter reset alone does not fix it. With the first version of the fix (clear
frame_rate_divisor_counterwhenvideo_sleep()setsstart_timestamp) the same case stillreported 0 frames for both divisor encoders in every run: the video thread renders further
frames between the reset and the start frame, and each of them advances the counter again, so
"the next frame is the start frame" is not a property a reset can give.
So the API now carries the frame the phase starts on:
video_output_align_frame_rate_divisor(video, start_timestamp, callback, param)makes video-iodrop the frames rendered before
start_timestampwithout moving the counter, and deliverthe first frame at or after it whatever the counter was. Same case is now green 5 of 5 runs,
with all three encoders encoding from the same first pts.
Also settled in the PR:
rust/obs-media-io(
Input::start_timestamp,VideoOutput::align_divisor(), shim + Windows/EXPORTentry);libobs/media-io/video-io.ckeeps the C reference and the C oracle renames the symbol soit does not collide in
cargo test. Tier 1 and a Tier 3 C-vs-Rust parity case(
divisor_align_matches) cover it.start_gpu_encode()'s own counter is advanced onlyafter the group's
start_timestampcheck, so pre-start frames never consume its slots.docs/features.mdline added (Enhanced Broadcasting, lower-frame-rate rung).test(video-io): pin the divisor phase that hides a group's start frame (
libobs: align a grouped encoder's divisor phase with the group start (#…
libobs: start a divisor encoder's phase at the group's start frame (#…
test(encoder-group): a divisor encoder starts on the group's start fr…
docs(features): the divisor rung start fix (#2920)
test(video-io): pin the divisor phase that hides a group's start frame (
libobs: align a grouped encoder's divisor phase with the group start (#…
libobs: clang-format the divisor-reset declaration (#2920)
libobs: start a divisor encoder's phase at the group's start frame (o…