Skip to content

libobs, obs-ffmpeg: Do not flash a Media Source's old frame on restart - #250

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/4667-media-stale-frame
Oct 11, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/4667-media-stale-frame

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 11, 2026

Copy link
Copy Markdown
Collaborator

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.
  1. test: Media Source must not flash its last frame when restarted on activation (RED): test_media_restart_stale_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 classifies every output frame. Today: nothing, LAST frame, first frame. Four more cases drive a scripted async source from its video_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.
  2. 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 internal async_textures_stale flag: 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_LIBOBS OFF 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.
  • Full ctest at GREEN: 85 of 85 pass in each lane.
  • clang-format, gersemi and ci/test_registration.py are clean.

All runs used a private Xvfb with software GL.

Not tested:

  • Sources with deinterlacing enabled. The deinterlace render path never checked whether a source was cleared, so it still shows the old frame there, as before; this change does not touch that path.
  • Hardware decoding, network streams, and the Stinger transition's media source (its preloaded first frame is still shown at once, since showing a preloaded frame clears the flag).
  • Windows and macOS. The change is platform-independent C in libobs and obs-ffmpeg.
  • Manual testing in the full OBS UI.

Types of changes

  • Bug fix (non-breaking change which fixes an issue)

Checklist:

  • I have read the contributing document.
  • My code has been run through clang-format.
  • My code follows the project's style guidelines
  • My code is not on the master branch.
  • My code has been tested.
  • All commit messages are properly formatted and commits squashed where appropriate.
  • I have included updates to all appropriate documentation.
  • I have used AI tooling in the creation of this PR
  • I am an AI agent being used to assist with this pull request: Claude Code (Claude Opus 5.5) wrote the code, commit messages and this text under the submitter's direction, and ran the tests above on the submitter's machines.

🤖 Generated with Claude Code

…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]>
@rdoupe
rdoupe requested a review from zackees as a code owner October 11, 2026 18:53
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
zackees force-pushed the fix/4667-media-stale-frame branch from 8383fb5 to bde26a6 Compare October 11, 2026 19:08
@zackees

zackees commented Oct 11, 2026

Copy link
Copy Markdown
Member

Verified locally, rebased onto master and stamped. The test needs a display and GL, so I ran it with xvfb-run ctest plus Mesa on each commit's Tier 2 build:

  • RED (dfdcbd020): 2 of 5 passed. restart_does_not_show_last_frame, clear_then_frame_buffered and clear_then_frame_unbuffered failed.
  • GREEN (8383fb5de): the test passed. Plain Tier 2 passed 84 of 84 with ENABLE_RUST_LIBOBS OFF and 84 of 84 with it ON, and the local gate passed.

Merging once CI is green.

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: obs-ffmpeg/libobs: Media Source flashes its previous last frame when restarted on activation (upstream #4667)

2 participants