Describe the Bug
When a user adds background music to a video that lacks an original audio track (or if the export process falls back to Attempt 2: Auto-recover), the FFmpeg export process can hang indefinitely.
If the user has "Loop music" enabled, the FFmpeg command utilizes -stream_loop -1. However, because hasOriginalAudio evaluates to false in this state, the amix filter (which normally bounds the duration using duration=first) is entirely bypassed. Crucially, the FFmpeg command is executed without the -shortest flag. This causes FFmpeg to process the infinite looped audio stream indefinitely, eventually leading to the browser tab crashing due to an Out of Memory (OOM) WebAssembly error.
Additionally, if "Loop music" is disabled but the background music file is longer than the video (e.g., a 3-minute song on a 10-second video), the resulting export will be 3 minutes long, with the video frozen on the final frame for the remaining 2 minutes and 50 seconds.
Steps to Reproduce
- Upload a video file that has no audio stream (or trigger the "Attempt 2" audio fallback).
- Go to the "Audio & Speed" settings.
- Upload a background music track that is longer than the video.
- (Optional but triggers the crash) Check the "Loop music" toggle.
- Click Export.
- Observe that the export progress hangs indefinitely until the browser tab crashes (if looping) or produces a video much longer than the original clip (if not looping).
Expected Behavior
The export process should correctly truncate the audio stream to match the duration of the video stream, preventing infinite loops and preventing the video from freezing on the last frame to accommodate a long audio track.
Proposed Fix
In src/lib/ffmpeg.ts, the -shortest flag needs to be conditionally appended to the FFmpeg arguments when background music is present but there is no original audio track to bound the amix filter.
// Add this logic before args.push(outputName) inside the buildArguments function
if (hasMusicTrack && !hasOriginalAudio) {
args.push("-shortest");
}
Describe the Bug
When a user adds background music to a video that lacks an original audio track (or if the export process falls back to
Attempt 2: Auto-recover), the FFmpeg export process can hang indefinitely.If the user has "Loop music" enabled, the FFmpeg command utilizes
-stream_loop -1. However, becausehasOriginalAudioevaluates tofalsein this state, theamixfilter (which normally bounds the duration usingduration=first) is entirely bypassed. Crucially, the FFmpeg command is executed without the-shortestflag. This causes FFmpeg to process the infinite looped audio stream indefinitely, eventually leading to the browser tab crashing due to an Out of Memory (OOM) WebAssembly error.Additionally, if "Loop music" is disabled but the background music file is longer than the video (e.g., a 3-minute song on a 10-second video), the resulting export will be 3 minutes long, with the video frozen on the final frame for the remaining 2 minutes and 50 seconds.
Steps to Reproduce
Expected Behavior
The export process should correctly truncate the audio stream to match the duration of the video stream, preventing infinite loops and preventing the video from freezing on the last frame to accommodate a long audio track.
Proposed Fix
In
src/lib/ffmpeg.ts, the-shortestflag needs to be conditionally appended to the FFmpeg arguments when background music is present but there is no original audio track to bound theamixfilter.