OpenReel Video - Professional browser-based video editor. Open source CapCut alternative. 100% browser-based, no installation, no cloud uploads, no watermarks.
TypeScript
fix: aggressive memory management for long video exports
Augustus Otu3ce1486c52b1
diff --git a/packages/core/src/export/export-engine.ts b/packages/core/src/export/export-engine.tsindex 045c9c48..fe784df7 100644--- a/packages/core/src/export/export-engine.ts+++ b/packages/core/src/export/export-engine.ts@@ -21,6 +21,7 @@ import { AudioEngine, getAudioEngine } from "../audio/audio-engine";import { titleEngine } from "../text/title-engine";import { graphicsEngine } from "../graphics/graphics-engine";import { UpscalingEngine, getUpscalingEngine } from "../video/upscaling";+import { getMediaEngine } from "../media/mediabunny-engine";export class ExportEngine {private mediabunny: typeof import("mediabunny") | null = null;@@ -369,7 +370,9 @@ export class ExportEngine {fullSettings.codec === "vp9" ||fullSettings.codec === "av1" ||fullSettings.codec === "h265";- const flushInterval = isIntensiveCodec ? 10 : 30;+ const microFlushInterval = isIntensiveCodec ? 5 : 10;+ const majorFlushInterval = 30;+ const cacheCleanInterval = 90;for (let frame = 0; frame < totalFrames; frame++) {if (this.abortController.signal.aborted) {@@ -412,10 +415,25 @@ export class ExportEngine {this.currentExport!.framesRendered = frame + 1;- if ((frame + 1) % flushInterval === 0) {+ if ((frame + 1) % microFlushInterval === 0) {await new Promise((resolve) => setTimeout(resolve, 0));}+ if ((frame + 1) % majorFlushInterval === 0) {+ await new Promise((resolve) => setTimeout(resolve, 50));+ }++ if ((frame + 1) % cacheCleanInterval === 0) {+ this.videoEngine?.clearVideoElementCache();+ try {+ const mediaEngine = getMediaEngine();+ mediaEngine.clearFrameCache();+ } catch {+ // MediaEngine may not be initialized+ }+ await new Promise((resolve) => setTimeout(resolve, 100));+ }+yield this.createProgress("rendering",(frame + 1) / totalFrames,diff --git a/packages/core/src/media/mediabunny-engine.ts b/packages/core/src/media/mediabunny-engine.tsindex c2fad0ae..8ea31089 100644--- a/packages/core/src/media/mediabunny-engine.ts+++ b/packages/core/src/media/mediabunny-engine.ts@@ -88,6 +88,14 @@ export class MediaBunnyEngine {return this.initialized && this.mediabunny !== null;}+ clearFrameCache(): void {+ this.frameCache.clear();+ }++ getFrameCacheSize(): number {+ return this.frameCache.size;+ }+private ensureInitialized(): void {if (!this.mediabunny) {throw new Error("MediaBunny not initialized. Call initialize() first.");