Skip to content

bug: libobs: a restarted Media Source first plays the end of its previous playback (44.1 kHz files) (upstream obsproject/obs-studio#7063) #545

Closed

Description

@rdoupe

Upstream OBS bug, reported by norihiro in obsproject/obs-studio#7063 (OBS 28 beta, Fedora 35): when a Media Source plays an audio file whose sample rate differs from OBS's (44.1 kHz into 48 kHz) and is started again, the first thing heard is the end of the previous playback, then the file from its beginning. The report shows it in a recording of a chirp (the high-frequency end appears before the low-frequency start). It is still open upstream, and the code is the same in this fork.

Location

  • libobs/obs-source.c process_audio() converts a source's audio with source->resampler (libswresample), which holds back the last samples of every packet for its filter. They come out with the next packet.
  • The resampler is only recreated when the format, sample rate, channel layout or clock drift setting changes (reset_resampler()). When a file ends, the held-back samples stay, and when it is started again they are output in front of the new audio, however long after the end that is. libobs already treats a packet more than 70 ms (TS_SMOOTHING_THRESHOLD) from where the previous one ended as a new stream for its timing, but not for the resampler.

Class

Audio glitch (a click of old audio at the start of every restart), in recordings and streams.

How it is reached

  • Media Source with an audio or video file at a sample rate other than OBS's (44.1 kHz files into the default 48 kHz is the common case), played to its end and started again: Restart button, "Restart playback when source becomes active", a scene switch, a hotkey, obs-websocket TriggerMediaInputAction RESTART. Also any other audio source that stops and starts again with resampling.

Reproduced in the current release

AppImage 33.0.0-beta6-799, headless, private config, obs-websocket: a Media Source playing a 44.1 kHz WAV (0.5 s of silence, then 0.5 s of a 1 kHz tone), restarted three times 2 s apart while recording. The recording, scanned in 1 ms windows:

  • 44.1 kHz file: at each restart after the first, a burst of the tone (2 ms) half a second before the tone really starts.
  • The same file at 48 kHz: no burst.

Proposed fix and failing test

Fix: in process_audio(), remember where the next packet into the resampler should start; a packet more than 70 ms away from it (the same limit libobs already uses for timing) begins a new stream, so the resampler is recreated empty. Continuing packets, with or without jitter, are unchanged.

RED test (cmocka, test_audio_restart_resampler_tail, real libobs input path, no video):

  • a 44.1 kHz tone, then a packet of silence 1 s or 100 ms after the tone ended: the silence must come out silent (today: 23 samples of the old tone, peak 0.9);
  • controls: silence that continues the tone without a gap, or 20 ms late, keeps the end of the tone in front of it.

The two restart cases fail today.

Activity

  1. rdoupe commented on Oct 13, 2026

    @rdoupe
    CollaboratorAuthor

    Claiming: this issue.

    1. RED: test_audio_restart_resampler_tail (2 of 4 failing): a 44.1 kHz source restarted after a gap gets the old tone first.
    2. GREEN: recreate the source's resampler when a packet does not continue the previous one (more than 70 ms off), continuing audio unchanged.
      PR today.
  2. added a commit that references this issue on Oct 13, 2026
    49ffbd6
  3. rdoupe commented on Oct 13, 2026

    @rdoupe
    CollaboratorAuthor

    @norihiro you reported this in obsproject/obs-studio#7063 (a Media Source playing a 44.1 kHz file, started again, first plays the end of its previous playback), so a heads-up: it's fixed here in obs-rust by #546, with a regression test.

    Cause: libobs converts the source's audio with a libswresample resampler, which holds back the last samples of every packet for its filter and puts them in front of the next packet, however much later that comes. After a file ended, those samples stayed in the resampler and came out at the start of the next playback. The resampler is now recreated empty when a packet starts more than 70 ms from where the previous one ended (the limit libobs already uses to tell a continuing stream from a new one); audio that continues normally, jitter included, goes through unchanged. In the obs-rust release, two of three restarts of a 44.1 kHz test file started with a 2 ms burst of the old tone; with the fix none did.

    Workaround on stock OBS: use files at OBS's own sample rate (Settings > Audio), since no resampling means nothing is held back.

    It will be in the next obs-rust daily release after 0.1.0-beta.20261012: https://github.com/obs-rust/obs-studio/releases (Windows, macOS and Linux builds; 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 restarts still start with the old audio 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