Skip to content

fix: prevent infinite export loops for background music on audio-less videos#1580

Open
Abhishek2005-ard wants to merge 11 commits into
magic-peach:mainfrom
Abhishek2005-ard:fix/ffmpeg-infinite-loop
Open

fix: prevent infinite export loops for background music on audio-less videos#1580
Abhishek2005-ard wants to merge 11 commits into
magic-peach:mainfrom
Abhishek2005-ard:fix/ffmpeg-infinite-loop

Conversation

@Abhishek2005-ard

Copy link
Copy Markdown

Description

This PR resolves a critical issue where the FFmpeg export process could hang indefinitely or freeze the video frame when exporting a video that lacks an original audio track but has a background music track applied.

When hasOriginalAudio was false, the audio stream wasn't bounded by the amix filter's duration=first parameter, and the -shortest flag was missing. This resulted in Out-of-Memory (OOM) browser crashes when "Loop music" was enabled, and produced exports with frozen video tails when the music track was longer than the video clip.

Changes Made

  • Added the apad filter to the background music input stream when hasOriginalAudio is false. This guarantees the audio stream is always at least as long as the video stream.
  • Injected the -shortest flag into the FFmpeg execution arguments for video exports. This forces the encoder to safely terminate exactly when the video stream ends, gracefully preventing infinite loops and frozen frames.

Impact

This guarantees stability when adding custom music to silent videos. It completely prevents browser tab crashes caused by unbounded WASM memory usage and ensures output durations are perfectly matched.

Testing

  • Verified logic with "Loop music" enabled on audio-less videos.
  • Verified logic with music tracks longer than the original video duration.
  • Verified logic with music tracks shorter than the original video duration.
  • Passed all 71 existing test suites via npm test.

close #1577

@vercel

vercel Bot commented Jun 14, 2026

Copy link
Copy Markdown

@Abhishek2005-ard is attempting to deploy a commit to the magic-peach1's projects Team on Vercel.

A member of the Team first needs to authorize it.

@github-actions github-actions Bot added level:advanced Advanced level - 55 pts type:bug Bug fix type:testing Testing labels Jun 14, 2026
@github-actions

Copy link
Copy Markdown
Contributor

👋 Thanks for your PR, @Abhishek2005-ard!

Welcome to Reframe — a browser-based video editor built for everyone 🎬

What happens next

  1. 🤖 Automated checks — build & TypeScript typecheck will run automatically
  2. Vercel preview — a preview deployment will be created (requires maintainer authorization for fork PRs)
  3. 👀 Code review — a maintainer will review your changes
  4. 🚀 Merge — once approved, your PR will be merged!

Quick checklist

  • PR title follows Conventional Commits (e.g. feat: add dark mode)
  • Linked the issue this PR closes (e.g. Closes #123)
  • Tested the changes locally (bun run dev)
  • Build passes (bun run build)

Useful links

Happy coding! 🎉

@github-actions

github-actions Bot commented Jun 14, 2026

Copy link
Copy Markdown
Contributor

✅ PR Format Check Passed — @Abhishek2005-ard

Basic format checks passed. A maintainer will review your code changes.

This does not mean the PR is approved — it just means the format is correct.

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

level:advanced Advanced level - 55 pts type:bug Bug fix type:testing Testing

Projects

None yet

Development

Successfully merging this pull request may close these issues.

Bug: Infinite export loop / OOM crash when adding looping background music to audio-less videos

1 participant