Repository navigation
libobs, obs-ffmpeg: Do not flash a Media Source's old frame on restart - #250
Merged
Merged
Conversation
…tivation (RED) With "Restart playback when source becomes active" on and "Show nothing when playback ends" off, the last frame stays on the source after playback ends. When the source leaves the program and comes back, activation only queues the restart; libobs runs queued media actions at the start of the next video tick, so the activating tick still draws the previous playback's last frame before playback starts over. restart_does_not_show_last_frame plays a generated clip (bright first frame, dark last frame) through the real ffmpeg_source in a scene, lets it end, switches the program to an empty scene and back, and checks every output frame. Today the output goes: nothing, LAST frame, first frame. The other cases cover the libobs half with a scripted async source whose video_tick clears it with obs_source_output_video(source, NULL) and then queues or preloads a new frame on the next tick, so each step lands on a known tick: - clear_then_frame_buffered and _unbuffered: today the cleared picture is drawn again after the clear, before the new frame is uploaded. - clear_still_clears and clear_then_preloaded_frame pass today and guard the fix: a clear must still clear, and a preloaded frame must show on the tick after the clear. 3 of 5 fail on this commit. Reported upstream in obsproject/obs-studio#4667 by mercantigo (earlier obsproject/obs-studio#2906). Refs obs-rust#249. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A Media Source restarted on activation showed the last frame of its previous playback before playing from the start. Two separate gaps let the old frame through: - ffmpeg_source_activate() only queues the restart; libobs runs queued media actions at the start of the next video tick, after the activating tick has drawn the old frame. Clear the source when activating, as the start already does once it runs. - obs_source_output_video(source, NULL) clears the frame queue but leaves the async textures holding the old picture. The next queued frame makes the source active again at once, but only reaches the textures when it is rendered; a tick that falls in between draws the old picture. Mark the textures stale on a clear and skip drawing them until a new frame is uploaded or a preloaded frame is shown. Either change alone still shows the old frame for one output frame. After a clear the first new frame is still taken on the next tick, so a source shows nothing for at most that tick instead of its old picture. Reported upstream in obsproject/obs-studio#4667 by mercantigo (earlier obsproject/obs-studio#2906). The activation half follows Poodmund's obsproject/obs-studio#11881. Fixes obs-rust#249. Co-Authored-By: Poodmund <[email protected]> Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]> Local-Gate: v1 tree=063f996b61117444efb24c1f29ce047f694f28d4 secs=122 lanes=lint:run,rust-test:run,tier2-linux:run Ci-Attestation: {"at":1791745713,"gate":"rust/all/fmt","host":"linux-x86_64","key":"372abb5d92176bf6d0c6a26f6228c920649b3df81fcec0bbf24f1ab3fe91e168","lane":"lint","parents":["dfdcbd0205e472b225ed605fe6c0aade08cb989f"],"secs":44,"stamp":"c4e29866047d059e697f9ce0d4bb526f","tree":"063f996b61117444efb24c1f29ce047f694f28d4","v":1,"via":"run"} Ci-Attestation: {"at":1791745713,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"372abb5d92176bf6d0c6a26f6228c920649b3df81fcec0bbf24f1ab3fe91e168","lane":"lint","parents":["dfdcbd0205e472b225ed605fe6c0aade08cb989f"],"secs":44,"stamp":"105893ca323c35b9008b8cfe9bef6686","tree":"063f996b61117444efb24c1f29ce047f694f28d4","v":1,"via":"run"} Ci-Attestation: {"at":1791745713,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"bcb469fa09bd4cc443cb908bcdc712951bee7148cf928df4721da754c9458ca0","lane":"rust-test","parents":["dfdcbd0205e472b225ed605fe6c0aade08cb989f"],"secs":30,"stamp":"5e90e5968de8b6aa0e64538a340e8fe4","tree":"063f996b61117444efb24c1f29ce047f694f28d4","v":1,"via":"run"} Ci-Attestation: {"at":1791745713,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"079598cf7af0b4420353ffb7b6181684d77d07450f0664cf8ac831e7d7945e80","lane":"tier2-linux","parents":["dfdcbd0205e472b225ed605fe6c0aade08cb989f"],"secs":48,"stamp":"9b77de4ae71ca954ad52e529e7affa3e","tree":"063f996b61117444efb24c1f29ce047f694f28d4","v":1,"via":"run"}
zackees
force-pushed
the
fix/4667-media-stale-frame
branch
from
October 11, 2026 19:08
8383fb5 to
bde26a6
Compare
Member
|
Verified locally, rebased onto master and stamped. The test needs a display and GL, so I ran it with
Merging once CI is green. |
This was referenced Oct 11, 2026
bug: obs-ffmpeg: Media Source shows empty frames when restarted on activation (upstream #10488)
#321
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
A Media Source that restarts when it becomes active no longer flashes the last frame of its previous playback before playing from the start.
With "Restart playback when source becomes active" on and "Show nothing when playback ends" off, the last frame stays on the source after playback ends. Two separate gaps then let it through when the source comes back:
ffmpeg_source_activate()only queues the restart. libobs runs queued media actions on the next video tick, after the activating tick has drawn the old frame.obs_source_output_video(source, NULL)clears the frame queue but leaves the async textures holding the old picture. The next queued frame makes the source active again at once, but only reaches the textures when it is rendered, so a render in between draws the old picture.test: Media Source must not flash its last frame when restarted on activation (RED):test_media_restart_stale_frameplays a generated clip (bright first frame, dark last frame) through the realffmpeg_sourcein a scene, lets it end, switches the program to an empty scene and back, and classifies every output frame. Today: nothing, LAST frame, first frame. Four more cases drive a scripted async source from itsvideo_tick, so each step lands on a known tick: clear then queue a frame (buffered and unbuffered) fails today because the cleared picture is drawn again; clear alone, and clear then show a preloaded frame, pass today and guard the fix. 3 of 5 fail on this commit.libobs, obs-ffmpeg: Do not flash a Media Source's old frame on restart:ffmpeg_source_activate()clears the source before queueing the restart. libobs gets an internalasync_textures_staleflag: set by a clear, cleared when a frame is uploaded or a preloaded frame is shown, and stale textures are not drawn. All 5 pass.Either half alone still shows the old frame for one output frame (checked by applying each on its own). After a clear, libobs still takes the first new frame on the next tick, so a cleared source shows nothing for at most that tick instead of its old picture. No API or struct visible to plugins changes.
Poodmund's upstream PR obsproject/obs-studio#11881 found the activation half, and this keeps it (credited as co-author). On its own it still leaves the libobs race, so the old frame can still appear for one frame. #11881 also clears the source on every deactivation and before every preload, which would blank a source that is still showing elsewhere (for example in the Studio Mode preview) and is not needed for this bug, so those parts are left out.
Motivation and Context
Fixes #249 (upstream obsproject/obs-studio#4667, reported by mercantigo; earlier obsproject/obs-studio#2906)
Why this one: open upstream since 2021 and confirmed on every release since 26.x by SimonGZ, CSMBY, parish-of-brentford, codemann8, VirtuallyJesse, DrewSunn, RoyceRemix, contentfree and SpokeLee. It shows a wrong frame on stream and in recordings whenever a scene with an animated overlay or intro is switched back to, and people have built workarounds around it. Eriknpy and LightningXCE asked on #11881 for a fix to be merged; this one comes with tests for both halves.
How Has This Been Tested?
Automated, in both libobs lanes (
ENABLE_RUST_LIBOBSOFF and ON):test_media_restart_stale_frame: 3 of 5 fail at the RED commit and 5 of 5 pass at the GREEN commit in both lanes; 10 of 10 repeated runs pass at GREEN in each lane.ci/test_registration.pyare clean.All runs used a private Xvfb with software GL.
Not tested:
Types of changes
Checklist:
🤖 Generated with Claude Code