Repository navigation
obs-ffmpeg: Make a keyframe when an output joins a running encoder - #598
Merged
zackees merged 2 commits intoOct 13, 2026
Merged
Conversation
test_encoder_join_keyframe checked the request_keyframe path with a stand-in encoder only. Add cases that run the same scenario, a replay buffer running on a video encoder with a 10 s keyframe interval and a recording that joins it, with the real encoders, loaded from the built obs-x264 and obs-ffmpeg modules: x264, VA-API H.264 and HEVC, AOM AV1 and SVT-AV1. The joining output's first packet must be a keyframe made from the frame the encoder got when it joined, give or take a few frames. x264 passes; it implements request_keyframe. The four obs-ffmpeg encoders do not, and their joining output gets nothing within 3 s: it waits for the next scheduled keyframe. Each case skips when its encoder is not available (no VA-API device, FFmpeg built without the library). The core video size grows to 320x240 for the hardware encoders' minimum size. Refs obs-rust#597. Co-Authored-By: Claude Opus 5.5 <[email protected]>
A recording started while the replay buffer runs joins the video encoder the replay buffer already runs, and gets no packet before a keyframe. libobs asks the encoder for one through request_keyframe, but only obs-x264 implemented it: with the VA-API, AOM AV1 and SVT-AV1 encoders the recording still waited for the next scheduled keyframe (VA-API's default interval is 120 frames, 6 s at 20 fps), so it missed its first seconds, and one stopped before that keyframe came out empty after a slow stop. Implement request_keyframe for the VA-API H.264 and HEVC encoders and for AOM AV1 and SVT-AV1: the next frame goes to FFmpeg with pict_type AV_PICTURE_TYPE_I, which FFmpeg's VA-API encoders turn into an IDR frame, libaom into a forced keyframe and SVT-AV1 into a key picture. The joining output's first packet is now a keyframe made from the frame the encoder got when it joined, within a frame either way. Fixes obs-rust#597. Co-Authored-By: Claude Opus 5.5 <[email protected]> Local-Gate: v1 tree=327ccadef8c1c1d5fbd37bd9149ba57169e0a1aa secs=457 lanes=lint:run,rust-test:run,cross:run,tier2-linux:run Ci-Attestation: {"at":1791908926,"gate":"rust/all/fmt","host":"linux-x86_64","key":"af20fb1baf63482c50ae11f2c5dd4a971494d9e9b8bcc875d0dfde2f7bb06483","lane":"lint","parents":["a503d6bd4d832aa17b93d0f144d4004dca8d55d9"],"secs":36,"stamp":"86ebec723f1221d2c596efa087386d09","tree":"327ccadef8c1c1d5fbd37bd9149ba57169e0a1aa","v":1,"via":"run"} Ci-Attestation: {"at":1791908926,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"af20fb1baf63482c50ae11f2c5dd4a971494d9e9b8bcc875d0dfde2f7bb06483","lane":"lint","parents":["a503d6bd4d832aa17b93d0f144d4004dca8d55d9"],"secs":36,"stamp":"cdf79df460b44bcf0ef07b9b6bf4a160","tree":"327ccadef8c1c1d5fbd37bd9149ba57169e0a1aa","v":1,"via":"run"} Ci-Attestation: {"at":1791908926,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"b5ffc7156f5cabe6c8c9936bf0eeaf65ee623ac9455faffb7501396544aa7f66","lane":"rust-test","parents":["a503d6bd4d832aa17b93d0f144d4004dca8d55d9"],"secs":118,"stamp":"1a1e4ebc14fec5ecec979279d6a12f57","tree":"327ccadef8c1c1d5fbd37bd9149ba57169e0a1aa","v":1,"via":"run"} Ci-Attestation: {"at":1791908926,"gate":"rust/x86_64-pc-windows-msvc/clippy","host":"linux-x86_64","key":"6431330132a19677a0deab32b8e17d5098a4add0d51c70289e589018cdf10199","lane":"cross","parents":["a503d6bd4d832aa17b93d0f144d4004dca8d55d9"],"secs":112,"stamp":"0410f2183f65cc571486558e49dac07e","tree":"327ccadef8c1c1d5fbd37bd9149ba57169e0a1aa","v":1,"via":"run"} Ci-Attestation: {"at":1791908926,"gate":"rust/x86_64-pc-windows-msvc/dylint","host":"linux-x86_64","key":"6431330132a19677a0deab32b8e17d5098a4add0d51c70289e589018cdf10199","lane":"cross","parents":["a503d6bd4d832aa17b93d0f144d4004dca8d55d9"],"secs":112,"stamp":"20ce29cbd541e274c2cb3d85354528a7","tree":"327ccadef8c1c1d5fbd37bd9149ba57169e0a1aa","v":1,"via":"run"} Ci-Attestation: {"at":1791908926,"gate":"rust/aarch64-apple-darwin/clippy","host":"linux-x86_64","key":"6431330132a19677a0deab32b8e17d5098a4add0d51c70289e589018cdf10199","lane":"cross","parents":["a503d6bd4d832aa17b93d0f144d4004dca8d55d9"],"secs":112,"stamp":"44250b48177e804f97ec76f8ea0b37f7","tree":"327ccadef8c1c1d5fbd37bd9149ba57169e0a1aa","v":1,"via":"run"} Ci-Attestation: {"at":1791908926,"gate":"rust/aarch64-apple-darwin/dylint","host":"linux-x86_64","key":"6431330132a19677a0deab32b8e17d5098a4add0d51c70289e589018cdf10199","lane":"cross","parents":["a503d6bd4d832aa17b93d0f144d4004dca8d55d9"],"secs":112,"stamp":"4bc13733b542482410c53535ad8aa0f9","tree":"327ccadef8c1c1d5fbd37bd9149ba57169e0a1aa","v":1,"via":"run"} Ci-Attestation: {"at":1791908926,"gate":"rust/x86_64-apple-darwin/clippy","host":"linux-x86_64","key":"6431330132a19677a0deab32b8e17d5098a4add0d51c70289e589018cdf10199","lane":"cross","parents":["a503d6bd4d832aa17b93d0f144d4004dca8d55d9"],"secs":112,"stamp":"4a126c73a3fd2c17c46e6ab2a25b82c1","tree":"327ccadef8c1c1d5fbd37bd9149ba57169e0a1aa","v":1,"via":"run"} Ci-Attestation: {"at":1791908926,"gate":"rust/x86_64-apple-darwin/dylint","host":"linux-x86_64","key":"6431330132a19677a0deab32b8e17d5098a4add0d51c70289e589018cdf10199","lane":"cross","parents":["a503d6bd4d832aa17b93d0f144d4004dca8d55d9"],"secs":112,"stamp":"e2e03f783385a1dbaeb861a1151c59ad","tree":"327ccadef8c1c1d5fbd37bd9149ba57169e0a1aa","v":1,"via":"run"} Ci-Attestation: {"at":1791908926,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"9ba0af34b22c0e234ad29e8bf970298f153cc818333da15a9c05d33ce81f489a","lane":"tier2-linux","parents":["a503d6bd4d832aa17b93d0f144d4004dca8d55d9"],"secs":191,"stamp":"aa67c4c8d78a4db655c6e4f1ed170f9e","tree":"327ccadef8c1c1d5fbd37bd9149ba57169e0a1aa","v":1,"via":"run"}
Member
|
Verified locally under xvfb-run (Tier 2 image + mesa): |
zackees
force-pushed
the
fix/keyframe-request-more-encoders
branch
from
October 13, 2026 16:28
00038db to
44170a4
Compare
This was referenced Oct 16, 2026
Closed
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.
Description
Follow-up to #594: a recording started while the replay buffer runs now also starts right away with the VA-API H.264 and HEVC encoders and with AOM AV1 and SVT-AV1, not only with x264. Before, at 20 fps with VA-API's default keyframe interval, a 6 s recording held 3 s, and one stopped before the encoder's next keyframe took over 3 s to stop and left an unreadable file.
#594 added the optional
request_keyframetoobs_encoder_info; libobs calls it when an output starts on a video encoder that already runs, because the new output gets no packet before a keyframe. This implements it in obs-ffmpeg: the next frame goes to FFmpeg withpict_type = AV_PICTURE_TYPE_I, which FFmpeg's VA-API encoders turn into an IDR frame, libaom into a forced keyframe (AOM_EFLAG_FORCE_KF) and SVT-AV1 into a key picture. The flag is set atomically by the request and taken by the next encode, as in obs-x264. No API change.test/cmocka: Add failing join cases for the encoders OBS ships on Linux:test_encoder_join_keyframegets cases that load the built obs-x264 and obs-ffmpeg modules and run the join with the real encoders, each set to a 10 s keyframe interval: x264, VA-API H.264, VA-API HEVC, AOM AV1, SVT-AV1. The joining output's first packet must be a keyframe made from the frame the encoder got when the output joined (within 3 frames; a scheduled keyframe is 300 frames away). Each case skips when its encoder is not available (no VA-API device, FFmpeg without the library), so CI runs what its FFmpeg has. Core video grows to 320x240 for the hardware encoders' minimum size.obs-ffmpeg: Make a keyframe when an output joins a running encoder: the fix.Encoders covered and not covered:
ffmpeg_vaapi,hevc_ffmpeg_vaapi)*_tex)vaapi_encode_internal); headless, they fall back to the copy encoders, so the GPU-texture path itself was not exercisedffmpeg_video_encode, one line once testedMotivation and Context
Fixes #597 (follow-up to #594; upstream obsproject/obs-studio#12069).
Reproduced headless, private config, over obs-websocket: Advanced output (the replay buffer shares the recording encoder), mkv, 20 fps, replay buffer 20 s, a Media Source looping a clip. Rounds: start the replay buffer, record from 3 s later for 6 s; and record from 1 s later for 2 s; twice each.
Why this one: our own half-fix: #594 fixed the reported data loss only for x264, and the same scenario still loses data with the hardware and AV1 encoders Linux users pick.
How Has This Been Tested?
Automated, in both libobs lanes (
ENABLE_RUST_LIBOBSOFF and ON):test_encoder_join_keyframe: 4 of 8 cases fail at the RED commit in each lane (VA-API H.264, VA-API HEVC, AOM AV1, SVT-AV1: no packet within 3 s); 8 of 8 pass at GREEN, 8 runs in each lane, the joining output's first packet a keyframe after 23-64 ms, within one frame of the join (x264: 0.7 s, its lookahead). All cases ran (no skips) under Xvfb, and also with the system graphics module masked as in CI; without a display every case skips, and with VA-API unavailable only the two VA-API cases skip.open_crashes_without_obs_coreskips).By hand: the end-to-end runs above with a frontend build of this branch (Rust libobs, obs-websocket). Not tested on Windows or macOS (the changed encoders are Linux-only except AOM/SVT AV1, whose change is the same FFmpeg call).
Types of changes
Checklist:
🤖 Generated with Claude Code