Skip to content

bug: libobs: Media Source loses its audio sync offset when it restarts (upstream #11640) #286

Closed

Description

@rdoupe

Upstream OBS bug, reported by Penwy in obsproject/obs-studio#11640 (with a video; reproduced on Ubuntu 24.04 with 31.0.0 and on Windows 11 with 30.2.3). Code unchanged in this fork.

Location

  • libobs/obs-source.c:1497: reset_audio_data() empties a source's audio buffer and makes it start at the current system time, without the source's sync offset.
  • libobs/obs-source.c:3831: obs_source_show_preloaded_video(), called when a Media Source starts playback, resets the buffer that way; handle_ts_jump() (:1509) does the same after a timestamp jump of more than 2 s.
  • source_output_audio_data() then appends every packet that continues seamlessly from that time to the buffer as it is (push_back); the sync offset is only added to a packet's own timestamp, which only matters when a packet is placed. So the offset is lost until something forces a placement.

Class

Audio/video desync: the audio delay set in Advanced Audio Properties stops applying, in recordings and streams.

How it is reached

Give a Media Source an audio sync offset and start it (upstream: after transitioning away to a scene with another media source and back). The audio plays without the delay from then on. Whether the packets after the reset continue seamlessly depends on the media timeline: upstream it happened after a scene round trip; in this fork it already happens when the first Media Source of the process starts.

Reproduced with the real ffmpeg_source and a generated clip with a flash and a click at the same time, offset 300 ms: the program audio's click lagged the flash by −69 ms instead of ~230 ms. After obs_source_show_preloaded_video() or a >2 s timestamp jump, the buffer starts 0 ms after the reset instead of 300 ms.

Proposed fix and failing test

Fix: after either reset, start the buffer at that system time shifted by the sync offset (and the resampler offset), where a packet placed on its own would land. Packets placed by their own timestamp are unchanged.

RED test (cmocka, test_media_sync_offset_restart): four cases run the real Media Source and measure the program audio/video lag before and after a round trip through a second scene with another media source (looping clip, long time away, ended clip, and a no-offset guard); two cases drive obs_source_show_preloaded_video() and a timestamp jump directly. 3 of 6 fail today.

Activity

  1. rdoupe commented on Oct 11, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: this issue.

    1. RED: test_media_sync_offset_restart (3 of 6 failing): the real Media Source with a 300 ms offset, program audio/video lag measured before and after a scene round trip, plus both buffer-reset paths driven directly.
    2. GREEN: start the audio buffer at the reset time shifted by the sync offset.
      PR today.
  2. added 2 commits that reference this issue on Oct 11, 2026
    bf3c8ea
    8e52822
  3. rdoupe commented on Oct 12, 2026

    @rdoupe
    CollaboratorAuthor

    @Penwy you reported this in obsproject/obs-studio#11640, so a heads-up: it's fixed here in obs-rust by #287, merged today with a regression test.

    Cause: when a Media Source starts playback, OBS shows the preloaded first frame and empties the source's audio buffer so the audio continues from that frame. The buffer was restarted at the current time without the sync offset, and every following packet that continued seamlessly was appended as is, so the offset was skipped until something forced a resync. A timestamp jump of more than 2 s reset the buffer the same way. Now both resets start the buffer shifted by the sync offset. The test plays a clip with a flash and a click through a real Media Source with a 300 ms offset and measures program audio against video before and after a round trip through a second scene with another media source; it also drives both reset paths directly, where the buffer used to start 0 ms after the reset and now starts 300 ms after it.

    One difference from your report: in this fork the offset was already lost at the first activation, not only after the round trip; the cause is the same.

    Workaround on stock OBS: change the sync offset (or toggle it off and on) after the source restarts.

    obs-rust is an AI-assisted fork of OBS; on Arch it's obs-studio-rust-git in the AUR.

    If you try it, a short reply here on whether the delay now survives your transition would really help.

  4. Penwy commented on Oct 12, 2026

    @Penwy
    Contributor

    I thank you for the kind thought, but I am in no way whatsoever interested in this project

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