From 35dd233474010fa8b0135f465b268d201b687a37 Mon Sep 17 00:00:00 2001 From: shahabhilash Date: Wed, 27 May 2026 16:30:39 +0530 Subject: [PATCH] fix: enforce -t flag on export to prevent infinite loop with background music --- src/lib/ffmpeg.ts | 13 ++++++------- 1 file changed, 6 insertions(+), 7 deletions(-) diff --git a/src/lib/ffmpeg.ts b/src/lib/ffmpeg.ts index 625387d2..68785421 100644 --- a/src/lib/ffmpeg.ts +++ b/src/lib/ffmpeg.ts @@ -556,13 +556,12 @@ interface PositionCoords { if (shouldKeepAudio) args.push("-c:a", "aac", "-b:a", "128k"); } - // Add explicit output duration when speed != 1 to prevent slight duration - // overshoot caused by encoder/filter pipeline frame flush at stream end. - if (recipe.speed !== 1) { - const sourceDuration = (recipe.trimEnd ?? videoDuration) - recipe.trimStart; - const outputDuration = sourceDuration / recipe.speed; - args.push("-t", outputDuration.toFixed(6)); - } + // Add explicit output duration to prevent slight duration overshoot + // caused by encoder/filter pipeline frame flush at stream end, + // and to prevent infinite loops when adding looped audio to silent videos. + const sourceDuration = (recipe.trimEnd ?? videoDuration) - recipe.trimStart; + const outputDuration = sourceDuration / recipe.speed; + args.push("-t", outputDuration.toFixed(6)); args.push(outputName); return args;