From ebe2bc5c1673fce2234ccb9c1e3142272de1fa7b Mon Sep 17 00:00:00 2001 From: webadderall <131426131+webadderall@users.noreply.github.com> Date: Sat, 18 Apr 2026 20:45:46 +1000 Subject: [PATCH] fix: audio regions on silent video, interleaved >2ch stride, coderabbit config - Fall back to video container duration when mainBuffer is null but audioRegions are present (prevents empty output) - Use data.numberOfChannels as deinterleave stride instead of capped dataChannels (fixes garbled audio for 5.1+ sources) - Fix .coderabbit.yaml: '*' is not valid regex, use '.*' --- .coderabbit.yaml | 2 +- src/lib/exporter/audioEncoder.ts | 11 +++++++---- 2 files changed, 8 insertions(+), 5 deletions(-) diff --git a/.coderabbit.yaml b/.coderabbit.yaml index bb10f9a6..2045b00d 100644 --- a/.coderabbit.yaml +++ b/.coderabbit.yaml @@ -2,4 +2,4 @@ reviews: auto_review: enabled: true base_branches: - - "*" + - ".*" diff --git a/src/lib/exporter/audioEncoder.ts b/src/lib/exporter/audioEncoder.ts index 154b0e4b..31bf5553 100644 --- a/src/lib/exporter/audioEncoder.ts +++ b/src/lib/exporter/audioEncoder.ts @@ -593,7 +593,7 @@ export class AudioProcessor { let sourceDurationSec: number; if (mainBuffer) { sourceDurationSec = mainBuffer.duration; - } else if (hasExternalSources) { + } else if (hasExternalSources || regionEntries.length > 0) { sourceDurationSec = await this.getMediaDurationSec(videoUrl); } else { sourceDurationSec = primaryBuffer?.duration ?? 0; @@ -983,20 +983,23 @@ export class AudioProcessor { ); } } else if (format) { - // Interleaved format — deinterleave into per-channel arrays + // Interleaved format — deinterleave into per-channel arrays. + // Use data.numberOfChannels as stride (not capped dataChannels) + // since the raw buffer contains all source channels. + const srcChannels = data.numberOfChannels; const size = data.allocationSize({ planeIndex: 0 }); const bytes = new ArrayBuffer(size); data.copyTo(bytes, { planeIndex: 0 }); const interleaved = this.rawToFloat32( bytes, format, - frames * dataChannels, + frames * srcChannels, ); for (let ch = 0; ch < dataChannels; ch++) { const chData = new Float32Array(frames); for (let i = 0; i < frames; i++) { chData[i] = - interleaved[i * dataChannels + ch]; + interleaved[i * srcChannels + ch]; } channelChunks[ch].push(chData); }