Skip to content

Create polished demo videos without editing skills. Mac/Windows/Linux

feat: align preview and export rendering

webadderallebf68e65cd8b
diff --git a/src/components/video-editor/VideoPlayback.tsx b/src/components/video-editor/VideoPlayback.tsx
index 488bc3a9..5bf85170 100644
--- a/src/components/video-editor/VideoPlayback.tsx
+++ b/src/components/video-editor/VideoPlayback.tsx
@@ -166,7 +166,10 @@ import {
SNAP_TO_EDGES_RATIO_AUTO,
} from "./videoPlayback/cursorFollowCamera";
import { clampFocusToStage as clampFocusToStageUtil } from "./videoPlayback/focusUtils";
-import { layoutVideoContent as layoutVideoContentUtil } from "./videoPlayback/layoutUtils";
+import {
+ layoutVideoContent as layoutVideoContentUtil,
+ scalePreviewBorderRadius,
+} from "./videoPlayback/layoutUtils";
import { updateOverlayIndicator } from "./videoPlayback/overlayUtils";
import { createVideoEventHandlers } from "./videoPlayback/videoEventHandlers";
import {
@@ -176,7 +179,6 @@ import {
import { findDominantRegion } from "./videoPlayback/zoomRegionUtils";
import {
applyZoomTransform,
- computeFocusFromTransform,
computeZoomTransform,
createMotionBlurState,
type MotionBlurState,
@@ -197,6 +199,19 @@ type PlaybackAnimationState = {
y: number;
};
+type SceneTransformState = {
+ scale: number;
+ x: number;
+ y: number;
+};
+
+type AnnotationRecordingRect = {
+ x: number;
+ y: number;
+ width: number;
+ height: number;
+};
+
function createPlaybackAnimationState(): PlaybackAnimationState {
return {
scale: 1,
@@ -496,6 +511,19 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
null,
);
const [frameUpdateCounter, setFrameUpdateCounter] = useState(0);
+ const [annotationSceneTransform, setAnnotationSceneTransform] =
+ useState<SceneTransformState>({
+ scale: 1,
+ x: 0,
+ y: 0,
+ });
+ const [annotationRecordingRect, setAnnotationRecordingRect] =
+ useState<AnnotationRecordingRect>({
+ x: 0,
+ y: 0,
+ width: 0,
+ height: 0,
+ });
useEffect(() => {
let framesSignature = getRegisteredFramesSignature();
@@ -847,7 +875,11 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
y: 0,
width: scaledSize,
height: scaledSize,
- radius: webcamCornerRadius,
+ radius: scalePreviewBorderRadius(
+ overlay.clientWidth,
+ overlay.clientHeight,
+ webcamCornerRadius,
+ ),
});
bubble.style.filter = `drop-shadow(0 ${Math.round(scaledSize * 0.06)}px ${Math.round(
scaledSize * 0.22,
@@ -997,6 +1029,23 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
renderWidth: result.maskRect.width * renderResolution,
renderHeight: result.maskRect.height * renderResolution,
};
+ setAnnotationRecordingRect((current) => {
+ if (
+ Math.abs(current.x - result.maskRect.x) < 0.1 &&
+ Math.abs(current.y - result.maskRect.y) < 0.1 &&
+ Math.abs(current.width - result.maskRect.width) < 0.1 &&
+ Math.abs(current.height - result.maskRect.height) < 0.1
+ ) {
+ return current;
+ }
+
+ return {
+ x: result.maskRect.x,
+ y: result.maskRect.y,
+ width: result.maskRect.width,
+ height: result.maskRect.height,
+ };
+ });
cropBoundsRef.current = result.cropBounds;
// Sync extension cursor effects canvas resolution with renderer
@@ -1983,6 +2032,7 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
if (cursorOverlayEnabled) {
const cursorOverlay = new PixiCursorOverlay({
dotRadius: DEFAULT_CURSOR_CONFIG.dotRadius * cursorSizeRef.current,
+ minViewportScale: 0,
style: cursorStyleRef.current,
smoothingFactor: cursorSmoothingRef.current,
springTuning: {
@@ -2193,6 +2243,21 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
state.x = appliedTransform.x;
state.y = appliedTransform.y;
state.appliedScale = appliedTransform.scale;
+ setAnnotationSceneTransform((current) => {
+ if (
+ Math.abs(current.scale - appliedTransform.scale) < 0.001 &&
+ Math.abs(current.x - appliedTransform.x) < 0.1 &&
+ Math.abs(current.y - appliedTransform.y) < 0.1
+ ) {
+ return current;
+ }
+
+ return {
+ scale: appliedTransform.scale,
+ x: appliedTransform.x,
+ y: appliedTransform.y,
+ };
+ });
};
const ticker = () => {
@@ -2200,7 +2265,7 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
return;
}
- const { region, strength, blendedScale, transition } = findDominantRegion(
+ const { region, strength, blendedScale } = findDominantRegion(
zoomRegionsRef.current,
currentTimeRef.current,
{
@@ -2245,47 +2310,6 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
targetScaleFactor = zoomScale;
targetFocus = regionFocus;
targetProgress = strength;
-
- if (transition) {
- const startTransform = computeZoomTransform({
- stageSize: stageSizeRef.current,
- baseMask: baseMaskRef.current,
- zoomScale: transition.startScale,
- zoomProgress: 1,
- focusX: transition.startFocus.cx,
- focusY: transition.startFocus.cy,
- });
- const endTransform = computeZoomTransform({
- stageSize: stageSizeRef.current,
- baseMask: baseMaskRef.current,
- zoomScale: transition.endScale,
- zoomProgress: 1,
- focusX: transition.endFocus.cx,
- focusY: transition.endFocus.cy,
- });
-
- const interpolatedTransform = {
- scale:
- startTransform.scale +
- (endTransform.scale - startTransform.scale) * transition.progress,
- x:
- startTransform.x +
- (endTransform.x - startTransform.x) * transition.progress,
- y:
- startTransform.y +
- (endTransform.y - startTransform.y) * transition.progress,
- };
-
- targetScaleFactor = interpolatedTransform.scale;
- targetFocus = computeFocusFromTransform({
- stageSize: stageSizeRef.current,
- baseMask: baseMaskRef.current,
- zoomScale: interpolatedTransform.scale,
- x: interpolatedTransform.x,
- y: interpolatedTransform.y,
- });
- targetProgress = 1;
- }
}
const state = animationStateRef.current;
@@ -3044,58 +3068,97 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
</div>
</div>
) : null}
- {(() => {
- const filtered = (annotationRegions || []).filter((annotation) => {
- if (
- typeof annotation.startMs !== "number" ||
- typeof annotation.endMs !== "number"
- )
- return false;
-
- if (annotation.id === selectedAnnotationId) return true;
-
- const timeMs = Math.round(currentTime * 1000);
- return timeMs >= annotation.startMs && timeMs <= annotation.endMs;
- });
-
- // Sort by z-index (lowest to highest) so higher z-index renders on top
- const sorted = [...filtered].sort((a, b) => a.zIndex - b.zIndex);
-
- // Handle click-through cycling: when clicking same annotation, cycle to next
- const handleAnnotationClick = (clickedId: string) => {
- if (!onSelectAnnotation) return;
-
- // If clicking on already selected annotation and there are multiple overlapping
- if (clickedId === selectedAnnotationId && sorted.length > 1) {
- // Find current index and cycle to next
- const currentIndex = sorted.findIndex(
- (a) => a.id === clickedId,
- );
- const nextIndex = (currentIndex + 1) % sorted.length;
- onSelectAnnotation(sorted[nextIndex].id);
- } else {
- // First click or clicking different annotation
- onSelectAnnotation(clickedId);
- }
- };
-
- return sorted.map((annotation) => (
- <AnnotationOverlay
- key={annotation.id}
- annotation={annotation}
- isSelected={annotation.id === selectedAnnotationId}
- containerWidth={overlayRef.current?.clientWidth || 800}
- containerHeight={overlayRef.current?.clientHeight || 600}
- onPositionChange={(id, position) =>
- onAnnotationPositionChange?.(id, position)
- }
- onSizeChange={(id, size) => onAnnotationSizeChange?.(id, size)}
- onClick={handleAnnotationClick}
- zIndex={annotation.zIndex}
- isSelectedBoost={annotation.id === selectedAnnotationId}
- />
- ));
- })()}
+ <div
+ className="absolute inset-0"
+ style={{
+ pointerEvents: "none",
+ transform: `matrix(${annotationSceneTransform.scale}, 0, 0, ${annotationSceneTransform.scale}, ${annotationSceneTransform.x}, ${annotationSceneTransform.y})`,
+ transformOrigin: "top left",
+ }}
+ >
+ <div
+ className="absolute"
+ style={{
+ pointerEvents: "none",
+ left: annotationRecordingRect.x || 0,
+ top: annotationRecordingRect.y || 0,
+ width:
+ annotationRecordingRect.width ||
+ (overlayRef.current?.clientWidth || 800),
+ height:
+ annotationRecordingRect.height ||
+ (overlayRef.current?.clientHeight || 600),
+ }}
+ >
+ {(() => {
+ const filtered = (annotationRegions || []).filter((annotation) => {
+ if (
+ typeof annotation.startMs !== "number" ||
+ typeof annotation.endMs !== "number"
+ )
+ return false;
+
+ if (annotation.id === selectedAnnotationId) return true;
+
+ const timeMs = Math.round(currentTime * 1000);
+ return timeMs >= annotation.startMs && timeMs <= annotation.endMs;
+ });
+
+ const sorted = [...filtered].sort((a, b) => a.zIndex - b.zIndex);
+
+ const handleAnnotationClick = (clickedId: string) => {
+ if (!onSelectAnnotation) return;
+
+ if (clickedId === selectedAnnotationId && sorted.length > 1) {
+ const currentIndex = sorted.findIndex(
+ (a) => a.id === clickedId,
+ );
+ const nextIndex = (currentIndex + 1) % sorted.length;
+ onSelectAnnotation(sorted[nextIndex].id);
+ } else {
+ onSelectAnnotation(clickedId);
+ }
+ };
+
+ return sorted.map((annotation) => (
+ <AnnotationOverlay
+ key={annotation.id}
+ annotation={annotation}
+ isSelected={annotation.id === selectedAnnotationId}
+ containerWidth={
+ annotationRecordingRect.width ||
+ (overlayRef.current?.clientWidth || 800)
+ }
+ containerHeight={
+ annotationRecordingRect.height ||
+ (overlayRef.current?.clientHeight || 600)
+ }
+ recordingRect={{
+ x: 0,
+ y: 0,
+ width:
+ annotationRecordingRect.width ||
+ (overlayRef.current?.clientWidth || 800),
+ height:
+ annotationRecordingRect.height ||
+ (overlayRef.current?.clientHeight || 600),
+ }}
+ sceneTransform={{ scale: 1, x: 0, y: 0 }}
+ interactionScale={annotationSceneTransform.scale}
+ onPositionChange={(id, position) =>
+ onAnnotationPositionChange?.(id, position)
+ }
+ onSizeChange={(id, size) =>
+ onAnnotationSizeChange?.(id, size)
+ }
+ onClick={handleAnnotationClick}
+ zIndex={annotation.zIndex}
+ isSelectedBoost={annotation.id === selectedAnnotationId}
+ />
+ ));
+ })()}
+ </div>
+ </div>
</div>
)}
{/* Keep the source video off-screen instead of display:none so the
diff --git a/src/components/video-editor/videoPlayback/cursorRenderer.ts b/src/components/video-editor/videoPlayback/cursorRenderer.ts
index 2055c607..d957b110 100644
--- a/src/components/video-editor/videoPlayback/cursorRenderer.ts
+++ b/src/components/video-editor/videoPlayback/cursorRenderer.ts
@@ -76,6 +76,8 @@ export type NativeCursorAtlas = {
export interface CursorRenderConfig {
/** Base cursor height in pixels (at reference width of 1920px) */
dotRadius: number;
+ /** Minimum viewport scale applied to cursor sizing. */
+ minViewportScale: number;
/** Cursor fill color (hex number for PixiJS) */
dotColor: number;
/** Cursor opacity (0–1) */
@@ -108,8 +110,25 @@ export interface CursorRenderConfig {
style: CursorStyle;
}
+const REFERENCE_WIDTH = 1920;
+const MIN_CURSOR_VIEWPORT_SCALE = 0.55;
+const CURSOR_MOTION_BLUR_BASE_MULTIPLIER = 0.08;
+const CURSOR_TIME_DISCONTINUITY_MS = 100;
+const CURSOR_SWAY_SMOOTHING_MULTIPLIER = 0.7;
+const CURSOR_SWAY_SMOOTHING_OFFSET = 0.18;
+const CURSOR_SVG_DROP_SHADOW_FILTER = "drop-shadow(0px 2px 3px rgba(0, 0, 0, 0.35))";
+const CURSOR_SHADOW_COLOR = 0x000000;
+const CURSOR_SHADOW_ALPHA = 0.35;
+const CURSOR_SHADOW_OFFSET_X = 0;
+const CURSOR_SHADOW_OFFSET_Y = 2;
+const CURSOR_SHADOW_BLUR = 3;
+const CURSOR_SHADOW_PADDING = 12;
+const NATIVE_CURSOR_ATLAS_DRAW_HEIGHT = 256;
+const NATIVE_CURSOR_ATLAS_PADDING = 2;
+
export const DEFAULT_CURSOR_CONFIG: CursorRenderConfig = {
dotRadius: 28,
+ minViewportScale: MIN_CURSOR_VIEWPORT_SCALE,
dotColor: 0xffffff,
dotAlpha: 0.95,
trailLength: 0,
@@ -130,22 +149,6 @@ export const DEFAULT_CURSOR_CONFIG: CursorRenderConfig = {
sway: 0,
style: DEFAULT_CURSOR_STYLE,
};
-
-const REFERENCE_WIDTH = 1920;
-const MIN_CURSOR_VIEWPORT_SCALE = 0.55;
-const CURSOR_MOTION_BLUR_BASE_MULTIPLIER = 0.08;
-const CURSOR_TIME_DISCONTINUITY_MS = 100;
-const CURSOR_SWAY_SMOOTHING_MULTIPLIER = 0.7;
-const CURSOR_SWAY_SMOOTHING_OFFSET = 0.18;
-const CURSOR_SVG_DROP_SHADOW_FILTER = "drop-shadow(0px 2px 3px rgba(0, 0, 0, 0.35))";
-const CURSOR_SHADOW_COLOR = 0x000000;
-const CURSOR_SHADOW_ALPHA = 0.35;
-const CURSOR_SHADOW_OFFSET_X = 0;
-const CURSOR_SHADOW_OFFSET_Y = 2;
-const CURSOR_SHADOW_BLUR = 3;
-const CURSOR_SHADOW_PADDING = 12;
-const NATIVE_CURSOR_ATLAS_DRAW_HEIGHT = 256;
-const NATIVE_CURSOR_ATLAS_PADDING = 2;
let cursorAssetsPromise: Promise<void> | null = null;
let cursorPackAssetsPromise: Promise<void> | null = null;
let loadedCursorPackSourcesSignature = "";
@@ -556,10 +559,7 @@ export async function preloadCursorAssets() {
sourceAsset.fallbackAnchor,
);
- return [
- key,
- asset,
- ] as const;
+ return [key, asset] as const;
} catch (error) {
console.warn(
`[CursorRenderer] Failed to load cursor image for: ${style}/${key}`,
@@ -807,8 +807,11 @@ function findLatestStableCursorType(samples: CursorTelemetryPoint[], timeMs: num
return findLatestSample(samples, timeMs)?.cursorType ?? "arrow";
}
-function getCursorViewportScale(viewport: CursorViewportRect) {
- return Math.max(MIN_CURSOR_VIEWPORT_SCALE, viewport.width / REFERENCE_WIDTH);
+function getCursorViewportScale(
+ viewport: CursorViewportRect,
+ minViewportScale = MIN_CURSOR_VIEWPORT_SCALE,
+) {
+ return Math.max(minViewportScale, viewport.width / REFERENCE_WIDTH);
}
function getCursorSwaySpringConfig(smoothingFactor: number, springTuning: CursorSpringTuning) {
@@ -1341,7 +1344,9 @@ export class PixiCursorOverlay {
const projectedTarget = projectCursorPositionToViewport(target, viewport.sourceCrop);
- const h = this.config.dotRadius * getCursorViewportScale(viewport);
+ const h =
+ this.config.dotRadius *
+ getCursorViewportScale(viewport, this.config.minViewportScale);
const { cursorType, clickSample, clickBounceProgress, clickProgress } =
getCursorVisualState(
samples,
@@ -1395,7 +1400,8 @@ export class PixiCursorOverlay {
if (shouldShowCursorSprite) {
const sameFrameTime =
- this.lastRenderedTimeMs !== null && Math.abs(this.lastRenderedTimeMs - timeMs) < 0.0001;
+ this.lastRenderedTimeMs !== null &&
+ Math.abs(this.lastRenderedTimeMs - timeMs) < 0.0001;
const hasTimeDiscontinuity =
this.lastRenderedTimeMs !== null &&
Math.abs(timeMs - this.lastRenderedTimeMs) > CURSOR_TIME_DISCONTINUITY_MS;
@@ -1636,14 +1642,13 @@ export function drawCursorOnCanvas(
const px = viewport.x + smoothedState.x * viewport.width;
const py = viewport.y + smoothedState.y * viewport.height;
- const h = config.dotRadius * getCursorViewportScale(viewport);
- const { cursorType, clickSample, clickBounceProgress, clickProgress } =
- getCursorVisualState(
- samples,
- timeMs,
- config.clickBounceDuration,
- config.clickEffectDurationMs,
- );
+ const h = config.dotRadius * getCursorViewportScale(viewport, config.minViewportScale);
+ const { cursorType, clickSample, clickBounceProgress, clickProgress } = getCursorVisualState(
+ samples,
+ timeMs,
+ config.clickBounceDuration,
+ config.clickEffectDurationMs,
+ );
const projectedClickSample = clickSample
? projectCursorPositionToViewport(clickSample, viewport.sourceCrop)
: null;
diff --git a/src/lib/exporter/frameRenderer.ts b/src/lib/exporter/frameRenderer.ts
index 049c25bb..6ba9ef23 100644
--- a/src/lib/exporter/frameRenderer.ts
+++ b/src/lib/exporter/frameRenderer.ts
@@ -45,7 +45,6 @@ import { getWebcamMediaTargetTimeSeconds } from "@/components/video-editor/video
import { findDominantRegion } from "@/components/video-editor/videoPlayback/zoomRegionUtils";
import {
applyZoomTransform,
- computeFocusFromTransform,
computeZoomTransform,
createMotionBlurState,
type MotionBlurState,
@@ -1547,6 +1546,9 @@ export class FrameRenderer {
this.config.height,
temporalSnapshot.timeMs,
scaleFactor,
+ undefined,
+ temporalSnapshot.sceneTransform,
+ this.layoutCache?.maskRect,
);
}
@@ -1731,6 +1733,13 @@ export class FrameRenderer {
this.config.height,
timeMs,
scaleFactor,
+ undefined,
+ {
+ scale: this.animationState.appliedScale,
+ x: this.animationState.x,
+ y: this.animationState.y,
+ },
+ this.layoutCache?.maskRect,
);
}
@@ -1961,7 +1970,7 @@ export class FrameRenderer {
private updateAnimationState(timeMs: number): number {
if (!this.cameraContainer || !this.layoutCache) return 0;
- const { region, strength, blendedScale, transition } = findDominantRegion(
+ const { region, strength, blendedScale } = findDominantRegion(
this.config.zoomRegions,
timeMs,
{
@@ -2001,43 +2010,6 @@ export class FrameRenderer {
targetScaleFactor = zoomScale;
targetFocus = regionFocus;
targetProgress = strength;
-
- if (transition) {
- const startTransform = computeZoomTransform({
- stageSize: this.layoutCache.stageSize,
- baseMask: this.layoutCache.maskRect,
- zoomScale: transition.startScale,
- zoomProgress: 1,
- focusX: transition.startFocus.cx,
- focusY: transition.startFocus.cy,
- });
- const endTransform = computeZoomTransform({
- stageSize: this.layoutCache.stageSize,
- baseMask: this.layoutCache.maskRect,
- zoomScale: transition.endScale,
- zoomProgress: 1,
- focusX: transition.endFocus.cx,
- focusY: transition.endFocus.cy,
- });
-
- const interpolatedTransform = {
- scale:
- startTransform.scale +
- (endTransform.scale - startTransform.scale) * transition.progress,
- x: startTransform.x + (endTransform.x - startTransform.x) * transition.progress,
- y: startTransform.y + (endTransform.y - startTransform.y) * transition.progress,
- };
-
- targetScaleFactor = interpolatedTransform.scale;
- targetFocus = computeFocusFromTransform({
- stageSize: this.layoutCache.stageSize,
- baseMask: this.layoutCache.maskRect,
- zoomScale: interpolatedTransform.scale,
- x: interpolatedTransform.x,
- y: interpolatedTransform.y,
- });
- targetProgress = 1;
- }
}
const state = this.animationState;
diff --git a/src/lib/exporter/modernFrameRenderer.test.ts b/src/lib/exporter/modernFrameRenderer.test.ts
index 1f43a9c9..688e51f2 100644
--- a/src/lib/exporter/modernFrameRenderer.test.ts
+++ b/src/lib/exporter/modernFrameRenderer.test.ts
@@ -236,6 +236,45 @@ describe("ModernFrameRenderer blur export path", () => {
expect(renderer.capturePixelsForNativeExport()).not.toBeNull();
});
+ it("uses the sampled scene transform for blur annotations during temporal blur", async () => {
+ const renderer = createRenderer() as any;
+ renderer.config.zoomTemporalMotionBlur = 1;
+ renderer.config.zoomMotionBlurSampleCount = 3;
+ renderer.config.zoomMotionBlurShutterFraction = 0.5;
+ renderer.app = { canvas: createMockCanvas() };
+ renderer.annotationScaleFactor = 1;
+ renderer.annotationAssets = { imageCache: new Map() };
+ renderer.updateCaptionLayer = vi.fn();
+ renderer.renderSceneSample = vi.fn(async (sampleTimestamp: number) => ({
+ timeMs: sampleTimestamp / 1000,
+ cursorTimeMs: sampleTimestamp / 1000,
+ backgroundTimelineTimeMs: sampleTimestamp / 1000,
+ sceneTransform: { scale: 1.75, x: 120, y: -48 },
+ zoom: { scale: 1, focusX: 0.5, focusY: 0.5, progress: 0 },
+ }));
+
+ await renderer.renderTemporalMotionBlurFrame(1_000_000, 1_000_000, 1_000_000, 33_333, {
+ stageSize: { width: 1920, height: 1080 },
+ videoSize: { width: 1920, height: 1080 },
+ baseScale: 1,
+ baseOffset: { x: 0, y: 0 },
+ maskRect: {
+ x: 0,
+ y: 0,
+ width: 1920,
+ height: 1080,
+ sourceCrop: { x: 0, y: 0, width: 1, height: 1 },
+ },
+ });
+
+ expect(renderAnnotations).toHaveBeenCalled();
+ expect(vi.mocked(renderAnnotations).mock.lastCall?.[7]).toEqual({
+ scale: 1.75,
+ x: 120,
+ y: -48,
+ });
+ });
+
it("prefers decoder-backed sync for video wallpapers during export", async () => {
vi.clearAllMocks();
const renderer = new FrameRenderer({
diff --git a/src/lib/exporter/modernFrameRenderer.ts b/src/lib/exporter/modernFrameRenderer.ts
index 6ab918d8..72b862cb 100644
--- a/src/lib/exporter/modernFrameRenderer.ts
+++ b/src/lib/exporter/modernFrameRenderer.ts
@@ -15,8 +15,8 @@ import type {
AnnotationRegion,
AutoCaptionSettings,
CaptionCue,
- CursorClickEffectStyle,
CropRegion,
+ CursorClickEffectStyle,
CursorStyle,
CursorTelemetryPoint,
Padding,
@@ -39,7 +39,10 @@ import {
PixiCursorOverlay,
preloadCursorAssets,
} from "@/components/video-editor/videoPlayback/cursorRenderer";
-import { computePaddedLayout } from "@/components/video-editor/videoPlayback/layoutUtils";
+import {
+ computePaddedLayout,
+ scalePreviewBorderRadius,
+} from "@/components/video-editor/videoPlayback/layoutUtils";
import {
createSpringState,
getZoomSpringConfig,
@@ -51,7 +54,6 @@ import { getWebcamMediaTargetTimeSeconds } from "@/components/video-editor/video
import { findDominantRegion } from "@/components/video-editor/videoPlayback/zoomRegionUtils";
import {
applyZoomTransform,
- computeFocusFromTransform,
computeZoomTransform,
createMotionBlurState,
type MotionBlurState,
@@ -599,7 +601,7 @@ export class FrameRenderer {
this.webcamRootContainer.visible = false;
this.overlayContainer.addChild(this.webcamRootContainer);
- this.overlayContainer.addChild(this.annotationContainer);
+ this.cameraContainer.addChild(this.annotationContainer);
this.overlayContainer.addChild(this.captionContainer);
this.videoMaskGraphics = new Graphics();
@@ -622,14 +624,14 @@ export class FrameRenderer {
massMultiplier: this.config.cursorSpringMassMultiplier,
},
motionBlur: this.config.cursorMotionBlur ?? 0,
- clickEffect:
- this.config.cursorClickEffect ?? DEFAULT_CURSOR_CONFIG.clickEffect,
+ clickEffect: this.config.cursorClickEffect ?? DEFAULT_CURSOR_CONFIG.clickEffect,
clickEffectColor:
this.config.cursorClickEffectColor ?? DEFAULT_CURSOR_CONFIG.clickEffectColor,
clickEffectScale:
this.config.cursorClickEffectScale ?? DEFAULT_CURSOR_CONFIG.clickEffectScale,
clickEffectOpacity:
- this.config.cursorClickEffectOpacity ?? DEFAULT_CURSOR_CONFIG.clickEffectOpacity,
+ this.config.cursorClickEffectOpacity ??
+ DEFAULT_CURSOR_CONFIG.clickEffectOpacity,
clickEffectDurationMs:
this.config.cursorClickEffectDurationMs ??
DEFAULT_CURSOR_CONFIG.clickEffectDurationMs,
@@ -1467,9 +1469,7 @@ export class FrameRenderer {
private calculateAnnotationScaleFactor(): number {
const previewWidth = this.config.previewWidth || 1920;
const previewHeight = this.config.previewHeight || 1080;
- const scaleX = this.config.width / previewWidth;
- const scaleY = this.config.height / previewHeight;
- return (scaleX + scaleY) / 2;
+ return (this.config.width / previewWidth + this.config.height / previewHeight) / 2;
}
private hasActiveBlurAnnotations(timeMs: number): boolean {
@@ -1561,6 +1561,7 @@ export class FrameRenderer {
private async composeBlurAnnotationFrame(
timeMs: number,
+ sceneTransform?: { scale: number; x: number; y: number },
sourceCanvas?: CanvasImageSource,
): Promise<void> {
if (!this.app) {
@@ -1586,6 +1587,12 @@ export class FrameRenderer {
timeMs,
this.annotationScaleFactor,
this.annotationAssets ?? undefined,
+ sceneTransform ?? {
+ scale: this.animationState.appliedScale,
+ x: this.animationState.x,
+ y: this.animationState.y,
+ },
+ this.layoutCache?.maskRect,
);
this.drawCaptionOverlay(context);
@@ -1609,10 +1616,16 @@ export class FrameRenderer {
);
for (const annotation of annotations) {
- const x = (annotation.position.x / 100) * this.config.width;
- const y = (annotation.position.y / 100) * this.config.height;
- const width = (annotation.size.width / 100) * this.config.width;
- const height = (annotation.size.height / 100) * this.config.height;
+ const annotationRect = this.layoutCache?.maskRect ?? {
+ x: 0,
+ y: 0,
+ width: this.config.width,
+ height: this.config.height,
+ };
+ const x = annotationRect.x + (annotation.position.x / 100) * annotationRect.width;
+ const y = annotationRect.y + (annotation.position.y / 100) * annotationRect.height;
+ const width = (annotation.size.width / 100) * annotationRect.width;
+ const height = (annotation.size.height / 100) * annotationRect.height;
if (width <= 0 || height <= 0) {
continue;
@@ -2549,15 +2562,10 @@ export class FrameRenderer {
const usesDefaultCropRegion = isWebcamCropRegionDefault(this.config.webcam?.cropRegion);
const needsCacheBackedSource =
!usesDefaultCropRegion ||
- (typeof HTMLVideoElement !== "undefined" &&
- liveSource instanceof HTMLVideoElement);
+ (typeof HTMLVideoElement !== "undefined" && liveSource instanceof HTMLVideoElement);
if (needsCacheBackedSource) {
- this.refreshWebcamFrameCache(
- liveSource,
- liveSourceWidth,
- liveSourceHeight,
- );
+ this.refreshWebcamFrameCache(liveSource, liveSourceWidth, liveSourceHeight);
const cachedSource = this.getCachedWebcamRenderSource();
if (cachedSource) {
this.setWebcamRenderMode("live");
@@ -3129,7 +3137,11 @@ export class FrameRenderer {
(this.config.annotationRegions?.length ?? 0) > 0 ||
Boolean(this.captionCanvas && this.captionSprite?.visible);
if (hasOverlayCanvasWork) {
- await this.composeBlurAnnotationFrame(resolvedSnapshot.timeMs, compositeState.canvas);
+ await this.composeBlurAnnotationFrame(
+ resolvedSnapshot.timeMs,
+ resolvedSnapshot.sceneTransform,
+ compositeState.canvas,
+ );
} else {
this.outputCanvasOverride = compositeState.canvas;
}
@@ -3536,10 +3548,7 @@ export class FrameRenderer {
this.videoSprite.scale.set(layout.scale);
this.videoSprite.position.set(layout.spriteX, layout.spriteY);
- const previewWidth = this.config.previewWidth || 1920;
- const previewHeight = this.config.previewHeight || 1080;
- const canvasScaleFactor = Math.min(width / previewWidth, height / previewHeight);
- const scaledBorderRadius = borderRadius * canvasScaleFactor;
+ const scaledBorderRadius = scalePreviewBorderRadius(width, height, borderRadius);
this.videoMaskGraphics.clear();
drawSquircleOnGraphics(this.videoMaskGraphics, {
@@ -3689,7 +3698,7 @@ export class FrameRenderer {
return 0;
}
- const { region, strength, blendedScale, transition } = findDominantRegion(
+ const { region, strength, blendedScale } = findDominantRegion(
this.config.zoomRegions,
timeMs,
{
@@ -3728,43 +3737,6 @@ export class FrameRenderer {
targetScaleFactor = zoomScale;
targetFocus = regionFocus;
targetProgress = strength;
-
- if (transition) {
- const startTransform = computeZoomTransform({
- stageSize: this.layoutCache.stageSize,
- baseMask: this.layoutCache.maskRect,
- zoomScale: transition.startScale,
- zoomProgress: 1,
- focusX: transition.startFocus.cx,
- focusY: transition.startFocus.cy,
- });
- const endTransform = computeZoomTransform({
- stageSize: this.layoutCache.stageSize,
- baseMask: this.layoutCache.maskRect,
- zoomScale: transition.endScale,
- zoomProgress: 1,
- focusX: transition.endFocus.cx,
- focusY: transition.endFocus.cy,
- });
-
- const interpolatedTransform = {
- scale:
- startTransform.scale +
- (endTransform.scale - startTransform.scale) * transition.progress,
- x: startTransform.x + (endTransform.x - startTransform.x) * transition.progress,
- y: startTransform.y + (endTransform.y - startTransform.y) * transition.progress,
- };
-
- targetScaleFactor = interpolatedTransform.scale;
- targetFocus = computeFocusFromTransform({
- stageSize: this.layoutCache.stageSize,
- baseMask: this.layoutCache.maskRect,
- zoomScale: interpolatedTransform.scale,
- x: interpolatedTransform.x,
- y: interpolatedTransform.y,
- });
- targetProgress = 1;
- }
}
const state = this.animationState;
diff --git a/src/lib/exporter/modernVideoExporter.nativeStaticLayout.test.ts b/src/lib/exporter/modernVideoExporter.nativeStaticLayout.test.ts
index d3279110..4b7d5b2a 100644
--- a/src/lib/exporter/modernVideoExporter.nativeStaticLayout.test.ts
+++ b/src/lib/exporter/modernVideoExporter.nativeStaticLayout.test.ts
@@ -69,6 +69,7 @@ function createExporter(overrides: Record<string, unknown> = {}) {
ctx: CanvasRenderingContext2D,
wallpaper: string,
) => CanvasGradient | null;
+ getNativeStaticLayoutCursorSize: (contentWidth: number) => number;
};
}
@@ -235,6 +236,14 @@ describe("ModernVideoExporter native static-layout eligibility", () => {
).toBeNull();
});
+ it("scales native static-layout cursor size with a minimum visible floor", () => {
+ const exporter = createExporter({ cursorSize: 3, cursorStyle: "tahoe" });
+
+ expect(exporter.getNativeStaticLayoutCursorSize(1920)).toBeCloseTo(84, 6);
+ expect(exporter.getNativeStaticLayoutCursorSize(960)).toBeCloseTo(46.2, 6);
+ expect(exporter.getNativeStaticLayoutCursorSize(480)).toBeCloseTo(46.2, 6);
+ });
+
it("skips native static-layout when cursor click effects are enabled", () => {
const exporter = createExporter({
showCursor: true,
diff --git a/src/lib/exporter/modernVideoExporter.ts b/src/lib/exporter/modernVideoExporter.ts
index 5b65882b..122537de 100644
--- a/src/lib/exporter/modernVideoExporter.ts
+++ b/src/lib/exporter/modernVideoExporter.ts
@@ -25,7 +25,10 @@ import {
SNAP_TO_EDGES_RATIO_AUTO,
} from "@/components/video-editor/videoPlayback/cursorFollowCamera";
import { buildNativeCursorAtlas } from "@/components/video-editor/videoPlayback/cursorRenderer";
-import { computePaddedLayout } from "@/components/video-editor/videoPlayback/layoutUtils";
+import {
+ computePaddedLayout,
+ scalePreviewBorderRadius,
+} from "@/components/video-editor/videoPlayback/layoutUtils";
import {
createSpringState,
getZoomSpringConfig,
@@ -34,10 +37,7 @@ import {
} from "@/components/video-editor/videoPlayback/motionSmoothing";
import { getCursorStyleSizeMultiplier } from "@/components/video-editor/videoPlayback/uploadedCursorAssets";
import { findDominantRegion } from "@/components/video-editor/videoPlayback/zoomRegionUtils";
-import {
- computeFocusFromTransform,
- computeZoomTransform,
-} from "@/components/video-editor/videoPlayback/zoomTransform";
+import { computeZoomTransform } from "@/components/video-editor/videoPlayback/zoomTransform";
import {
getWebcamOverlayPosition,
getWebcamOverlaySizePx,
@@ -2126,13 +2126,9 @@ export class ModernVideoExporter {
for (let frameIndex = 0; frameIndex < totalFrames; frameIndex += 1) {
const timeMs = frameIndex * frameDurationMs;
- const { region, strength, blendedScale, transition } = findDominantRegion(
- zoomRegions,
- timeMs,
- {
- connectZooms: this.config.connectZooms,
- },
- );
+ const { region, strength, blendedScale } = findDominantRegion(zoomRegions, timeMs, {
+ connectZooms: this.config.connectZooms,
+ });
let targetScale = 1;
let targetFocus = DEFAULT_FOCUS;
@@ -2160,46 +2156,6 @@ export class ModernVideoExporter {
targetScale = zoomScale;
targetFocus = regionFocus;
targetProgress = strength;
-
- if (transition) {
- const startTransform = computeZoomTransform({
- stageSize,
- baseMask,
- zoomScale: transition.startScale,
- zoomProgress: 1,
- focusX: transition.startFocus.cx,
- focusY: transition.startFocus.cy,
- });
- const endTransform = computeZoomTransform({
- stageSize,
- baseMask,
- zoomScale: transition.endScale,
- zoomProgress: 1,
- focusX: transition.endFocus.cx,
- focusY: transition.endFocus.cy,
- });
- const interpolatedTransform = {
- scale:
- startTransform.scale +
- (endTransform.scale - startTransform.scale) * transition.progress,
- x:
- startTransform.x +
- (endTransform.x - startTransform.x) * transition.progress,
- y:
- startTransform.y +
- (endTransform.y - startTransform.y) * transition.progress,
- };
-
- targetScale = interpolatedTransform.scale;
- targetFocus = computeFocusFromTransform({
- stageSize,
- baseMask,
- zoomScale: interpolatedTransform.scale,
- x: interpolatedTransform.x,
- y: interpolatedTransform.y,
- });
- targetProgress = 1;
- }
}
const projectedTransform = computeZoomTransform({
@@ -2336,13 +2292,11 @@ export class ModernVideoExporter {
const sourceCrop = this.isDefaultCropRegion()
? null
: this.getNativeStaticLayoutSourceCrop(videoInfo);
- const previewWidth = this.config.previewWidth || 1920;
- const previewHeight = this.config.previewHeight || 1080;
- const canvasScaleFactor = Math.min(
- this.config.width / previewWidth,
- this.config.height / previewHeight,
+ const borderRadius = scalePreviewBorderRadius(
+ this.config.width,
+ this.config.height,
+ this.config.borderRadius ?? 0,
);
- const borderRadius = Math.max(0, (this.config.borderRadius ?? 0) * canvasScaleFactor);
const shadowIntensity = this.config.showShadow
? Math.min(1, Math.max(0, this.config.shadowIntensity))
: 0;
@@ -2533,8 +2487,7 @@ export class ModernVideoExporter {
timelineSegments,
chunkDurationSec: STATIC_LAYOUT_CHUNK_DURATION_SEC,
experimentalWindowsGpuCompositor: this.config.experimentalNativeExport === true,
- experimentalNvidiaCudaExport:
- this.config.experimentalNvidiaCudaExport === true,
+ experimentalNvidiaCudaExport: this.config.experimentalNvidiaCudaExport === true,
audioOptions: {
...audioOptions,
outputDurationSec: effectiveDuration,