[BUG] importing clip devours RAM until desktop crash
Platform
Windows 11
Browser
Firefox 145.0.2 (64-bit)
Current Behavior
https://github.com/user-attachments/assets/66cc7a93-bf53-44d5-95e0-4e44018b3b29
When importing ~20 sec clip, OpenCut uses ram until desktop crashes
Expected Behavior
For RAM usage to not skyrocket
Recurrence Probability
Always
Steps To Reproduce
Grab clip Import clip to media selection Watch Task Manager in horror
Anything else?
I closed the tab in this clip, but if i let it keep going, Windows would've crashed.
The web version on Ubuntu Firefox full up my 64GB memory in less than a minute! CREAZY!!
Seems the same with https://github.com/OpenCut-app/OpenCut/issues/637#issuecomment-3494577626
Same behavior on Chrome & Firefox, Fedora 43
https://github.com/user-attachments/assets/28be059c-a6b0-415e-a084-d1fa728dbce7 https://github.com/user-attachments/assets/ca89d91b-67bc-4f88-b244-11de3e47de42
Same on Zen Browser (Firefox Fork) on Ubuntu 24.04.01 LTS
I thought that it's insane enough for my OpenCut to crash with my ram of 16GB.😂 Seems still can't fix it. I'm desperate.😭
what
Root cause, for whoever picks this up (leaving this here since opencut-app/opencut-classic — the repo this code actually lives in — was archived on 2026-05-17, so it can no longer take PRs):
Importing a video triggers a timeline waveform render, which goes through apps/web/src/services/waveform-cache/service.ts. For file-backed sources, that code:
- Reads the entire raw video file into memory via
sourceFile.arrayBuffer() - Duplicates that buffer with
.slice(0) - Runs the browser's native
AudioContext.decodeAudioData()over the whole thing
decodeAudioData decodes the full track to full-resolution PCM in one contiguous AudioBuffer — just to draw a small downsampled waveform. For a long or high-resolution file that's gigabytes of transient RAM, which matches both reports here: RAM spikes far past the source file size and the tab/desktop crashes, worse with longer/larger files.
Fix: decode via mediabunny's AudioBufferSink (already a project dependency, already used the same way in media/audio.ts and core/managers/audio-manager.ts) instead of decodeAudioData, so audio streams in bounded chunks and peak-per-bucket waveform amplitudes are accumulated incrementally — peak memory stays bounded by chunk size instead of file duration. Also short-circuits when a clip has no audio track (previously it would still decode raw video bytes as audio unconditionally).
Verified locally against opencut-classic: imported 5 clips totaling ~580MB, browser process RAM stayed flat (~850MB, proportional to baseline + actual data) instead of spiking, waveform still rendered correctly.
Diff, since it can't be opened as a PR against the archived repo: https://github.com/hp-8/opencut-classic/commit/d5c906dac6ed59c798e1335808974267550d44db (branch: https://github.com/hp-8/opencut-classic/tree/fix/waveform-import-memory-crash)
Note for the rewrite in this repo: current main here doesn't have a media-import/audio-decode path yet, so this specific bug doesn't reproduce against it today — but the same pitfall (full-file decodeAudioData for waveform generation) is worth avoiding when that pipeline gets rebuilt.