Repository navigation
media-playback: Clear end of file when seeking - #313
Merged
Merged
Conversation
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]>
zackees
approved these changes
Oct 12, 2026
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"}
Member
|
Verified locally on master. The test needs a display, so I ran it with
Merging once CI is green. |
zackees
force-pushed
the
fix/11195-mp3-cover-seek
branch
from
October 12, 2026 04:16
b64d9ba to
2c06829
Compare
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
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), andmedia.ccounts 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 setsm->eof.seek_to()repositions the demuxer and flushes the decoders but never clearedm->eof(onlymp_media_reset()does), so after a seek no more packets were read, both decoders drained, playback ended and the source reset to 0.test/cmocka: Add RED test for seeking audio with cover art:test_media_cover_art_seekplays a generated 5 s tone through the realffmpeg_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:3 of 5 fail.
media-playback: Clear end of file when seeking: once a local file has been repositioned,seek_to()clearsm->eof, since a seek invalidates the demuxer's end of file. A libavformat probe confirmed FFmpeg queues the cover packet again after everyav_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_LIBOBSOFF 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).ci/test_registration.pyare clean; the test is registered for Linux only, with its working directory inside that guard.Not tested / not fixed:
libobs/audio-monitoring/win32/wasapi-output.c(process_audio_delay()never updatesprev_video_tsafter the cover frame is output again), and needs Windows to verify; it is not part of this change.Types of changes
Checklist:
🤖 Generated with Claude Code