Skip to content

bug: media-playback: Media Source seek lands on the keyframe before the requested time (upstream obsproject/obs-websocket#1190) #478

Closed

Description

@rdoupe

Upstream OBS bug, reported by casperboone in obsproject/obs-websocket#1190 (OBS 30.0.2, macOS: SetMediaInputCursor to 20210 ms gives 20040 ms, 28242 ms gives 26600 ms). lrq51678, jwetzell (the reported mediaCursor is about 3 seconds off) and chnoma (OBS 31.0.0, Linux: positions snap down to 3 second steps, 1500 -> 0, 5500 -> 3000) see the same. chnoma traced it to AVSEEK_FLAG_BACKWARD in media-playback, so it is not specific to obs-websocket: the Media Source seek bar does the same. The code has not changed in this fork.

Location

  • shared/media-playback/media-playback/media.c seek_to() (lines 530-564): seeks the demuxer with AVSEEK_FLAG_BACKWARD (line 539), which lands on the keyframe at or before the target, flushes the decoders and presents the first frame they return. Nothing skips the frames between the keyframe and the target.
  • mp_media_get_current_time() (line 1131) reports the decoders' next pts, so the media time is the keyframe's too.
  • shared/media-playback/media-playback/cache.c seek_to() (lines 164-213), used when the source fully decodes the file: compares the seek position, in microseconds, with frame timestamps in nanoseconds, so every seek goes to the start of the file.

Class

Wrong result (seek position and reported time), not subjective: the requested time is ignored.

How it is reached

  • obs-websocket SetMediaInputCursor / OffsetMediaInputCursor, then GetMediaInputStatus.
  • Dragging or clicking the seek bar in the Media Source controls.
  • Any file whose keyframes are far apart (most camera and screen recordings use 2 to 10 seconds).

Reproduced in the current release AppImage (33.0.0-beta6-799, Rust libobs), headless with obs-websocket. Media Source on a 30 fps file with a keyframe every 3 seconds and the frame number drawn on each frame, paused:

Seek to Media time reported Frame shown Expected frame
1500 ms 33 ms 0 45
2000 ms 33 ms 0 60
5500 ms 3033 ms 90 165
7000 ms 6033 ms 180 210

With "fully decode" on (the cached path), seeks to 1500 ms and 5500 ms both went back to the start (66 ms).

Upstream work

None found (no upstream PR touches the media-playback seek).

Proposed fix and failing test

Fix: keep the backward seek (the decoder needs to start at a keyframe), then drop the decoded video and audio frames that end at or before the target until both streams have a frame at the target. Only seeks the user asks for do this; restarts and files without a duration are unchanged. In the cached path, convert the seek position to nanoseconds before comparing it with frame timestamps.

RED test (cmocka, test_media_seek_keyframe, no display needed). It writes a 30 fps MPEG-4 clip with a keyframe every 90 frames, each frame carrying its number in flat luma blocks (one clip also has AAC audio whose level steps up every 500 ms), and plays it through media-playback. Cases:

  • paused seeks to 1500 ms and 5500 ms: frame shown and media time;
  • a seek while playing: the first frame after it;
  • a seek with audio: the first audio level after it;
  • a seek to the last frame;
  • the cached path;
  • a guard: a seek onto a keyframe (passes today).

6 of 7 fail today.

Activity

  1. rdoupe commented on Oct 13, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: this issue.

    1. RED: test_media_seek_keyframe (7 cases): a 30 fps clip with a keyframe every 3 seconds is played through media-playback and seeked; paused and playing seeks land on the keyframe before the target (1500 ms shows frame 0 at 33 ms, 5500 ms shows frame 90 at 3033 ms), and the "fully decode" path goes back to the start. 6 of 7 fail on master (the seek onto a keyframe is a guard). Reproduced in the current release AppImage over obs-websocket.
    2. GREEN: keep the backward seek, then drop decoded video and audio frames before the target for user seeks; convert the cached path's seek position to nanoseconds before comparing.
      PR today.
  2. rdoupe commented on Oct 13, 2026

    @rdoupe
    CollaboratorAuthor

    @casperboone you reported this in obsproject/obs-websocket#1190 (SetMediaInputCursor to 20210 ms landing on 20040, 28242 on 26600), so a heads-up: it's fixed here in obs-rust by #479, with a regression test.

    Cause: the Media Source seeks with FFmpeg's backward flag, which lands on the keyframe before the requested time, then shows the first frame the decoder returns and reports that keyframe's time. It wasn't the websocket: the same happens from the media controls. chnoma traced it to that flag in the upstream thread. Seeks now decode forward from the keyframe and drop frames before the target, so the picture and the reported time both land on the time you asked for. The "fully decode" (cached) path had a second bug that sent every seek near the start; that's fixed too.

    Workaround on stock OBS: encode the file with a short keyframe interval (for example -g 30 at 30 fps), so the nearest earlier keyframe is close to any target.

    It will be in the next obs-rust daily release after 0.1.0-beta.20261012: https://github.com/obs-rust/obs-studio/releases (on Arch it's obs-studio-rust-git in the AUR). obs-rust is an AI-assisted fork of OBS.

    If you get a chance to try it, a reply here on whether your seeks land where you asked would really help.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Metadata

Metadata

Assignees

No one assigned

    Labels

    No labels
    No labels

    Type

    No type

    Projects

    Milestone

    No milestone

    Relationships

    None yet

    Development

    No branches or pull requests

    Issue actions