Skip to content

Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.

fix(camera): show the framing picture only in its own shape

EtienneLescotc014c9f702a3
diff --git a/src/components/ai-edition/RightPanes.layout.test.tsx b/src/components/ai-edition/RightPanes.layout.test.tsx
index 68bc6c37a..32d9c1cd7 100644
--- a/src/components/ai-edition/RightPanes.layout.test.tsx
+++ b/src/components/ai-edition/RightPanes.layout.test.tsx
@@ -138,6 +138,22 @@ describe("LayoutPane camera availability", () => {
});
});
+describe("LayoutPane webcam framing picture", () => {
+ // Shown in the camera's own shape only: before its metadata the box is a 16:9 guess, and a
+ // picture drawn in it would be stretched.
+ it("shows the camera once its own shape is known", () => {
+ renderLayout(seedProject(true));
+ const video = document.querySelector('[class*="framingVideo"]') as HTMLVideoElement;
+ expect(video.style.visibility).toBe("hidden");
+
+ Object.defineProperty(video, "videoWidth", { configurable: true, value: 640 });
+ Object.defineProperty(video, "videoHeight", { configurable: true, value: 480 });
+ fireEvent.loadedMetadata(video);
+
+ expect(video.style.visibility).toBe("visible");
+ });
+});
+
// #412. The pan used to be read back out of the crop rect, which cannot hold it: at 100%
// zoom the crop IS the frame, so its offset is 0 for every pan the user could have chosen.
// A trip down to 100% therefore erased the framing rather than suspending it.
diff --git a/src/components/ai-edition/RightPanes.tsx b/src/components/ai-edition/RightPanes.tsx
index 798327825..8be27fdf9 100644
--- a/src/components/ai-edition/RightPanes.tsx
+++ b/src/components/ai-edition/RightPanes.tsx
@@ -3317,8 +3317,12 @@ function WebcamFraming({
}) {
const boxRef = useRef<HTMLDivElement | null>(null);
const dragRef = useRef<{ x: number; y: number; pan: { x: number; y: number } } | null>(null);
- // The camera's own shape, once its metadata says; 16:9 until then.
- const [aspect, setAspect] = useState(16 / 9);
+ // The camera's own shape, read from ITS metadata: tied to the source it was read from, so
+ // another camera starts over at 16:9, and the picture stays hidden until its own shape is
+ // known rather than showing a frame in the previous one's.
+ const [metadata, setMetadata] = useState<{ src: string; aspect: number } | null>(null);
+ const ready = src !== null && metadata?.src === src;
+ const aspect = ready ? metadata.aspect : 16 / 9;
const movable = !disabled && crop.width < 0.999;
const clamp01 = (v: number) => Math.min(1, Math.max(0, v));
@@ -3347,6 +3351,7 @@ function WebcamFraming({
<video
className={styles.framingVideo}
src={src}
+ style={{ visibility: ready ? "visible" : "hidden" }}
muted
playsInline
preload="metadata"
@@ -3354,7 +3359,7 @@ function WebcamFraming({
onLoadedMetadata={(e) => {
const video = e.currentTarget;
if (video.videoWidth > 0 && video.videoHeight > 0) {
- setAspect(video.videoWidth / video.videoHeight);
+ setMetadata({ src, aspect: video.videoWidth / video.videoHeight });
}
// A frame from the take rather than its first one, which is often black.
video.currentTime = Math.min(1, (video.duration || 0) / 2);