Skip to content

fix(transcoder): snap A/V to a common origin at startup for AV-path sources#30

Merged
ntt0601zcoder merged 1 commit into
mainfrom
fix/transcoder-av-startup-snap
Jun 16, 2026
Merged

fix(transcoder): snap A/V to a common origin at startup for AV-path sources#30
ntt0601zcoder merged 1 commit into
mainfrom
fix/transcoder-av-startup-snap

Conversation

@ntt0601zcoder

Copy link
Copy Markdown
Owner

What

The transcoder maps audio and video onto its output timeline with a single shared offset, assuming both ride one source clock — true for MPEG-TS (shared PCR) but not always for AV-path/RTMP sources, where audio can flow for seconds before the first video keyframe and the two tracks may carry independently-based timestamps. The first track to emit seeded the offset, so a late-arriving second track inherited it and baked a large, permanent A/V offset into the output.

Observed on an RTMP-pull source: output A/V offset up to ~22 s (audio ahead / video lagging). HLS preserved it (audible lip-sync); DASH distorted it differently. Source probes showed the upstream A/V synced to a few ms, and ingest traces showed the raw-ingest (post-normaliser) V/A coherent — so the skew was introduced in the transcoder, not at ingest.

Fix

A per-track cross-track origin snap mirroring the ingest timeline normaliser's CrossTrackSnapMs: when the second track's mapped start diverges from the already-emitting track's output by more than crossTrackSnapMs (1 s), the source clocks are treated as independently based and the late track is snapped onto the early track's output line so both start in lockstep. Skews below the threshold are preserved so a genuine intrinsic A/V offset survives.

The shared offset, releaseAudio gate, and regress re-anchor are unchanged; the common steady-state path is byte-identical (the snap is zero unless triggered).

Validation

  • Unit tests: TestCrossTrackSnap, TestRebase_RTMPStartupAudioBeforeVideo_SnapsVideo, TestRebase_CoherentStartup_NoSnap.
  • Live: an RTMP-pull stream went from a ~22 s output A/V offset to within a few ms, stable across a 1.5 h soak with no drift or regression; UDP/MPEG-TS streams unaffected.
  • make check green (native package built + raced with local libav; lint 0 issues).

…ources

The transcoder maps audio and video onto the output timeline with a single
shared offset, assuming both ride one source clock — true for MPEG-TS (shared
PCR) but not always for AV-path/RTMP sources, where audio can flow for seconds
before the first video keyframe and the two tracks may carry independently-based
timestamps. The first track to emit seeded the offset, so a late-arriving
second track inherited it and baked a large, permanent A/V offset into the
output (observed up to ~22s on an RTMP-pull source: HLS preserved it as audible
lip-sync, DASH distorted it differently). Source probes showed the upstream A/V
synced to a few ms — the skew was introduced here, not at ingest.

Add a per-track cross-track origin snap mirroring the ingest timeline
normaliser's CrossTrackSnapMs: when the second track's mapped start diverges
from the already-emitting track's output by more than crossTrackSnapMs (1 s),
the source clocks are treated as independently based and the late track is
snapped onto the early track's output line so both start in lockstep. Skews
below the threshold are preserved so a genuine intrinsic A/V offset survives.
The shared offset, releaseAudio gate, and regress re-anchor are unchanged; the
common steady-state path is byte-identical (snap is zero unless triggered).

Validated live: an RTMP-pull stream went from a ~22 s output A/V offset to
within a few ms, stable across a 1.5 h soak with no drift or regression.

Tests: TestCrossTrackSnap, TestRebase_RTMPStartupAudioBeforeVideo_SnapsVideo,
TestRebase_CoherentStartup_NoSnap.
@ntt0601zcoder ntt0601zcoder merged commit 807f6f3 into main Jun 16, 2026
4 checks passed
@ntt0601zcoder ntt0601zcoder deleted the fix/transcoder-av-startup-snap branch June 16, 2026 07:02
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant