Skip to content

shared/media-playback: Show the last frames of non-looping media - #307

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/10425-gif-frames
Oct 12, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/10425-gif-frames

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

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:

  1. 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 the offset in mp_media_reset).

  2. The stop calls media_stopped, which clears the source with obs_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.

  3. test: Media Source shows every frame of a one-shot GIF: test_media_gif_last_frame writes a 10-frame GIF with libavformat (one distinct solid colour per frame, 100 ms each), plays it once through the real ffmpeg_source at 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.

  4. 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_LIBOBS OFF 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.
  • All test_media_* tests repeated 5 times: pass.
  • Full ctest at GREEN: 96 of 96 in each lane under a private Xvfb; without a display the new test's cases skip, like the other core tests.
  • clang-format, gersemi and ci/test_registration.py are clean.

Not tested / not fixed:

  • The Stinger "preload into memory" path (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.
  • 60 fps output, Windows (the reporter's platform), hardware decoding, GIFs with varying frame delays or a final frame over 3 s (the hold is capped there), audio+video clips at the end.
  • The upstream report bisects to 19.0.1; that commit was not identified.

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

rdoupe and others added 2 commits October 11, 2026 23:23
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]>
@rdoupe
rdoupe requested a review from zackees as a code owner October 12, 2026 03:35
@zackees
zackees merged commit 58e7567 into obs-rust:master Oct 12, 2026
23 checks passed
@zackees

zackees commented Oct 12, 2026

Copy link
Copy Markdown
Member

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

  • RED (627772224): 1 of 3 passed. gif_once_shows_every_frame and video_once_shows_every_frame failed.
  • GREEN (fb3a89723): the test passed. Plain Tier 2 passed 97 of 97 with ENABLE_RUST_LIBOBS OFF and 97 of 97 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: media-playback: non-looping media (e.g. a GIF) drops its last frames (upstream #10425)

2 participants