Repository navigation
libobs: Amend timestamp semantics for async video and audio - #12431
stephematician wants to merge 5 commits into
Conversation
34c4483 to
b46b5d3
Compare
This comment was marked as outdated.
This comment was marked as outdated.
b46b5d3 to
f4ab1c5
Compare
|
Some de-duplication or smoothing logic was added in 11b0fe1 (see also 3ea98b8 for deinterlaced source), and then adjusted further in 76870d1.
The existing code seems to short-circuit discarding a frame if the next frame is less than 2ms earlier than the current time (i.e. a frame must be at least 2ms 'old' to be displayed ... but only when we have more than one frame in the queue). This is justified as accounting for 'jitter' in source timestamps - but I don't understand exactly how this approach works. There are only partial answers provided in 76870d1. @jp9000 was the original author - perhaps they can explain the intention of the code. |
|
@jpark37 - I noticed in an older commit that you mentioned (for async buffered) "GV-USB2, Buffered: No regression (still broken)." Can you remember what "broken" meant in this case? Are there any tracked issues you are aware of for this? |
f2e4c8f to
37e7851
Compare
This comment was marked as outdated.
This comment was marked as outdated.
This comment was marked as resolved.
This comment was marked as resolved.
d9e4d1e to
6b9b0ad
Compare
|
Going to attack de-interlaced and 'directly set' timestamps in a different PR - but this at least fixes a number of cases that caused 'drift' for buffered video and fixes #12459 ✅ I was thinking @kkartaltepe might be well-placed to review, too. |
b9d3c2e to
b068ca4
Compare
This comment was marked as outdated.
This comment was marked as outdated.
b068ca4 to
61798ba
Compare
61798ba to
167a9b8
Compare
167a9b8 to
719fbc4
Compare
|
Rebased with master and updated the smoothing (in case @derrod is still interesting in reviewing).
I've added some video examples of the difference between master and updated timestamp + smoothing:
With updated async timestamp + smoothing:
A subtle difference (that I've outlined before) is that the master branch is always keeping one frame in hand (i.e. one frame behind). At 60FPS, this is 16ms of unnecessary latency, which may be perceptible for very sensitive people. At lower FPS it is definitely noticeable. |
Small helper function to ensure that the last system timestamp and the last frame timestamp are updated together
Amends logic of buffered async video tick procedure and the meaning of 'last_frame_ts' and 'last_frame_sys_ts' to be the timestamp from the source for the last readied frame and the system (video) timestamp when the last frame was ready, respectively. Fixes obsproject#12459 which is caused by the faulty test 'last_frame_ts == 0' to identify the start of a sequence. This generates false-positives when the first frame has a timestamp of zero. Now we test 'last_frame_sys_ts' as the system (video) timestamp is almost never zero. Fixes drift between source timestamps and system timestamps which leads to bogus lag. This was caused by incorrect accumulation of system timestamp values.
Limit the number of out-of-sequence frames that are discarded in async buffered source; after which the timestamp sequence is resent. Provides more reliable system timestamp estimate when e.g. v4l2-input devices are interrupted by setting changes.
Amends the smoothing mechanism introduced in 11b0fe1a. Incoming frames whose estimated delivery is within 1ms of the video clock are held back, and this triggers a 4ms threshold for readying a frame. After enough frames have been displayed, the threshold reverts to 1ms.
719fbc4 to
acd4c97
Compare
|
Rebased onto 32.1.1. |
derrod
left a comment
There was a problem hiding this comment.
I think this is fine for now.
Eventually we'll have to redo the whole async frame cache thing because it's so jank (I'd prefer just a user-configurable fixed-size buffer). But nobody's got time for that right now :(
|
Tagging #13972 for tracking: This PR might need revising in the case that all timestamps are zero. |
Description
This fixes (kludgey?) assignments to
last_frame_ts; restoring it to mean exactly the (supplied) timestamp of the last "readied" frame; and replaceslast_sys_timestampwithlast_frame_sys_ts- which tracks the system (video) time that corresponds to the last readied frames' (supplied) timestamp. This eliminates a faulty comparison betweenlast_frame_tsand the incoming frames' timestamp(s).Some small adjustments are made to the tolerance mechanism introduced in 11b0fe1 to ensure comparably smooth delivery of frames.
TODO:
De-interlaced sources are not yet refactored (need a suitable test)- this will be covered in another PR.This will be broken into smaller atomic commits.A timestamp invalidation check needs to be added back in (need a suitable test).Motivation and Context
Instead of the tone playing while the square is white - the tone is being played while it is black.
last_frame_ts.How Has This Been Tested?
Using test input sources
I tested this with the "Sync Test (Async Video/Audio Source)" added to a scene and:
With the recorded video I checked frame-by-frame (e.g. with Shotcut) that the audio and video were aligned when expected (i.e. that if the frame was black, the audio at the start of the frame is silent; and for a white frame, the audio starts with the tone).
One-frame latency was eliminated and audio was synchronised.
Gstreamer test source
Started a loopback device using
modprobe video_nr=10and fed it a test via gstreamer:Added a "Video Capture Device (V4L2)" to a scene; and recorded with OBS at 30, 50, and 60 FPS. Checked frame-by-frame for audio synchronisation and consistency of pattern of new frames, e.g.:
T, T, F, T, FifTwhen new frame)T,F,T,F,T,FifTwhen new frame).These were all the same results as master; except the one-frame latency is eliminated.
Logitech C270 webcam
Same tests as for gstreamer test feed, but instead of gstreamer, use a real webcam. The camera tested is a Logitech C270 at "30FPS". The Logitech C270 produces frame intervals of 32ms, 32ms, 36ms and an actual frame rate of about 29.85 - so something of a 'stress' test of how to deliver smooth frames.
These all had the same (or very similar) result as master; except the one-frame latency is eliminated (false duplication at start of sequence).
Media source (FFMPEG)
Inserted a "Media Source" in the scene playing an MP4 at 25FPS (from sample-videos.com), recorded with OBS at 25, 30, and 50 FPS. Checked frame-by-frame for audio synchronisation and consistency of pattern of new frames.
Audio synchronisation was one-frame better than master (e.g. no longer advanced by one frame compared to video); pattern of new frames as per master except the one-frame latency is eliminated.
Types of changes
Checklist: