Skip to content

Buffered async video lags behind #12459

Open

Description

@stephematician

Operating System Info

Ubuntu 24.04

Other OS

No response

OBS Studio Version

31.1.2

OBS Studio Version (Other)

No response

OBS Studio Log URL

https://obsproject.com/logs/MLjBf83CxDTC3U8y

OBS Studio Crash Log URL

No response

Expected Behavior

The square for the Sync Test (Async Video/Audio Source) should alternative from black to white every second. There should be a tone playing when the square is white.

Current Behavior

In the original version of the (test) source: The tone plays while the audio is black, and is silent while it is white.

In the modified version (using absolute timestamps): there is a 1 second delay before the square starts alternating colour.

Steps to Reproduce

  1. Build OBS with the test sources.
  2. Add a Sync Test (Async Video/Audio Source) to the scene.
  3. Start/End recording then listen to result.

I also modified the test source to use an absolute timestamp (i.e. one that doesn't start at zero) by making the following changes:

--- a/test/test-input/sync-async-source.c
+++ b/test/test-input/sync-async-source.c
@@ -60,7 +60,7 @@ static void *video_thread(void *data)
        uint64_t cur_time = os_gettime_ns();
        bool whitelist = false;
        double cos_val = 0.0;
-       uint64_t start_time = cur_time;
+       // uint64_t start_time = cur_time;
 
        struct obs_source_frame frame = {
                .data = {[0] = (uint8_t *)pixels},
@@ -80,8 +80,8 @@ static void *video_thread(void *data)
        while (os_event_try(ast->stop_signal) == EAGAIN) {
                fill_texture(pixels, whitelist ? 0xFFFFFFFF : 0xFF000000);
 
-               frame.timestamp = cur_time - start_time;
-               audio.timestamp = cur_time - start_time;
+               frame.timestamp = cur_time; // - start_time;
+               audio.timestamp = cur_time; //- start_time;
 
                if (whitelist) {
                        for (size_t i = 0; i < sample_rate; i++) {

I then performed the same test.

Anything else we should know?

There are two relatively obvious causes of these bugs within obs-source.c: Firstly, the following test incorrectly short-circuits the frame-readying procedure if the first timestamp was zero:

if (!source->last_frame_ts || ready_async_frame(source, sys_time)) {

The second issue is that changes in the system (video) time are only accounted for when the queue is non-empty. This effectively guarantees that async video is one frame behind at all times; see the code surrounding:

source->last_frame_ts += sys_offset;
).

The potential for incorrect accumulation for last_frame_ts is almost certainly related to other issues with buffered async video observed here: https://obsproject.com/forum/threads/video-gradually-falling-behind-audio-where-can-i-start-investigating.187021/

Activity

  1. added a commit that references this issue on Jul 31, 2025
    16081c8
  2. added 5 commits that reference this issue on Aug 11, 2025
    d9e4d1e
    6b9b0ad
    b9d3c2e
    b068ca4
    61798ba
  3. added a commit that references this issue on Dec 24, 2025
    167a9b8
  4. added a commit that references this issue on Jan 4, 2026
    5d1c492
  5. added a commit that references this issue on Apr 6, 2026
    0297180
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

    No projects

      Milestone

      No milestone

      Relationships

      None yet

      Development

      No branches or pull requests

      Issue actions