Skip to content

OpenReel Video - Professional browser-based video editor. Open source CapCut alternative. 100% browser-based, no installation, no cloud uploads, no watermarks.

TypeScript

fix: use simple blend for preview, reserve optical flow for export only

Augustus Otuc254b9ab6868
diff --git a/packages/core/src/export/export-engine.ts b/packages/core/src/export/export-engine.ts
index fc200463..95dcacd4 100644
--- a/packages/core/src/export/export-engine.ts
+++ b/packages/core/src/export/export-engine.ts
@@ -276,6 +276,9 @@ export class ExportEngine {
);
this.videoEngine?.resetExportState();
+ if (this.videoEngine) {
+ this.videoEngine.exportMode = true;
+ }
if (timelineDuration <= 0) {
return {
@@ -483,6 +486,9 @@ export class ExportEngine {
mediaEngine.clearFrameCache();
this.videoEngine?.clearVideoElementCache();
this.videoEngine?.clearCache();
+ if (this.videoEngine) {
+ this.videoEngine.exportMode = false;
+ }
yield this.createProgress(
"muxing",
@@ -526,6 +532,9 @@ export class ExportEngine {
this.audioEngine?.clearCache();
this.videoEngine?.clearVideoElementCache();
this.videoEngine?.clearCache();
+ if (this.videoEngine) {
+ this.videoEngine.exportMode = false;
+ }
try {
getMediaEngine().disposeAllExportDecoders();
getMediaEngine().clearFrameCache();
diff --git a/packages/core/src/video/video-engine.ts b/packages/core/src/video/video-engine.ts
index 33229edf..b7a27f73 100644
--- a/packages/core/src/video/video-engine.ts
+++ b/packages/core/src/video/video-engine.ts
@@ -99,6 +99,7 @@ export class VideoEngine {
private effectsEngine: VideoEffectsEngine | null = null;
private lastExportTime: number = -1;
private exportFrameRate: number = 30;
+ exportMode: boolean = false;
/**
* Creates a new VideoEngine instance.
@@ -279,7 +280,7 @@ export class VideoEngine {
private interpFrameCache: Map<string, { bitmap: ImageBitmap; time: number }> =
new Map();
- private static readonly INTERP_FRAME_CACHE_MAX = 4;
+ private static readonly INTERP_FRAME_CACHE_MAX = 2;
private getCachedInterpFrame(key: string): ImageBitmap | null {
const entry = this.interpFrameCache.get(key);
@@ -364,6 +365,17 @@ export class VideoEngine {
if (!frame1 || !frame2) return null;
+ if (!this.exportMode) {
+ const canvas = new OffscreenCanvas(frame1.width, frame1.height);
+ const ctx = canvas.getContext("2d")!;
+ ctx.globalAlpha = 1 - interpInfo.t;
+ ctx.drawImage(frame1, 0, 0);
+ ctx.globalAlpha = interpInfo.t;
+ ctx.drawImage(frame2, 0, 0);
+ ctx.globalAlpha = 1;
+ return canvas.transferToImageBitmap();
+ }
+
const engine = getFrameInterpolationEngine();
const quality = clip.interpolationQuality ?? "medium";
engine.setQuality(quality);