Repository navigation
Description
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
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
- Build OBS with the test sources.
- Add a Sync Test (Async Video/Audio Source) to the scene.
- 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:
obs-studio/libobs/obs-source.c
Line 4072 in 7778070
| 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:
obs-studio/libobs/obs-source.c
Line 4016 in 7778070
| 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
libobs: Fix timestamp semantics in async video
libobs: Amend timestamp semantics in async video
libobs: Amend timestamp semantics in async video
libobs: Amend timestamp semantics in async video
libobs: Amend timestamp semantics in async video
libobs: Amend timestamp semantics in async video
libobs: Amend timestamp semantics in async video
libobs: Amend timestamp semantics in async video
libobs: Amend timestamp semantics in async video