Repository navigation
shared/media-playback: Show the last frames of non-looping media - #307
Merged
Merged
Conversation
Plays a generated ten-frame GIF (a distinct solid colour per frame, 100 ms each) through the real ffmpeg_source with Loop off and "Show nothing when playback ends" on, and classifies every program output frame. Every frame must appear, in order, and the last one must stay up for at least two output frames. Guards: the same GIF looping (two full loops in order) and the same frames as a raw video file played once. On master (30 fps output, xvfb) the one-shot GIF and the one-shot video both show only 8 of 10 frames: the last two are cleared before they are displayed. The looping GIF passes. Without a display every case skips. Reported upstream in obsproject/obs-studio#10425 by XC3N. Refs obs-rust#306. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
A Media Source with Loop off and "Show nothing when playback ends" on (the default) cleared itself before its last frames were displayed, so a one-shot GIF stopped short of its end. The media thread treated playback as ended as soon as it had output the last frame, without waiting for that frame's duration, and stopping clears the source with obs_source_output_video(NULL). That clear drops the frames libobs still has queued, and libobs shows a buffered async frame up to about one frame interval plus one output frame after it is output. So the last frame was never shown and the one before it often was not either. When non-looping playback reaches the end, hold the last frame for its duration, the interval between the last two frames and two output frames before ending, much like looping playback already waits for the last frame's duration before it starts over. A user stop still clears at once. With a ten-frame GIF at 100 ms per frame and 30 fps output, the one-shot GIF and the same frames as video now show all 10 frames instead of 8, the last for 4-5 output frames; looping playback is unchanged. Fixes obs-rust#306. Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Member
|
Verified locally, rebased onto master and stamped. The test needs a display, so I ran it with
Merging once CI is green. |
This was referenced Oct 12, 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
A Media Source playing a GIF or clip once (Loop off) now shows its last frames instead of cutting them.
Two things add up:
When the media thread runs out of frames with looping off,
mp_media_eof()stops playback at once, without waiting for the last frame's duration (looping waits for it through theoffsetinmp_media_reset).The stop calls
media_stopped, which clears the source withobs_source_output_video(NULL), and that drops every frame libobs has queued but not yet shown (free_async_cache). Media sources run in buffered mode, where libobs shows a frame up to about one frame interval plus one output frame after it is output (measured: 133 ms after output for 100 ms frames at 30 fps). So the last frame, and usually the one before it, is never shown, matching the report's "about 90% of frames". It is not GIF-specific; at video frame rates it is just hard to see. "Show nothing when playback ends" is on by default.test: Media Source shows every frame of a one-shot GIF:test_media_gif_last_framewrites a 10-frame GIF with libavformat (one distinct solid colour per frame, 100 ms each), plays it once through the realffmpeg_sourceat 30 fps output, and records which colours appear on program output and in what order. Today: 8 of 10 frames for the one-shot GIF and for a one-shot video clip (raw BGRA guard); the looping GIF guard passes. 2 of 3 fail.shared/media-playback: Show the last frames of non-looping media: when playback reaches its end with Loop off, the media thread keeps the last frame up before it stops: the last frame's duration, plus the interval between the last two frames, plus two output frames (obs_get_frame_interval_ns()), each part capped at 3 s like the thread's existing inter-frame limit. A user stop still clears at once and looping is untouched; the "media ended" signal fires correspondingly later. All 10 frames now appear in order. All 3 pass.Rejected alternatives: changing libobs's async frame clock (it would shift timing and A/V sync for every buffered async source), and keeping queued frames on clear (it would bring back the stale-frame flash on restart fixed in #250). The part of the wait that covers libobs's display delay is a bound derived from how libobs schedules frames, not a measurement, so the last frame stays up 1-2 output frames longer than its nominal time.
Motivation and Context
Fixes #306 (upstream obsproject/obs-studio#10425, reported by XC3N, reproduced by RytoEX)
Why this one: one-shot GIFs and clips (alerts, stingers-as-media, intros) lose their ending on stream and in recordings. No upstream fix exists.
How Has This Been Tested?
Automated, in both libobs lanes (
ENABLE_RUST_LIBOBSOFF and ON), rebased on current master:test_media_gif_last_frame: 2 of 3 fail at the RED commit (deterministic over several runs), 3 of 3 pass at GREEN.test_media_*tests repeated 5 times: pass.ci/test_registration.pyare clean.Not tested / not fixed:
full_decode,cache.c) still loses its last frame; it is only reachable from stinger transitions and left unchanged here to keep stinger timing as it is.Types of changes
Checklist:
🤖 Generated with Claude Code