diff --git a/src/lib/exporter/frameRenderer.ts b/src/lib/exporter/frameRenderer.ts index 7dd93b3..9b1cf6d 100644 --- a/src/lib/exporter/frameRenderer.ts +++ b/src/lib/exporter/frameRenderer.ts @@ -78,6 +78,7 @@ interface FrameRenderConfig { previewWidth?: number; previewHeight?: number; cursorTelemetry?: import("@/components/video-editor/types").CursorTelemetryPoint[]; + platform: string; } interface AnimationState { @@ -124,9 +125,11 @@ export class FrameRenderer { private smoothedAutoFocus: { cx: number; cy: number } | null = null; private prevAnimationTimeMs: number | null = null; private prevTargetProgress = 0; + private isLinux = false; constructor(config: FrameRenderConfig) { this.config = config; + this.isLinux = config.platform === "linux"; this.animationState = { scale: 1, focusX: DEFAULT_FOCUS.cx, @@ -189,10 +192,8 @@ export class FrameRenderer { this.compositeCanvas.height = this.config.height; // On Linux, getImageData() is called frequently causing frequent CPU readback - const isLinux = (await window.electronAPI.getPlatform()) === "linux"; - this.compositeCtx = this.compositeCanvas.getContext("2d", { - willReadFrequently: isLinux, + willReadFrequently: this.isLinux, }); if (!this.compositeCtx) { @@ -730,7 +731,10 @@ export class FrameRenderer { private compositeWithShadows(webcamFrame?: VideoFrame | null): void { if (!this.compositeCanvas || !this.compositeCtx || !this.app) return; - const videoCanvas = this.readbackVideoCanvas(); + const videoCanvas = this.isLinux + ? this.readbackVideoCanvas() + : (this.app.canvas as HTMLCanvasElement); + const ctx = this.compositeCtx; const w = this.compositeCanvas.width; const h = this.compositeCanvas.height; diff --git a/src/lib/exporter/gifExporter.ts b/src/lib/exporter/gifExporter.ts index 58ed693..81c540e 100644 --- a/src/lib/exporter/gifExporter.ts +++ b/src/lib/exporter/gifExporter.ts @@ -115,7 +115,10 @@ export class GifExporter { async export(): Promise { let webcamFrameQueue: AsyncVideoFrameQueue | null = null; + try { + const platform = await window.electronAPI.getPlatform(); + this.cleanup(); this.cancelled = false; @@ -153,6 +156,7 @@ export class GifExporter { previewWidth: this.config.previewWidth, previewHeight: this.config.previewHeight, cursorTelemetry: this.config.cursorTelemetry, + platform, }); await this.renderer.initialize(); diff --git a/src/lib/exporter/videoExporter.ts b/src/lib/exporter/videoExporter.ts index 61ad727..13c0696 100644 --- a/src/lib/exporter/videoExporter.ts +++ b/src/lib/exporter/videoExporter.ts @@ -111,9 +111,9 @@ export class VideoExporter { this.cancelled = false; this.fatalEncoderError = null; - const platform = await window.electronAPI.getPlatform(); - try { + const platform = await window.electronAPI.getPlatform(); + const streamingDecoder = new StreamingVideoDecoder(); this.streamingDecoder = streamingDecoder; const videoInfo = await streamingDecoder.loadMetadata(this.config.videoUrl); @@ -148,6 +148,7 @@ export class VideoExporter { previewWidth: this.config.previewWidth, previewHeight: this.config.previewHeight, cursorTelemetry: this.config.cursorTelemetry, + platform, }); this.renderer = renderer; await renderer.initialize();