Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix: lower in-memory source threshold and skip waveform for huge files

my_mac3f07f3c6a174
diff --git a/src/lib/exporter/sourceFileLimits.ts b/src/lib/exporter/sourceFileLimits.ts
index fcd9de6a7..778e2ab50 100644
--- a/src/lib/exporter/sourceFileLimits.ts
+++ b/src/lib/exporter/sourceFileLimits.ts
@@ -1,12 +1,16 @@
/**
- * Largest source file we are willing to read fully into memory in one shot.
+ * Largest source file we are willing to read whole via the `read-binary-file`
+ * IPC and hand around as a single in-memory `ArrayBuffer`/`Blob`.
*
- * Node's `fs.readFile` (behind the `read-binary-file` IPC) throws
- * `ERR_FS_FILE_TOO_LARGE` above 2 GiB, and a multi-GB `ArrayBuffer`/`Blob` would
- * exhaust memory on typical machines anyway. Recordings above this threshold are
- * streamed on demand instead (into OPFS for demuxing; skipped for the in-memory
- * source-copy and waveform/decodeAudioData paths).
+ * `read-binary-file` reads the file with Node's `fs.readFile` (which itself
+ * throws above 2 GiB) and returns the bytes over IPC, where Electron
+ * structured-clones them — copying the whole buffer in the main process. For a
+ * large recording this transiently needs ~2× the file size in the main process
+ * and crashes it on a memory-constrained machine (observed: a ~1 GB recording
+ * hard-crashes a 16 GB Mac). So the safe cutoff is far below the 2 GiB read cap.
*
- * Kept comfortably below the 2 GiB cap to leave headroom.
+ * Above this size, recordings are streamed on demand instead — into OPFS in
+ * fixed-size chunks for demuxing (export/captions), and the in-memory
+ * source-copy and waveform paths are skipped.
*/
-export const MAX_IN_MEMORY_SOURCE_BYTES = 1.5 * 1024 * 1024 * 1024;
+export const MAX_IN_MEMORY_SOURCE_BYTES = 256 * 1024 * 1024;
diff --git a/src/lib/exporter/streamingDecoder.ts b/src/lib/exporter/streamingDecoder.ts
index 1c26c51a2..f4cd6819a 100644
--- a/src/lib/exporter/streamingDecoder.ts
+++ b/src/lib/exporter/streamingDecoder.ts
@@ -5,6 +5,7 @@ import {
materializeLocalSourceFile,
releaseLocalSourceFile,
} from "./localSourceFile";
+import { MAX_IN_MEMORY_SOURCE_BYTES } from "./sourceFileLimits";
const SOURCE_LOAD_TIMEOUT_MS = 60_000;
// Large local recordings are streamed into OPFS before demuxing, which is
@@ -151,10 +152,16 @@ export async function loadFileAsArrayBuffer(
if (!isRemoteUrl && window.electronAPI) {
// This path loads the entire file into an ArrayBuffer (it feeds the trim
- // waveform), so it deliberately uses the single-shot read rather than the
- // OPFS streaming loader. Recordings above ~2 GiB fail here and the caller
- // (useAudioPeaks) degrades to no waveform — the export path does not rely
- // on this function.
+ // waveform) and cannot stream, since decodeAudioData needs the whole file.
+ // readBinaryFile also copies the bytes in the main process during IPC, so a
+ // large recording would exhaust memory and crash. The waveform is cosmetic,
+ // so skip it above the in-memory limit; useAudioPeaks (the only caller)
+ // catches the throw and degrades to no waveform. The export path streams
+ // instead and does not rely on this function.
+ const info = await window.electronAPI.getReadableFileInfo?.(videoUrl);
+ if (info?.success && typeof info.size === "number" && info.size > MAX_IN_MEMORY_SOURCE_BYTES) {
+ throw new Error("Recording is too large to load into memory for waveform rendering.");
+ }
const result = await window.electronAPI.readBinaryFile(videoUrl);
if (!result.success || !result.data) {
throw new Error(result.message || result.error || "Failed to read source video");