mirror of
https://github.com/Nikolay-Shirokov/cc-1c-skills.git
synced 2026-06-16 10:43:18 +03:00
fix(web-test): fix amix silence with many adelay inputs (int64 overflow)
ffmpeg amix + adelay with large delays causes timestamp overflow (dts near INT64_MAX), producing silent/truncated audio. Fix: use a silence reference track as first amix input with duration=first, so amix runs for full video length regardless of delayed stream timestamps. Co-Authored-By: Claude Opus 4.6 <noreply@anthropic.com>
This commit is contained in:
@@ -3331,15 +3331,20 @@ export async function addNarration(videoPath, opts = {}) {
|
||||
|
||||
const label = `a${i}`;
|
||||
mixLabels.push(`[${label}]`);
|
||||
filterParts.push(`[${i}]${filters.length ? filters.join(',') : 'acopy'}[${label}]`);
|
||||
// Input indices are shifted by 1 because silence reference is input [0]
|
||||
filterParts.push(`[${i + 1}]${filters.length ? filters.join(',') : 'acopy'}[${label}]`);
|
||||
}
|
||||
|
||||
// Generate a silence reference track as input [0] so amix runs for full video duration
|
||||
const silencePath = pathJoin(tempDir, 'silence.mp3');
|
||||
generateSilence(silencePath, Math.ceil(videoDuration), ffmpegPath);
|
||||
|
||||
const filterComplex = filterParts.join(';') + ';' +
|
||||
mixLabels.join('') + `amix=inputs=${captions.length}:normalize=0`;
|
||||
`[0]${mixLabels.join('')}amix=inputs=${captions.length + 1}:normalize=0:duration=first`;
|
||||
|
||||
const narrationPath = pathJoin(tempDir, 'narration.mp3');
|
||||
execFileSync(ffmpegPath, [
|
||||
'-y', ...ffmpegInputs,
|
||||
'-y', '-i', silencePath, ...ffmpegInputs,
|
||||
'-filter_complex', filterComplex,
|
||||
'-t', String(Math.ceil(videoDuration)),
|
||||
'-c:a', 'libmp3lame', '-b:a', '128k', narrationPath,
|
||||
|
||||
Reference in New Issue
Block a user