Create polished demo videos without editing skills. Mac/Windows/Linux
Improve webcam crop preview and export
wizardAEI8527afe8eec1
diff --git a/src/components/video-editor/SettingsPanel.tsx b/src/components/video-editor/SettingsPanel.tsxindex 42ee6684..694a51bc 100644--- a/src/components/video-editor/SettingsPanel.tsx+++ b/src/components/video-editor/SettingsPanel.tsx@@ -453,6 +453,9 @@ interface SettingsPanelProps {borderRadius?: number;onBorderRadiusChange?: (radius: number) => void;webcam?: WebcamOverlaySettings;+ webcamPreviewSrc?: string | null;+ webcamPreviewCurrentTime?: number;+ webcamPreviewPlaying?: boolean;onWebcamChange?: (webcam: WebcamOverlaySettings) => void;onUploadWebcam?: () => void;onClearWebcam?: () => void;@@ -815,6 +818,9 @@ export function SettingsPanel({borderRadius = 12.5,onBorderRadiusChange,webcam,+ webcamPreviewSrc = null,+ webcamPreviewCurrentTime = 0,+ webcamPreviewPlaying = false,onWebcamChange,onUploadWebcam,onClearWebcam,@@ -2914,6 +2920,10 @@ export function SettingsPanel({<WebcamCropControlcropRegion={webcamCrop}mirrored={webcam?.mirror ?? true}+ previewSrc={webcamPreviewSrc}+ previewCurrentTime={webcamPreviewCurrentTime}+ previewPlaying={webcamPreviewPlaying}+ previewTimeOffsetMs={webcam?.timeOffsetMs}onCropChange={(cropRegion) => updateWebcam({ cropRegion })}/></div>diff --git a/src/components/video-editor/VideoEditor.tsx b/src/components/video-editor/VideoEditor.tsxindex 13c3440a..6483ca13 100644--- a/src/components/video-editor/VideoEditor.tsx+++ b/src/components/video-editor/VideoEditor.tsx@@ -74,13 +74,13 @@ import {getMediaSyncPlaybackRate,} from "@/lib/mediaTiming";import { matchesShortcut } from "@/lib/shortcuts";+import { cn } from "@/lib/utils";import {ASPECT_RATIOS,type AspectRatio,getAspectRatioLabel,getAspectRatioValue,} from "@/utils/aspectRatioUtils";-import { cn } from "@/lib/utils";import { ExtensionIcon } from "./ExtensionIcon";const PhCursorFill = (props: { className?: string; weight?: "fill" | "regular" }) => (@@ -105,17 +105,17 @@ const PhSettings = (props: { className?: string; weight?: "fill" | "regular" })import { extensionHost } from "@/lib/extensions";import { resolveAutoCaptionSourcePath } from "./autoCaptionSource";import { CropControl } from "./CropControl";-import { updateCaptionCuesForEditedTarget, type CaptionEditTarget } from "./captionEditing";+import { type CaptionEditTarget, updateCaptionCuesForEditedTarget } from "./captionEditing";import { ExportSettingsMenu } from "./ExportSettingsMenu";import ExtensionManager from "./ExtensionManager";import {+ type EditorPreset,+ type EditorPresetSnapshot,loadEditorPreferences,loadEditorPresets,saveEditorPreferences,saveEditorPresets,serializeEditorPresetSnapshot,- type EditorPreset,- type EditorPresetSnapshot,} from "./editorPreferences";import ProjectBrowserDialog, { type ProjectLibraryEntry } from "./ProjectBrowserDialog";import {@@ -941,7 +941,7 @@ export default function VideoEditor() {setActiveEditorPresetId(preset.id);applyEditorPresetSnapshot(preset.snapshot);toast.success(- t("editor.presets.toasts.applied", "Applied preset \"{{name}}\"", {+ t("editor.presets.toasts.applied", 'Applied preset "{{name}}"', {name: preset.name,}),);@@ -979,10 +979,7 @@ export default function VideoEditor() {updatedAt: timestamp,snapshot,};- const nextPresets = [- nextPreset,- ...editorPresets,- ];+ const nextPresets = [nextPreset, ...editorPresets];if (!saveEditorPresets(nextPresets)) {toast.error(@@ -997,7 +994,7 @@ export default function VideoEditor() {setEditorPresets(nextPresets);setActiveEditorPresetId(nextPreset.id);toast.success(- t("editor.presets.toasts.saved", "Saved preset \"{{name}}\"", {+ t("editor.presets.toasts.saved", 'Saved preset "{{name}}"', {name: normalizedName,}),);@@ -1029,7 +1026,7 @@ export default function VideoEditor() {setActiveEditorPresetId(null);}toast.success(- t("editor.presets.toasts.deleted", "Deleted preset \"{{name}}\"", {+ t("editor.presets.toasts.deleted", 'Deleted preset "{{name}}"', {name: preset.name,}),);@@ -1883,24 +1880,27 @@ export default function VideoEditor() {setCurrentTime(0);setDuration(0);- setError(null);- setVideoSourcePath(sourcePath);- setVideoPath(await resolveVideoUrl(sourcePath));- setCurrentProjectPath(path ?? null);- pendingFreshRecordingAutoZoomPathRef.current = null;- if (normalizedEditor.webcam.sourcePath) {- await window.electronAPI.setCurrentRecordingSession?.({+ setError(null);+ setVideoSourcePath(sourcePath);+ setVideoPath(await resolveVideoUrl(sourcePath));+ setCurrentProjectPath(path ?? null);+ pendingFreshRecordingAutoZoomPathRef.current = null;+ if (normalizedEditor.webcam.sourcePath) {+ await window.electronAPI.setCurrentRecordingSession?.(+ {videoPath: sourcePath,webcamPath: normalizedEditor.webcam.sourcePath,timeOffsetMs: normalizedEditor.webcam.timeOffsetMs,- }, {+ },+ {preserveProjectPath: Boolean(path),- });- } else {- await window.electronAPI.setCurrentVideoPath(sourcePath, {- preserveProjectPath: Boolean(path),- });- }+ },+ );+ } else {+ await window.electronAPI.setCurrentVideoPath(sourcePath, {+ preserveProjectPath: Boolean(path),+ });+ }setWallpaper(normalizedEditor.wallpaper);setShadowIntensity(normalizedEditor.shadowIntensity);@@ -2028,18 +2028,21 @@ export default function VideoEditor() {return;}- await window.electronAPI.setCurrentRecordingSession({- videoPath: currentSourcePath,- webcamPath,- timeOffsetMs:- webcamPath && Number.isFinite(timeOffsetMs)- ? (timeOffsetMs ?? DEFAULT_WEBCAM_TIME_OFFSET_MS)- : webcamPath- ? webcam.timeOffsetMs- : DEFAULT_WEBCAM_TIME_OFFSET_MS,- }, {- preserveProjectPath: Boolean(currentProjectPath),- });+ await window.electronAPI.setCurrentRecordingSession(+ {+ videoPath: currentSourcePath,+ webcamPath,+ timeOffsetMs:+ webcamPath && Number.isFinite(timeOffsetMs)+ ? (timeOffsetMs ?? DEFAULT_WEBCAM_TIME_OFFSET_MS)+ : webcamPath+ ? webcam.timeOffsetMs+ : DEFAULT_WEBCAM_TIME_OFFSET_MS,+ },+ {+ preserveProjectPath: Boolean(currentProjectPath),+ },+ );},[currentProjectPath, currentSourcePath, webcam.timeOffsetMs],);@@ -2047,13 +2050,16 @@ export default function VideoEditor() {const syncActiveVideoSource = useCallback(async (sourcePath: string, webcamPath?: string | null) => {if (webcamPath) {- await window.electronAPI.setCurrentRecordingSession?.({- videoPath: sourcePath,- webcamPath,- timeOffsetMs: webcam.timeOffsetMs,- }, {- preserveProjectPath: Boolean(currentProjectPath),- });+ await window.electronAPI.setCurrentRecordingSession?.(+ {+ videoPath: sourcePath,+ webcamPath,+ timeOffsetMs: webcam.timeOffsetMs,+ },+ {+ preserveProjectPath: Boolean(currentProjectPath),+ },+ );return;}@@ -2606,10 +2612,13 @@ export default function VideoEditor() {.split(/[\\/]/).pop()?.replace(/\.[^.]+$/, "") || `project-${Date.now()}`;- let targetProjectPath = forceSaveAs ? undefined : (currentProjectPath ?? undefined);+ let targetProjectPath = forceSaveAs+ ? undefined+ : (currentProjectPath ?? undefined);if (!forceSaveAs && !targetProjectPath) {- const activeProjectResult = await window.electronAPI.loadCurrentProjectFile();+ const activeProjectResult =+ await window.electronAPI.loadCurrentProjectFile();if (activeProjectResult.success && activeProjectResult.path) {targetProjectPath = activeProjectResult.path;setCurrentProjectPath(activeProjectResult.path);@@ -3642,22 +3651,25 @@ export default function VideoEditor() {);}, []);- const handleAudioVolumeChange = useCallback((volume: number) => {- if (!selectedAudioId) {- return;- }+ const handleAudioVolumeChange = useCallback(+ (volume: number) => {+ if (!selectedAudioId) {+ return;+ }- if (!Number.isFinite(volume)) {- return;- }+ if (!Number.isFinite(volume)) {+ return;+ }- const nextVolume = Math.max(0, Math.min(1, volume));- setAudioRegions((prev) =>- prev.map((region) =>- region.id === selectedAudioId ? { ...region, volume: nextVolume } : region,- ),- );- }, [selectedAudioId]);+ const nextVolume = Math.max(0, Math.min(1, volume));+ setAudioRegions((prev) =>+ prev.map((region) =>+ region.id === selectedAudioId ? { ...region, volume: nextVolume } : region,+ ),+ );+ },+ [selectedAudioId],+ );const handleAudioDelete = useCallback((id: string) => {@@ -5271,7 +5283,10 @@ export default function VideoEditor() {><span className="flex items-center gap-1.5"><BookmarkSimple weight="fill" className="h-4 w-4" />- <span>{currentEditorPreset?.name ?? t("editor.presets.label", "Presets")}</span>+ <span>+ {currentEditorPreset?.name ??+ t("editor.presets.label", "Presets")}+ </span></span><ChevronDown className="h-3.5 w-3.5 text-foreground" /></button>@@ -5290,15 +5305,26 @@ export default function VideoEditor() {className="space-y-2"><p className="text-[11px] font-medium text-foreground">- {t("editor.presets.saveCurrentAs", "Save current preset as")}+ {t(+ "editor.presets.saveCurrentAs",+ "Save current preset as",+ )}</p><div className="flex items-center gap-2"><Inputvalue={presetNameDraft}- onChange={(event) => setPresetNameDraft(event.target.value)}+ onChange={(event) =>+ setPresetNameDraft(event.target.value)+ }className="h-9 rounded-xl border-foreground/10 bg-background/70 text-sm"- placeholder={t("editor.presets.namePlaceholder", "Preset name")}- aria-label={t("editor.presets.namePlaceholder", "Preset name")}+ placeholder={t(+ "editor.presets.namePlaceholder",+ "Preset name",+ )}+ aria-label={t(+ "editor.presets.namePlaceholder",+ "Preset name",+ )}/><Buttontype="submit"@@ -5321,7 +5347,8 @@ export default function VideoEditor() {</div>) : (editorPresets.map((preset) => {- const isActive = preset.id === currentEditorPreset?.id;+ const isActive =+ preset.id === currentEditorPreset?.id;return (<divkey={preset.id}@@ -5334,15 +5361,23 @@ export default function VideoEditor() {><buttontype="button"- onClick={() => handleApplyEditorPreset(preset.id)}+ onClick={() =>+ handleApplyEditorPreset(preset.id)+ }className="flex min-w-0 flex-1 items-center justify-between text-left">- <span className="truncate pr-3">{preset.name}</span>- {isActive ? <Check className="h-3.5 w-3.5 shrink-0 text-[#2563EB]" /> : null}+ <span className="truncate pr-3">+ {preset.name}+ </span>+ {isActive ? (+ <Check className="h-3.5 w-3.5 shrink-0 text-[#2563EB]" />+ ) : null}</button><buttontype="button"- onClick={() => handleDeleteEditorPreset(preset.id)}+ onClick={() =>+ handleDeleteEditorPreset(preset.id)+ }className="inline-flex h-7 w-7 shrink-0 items-center justify-center rounded-lg text-muted-foreground transition-colors hover:bg-foreground/8 hover:text-foreground"aria-label={t("editor.presets.deleteAriaLabel",@@ -5759,6 +5794,9 @@ export default function VideoEditor() {borderRadius={borderRadius}onBorderRadiusChange={setBorderRadius}webcam={webcam}+ webcamPreviewSrc={webcam.sourcePath ? resolvedWebcamVideoUrl : null}+ webcamPreviewCurrentTime={currentTime}+ webcamPreviewPlaying={isPlaying}onWebcamChange={setWebcam}onUploadWebcam={handleUploadWebcam}onClearWebcam={handleClearWebcam}diff --git a/src/components/video-editor/WebcamCropControl.tsx b/src/components/video-editor/WebcamCropControl.tsxindex 49eada33..0d727172 100644--- a/src/components/video-editor/WebcamCropControl.tsx+++ b/src/components/video-editor/WebcamCropControl.tsx@@ -1,6 +1,7 @@-import { useEffect, useId, useRef, useState } from "react";+import { useCallback, useEffect, useId, useRef, useState } from "react";import { cn } from "@/lib/utils";import type { CropRegion } from "./types";+import { getWebcamPreviewTargetTimeSeconds } from "./videoPlayback/webcamSync";import { normalizeWebcamCropRegion } from "./webcamOverlay";type CropHandle = "move" | "nw" | "ne" | "sw" | "se";@@ -16,6 +17,10 @@ const HANDLE_LABELS: Record<CropHandle, string> = {interface WebcamCropControlProps {cropRegion: CropRegion;mirrored?: boolean;+ previewSrc?: string | null;+ previewCurrentTime?: number;+ previewPlaying?: boolean;+ previewTimeOffsetMs?: number | null;onCropChange: (cropRegion: CropRegion) => void;}@@ -26,6 +31,12 @@ interface DragState {initialCrop: CropRegion;}+interface PreviewFrame {+ src: string | null;+ width: number;+ height: number;+}+const MIN_CROP_SIZE = 0.08;const KEYBOARD_STEP = 0.01;const KEYBOARD_FAST_STEP = 0.05;@@ -61,32 +72,51 @@ function clamp(value: number, min: number, max: number): number {return Math.min(max, Math.max(min, value));}-function normalizeSquareCropRegion(cropRegion: CropRegion): CropRegion {+function normalizeAspectCropRegion(cropRegion: CropRegion, displayAspectRatio: number): CropRegion {const crop = normalizeWebcamCropRegion(cropRegion);- const size = clamp(Math.min(crop.width, crop.height), MIN_CROP_SIZE, 1);- const x = clamp(crop.x, 0, 1 - size);- const y = clamp(crop.y, 0, 1 - size);-- return { x, y, width: size, height: size };+ const aspectRatio =+ Number.isFinite(displayAspectRatio) && displayAspectRatio > 0 ? displayAspectRatio : 1;+ const maxWidth = Math.min(1, 1 / aspectRatio);+ const minWidth = Math.min(MIN_CROP_SIZE, maxWidth);+ const width = clamp(Math.min(crop.width, crop.height / aspectRatio), minWidth, maxWidth);+ const height = width * aspectRatio;+ const centerX = crop.x + crop.width / 2;+ const centerY = crop.y + crop.height / 2;+ const x = clamp(centerX - width / 2, 0, 1 - width);+ const y = clamp(centerY - height / 2, 0, 1 - height);++ return { x, y, width, height };}-function flipCropHorizontally(cropRegion: CropRegion): CropRegion {- const crop = normalizeSquareCropRegion(cropRegion);+function flipCropHorizontally(cropRegion: CropRegion, displayAspectRatio: number): CropRegion {+ const crop = normalizeAspectCropRegion(cropRegion, displayAspectRatio);return {...crop,x: clamp(1 - crop.x - crop.width, 0, 1 - crop.width),};}-function resizeCrop(cropRegion: CropRegion, handle: CropHandle, deltaX: number, deltaY: number) {- const crop = normalizeSquareCropRegion(cropRegion);+function resizeCrop(+ cropRegion: CropRegion,+ handle: CropHandle,+ deltaX: number,+ deltaY: number,+ displayAspectRatio: number,+) {+ const aspectRatio =+ Number.isFinite(displayAspectRatio) && displayAspectRatio > 0 ? displayAspectRatio : 1;+ const crop = normalizeAspectCropRegion(cropRegion, aspectRatio);+ const minWidth = Math.min(MIN_CROP_SIZE, Math.min(1, 1 / aspectRatio));if (handle === "move") {- return normalizeSquareCropRegion({- ...crop,- x: clamp(crop.x + deltaX, 0, 1 - crop.width),- y: clamp(crop.y + deltaY, 0, 1 - crop.height),- });+ return normalizeAspectCropRegion(+ {+ ...crop,+ x: clamp(crop.x + deltaX, 0, 1 - crop.width),+ y: clamp(crop.y + deltaY, 0, 1 - crop.height),+ },+ aspectRatio,+ );}let left = crop.x;@@ -95,55 +125,87 @@ function resizeCrop(cropRegion: CropRegion, handle: CropHandle, deltaX: number,let bottom = crop.y + crop.height;if (handle === "nw") {- const delta = Math.max(deltaX, deltaY);- const nextSize = clamp(crop.width - delta, MIN_CROP_SIZE, Math.min(right, bottom));- left = right - nextSize;- top = bottom - nextSize;+ const delta = Math.max(deltaX, deltaY / aspectRatio);+ const nextWidth = clamp(+ crop.width - delta,+ minWidth,+ Math.min(right, bottom / aspectRatio),+ );+ left = right - nextWidth;+ top = bottom - nextWidth * aspectRatio;}if (handle === "ne") {- const delta = Math.max(deltaX, -deltaY);- const nextSize = clamp(crop.width + delta, MIN_CROP_SIZE, Math.min(1 - left, bottom));- right = left + nextSize;- top = bottom - nextSize;+ const delta = Math.max(deltaX, -deltaY / aspectRatio);+ const nextWidth = clamp(+ crop.width + delta,+ minWidth,+ Math.min(1 - left, bottom / aspectRatio),+ );+ right = left + nextWidth;+ top = bottom - nextWidth * aspectRatio;}if (handle === "sw") {- const delta = Math.max(-deltaX, deltaY);- const nextSize = clamp(crop.width + delta, MIN_CROP_SIZE, Math.min(right, 1 - top));- left = right - nextSize;- bottom = top + nextSize;+ const delta = Math.max(-deltaX, deltaY / aspectRatio);+ const nextWidth = clamp(+ crop.width + delta,+ minWidth,+ Math.min(right, (1 - top) / aspectRatio),+ );+ left = right - nextWidth;+ bottom = top + nextWidth * aspectRatio;}if (handle === "se") {- const delta = Math.max(deltaX, deltaY);- const nextSize = clamp(crop.width + delta, MIN_CROP_SIZE, Math.min(1 - left, 1 - top));- right = left + nextSize;- bottom = top + nextSize;+ const delta = Math.max(deltaX, deltaY / aspectRatio);+ const nextWidth = clamp(+ crop.width + delta,+ minWidth,+ Math.min(1 - left, (1 - top) / aspectRatio),+ );+ right = left + nextWidth;+ bottom = top + nextWidth * aspectRatio;}- return normalizeSquareCropRegion({- x: left,- y: top,- width: right - left,- height: bottom - top,- });+ return normalizeAspectCropRegion(+ {+ x: left,+ y: top,+ width: right - left,+ height: bottom - top,+ },+ aspectRatio,+ );}export function WebcamCropControl({cropRegion,mirrored = false,+ previewSrc = null,+ previewCurrentTime = 0,+ previewPlaying = false,+ previewTimeOffsetMs = 0,onCropChange,}: WebcamCropControlProps) {const containerRef = useRef<HTMLDivElement | null>(null);+ const previewVideoRef = useRef<HTMLVideoElement | null>(null);const dragStateRef = useRef<DragState | null>(null);const pendingCropRef = useRef<CropRegion | null>(null);const pendingFrameRef = useRef<number | null>(null);const maskId = `webcam-crop-mask-${useId().replace(/:/g, "")}`;const [activeHandle, setActiveHandle] = useState<CropHandle | null>(null);const [draftVisualCrop, setDraftVisualCrop] = useState<CropRegion | null>(null);- const sourceCrop = normalizeSquareCropRegion(cropRegion);- const propVisualCrop = mirrored ? flipCropHorizontally(sourceCrop) : sourceCrop;+ const [previewFrame, setPreviewFrame] = useState<PreviewFrame | null>(null);+ const hasPreviewFrame = previewSrc !== null && previewFrame?.src === previewSrc;+ const previewAspectRatio =+ hasPreviewFrame && previewFrame && previewFrame.width > 0 && previewFrame.height > 0+ ? previewFrame.width / previewFrame.height+ : 1;+ const sourceCrop = normalizeAspectCropRegion(cropRegion, previewAspectRatio);+ const propVisualCrop = mirrored+ ? flipCropHorizontally(sourceCrop, previewAspectRatio)+ : sourceCrop;const crop = draftVisualCrop ?? propVisualCrop;const cropLeft = crop.x * 100;const cropTop = crop.y * 100;@@ -164,8 +226,62 @@ export function WebcamCropControl({pendingCropRef.current = null;onCropChange(nextCrop);};+ const syncPreviewMedia = useCallback(() => {+ const video = previewVideoRef.current;+ if (!video || !previewSrc) {+ return;+ }++ const webcamDuration = Number.isFinite(video.duration) ? video.duration : null;+ const targetTime = getWebcamPreviewTargetTimeSeconds({+ currentTime: previewCurrentTime,+ webcamDuration,+ timeOffsetMs: previewTimeOffsetMs,+ });+ const mediaTargetTime =+ targetTime <= 0 && webcamDuration !== null && webcamDuration > 0+ ? Math.min(1 / 60, webcamDuration)+ : targetTime;+ const driftThreshold = previewPlaying ? 0.35 : 0.01;++ if (Math.abs(video.currentTime - mediaTargetTime) > driftThreshold) {+ try {+ video.currentTime = mediaTargetTime;+ } catch {+ /* Ignore browsers that reject seeks while metadata is settling. */+ }+ }++ if (previewPlaying) {+ const playPromise = video.play();+ if (playPromise) {+ playPromise.catch(() => undefined);+ }+ } else {+ video.pause();+ }+ }, [previewCurrentTime, previewPlaying, previewSrc, previewTimeOffsetMs]);++ const handlePreviewFrameReady = useCallback(() => {+ const video = previewVideoRef.current;+ if (video && video.videoWidth > 0 && video.videoHeight > 0) {+ setPreviewFrame({+ src: previewSrc,+ width: video.videoWidth,+ height: video.videoHeight,+ });+ }+ syncPreviewMedia();+ }, [previewSrc, syncPreviewMedia]);++ useEffect(() => {+ syncPreviewMedia();+ }, [syncPreviewMedia]);+const commitVisualCrop = (nextVisualCrop: CropRegion, immediate = false) => {- const nextCrop = mirrored ? flipCropHorizontally(nextVisualCrop) : nextVisualCrop;+ const nextCrop = mirrored+ ? flipCropHorizontally(nextVisualCrop, previewAspectRatio)+ : nextVisualCrop;if (immediate) {cancelPendingCommit();pendingCropRef.current = null;@@ -242,6 +358,7 @@ export function WebcamCropControl({dragState.handle,pointer.x - dragState.startX,pointer.y - dragState.startY,+ previewAspectRatio,);setDraftVisualCrop(nextVisualCrop);commitVisualCrop(nextVisualCrop);@@ -285,21 +402,42 @@ export function WebcamCropControl({}event.preventDefault();event.stopPropagation();- commitVisualCrop(resizeCrop(crop, handle, delta.x, delta.y), true);+ commitVisualCrop(resizeCrop(crop, handle, delta.x, delta.y, previewAspectRatio), true);};return (<divref={containerRef}className="relative w-full touch-none select-none overflow-hidden rounded-lg border border-foreground/10 bg-editor-dialog-alt"- style={{ aspectRatio: 1 }}+ style={{ aspectRatio: previewAspectRatio }}onPointerMove={handlePointerMove}onPointerUp={endDrag}onPointerCancel={endDrag}>- <div className="absolute inset-0 bg-editor-dialog-alt" />- <div className="absolute inset-0 bg-[linear-gradient(hsl(var(--foreground)/0.12)_1px,transparent_1px),linear-gradient(90deg,hsl(var(--foreground)/0.12)_1px,transparent_1px)] bg-[size:12.5%_12.5%]" />- <div className="absolute inset-0 bg-[linear-gradient(135deg,hsl(var(--foreground)/0.06),transparent_46%,hsl(var(--foreground)/0.04))]" />+ {previewSrc ? (+ <video+ ref={previewVideoRef}+ src={previewSrc}+ className="pointer-events-none absolute inset-0 block h-full w-full object-fill"+ style={{+ opacity: hasPreviewFrame ? 1 : 0,+ transform: mirrored ? "scaleX(-1)" : undefined,+ }}+ muted+ playsInline+ preload="auto"+ aria-hidden="true"+ onLoadedMetadata={handlePreviewFrameReady}+ onLoadedData={handlePreviewFrameReady}+ onSeeked={handlePreviewFrameReady}+ />+ ) : null}+ <div+ className={cn(+ "absolute inset-0 bg-editor-dialog-alt transition-opacity",+ previewSrc && hasPreviewFrame ? "opacity-0" : "opacity-100",+ )}+ /><svg className="pointer-events-none absolute inset-0 h-full w-full"><defs>diff --git a/src/lib/exporter/modernFrameRenderer.test.ts b/src/lib/exporter/modernFrameRenderer.test.tsindex ccb3374f..5fcd55dc 100644--- a/src/lib/exporter/modernFrameRenderer.test.ts+++ b/src/lib/exporter/modernFrameRenderer.test.ts@@ -224,3 +224,27 @@ describe("ModernFrameRenderer blur export path", () => {expect(renderer.backgroundVideoElement).toBeNull();});});++describe("ModernFrameRenderer webcam frame cache", () => {+ it("keeps the refresh throttle for default crop regions", () => {+ const renderer = createRenderer() as any;++ renderer.config.webcam.cropRegion = { x: 0, y: 0, width: 1, height: 1 };+ renderer.webcamFrameCacheCanvas = { width: 1280, height: 720 };+ renderer.lastWebcamCacheRefreshTime = 10;+ renderer.currentVideoTime = 10.1;++ expect(renderer.shouldRefreshWebcamFrameCache(1280, 720)).toBe(false);+ });++ it("bypasses the refresh throttle for cropped webcam regions", () => {+ const renderer = createRenderer() as any;++ renderer.config.webcam.cropRegion = { x: 0.25, y: 0, width: 0.5, height: 1 };+ renderer.webcamFrameCacheCanvas = { width: 640, height: 720 };+ renderer.lastWebcamCacheRefreshTime = 10;+ renderer.currentVideoTime = 10.1;++ expect(renderer.shouldRefreshWebcamFrameCache(1280, 720)).toBe(true);+ });+});diff --git a/src/lib/exporter/modernFrameRenderer.ts b/src/lib/exporter/modernFrameRenderer.tsindex bf3c3f2c..b6f42814 100644--- a/src/lib/exporter/modernFrameRenderer.ts+++ b/src/lib/exporter/modernFrameRenderer.ts@@ -1812,7 +1812,8 @@ export class FrameRenderer {}private shouldRefreshWebcamFrameCache(width: number, height: number): boolean {- const sourceRect = getWebcamCropSourceRect(this.config.webcam?.cropRegion, width, height);+ const cropRegion = this.config.webcam?.cropRegion;+ const sourceRect = getWebcamCropSourceRect(cropRegion, width, height);const targetWidth = Math.max(1, Math.ceil(sourceRect.sw));const targetHeight = Math.max(1, Math.ceil(sourceRect.sh));@@ -1824,6 +1825,10 @@ export class FrameRenderer {return true;}+ if (!isWebcamCropRegionDefault(cropRegion)) {+ return true;+ }+if (this.lastWebcamCacheRefreshTime === null) {return true;}