Skip to content
Draft
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 @@ -3874,13 +3877,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 @@ -3906,7 +3920,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,
})
}
/>
</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 @@ -2340,6 +2340,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 @@ -182,9 +182,10 @@ import {
type MotionBlurState,
} from "./videoPlayback/zoomTransform";
import {
getCropMatchedWebcamHeightPercent,
getWebcamCropSourceRect,
getWebcamOverlayDimensionsPx,
getWebcamOverlayPosition,
getWebcamOverlaySizePx,
} from "./webcamOverlay";

type PlaybackAnimationState = {
Expand Down Expand Up @@ -768,7 +769,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 @@ -779,6 +781,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 @@ -789,21 +798,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 @@ -817,18 +827,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 @@ -839,18 +851,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 @@ -871,8 +884,9 @@ const VideoPlayback = forwardRef<VideoPlaybackRef, VideoPlaybackProps>(
webcamPositionY,
webcamReactToZoom,
webcamShadow,
webcamSize,
webcamHeight,
webcamVideoPath,
webcamWidth,
],
);

Expand Down
Loading