diff --git a/src/lib/ffmpeg.ts b/src/lib/ffmpeg.ts index 017b0511..2213cee9 100644 --- a/src/lib/ffmpeg.ts +++ b/src/lib/ffmpeg.ts @@ -614,13 +614,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;