Record your screen, ship a demo. Free and open-source, GPU-accelerated, no watermarks, no subscriptions. Windows, macOS, Linux. Actively maintained.
TypeScript cross-platformelectronffmpegopen-sourceproduct-demorustscreen-capturescreen-recorderscreen-recordingscreen-studioscreencastspeech-to-texttypescriptvideo-editingvideo-editorwaylandwgpuwhisper
fix(layout): resolve the webcam layout per clip, not once per timeline
Etienne Lescot1c4bc636788a
diff --git a/src/components/ai-edition/PreviewCanvas.tsx b/src/components/ai-edition/PreviewCanvas.tsxindex 4e430d5e8..86879fd12 100644--- a/src/components/ai-edition/PreviewCanvas.tsx+++ b/src/components/ai-edition/PreviewCanvas.tsx@@ -214,8 +214,21 @@ export function PreviewCanvas(props: PreviewCanvasProps) {);const cropRegion: CropRegion = activeClip?.cropRegion ?? DEFAULT_CROP_REGION;+ // P4 — the layout preset is global (one panel for the whole timeline) but the camera+ // is per clip, so the layout has to be resolved against the clip under the playhead.+ const activeCameraTrack = useMemo(+ () => resolveActiveCameraTrack(assets, props.clips, props.currentTimeSec),+ [assets, props.clips, props.currentTimeSec],+ );+ const activeClipHasCamera = Boolean(activeCameraTrack?.visible && activeCameraTrack.sourcePath);+const layout = useMemo(() => {- const preset = settings.webcamLayoutPreset as WebcamLayoutPreset;+ // A clip with no camera lays out as "no-webcam", whatever the panel says. Hiding+ // only the webcam slot is not enough: the block presets size the SCREEN off the+ // block, so the screen stayed squeezed into its half with nothing beside it.+ const preset = (+ activeClipHasCamera ? settings.webcamLayoutPreset : "no-webcam"+ ) as WebcamLayoutPreset;const mask = settings.webcamMaskShape as WebcamMaskShape;// ponytail: padding shrinks the available content area for ALL layouts// (PiP/dual/stack) so the screen doesn't fill the canvas edge-to-edge.@@ -240,7 +253,7 @@ export function PreviewCanvas(props: PreviewCanvasProps) {canvasSize: frameSize,maxContentSize,screenSize: croppedScreenSize,- webcamSize: settings.webcamLayoutPreset === "no-webcam" ? null : WEBCAM_SOURCE_SIZE,+ webcamSize: preset === "no-webcam" ? null : WEBCAM_SOURCE_SIZE,layoutPreset: preset,webcamSizePreset: settings.webcamSizePreset,// ponytail: PiP webcam is grabbable. Pass through the user's@@ -254,6 +267,7 @@ export function PreviewCanvas(props: PreviewCanvasProps) {frameSize,screenNativeSize,cropRegion,+ activeClipHasCamera,settings.webcamLayoutPreset,settings.webcamMaskShape,settings.webcamSizePreset,@@ -293,17 +307,9 @@ export function PreviewCanvas(props: PreviewCanvasProps) {() => buildWebcamStyle(effectiveLayout, settings, frameSize),[effectiveLayout, settings, frameSize],);- // P4 — the layout math above only knows the user's chosen preset- // (PiP/dual/stack), not whether the clip under the playhead actually has a- // camera. Without this, an empty (but styled — shadow, background) webcam- // slot stays visible for clips with no camera attached.- const activeCameraTrack = useMemo(- () => resolveActiveCameraTrack(assets, props.clips, props.currentTimeSec),- [assets, props.clips, props.currentTimeSec],- );- const showWebcamSlot = Boolean(- layout?.webcamRect && activeCameraTrack?.visible && activeCameraTrack.sourcePath,- );+ // `layout` already resolves to "no-webcam" (hence `webcamRect: null`) for a+ // camera-less clip, so this is belt-and-braces rather than the only guard.+ const showWebcamSlot = Boolean(layout?.webcamRect && activeClipHasCamera);const [isPlaying, setIsPlaying] = useState(false);const handleVideoElement = useMemo(() => props.onVideoElement, [props.onVideoElement]);// L'élément `<video>` lui-même n'est plus retenu : il ne servait qu'à échantillonner des pixelsdiff --git a/src/native/sceneDescription.test.ts b/src/native/sceneDescription.test.tsindex e40ff73c0..d5fdc7c9d 100644--- a/src/native/sceneDescription.test.ts+++ b/src/native/sceneDescription.test.ts@@ -864,6 +864,10 @@ describe("buildSceneDescription.settings mapping", () => {id: "a",originalPath: "/a.mp4",video: { codec: "h264", width: 1920, height: 1080, fps: 30 },+ // The camera the preset presupposes. A clip WITHOUT one lays out as+ // "no-webcam" whatever the panel says (see the camera-less cases below),+ // so there would be no rect here to convert.+ cameraTrack: { sourcePath: "/a-webcam.mp4", startMs: 0, offsetMs: 0, visible: true },});const doc = makeDoc({assets: [asset],@@ -1275,6 +1279,76 @@ describe("buildSceneDescription.layout.layoutByClip", () => {const scene = buildSceneDescription(twoClipDoc());expect(scene.layout.screenRect).toEqual(scene.layout.layoutByClip?.[0]?.screenRect);});++ // issue #248 — le preset est GLOBAL (un seul panneau) mais la camera est PAR CLIP.+ // Un projet melange sans probleme un enregistrement avec webcam et un import qui n'en+ // a pas ; le reglage ne doit s'appliquer qu'aux clips qui ont vraiment une camera.+ const mixedDoc = (preset: string) => {+ const withCam = makeAsset({+ id: "cam",+ originalPath: "/rec.mp4",+ video: { codec: "h264", width: 1920, height: 1080, fps: 30 },+ cameraTrack: { sourcePath: "/rec-webcam.webm", startMs: 0, offsetMs: 0, visible: true },+ });+ const noCam = makeAsset({+ id: "nocam",+ originalPath: "/import.mp4",+ video: { codec: "h264", width: 1920, height: 1080, fps: 30 },+ });+ return makeDoc({+ assets: [withCam, noCam],+ clips: [+ makeClip({+ id: "c1",+ assetId: "cam",+ sourceStartSec: 0,+ sourceEndSec: 4,+ timelineStartSec: 0,+ timelineEndSec: 4,+ }),+ makeClip({+ id: "c2",+ assetId: "nocam",+ sourceStartSec: 0,+ sourceEndSec: 4,+ timelineStartSec: 4,+ timelineEndSec: 8,+ }),+ ],+ legacyEditor: { webcamLayoutPreset: preset },+ });+ };++ it.each([+ "picture-in-picture",+ "dual-frame",+ "vertical-stack",+ ])("under %s, only the clip that HAS a camera gets a webcam rect", (preset) => {+ const byClip = buildSceneDescription(mixedDoc(preset)).layout.layoutByClip;+ if (!byClip) throw new Error("layoutByClip absent");+ expect(byClip[0]?.webcamRect).not.toBeNull();+ expect(byClip[1]?.webcamRect).toBeNull();+ });++ // Le coeur du bug rapporte : les presets en bloc dimensionnent l'ECRAN sur le bloc.+ // Masquer la seule vignette ne suffit pas — sans ca le clip sans camera gardait un+ // ecran comprime dans sa moitie, avec du vide a cote.+ it.each([+ "dual-frame",+ "vertical-stack",+ ])("under %s, the camera-less clip gets its full frame back", (preset) => {+ const scene = buildSceneDescription(mixedDoc(preset));+ const byClip = scene.layout.layoutByClip;+ if (!byClip) throw new Error("layoutByClip absent");+ const blocked = byClip[0]?.screenRect;+ const alone = byClip[1]?.screenRect;+ if (!blocked || !alone) throw new Error("entree manquante");+ // Meme source (1920x1080) des deux cotes : la seule difference est la camera.+ const area = (r: { width: number; height: number }) => r.width * r.height;+ expect(area(alone)).toBeGreaterThan(area(blocked) * 1.2);+ // Et il retrouve le ratio de sa source, au lieu du slot du bloc.+ expect(aspectOf(alone, scene.output)).toBeCloseTo(1920 / 1080, 1);+ });});// --- annotations -----------------------------------------------------------diff --git a/src/native/sceneDescription.ts b/src/native/sceneDescription.tsindex 4aa13987c..ae4beb5d9 100644--- a/src/native/sceneDescription.ts+++ b/src/native/sceneDescription.ts@@ -571,24 +571,40 @@ export function buildSceneDescription(height: Math.max(1, Math.round((video?.height || 1080) * (crop?.height ?? 1))),};};- const layoutForScreenSize = (screenSize: { width: number; height: number }) =>- computeCompositeLayout({+ /** Does THIS clip have a camera to lay out? Same expression as the `webcamPath` sent+ * with the clip above, so the layout and the decoder can never disagree about it.+ * Note this is NOT `hasAnyClipWithCamera` (which gates the Layout panel): that one+ * ignores `visible` on purpose, so the panel stays reachable to un-hide a camera. */+ const clipHasCamera = (clip: AxcutClip) => {+ const cam = assetById.get(clip.assetId)?.cameraTrack;+ return Boolean(cam?.visible && cam.sourcePath);+ };+ /**+ * The layout preset is GLOBAL — one panel for the whole timeline — but the camera is+ * per clip: a project mixes a screen+webcam recording with a plain import that has+ * none. A clip with no camera must lay out as if the preset were "no-webcam".+ *+ * Skipping this is not merely a stray thumbnail: the block presets (`dual-frame`,+ * `vertical-stack`) size the SCREEN off the block, so a camera-less clip kept the+ * screen squeezed into its half with nothing beside it. `has_webcam` (native) only+ * gates the camera's own draw — it cannot give the screen its frame back.+ */+ const layoutForClip = (screenSize: { width: number; height: number }, hasCamera: boolean) => {+ const preset = hasCamera ? settings.webcamLayoutPreset : "no-webcam";+ return computeCompositeLayout({canvasSize: outputDims,maxContentSize: {width: Math.round(outputDims.width * paddingFit),height: Math.round(outputDims.height * paddingFit),},screenSize,- webcamSize:- settings.webcamLayoutPreset === "no-webcam"- ? null- : (webcamSourceSize ?? { width: 960, height: 720 }),- layoutPreset: settings.webcamLayoutPreset,+ webcamSize: preset === "no-webcam" ? null : (webcamSourceSize ?? { width: 960, height: 720 }),+ layoutPreset: preset,webcamSizePreset: settings.webcamSizePreset,- webcamPosition:- settings.webcamLayoutPreset === "picture-in-picture" ? settings.webcamPosition : null,+ webcamPosition: preset === "picture-in-picture" ? settings.webcamPosition : null,webcamMaskShape: settings.webcamMaskShape,});+ };const toFrameFractions = (r: RenderRect) => ({x: r.x / outputDims.width,y: r.y / outputDims.height,@@ -603,7 +619,7 @@ export function buildSceneDescription(const shortSide = box ? Math.min(box.width, box.height) : 0;return box && shortSide > 0 && radius != null ? radius / shortSide : null;};- const resolvedLayoutOf = (layout: ReturnType<typeof layoutForScreenSize>) =>+ const resolvedLayoutOf = (layout: ReturnType<typeof layoutForClip>) =>layout? {screenRect: toFrameFractions(layout.screenRect),@@ -618,12 +634,12 @@ export function buildSceneDescription(// `for_clip_window` (Rust) selects the entry for the clip being composed, so the// draw path keeps reading a single `layout` and needs no per-clip branch of its own.const layoutByClip = visibleClips.map((clip, index) =>- resolvedLayoutOf(layoutForScreenSize(screenSourceSizeOf(clip, index))),+ resolvedLayoutOf(layoutForClip(screenSourceSizeOf(clip, index), clipHasCamera(clip))),);// Scalar fields stay the FIRST clip's layout: they are the fallback for a payload// without `layoutByClip`, and the value native starts from before any clip is active.const computedLayout = visibleClips[0]- ? layoutForScreenSize(screenSourceSizeOf(visibleClips[0], 0))+ ? layoutForClip(screenSourceSizeOf(visibleClips[0], 0), clipHasCamera(visibleClips[0])): null;const webcamRect = computedLayout?.webcamRect? toFrameFractions(computedLayout.webcamRect)