Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix auto focus export sync
Siddharth53f9851af997
diff --git a/src/components/video-editor/VideoPlayback.tsx b/src/components/video-editor/VideoPlayback.tsxindex d5207a60c..d47dfc7d6 100644--- a/src/components/video-editor/VideoPlayback.tsx+++ b/src/components/video-editor/VideoPlayback.tsx@@ -65,17 +65,11 @@ import {rotation3DPerspective,type SpeedRegion,type TrimRegion,- ZOOM_DEPTH_SCALES,type ZoomFocus,type ZoomRegion,} from "./types";-import {- AUTO_FOLLOW_RAMP_DISTANCE,- AUTO_FOLLOW_SMOOTHING_FACTOR,- AUTO_FOLLOW_SMOOTHING_FACTOR_MAX,- DEFAULT_FOCUS,-} from "./videoPlayback/constants";-import { adaptiveSmoothFactor, smoothCursorFocus } from "./videoPlayback/cursorFollowUtils";+import { AUTO_FOLLOW_PARAMS, DEFAULT_FOCUS } from "./videoPlayback/constants";+import { advanceFollowFocus } from "./videoPlayback/cursorFollowUtils";import {DEFAULT_CURSOR_CONFIG,PixiCursorOverlay,@@ -1329,7 +1323,9 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(motionBlurAmount: motionBlurAmountRef.current,transformOverride: transform,motionBlurState: motionBlurStateRef.current,- frameTimeMs: performance.now(),+ // Content time (not wall-clock) so camera motion-blur velocity matches export and is+ // correct under speed regions; export passes the same content `timeMs` (frameRenderer).+ frameTimeMs: currentTimeRef.current,});state.x = appliedTransform.x;@@ -1381,7 +1377,10 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(hasSelectedZoom && !isPlayingRef.current && !isPreviewingZoomRef.current;if (region && strength > 0 && !shouldShowUnzoomedView) {- const zoomScale = blendedScale ?? ZOOM_DEPTH_SCALES[region.depth];+ // Use getZoomScale (customScale-aware) to match export (frameRenderer) and the+ // magnification findDominantRegion already resolves the focus at — preview must not+ // fall back to the raw depth preset or it zooms/pans to a different level than export.+ const zoomScale = blendedScale ?? getZoomScale(region);const regionFocus = region.focus;targetScaleFactor = zoomScale;@@ -1393,17 +1392,21 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(const raw = targetFocus;const isZoomingIn =targetProgress < 0.999 && targetProgress >= prevTargetProgressRef.current;+ // Follow the cursor in CONTENT time (frame-rate independent) so the camera pans+ // at the same speed in preview and export. Snap to target when not actively+ // playing (paused/seek/scrub) — matches the zoom spring's snap.+ const focusAnimating =+ isPlayingRef.current && !isSeekingRef.current && !isScrubbingRef.current;+ const focusDtMs =+ prevZoomTimeMsRef.current === null+ ? 0+ : currentTimeRef.current - prevZoomTimeMsRef.current;if (targetProgress >= 0.999) {// Full zoom: adaptive smoothing — moves faster when far, decelerates when closeconst prev = smoothedAutoFocusRef.current ?? raw;- const factor = adaptiveSmoothFactor(- raw,- prev,- AUTO_FOLLOW_SMOOTHING_FACTOR,- AUTO_FOLLOW_SMOOTHING_FACTOR_MAX,- AUTO_FOLLOW_RAMP_DISTANCE,- );- const smoothed = smoothCursorFocus(raw, prev, factor);+ const smoothed = focusAnimating+ ? advanceFollowFocus(prev, raw, focusDtMs, AUTO_FOLLOW_PARAMS)+ : raw;smoothedAutoFocusRef.current = smoothed;targetFocus = smoothed;} else if (isZoomingIn) {@@ -1413,14 +1416,9 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(} else {// Zoom-out: keep smoothing for continuity — avoids snap at zoom-out startconst prev = smoothedAutoFocusRef.current ?? raw;- const factor = adaptiveSmoothFactor(- raw,- prev,- AUTO_FOLLOW_SMOOTHING_FACTOR,- AUTO_FOLLOW_SMOOTHING_FACTOR_MAX,- AUTO_FOLLOW_RAMP_DISTANCE,- );- const smoothed = smoothCursorFocus(raw, prev, factor);+ const smoothed = focusAnimating+ ? advanceFollowFocus(prev, raw, focusDtMs, AUTO_FOLLOW_PARAMS)+ : raw;smoothedAutoFocusRef.current = smoothed;targetFocus = smoothed;}diff --git a/src/components/video-editor/videoPlayback/constants.ts b/src/components/video-editor/videoPlayback/constants.tsindex b5b4bd1e0..64471657d 100644--- a/src/components/video-editor/videoPlayback/constants.ts+++ b/src/components/video-editor/videoPlayback/constants.ts@@ -11,3 +11,14 @@ export const ZOOM_SCALE_DEADZONE = 0.002;export const AUTO_FOLLOW_SMOOTHING_FACTOR = 0.1;export const AUTO_FOLLOW_SMOOTHING_FACTOR_MAX = 0.25;export const AUTO_FOLLOW_RAMP_DISTANCE = 0.15;+// Reference frame interval for the (content-time, frame-rate-independent) auto-focus follow. Both+// preview and export reframe their per-frame smoothing against this so they converge identically+// regardless of render fps. Lower fps here = floatier follow (tuned to the live-preview feel).+export const AUTO_FOLLOW_REFERENCE_MS = 1000 / 40;+// Bundled auto-follow params, shared by preview and export so the camera follows the cursor identically.+export const AUTO_FOLLOW_PARAMS = {+ minFactor: AUTO_FOLLOW_SMOOTHING_FACTOR,+ maxFactor: AUTO_FOLLOW_SMOOTHING_FACTOR_MAX,+ rampDistance: AUTO_FOLLOW_RAMP_DISTANCE,+ referenceMs: AUTO_FOLLOW_REFERENCE_MS,+} as const;diff --git a/src/components/video-editor/videoPlayback/cursorFollowUtils.ts b/src/components/video-editor/videoPlayback/cursorFollowUtils.tsindex 14dad24f1..646cf8762 100644--- a/src/components/video-editor/videoPlayback/cursorFollowUtils.ts+++ b/src/components/video-editor/videoPlayback/cursorFollowUtils.ts@@ -53,6 +53,53 @@ export function smoothCursorFocus(raw: ZoomFocus, prev: ZoomFocus, factor: numbe};}+export interface FollowParams {+ minFactor: number;+ maxFactor: number;+ rampDistance: number;+ referenceMs: number;+}++/**+ * Advance the auto-follow focus from `prev` toward the cursor target `raw` over `dtMs` of content+ * time. The distance-adaptive factor is reframed against `referenceMs` so the per-frame convergence+ * is (first-order) content-time based and matches between preview and export. Returns `prev` unchanged+ * when no content time elapsed (paused) so the camera holds still.+ */+export function advanceFollowFocus(+ prev: ZoomFocus,+ raw: ZoomFocus,+ dtMs: number,+ params: FollowParams,+): ZoomFocus {+ if (!(dtMs > 0)) return prev;+ const base = adaptiveSmoothFactor(+ raw,+ prev,+ params.minFactor,+ params.maxFactor,+ params.rampDistance,+ );+ const factor = timeCorrectedFollowFactor(base, dtMs, params.referenceMs);+ return smoothCursorFocus(raw, prev, factor);+}++/**+ * Make a per-frame smoothing `baseFactor` frame-rate independent by reframing it in CONTENT time.+ * The camera converges as `(1 - baseFactor)^(dtMs / referenceMs)` regardless of how that content time+ * is chunked into frames, so preview (variable editor fps) and export (fixed fps) follow the cursor+ * at the *same* speed. A larger `referenceMs` (lower reference fps) = floatier. Returns 0 when no+ * content time elapsed (paused) so the camera holds still.+ */+export function timeCorrectedFollowFactor(+ baseFactor: number,+ dtMs: number,+ referenceMs: number,+): number {+ if (!(dtMs > 0) || !(referenceMs > 0)) return 0;+ return 1 - (1 - baseFactor) ** (dtMs / referenceMs);+}+/*** Compute an adaptive smoothing factor that scales with distance:* far from target → faster (maxFactor), close → slower (minFactor).diff --git a/src/lib/exporter/frameRenderer.ts b/src/lib/exporter/frameRenderer.tsindex c8fc846a7..49351d7e8 100644--- a/src/lib/exporter/frameRenderer.ts+++ b/src/lib/exporter/frameRenderer.ts@@ -24,15 +24,10 @@ import {lerpRotation3D,} from "@/components/video-editor/types";import {- AUTO_FOLLOW_RAMP_DISTANCE,- AUTO_FOLLOW_SMOOTHING_FACTOR,- AUTO_FOLLOW_SMOOTHING_FACTOR_MAX,+ AUTO_FOLLOW_PARAMS,DEFAULT_FOCUS,} from "@/components/video-editor/videoPlayback/constants";-import {- adaptiveSmoothFactor,- smoothCursorFocus,-} from "@/components/video-editor/videoPlayback/cursorFollowUtils";+import { advanceFollowFocus } from "@/components/video-editor/videoPlayback/cursorFollowUtils";import { clampFocusToScale } from "@/components/video-editor/videoPlayback/focusUtils";import { findDominantRegion } from "@/components/video-editor/videoPlayback/zoomRegionUtils";import {@@ -425,7 +420,15 @@ export class FrameRenderer {throw new Error("Layout cache not initialized");}- // Apply transform once with maximum motion intensity from all ticks+ // Apply transform once with maximum motion intensity from all ticks.+ // CRITICAL: feed the spring-smoothed transform (appliedScale/x/y from updateAnimationState)+ // via transformOverride — exactly as the preview does. Without it, applyZoomTransform would+ // recompute the camera from the raw eased *target* (state.scale/progress/focus) and the spring+ // would be discarded for the camera container, so the export camera would snap to the target+ // every frame while the preview glides. That asymmetry is invisible for a static (manual-focus)+ // zoom but very visible for auto-focus, whose target pans with the cursor — it read as the+ // export being "snappier". Using the sprung transform also keeps the camera, mask and cursor+ // (which already read appliedScale/x/y) mutually consistent.applyZoomTransform({cameraContainer: this.cameraContainer,blurFilter: this.blurFilter,@@ -441,6 +444,11 @@ export class FrameRenderer {motionBlurAmount: this.config.motionBlurAmount ?? 0,motionBlurState: this.motionBlurState,frameTimeMs: timeMs,+ transformOverride: {+ scale: this.animationState.appliedScale,+ x: this.animationState.x,+ y: this.animationState.y,+ },});// Render the PixiJS stage to its canvas (video only, transparent background)@@ -809,20 +817,11 @@ export class FrameRenderer {if (region.focusMode === "auto" && !transition) {const raw = targetFocus;const dtMs = this.prevAnimationTimeMs != null ? timeMs - this.prevAnimationTimeMs : 0;- const framesElapsed = dtMs > 0 ? dtMs / (1000 / 60) : 1;const isZoomingIn = targetProgress < 0.999 && targetProgress >= this.prevTargetProgress;if (targetProgress >= 0.999) {// Full zoom: adaptive smoothing — moves faster when far, decelerates when closeconst prev = this.smoothedAutoFocus ?? raw;- const baseFactor = adaptiveSmoothFactor(- raw,- prev,- AUTO_FOLLOW_SMOOTHING_FACTOR,- AUTO_FOLLOW_SMOOTHING_FACTOR_MAX,- AUTO_FOLLOW_RAMP_DISTANCE,- );- const factor = 1 - Math.pow(1 - baseFactor, Math.max(1, framesElapsed));- const smoothed = smoothCursorFocus(raw, prev, factor);+ const smoothed = advanceFollowFocus(prev, raw, dtMs, AUTO_FOLLOW_PARAMS);this.smoothedAutoFocus = smoothed;targetFocus = smoothed;} else if (isZoomingIn) {@@ -832,15 +831,7 @@ export class FrameRenderer {} else {// Zoom-out: keep smoothing for continuity — avoids snap at zoom-out startconst prev = this.smoothedAutoFocus ?? raw;- const baseFactor = adaptiveSmoothFactor(- raw,- prev,- AUTO_FOLLOW_SMOOTHING_FACTOR,- AUTO_FOLLOW_SMOOTHING_FACTOR_MAX,- AUTO_FOLLOW_RAMP_DISTANCE,- );- const factor = 1 - Math.pow(1 - baseFactor, Math.max(1, framesElapsed));- const smoothed = smoothCursorFocus(raw, prev, factor);+ const smoothed = advanceFollowFocus(prev, raw, dtMs, AUTO_FOLLOW_PARAMS);this.smoothedAutoFocus = smoothed;targetFocus = smoothed;}