Skip to content
Open
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
35 changes: 31 additions & 4 deletions src/components/video-editor/SettingsPanel.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -107,6 +107,7 @@ import {
} from "./videoPlayback/uploadedCursorAssets";
import { WebcamCropControl } from "./WebcamCropControl";
import {
getCropMatchedWebcamHeightPercent,
getWebcamPositionForPreset,
normalizeWebcamCropRegion,
resolveWebcamCorner,
Expand Down Expand Up @@ -1662,6 +1663,8 @@ export function SettingsPanel({
const webcamPositionPreset = webcam?.positionPreset ?? DEFAULT_WEBCAM_POSITION_PRESET;
const webcamPositionX = webcam?.positionX ?? DEFAULT_WEBCAM_POSITION_X;
const webcamPositionY = webcam?.positionY ?? DEFAULT_WEBCAM_POSITION_Y;
const webcamWidth = webcam?.width ?? webcam?.size ?? DEFAULT_WEBCAM_SIZE;
const webcamHeight = webcam?.height ?? webcam?.size ?? DEFAULT_WEBCAM_SIZE;
const webcamCrop = normalizeWebcamCropRegion(webcam?.cropRegion);

const getWallpaperTileState = (candidateValue: string, previewPath?: string) => {
Expand Down Expand Up @@ -3871,13 +3874,24 @@ export function SettingsPanel({
/>
</div>
<SliderControl
label={tSettings("effects.webcamSize")}
value={webcam?.size ?? DEFAULT_WEBCAM_SIZE}
label={tSettings("effects.webcamWidth", "Webcam Width")}
value={webcamWidth}
defaultValue={DEFAULT_WEBCAM_SIZE}
min={10}
max={100}
step={1}
onChange={(v) => updateWebcam({ size: v })}
onChange={(v) => updateWebcam({ width: v, size: v })}
formatValue={(v) => `${Math.round(v)}%`}
parseInput={(text) => parseFloat(text.replace(/%$/, ""))}
/>
<SliderControl
label={tSettings("effects.webcamHeight", "Webcam Height")}
value={webcamHeight}
defaultValue={DEFAULT_WEBCAM_SIZE}
min={10}
max={100}
step={1}
onChange={(v) => updateWebcam({ height: v })}
formatValue={(v) => `${Math.round(v)}%`}
parseInput={(text) => parseFloat(text.replace(/%$/, ""))}
/>
Expand All @@ -3903,7 +3917,20 @@ export function SettingsPanel({
previewCurrentTime={webcamPreviewCurrentTime}
previewPlaying={webcamPreviewPlaying}
previewTimeOffsetMs={webcam?.timeOffsetMs}
onCropChange={(cropRegion) => updateWebcam({ cropRegion })}
onCropChange={(cropRegion, previewFrame) =>
updateWebcam({
cropRegion,
height: previewFrame
? getCropMatchedWebcamHeightPercent(
webcamWidth,
webcamWidth,
previewFrame.width,
previewFrame.height,
cropRegion,
)
: webcamHeight,
})
}
Comment on lines +3920 to +3933

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

⚠️ Potential issue | 🟠 Major

🧩 Analysis chain

🏁 Script executed:

#!/bin/bash
# Search for the getCropMatchedWebcamHeightPercent function definition and all call sites

echo "=== Function definition ==="
ast-grep --pattern 'function getCropMatchedWebcamHeightPercent($$$) { $$$ }'

echo -e "\n=== Export statement ==="
ast-grep --pattern 'export function getCropMatchedWebcamHeightPercent($$$) { $$$ }'

echo -e "\n=== All call sites ==="
rg -nP 'getCropMatchedWebcamHeightPercent\s*\(' -A 6

Repository: webadderallorg/Recordly

Length of output: 4445


Verify the second parameter to getCropMatchedWebcamHeightPercent.

Line 3926 passes webcamWidth as both the first and second parameter to getCropMatchedWebcamHeightPercent. The function signature is:

getCropMatchedWebcamHeightPercent(
  widthPercent: number,
  heightPercent: number,
  sourceWidth: number | null | undefined,
  sourceHeight: number | null | undefined,
  cropRegion: Partial<CropRegion> | null | undefined,
): number

All other call sites correctly pass a height-related value as the second parameter (e.g., webcam.height ?? webcam.size ?? 50 or rawWebcamHeight). Passing webcamWidth twice causes incorrect height calculations when the crop region changes.

The second parameter should be webcamHeight.

🔧 Suggested fix
 					onCropChange={(cropRegion, previewFrame) =>
 						updateWebcam({
 							cropRegion,
 							height: previewFrame
 								? getCropMatchedWebcamHeightPercent(
 										webcamWidth,
-										webcamWidth,
+										webcamHeight,
 										previewFrame.width,
 										previewFrame.height,
 										cropRegion,
 									)
 								: webcamHeight,
 						})
 					}
🤖 Prompt for AI Agents
Verify each finding against current code. Fix only still-valid issues, skip the
rest with a brief reason, keep changes minimal, and validate.

In `@src/components/video-editor/SettingsPanel.tsx` around lines 3920 - 3933, In
the onCropChange callback within SettingsPanel.tsx, the call to
getCropMatchedWebcamHeightPercent is passing webcamWidth as both the first and
second parameters. The function expects the first parameter to be widthPercent
and the second parameter to be heightPercent. Replace the second parameter
(currently webcamWidth) with webcamHeight to ensure correct height calculations
when the crop region changes.

/>
</div>
<div className="rounded-lg bg-foreground/[0.03] px-2.5 py-2">
Expand Down
8 changes: 8 additions & 0 deletions src/components/video-editor/VideoEditor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -2384,6 +2384,14 @@ export default function VideoEditor() {
smokeExportConfig.webcamSize === undefined
? prev.size
: smokeExportConfig.webcamSize,
width:
smokeExportConfig.webcamSize === undefined
? (prev.width ?? prev.size)
: smokeExportConfig.webcamSize,
height:
smokeExportConfig.webcamSize === undefined
? (prev.height ?? prev.size)
: smokeExportConfig.webcamSize,
}));
setError(null);
return;
Expand Down
50 changes: 32 additions & 18 deletions src/components/video-editor/VideoPlayback.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -180,9 +180,10 @@ import {
type MotionBlurState,
} from "./videoPlayback/zoomTransform";
import {
getCropMatchedWebcamHeightPercent,
getWebcamCropSourceRect,
getWebcamOverlayDimensionsPx,
getWebcamOverlayPosition,
getWebcamOverlaySizePx,
} from "./webcamOverlay";

type PlaybackAnimationState = {
Expand Down Expand Up @@ -925,7 +926,8 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
const motionBlurStateRef = useRef<MotionBlurState>(createMotionBlurState());
const webcamEnabled = webcam?.enabled ?? false;
const webcamMargin = webcam?.margin ?? 24;
const webcamSize = webcam?.size ?? DEFAULT_WEBCAM_SIZE;
const webcamWidth = webcam?.width ?? webcam?.size ?? DEFAULT_WEBCAM_SIZE;
const rawWebcamHeight = webcam?.height ?? webcam?.size ?? DEFAULT_WEBCAM_SIZE;
const webcamReactToZoom = webcam?.reactToZoom ?? DEFAULT_WEBCAM_REACT_TO_ZOOM;
const webcamPositionPreset = webcam?.positionPreset ?? webcam?.corner ?? "bottom-right";
const webcamPositionX = webcam?.positionX ?? 1;
Expand All @@ -936,6 +938,13 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
const webcamTimeOffsetMs = webcam?.timeOffsetMs;
const webcamCropRegion = webcam?.cropRegion;
const webcamMirror = webcam?.mirror ?? false;
const webcamHeight = getCropMatchedWebcamHeightPercent(
webcamWidth,
rawWebcamHeight,
webcamVideoDimensions?.width,
webcamVideoDimensions?.height,
webcamCropRegion,
);
const webcamCropPreviewContentStyle = useMemo<React.CSSProperties>(() => {
if (!webcamVideoDimensions) {
return { opacity: 0 };
Expand All @@ -946,21 +955,22 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
webcamVideoDimensions.width,
webcamVideoDimensions.height,
);
const coverScale = Math.max(1 / sw, 1 / sh);
const targetAspect = Math.max(0.01, webcamWidth) / Math.max(0.01, webcamHeight);
const coverScale = Math.max(targetAspect / sw, 1 / sh);
const drawWidth = webcamVideoDimensions.width * coverScale;
const drawHeight = webcamVideoDimensions.height * coverScale;
const drawX = (1 - sw * coverScale) / 2 - sx * coverScale;
const drawX = (targetAspect - sw * coverScale) / 2 - sx * coverScale;
const drawY = (1 - sh * coverScale) / 2 - sy * coverScale;

return {
left: `${drawX * 100}%`,
left: `${(drawX / targetAspect) * 100}%`,
top: `${drawY * 100}%`,
width: `${drawWidth * 100}%`,
width: `${(drawWidth / targetAspect) * 100}%`,
height: `${drawHeight * 100}%`,
maxWidth: "none",
willChange: "left, top, width, height",
};
}, [webcamCropRegion, webcamVideoDimensions]);
}, [webcamCropRegion, webcamHeight, webcamVideoDimensions, webcamWidth]);

const applyWebcamBubbleLayout = useCallback(
(zoomScale: number) => {
Expand All @@ -974,18 +984,20 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
return;
}

const scaledSize = getWebcamOverlaySizePx({
const scaledDimensions = getWebcamOverlayDimensionsPx({
containerWidth: overlay.clientWidth,
containerHeight: overlay.clientHeight,
sizePercent: webcamSize,
widthPercent: webcamWidth,
heightPercent: webcamHeight,
margin: webcamMargin,
zoomScale,
reactToZoom: webcamReactToZoom,
});
const { x, y } = getWebcamOverlayPosition({
containerWidth: overlay.clientWidth,
containerHeight: overlay.clientHeight,
size: scaledSize,
width: scaledDimensions.width,
height: scaledDimensions.height,
margin: webcamMargin,
positionPreset: webcamPositionPreset,
positionX: webcamPositionX,
Expand All @@ -996,18 +1008,19 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
bubble.style.display = "block";
bubble.style.left = `${x}px`;
bubble.style.top = `${y}px`;
bubble.style.width = `${scaledSize}px`;
bubble.style.height = `${scaledSize}px`;
bubble.style.aspectRatio = "1 / 1";
bubble.style.width = `${scaledDimensions.width}px`;
bubble.style.height = `${scaledDimensions.height}px`;
bubble.style.aspectRatio = `${scaledDimensions.width} / ${scaledDimensions.height}`;
const squirclePath = getSquircleSvgPath({
x: 0,
y: 0,
width: scaledSize,
height: scaledSize,
width: scaledDimensions.width,
height: scaledDimensions.height,
radius: webcamCornerRadius,
});
bubble.style.filter = `drop-shadow(0 ${Math.round(scaledSize * 0.06)}px ${Math.round(
scaledSize * 0.22,
const shadowSize = Math.min(scaledDimensions.width, scaledDimensions.height);
bubble.style.filter = `drop-shadow(0 ${Math.round(shadowSize * 0.06)}px ${Math.round(
shadowSize * 0.22,
)}px rgba(0, 0, 0, ${webcamShadow}))`;
bubble.style.borderRadius = "0px";
bubble.style.boxShadow = "none";
Expand All @@ -1028,8 +1041,9 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
webcamPositionY,
webcamReactToZoom,
webcamShadow,
webcamSize,
webcamHeight,
webcamVideoPath,
webcamWidth,
],
);

Expand Down
Loading