Skip to content

media-playback: Clear end of file when seeking - #313

Merged
zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/11195-mp3-cover-seek
Oct 12, 2026
Merged

zackees merged 2 commits into
obs-rust:masterfrom
rdoupe:fix/11195-mp3-cover-seek

Conversation

@rdoupe

@rdoupe rdoupe commented Oct 12, 2026

Copy link
Copy Markdown
Collaborator

Description

Seeking in an audio file with embedded cover art (MP3, FLAC, …) in a Media Source now continues from the new position instead of ending playback and jumping back to the start.

FFmpeg exposes the cover as a video stream with a single packet (AV_DISPOSITION_ATTACHED_PIC), and media.c counts it as video. After that one frame, mp_media_prepare_frames() keeps reading ahead for the next video frame, reaches the end of the file at once and sets m->eof. seek_to() repositions the demuxer and flushes the decoders but never cleared m->eof (only mp_media_reset() does), so after a seek no more packets were read, both decoders drained, playback ended and the source reset to 0.

  1. test/cmocka: Add RED test for seeking audio with cover art: test_media_cover_art_seek plays a generated 5 s tone through the real ffmpeg_source, as MP3 (libmp3lame; skipped without an MP3 encoder) and FLAC, with and without a JPEG cover, seeks to 2500 ms and watches the next 1500 ms of program audio and the media state:

    • MP3 with cover: ended 24 ms after the seek, tone heard 64 of 1500 ms — fails;
    • FLAC with cover: ended at 96 ms — fails;
    • MP3 with cover, seek after the scene was switched away and back: ended at 24 ms — fails;
    • MP3 and FLAC without cover: keep playing — guards.

    3 of 5 fail.

  2. media-playback: Clear end of file when seeking: once a local file has been repositioned, seek_to() clears m->eof, since a seek invalidates the demuxer's end of file. A libavformat probe confirmed FFmpeg queues the cover packet again after every av_seek_frame, so the cover keeps showing and the audio continues: with a cover, playback continues to ~4.0-4.1 s and the tone is heard ~1.47-1.51 s of the 1.5 s, the same as without one. All 5 pass.

Ignoring attached-picture streams (the reporter's workaround) was rejected: it removes the cover art users see, which the reporters wanted to keep. The change builds on #307's end-of-media handling in the same file.

Motivation and Context

Fixes #312 (upstream obsproject/obs-studio#11195, reported by ccc-rrr; also Sugam-Chand-M, olliesouthie and Colonel-Crapshot, confirmed by prgmitchell)

Why this one: most music files carry cover art, so the media slider was unusable for them in a Media Source. 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_cover_art_seek: 3 of 5 fail at the RED commit, 5 of 5 pass at GREEN (also 3 repeated runs).
  • Full ctest at GREEN: 99 of 99 in each lane under a private Xvfb, and without a display (the new test's cases skip, like the other core tests).
  • clang-format, gersemi and ci/test_registration.py are clean; the test is registered for Linux only, with its working directory inside that guard.

Not tested / not fixed:

  • The Windows-only "monitoring goes silent" symptom from OBS Studio refuses to monitor AND output certain mp3 files obsproject/obs-studio#9428 and #11739 has a different cause in libobs/audio-monitoring/win32/wasapi-output.c (process_audio_delay() never updates prev_video_ts after the cover frame is output again), and needs Windows to verify; it is not part of this change.
  • Hardware decoding, scrubbing while paused, network media, and actual monitoring output (the test checks program audio).

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

Plays a 5 s tone through the real ffmpeg_source, as MP3 and FLAC, with
and without an embedded cover (an attached picture), seeks to 2500 ms
with obs_source_media_set_time() and watches the next 1500 ms: the media
state, the media time and how long the tone reaches the program audio.
Another case shows the scene again after the program was on another
scene (restart on activate), checks playback starts over, then seeks.

On master (both the C and the Rust libobs lanes), the files with a cover
end and go back to the start instead of continuing from the seek:
- MP3 with cover: ended at 24 ms, tone heard for 64 ms of 1500 ms
- FLAC with cover: ended at 96 ms, tone heard for 64 ms
- MP3 with cover, seek after reactivation: ended at 24 ms, 42-64 ms heard
The guards without a cover keep playing: at 4008-4032 ms 1500 ms after
the seek, tone heard for 1472-1514 ms. Restarting playback when the
scene is shown again works on master.

Needs core video, so it runs under xvfb-run on Linux and skips without
a display.

Reported upstream in obsproject/obs-studio#11195 by ccc-rrr.

Refs obs-rust#312.

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 04:05
A Media Source playing an MP3 with an album cover could not be seeked:
clicking the seek bar made playback end and start over from the
beginning, and the same file without the cover seeked normally.

FFmpeg exposes the cover as a video stream with a single packet (an
attached picture). After that frame, mp_media_prepare_frames() keeps
reading ahead for the next video frame, reads to the end of the file at
once and sets m->eof. seek_to() moved the demuxer back into the file and
flushed the decoders, but kept m->eof, so no further packets were read:
both decoders drained, playback ended and the source reset to the start.
Only mp_media_reset() cleared it.

Clear m->eof once a local file has been repositioned. FFmpeg queues the
attached picture again after every seek, so the cover is shown again and
the audio continues from the new position. The cover keeps working as
the source's picture, as users expect, rather than being dropped.

Debugged into media.c by ccc-rrr in obsproject/obs-studio#11195.

Fixes obs-rust#312.

Co-Authored-By: Claude Opus 5.5 (1M context) <[email protected]>
Local-Gate: v1 tree=2ebdee176e507e0f32b72224d3b50f0028327767 secs=107 lanes=lint:run,rust-test:run,tier2-linux:run
Ci-Attestation: {"at":1791778610,"gate":"rust/all/fmt","host":"linux-x86_64","key":"e1a1e5768e635034649548bcabe4dc9ed8d3104fd0c8c1ecf2ff84f4a952db8c","lane":"lint","parents":["cc6a2fcbb7fe292c26578566fcebff51f17c8525"],"secs":16,"stamp":"7c7883cfcc5235a9fb50a96f0dccba79","tree":"2ebdee176e507e0f32b72224d3b50f0028327767","v":1,"via":"run"}
Ci-Attestation: {"at":1791778610,"gate":"rust/x86_64-unknown-linux-gnu/clippy","host":"linux-x86_64","key":"e1a1e5768e635034649548bcabe4dc9ed8d3104fd0c8c1ecf2ff84f4a952db8c","lane":"lint","parents":["cc6a2fcbb7fe292c26578566fcebff51f17c8525"],"secs":16,"stamp":"9d8bce006ce438f182500fd43a095f59","tree":"2ebdee176e507e0f32b72224d3b50f0028327767","v":1,"via":"run"}
Ci-Attestation: {"at":1791778610,"gate":"rust/x86_64-unknown-linux-gnu/test","host":"linux-x86_64","key":"904ce5d2957dbda3f08d04fadcc1041a5e81e5f462991b0271dc423d4a5d6103","lane":"rust-test","parents":["cc6a2fcbb7fe292c26578566fcebff51f17c8525"],"secs":47,"stamp":"0d3486ac1f87c3828d27300bf0168ad6","tree":"2ebdee176e507e0f32b72224d3b50f0028327767","v":1,"via":"run"}
Ci-Attestation: {"at":1791778610,"gate":"cpp/linux-x64/tier2","host":"linux-x86_64","key":"51823c24484e86334d3989ee9c1b4381f6e40af445424f96fed2bb1dae6ed8ec","lane":"tier2-linux","parents":["cc6a2fcbb7fe292c26578566fcebff51f17c8525"],"secs":44,"stamp":"bb0f308a4b545db8c1c3d96e9ccece96","tree":"2ebdee176e507e0f32b72224d3b50f0028327767","v":1,"via":"run"}
@zackees

zackees commented Oct 12, 2026

Copy link
Copy Markdown
Member

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

  • RED (cc6a2fcbb): 2 of 5 passed. mp3_with_cover_seeks, flac_with_cover_seeks and cover_restarts_and_seeks_after_reactivation failed.
  • GREEN (b64d9baec): the test passed. Plain Tier 2 passed 100 of 100 with ENABLE_RUST_LIBOBS OFF and 100 of 100 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: seeking audio with embedded cover art ends playback (upstream #11195)

2 participants