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
feat(format): add Auto, a frame shaped around the composition
EtienneLescot43580fd324a6
diff --git a/src/components/ai-edition/PreviewCanvas.tsx b/src/components/ai-edition/PreviewCanvas.tsxindex 247f7a2ab..bdb88b9d0 100644--- a/src/components/ai-edition/PreviewCanvas.tsx+++ b/src/components/ai-edition/PreviewCanvas.tsx@@ -49,13 +49,14 @@ import { locateVirtualPosition } from "@/lib/ai-edition/timeline/virtual-previewimport {computeCameraFullscreenRect,computeCompositeLayout,+ paddedContentSize,resolveWebcamLayoutPreset,type WebcamCompositeLayout,} from "@/lib/compositeLayout";import { classifyWallpaper, resolveImageWallpaperUrl } from "@/lib/wallpaper";import { getCssClipPath } from "@/lib/webcamMaskShapes";import { computeCameraFullscreenProgress } from "@/lib/zoomMath/cameraFullscreenUtils";-import { clamp, clamp01 } from "@/utils/math";+import { clamp01 } from "@/utils/math";import { AnnotationLayer } from "./AnnotationLayer";import { NativeCompositorOverlay } from "./NativeCompositorOverlay";import styles from "./NewEditorShell.module.css";@@ -245,16 +246,13 @@ export function PreviewCanvas(props: PreviewCanvasProps) {activeClipHasCamera,);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.- // In vertical-stack this caps the camera strip height: at padding=0 the- // camera reaches 40% of canvas; at padding=50 it falls to ~32%;- // at padding=100 the screen takes even more.- const paddingFit = clamp(1 - (clamp(settings.padding, 0, 100) / 100) * 0.4, 0.4, 1);- const maxContentSize = {- width: Math.round(frameSize.width * paddingFit),- height: Math.round(frameSize.height * paddingFit),- };+ // Padding shrinks the available content area for ALL layouts (PiP/dual/stack),+ // through the same `paddedContentSize` the scene description uses.+ const maxContentSize = paddedContentSize(+ frameSize,+ settings.padding,+ settings.aspectRatio === "auto",+ );// The screen box must be fit to the CROPPED aspect ratio, not the full// source frame's — otherwise VirtualPreview's crop math (which assumes// its container is already correctly proportioned for the crop) would@@ -288,6 +286,7 @@ export function PreviewCanvas(props: PreviewCanvasProps) {settings.webcamSizePreset,settings.webcamPosition,settings.padding,+ settings.aspectRatio,]);// Full Camera: during a cameraFullscreen region the webcam takes the wholediff --git a/src/components/ai-edition/RightPanes.tsx b/src/components/ai-edition/RightPanes.tsxindex bd3c3d3fd..bf11ade54 100644--- a/src/components/ai-edition/RightPanes.tsx+++ b/src/components/ai-edition/RightPanes.tsx@@ -47,7 +47,7 @@ import { WALLPAPER_MOTIONS, type WallpaperMotion } from "@/components/video-editimport { useI18n, useScopedT } from "@/contexts/I18nContext";import { resolveCaptionLane } from "@/lib/ai-edition/captions/settings";import { collapseTracksToPills, trackGroupId } from "@/lib/ai-edition/document/audioTracks";-import { collectNativeFormats } from "@/lib/ai-edition/document/outputFormat";+import { collectNativeFormats, pickOutputDims } from "@/lib/ai-edition/document/outputFormat";import type { InsertSide } from "@/lib/ai-edition/document/transcript";import type {AxcutAsset,@@ -2416,6 +2416,9 @@ export function VideoEffectsPane() {// can never disagree about what shape the footage is. Already sorted by clip count then by// pixel area, so [0] is "the shape most of this timeline is in" with no heuristic of ours.const nativeFormats = useMemo(() => (document ? collectNativeFormats(document) : []), [document]);+ // What Auto resolves to right now, shown on its row: the one entry whose shape moves with+ // the project (padding, camera layout, crop) has to say where it currently stands.+ const autoDims = useMemo(() => (document ? pickOutputDims(document, "auto") : null), [document]);const hasTiltedZoom = (document?.zoomRanges ?? []).some((z) => z.rotationPreset != null);const [fitMenuOpen, setFitMenuOpen] = useState(false);const [ratioMenuOpen, setRatioMenuOpen] = useState(false);@@ -2541,9 +2544,11 @@ export function VideoEffectsPane() {bakes it into a concrete token once clip dimensions are known, andleaves it alone until then. The group header below is localized, sowithout this the two would disagree in twelve locales. */}- {settings.aspectRatio === "native"- ? ts("effects.formatOriginal")- : getAspectRatioLabel(settings.aspectRatio)}+ {settings.aspectRatio === "auto"+ ? ts("effects.formatAuto")+ : settings.aspectRatio === "native"+ ? ts("effects.formatOriginal")+ : getAspectRatioLabel(settings.aspectRatio)}<ChevronDown size={11} /></button></PopoverTrigger>@@ -2555,6 +2560,25 @@ export function VideoEffectsPane() {className="w-auto border-0 bg-transparent p-0 shadow-none"><div className={styles.actionMenu} role="menu" aria-label={ts("effects.format")}>+ {/* Auto leads: it is the one entry that is a rule rather than a shape. */}+ <button+ type="button"+ role="menuitem"+ className={`${styles.actionMenuRow}${+ settings.aspectRatio === "auto" ? ` ${styles.isActive}` : ""+ }`}+ onClick={() => {+ setRatioMenuOpen(false);+ void set({ aspectRatio: "auto" });+ }}+ >+ <span className={styles.actionMenuMain}>{ts("effects.formatAuto")}</span>+ {autoDims ? (+ <span className={styles.actionMenuCount}>+ {`${autoDims.width}×${autoDims.height}`}+ </span>+ ) : null}+ </button>{ASPECT_RATIO_PRESETS.map((ratio) => (<buttontype="button"diff --git a/src/components/video-editor/projectPersistence.ts b/src/components/video-editor/projectPersistence.tsindex e3b7b2a44..44b8aa250 100644--- a/src/components/video-editor/projectPersistence.ts+++ b/src/components/video-editor/projectPersistence.ts@@ -126,16 +126,18 @@ function computeNormalizedWebcamLayoutPreset(webcamLayoutPreset: Partial<ProjectEditorState>["webcamLayoutPreset"],normalizedAspectRatio: AspectRatio,): WebcamLayoutPreset {+ // Auto takes its shape FROM the layout, so there is no orientation to gate the blocks on.+ const auto = normalizedAspectRatio === "auto";switch (webcamLayoutPreset) {case "picture-in-picture":case "no-webcam":return webcamLayoutPreset;case "vertical-stack":- return isPortraitAspectRatio(normalizedAspectRatio)+ return auto || isPortraitAspectRatio(normalizedAspectRatio)? webcamLayoutPreset: DEFAULT_WEBCAM_SETTINGS.layoutPreset;case "dual-frame":- return isPortraitAspectRatio(normalizedAspectRatio)+ return !auto && isPortraitAspectRatio(normalizedAspectRatio)? DEFAULT_WEBCAM_SETTINGS.layoutPreset: webcamLayoutPreset;default:diff --git a/src/i18n/locales/ar/settings.json b/src/i18n/locales/ar/settings.jsonindex 82b2884a3..4b2893f4d 100644--- a/src/i18n/locales/ar/settings.json+++ b/src/i18n/locales/ar/settings.json@@ -106,6 +106,7 @@"blurBg": "تمويه الخلفية","help": "تنسيق إطار التسجيل: ضبابية الخلفية، والظل، وضبابية الحركة، واستدارة الزوايا، والحشو حول الفيديو.","fitClipOne": "مقطع واحد",+ "formatAuto": "تلقائي","formatOriginal": "الأصلي","fitClipMany": "{{count}} مقاطع","frame": "الإطار",diff --git a/src/i18n/locales/cs/settings.json b/src/i18n/locales/cs/settings.jsonindex 72d06eb13..797a8c861 100644--- a/src/i18n/locales/cs/settings.json+++ b/src/i18n/locales/cs/settings.json@@ -106,6 +106,7 @@"blurBg": "Rozmazat pozadí","help": "Stylizace rámce pro nahrávku: rozmazání pozadí, vrhaný stín, pohybové rozmazání, zaoblení rohů a odsazení kolem videa.","fitClipOne": "{{count}} klip",+ "formatAuto": "Auto","formatOriginal": "Původní","fitClipMany": "{{count}} klipů","frame": "Rám",diff --git a/src/i18n/locales/de/settings.json b/src/i18n/locales/de/settings.jsonindex 105b01b85..e768908ee 100644--- a/src/i18n/locales/de/settings.json+++ b/src/i18n/locales/de/settings.json@@ -106,6 +106,7 @@"blurBg": "Hintergrund unscharf","help": "Rahmengestaltung der Aufnahme: Hintergrund-Unschärfe, Schlagschatten, Bewegungsunschärfe, Eckenrundung und Abstand um das Video.","fitClipOne": "{{count}} Clip",+ "formatAuto": "Auto","formatOriginal": "Original","fitClipMany": "{{count}} Clips","frame": "Rahmen",diff --git a/src/i18n/locales/en/settings.json b/src/i18n/locales/en/settings.jsonindex 703a58d42..2c58da7eb 100644--- a/src/i18n/locales/en/settings.json+++ b/src/i18n/locales/en/settings.json@@ -106,6 +106,7 @@"blurBg": "Blur background","help": "Frame styling for the recording: background blur, drop shadow, motion blur, corner radius, and padding around the video.","fitClipOne": "{{count}} clip",+ "formatAuto": "Auto","formatOriginal": "Original","fitClipMany": "{{count}} clips","frame": "Frame",diff --git a/src/i18n/locales/es/settings.json b/src/i18n/locales/es/settings.jsonindex a2838c843..d863cbb3c 100644--- a/src/i18n/locales/es/settings.json+++ b/src/i18n/locales/es/settings.json@@ -106,6 +106,7 @@"blurBg": "Desenfocar fondo","help": "Estilo del marco de la grabación: desenfoque de fondo, sombra, desenfoque de movimiento, radio de esquinas y margen alrededor del vídeo.","fitClipOne": "{{count}} clip",+ "formatAuto": "Auto","formatOriginal": "Original","fitClipMany": "{{count}} clips","frame": "Marco",diff --git a/src/i18n/locales/fr/settings.json b/src/i18n/locales/fr/settings.jsonindex 4955314d2..f63da7e8f 100644--- a/src/i18n/locales/fr/settings.json+++ b/src/i18n/locales/fr/settings.json@@ -106,6 +106,7 @@"blurBg": "Flou arrière-plan","help": "Mise en forme du cadre de l'enregistrement : flou d'arrière-plan, ombre portée, flou de mouvement, arrondi des coins et marge autour de la vidéo.","fitClipOne": "{{count}} clip",+ "formatAuto": "Auto","formatOriginal": "Original","fitClipMany": "{{count}} clips","frame": "Cadre",diff --git a/src/i18n/locales/it/settings.json b/src/i18n/locales/it/settings.jsonindex 76fd7da73..57b34a58e 100644--- a/src/i18n/locales/it/settings.json+++ b/src/i18n/locales/it/settings.json@@ -106,6 +106,7 @@"blurBg": "Sfuma sfondo","help": "Stile della cornice della registrazione: sfocatura dello sfondo, ombra, sfocatura di movimento, raggio degli angoli e margine attorno al video.","fitClipOne": "{{count}} clip",+ "formatAuto": "Auto","formatOriginal": "Originale","fitClipMany": "{{count}} clip","frame": "Cornice",diff --git a/src/i18n/locales/ja-JP/settings.json b/src/i18n/locales/ja-JP/settings.jsonindex 2f605defa..933bf2c4b 100644--- a/src/i18n/locales/ja-JP/settings.json+++ b/src/i18n/locales/ja-JP/settings.json@@ -106,6 +106,7 @@"blurBg": "背景をぼかす","help": "録画フレームのスタイル設定: 背景ぼかし、ドロップシャドウ、モーションブラー、角丸、動画まわりの余白。","fitClipOne": "{{count}} クリップ",+ "formatAuto": "自動","formatOriginal": "元のサイズ","fitClipMany": "{{count}} クリップ","frame": "フレーム",diff --git a/src/i18n/locales/ko-KR/settings.json b/src/i18n/locales/ko-KR/settings.jsonindex 7606549bd..e87357910 100644--- a/src/i18n/locales/ko-KR/settings.json+++ b/src/i18n/locales/ko-KR/settings.json@@ -106,6 +106,7 @@"blurBg": "배경 흐림","help": "녹화 프레임 스타일: 배경 흐림, 그림자, 모션 블러, 모서리 둥글기, 영상 주변 여백.","fitClipOne": "{{count}}개 클립",+ "formatAuto": "자동","formatOriginal": "원본","fitClipMany": "{{count}}개 클립","frame": "프레임",diff --git a/src/i18n/locales/pt-BR/settings.json b/src/i18n/locales/pt-BR/settings.jsonindex 7c276023e..36b3fae9d 100644--- a/src/i18n/locales/pt-BR/settings.json+++ b/src/i18n/locales/pt-BR/settings.json@@ -106,6 +106,7 @@"blurBg": "Desfocar Fundo","help": "Estilo do quadro da gravação: desfoque de fundo, sombra, desfoque de movimento, raio dos cantos e margem em volta do vídeo.","fitClipOne": "{{count}} clipe",+ "formatAuto": "Auto","formatOriginal": "Original","fitClipMany": "{{count}} clipes","frame": "Moldura",diff --git a/src/i18n/locales/ru/settings.json b/src/i18n/locales/ru/settings.jsonindex e02adfff8..ea5f4d66d 100644--- a/src/i18n/locales/ru/settings.json+++ b/src/i18n/locales/ru/settings.json@@ -106,6 +106,7 @@"blurBg": "Размытие фона","help": "Оформление кадра записи: размытие фона, тень, размытие движения, скругление углов и отступ вокруг видео.","fitClipOne": "{{count}} клип",+ "formatAuto": "Авто","formatOriginal": "Исходный","fitClipMany": "{{count}} клипов","frame": "Рамка",diff --git a/src/i18n/locales/tr/settings.json b/src/i18n/locales/tr/settings.jsonindex e46102289..39c8f912c 100644--- a/src/i18n/locales/tr/settings.json+++ b/src/i18n/locales/tr/settings.json@@ -106,6 +106,7 @@"blurBg": "Arka Planı Bulanıklaştır","help": "Kayıt çerçevesinin biçimi: arka plan bulanıklığı, gölge, hareket bulanıklığı, köşe yuvarlaklığı ve videonun çevresindeki boşluk.","fitClipOne": "{{count}} klip",+ "formatAuto": "Otomatik","formatOriginal": "Orijinal","fitClipMany": "{{count}} klip","frame": "Çerçeve",diff --git a/src/i18n/locales/vi/settings.json b/src/i18n/locales/vi/settings.jsonindex acffce66c..628841831 100644--- a/src/i18n/locales/vi/settings.json+++ b/src/i18n/locales/vi/settings.json@@ -106,6 +106,7 @@"blurBg": "Làm mờ nền","help": "Kiểu khung của bản ghi: làm mờ nền, đổ bóng, mờ chuyển động, bo góc và khoảng đệm quanh video.","fitClipOne": "{{count}} clip",+ "formatAuto": "Tự động","formatOriginal": "Gốc","fitClipMany": "{{count}} clip","frame": "Khung",diff --git a/src/i18n/locales/zh-CN/settings.json b/src/i18n/locales/zh-CN/settings.jsonindex 79ea4fe67..09f89c789 100644--- a/src/i18n/locales/zh-CN/settings.json+++ b/src/i18n/locales/zh-CN/settings.json@@ -106,6 +106,7 @@"blurBg": "模糊背景","help": "录制画面的边框样式:背景模糊、投影、运动模糊、圆角半径以及视频四周的内边距。","fitClipOne": "{{count}} 个片段",+ "formatAuto": "自动","formatOriginal": "原始","fitClipMany": "{{count}} 个片段","frame": "画框",diff --git a/src/i18n/locales/zh-TW/settings.json b/src/i18n/locales/zh-TW/settings.jsonindex c564c101b..684054a8d 100644--- a/src/i18n/locales/zh-TW/settings.json+++ b/src/i18n/locales/zh-TW/settings.json@@ -106,6 +106,7 @@"blurBg": "模糊背景","help": "錄製畫面的外框樣式:背景模糊、陰影、動態模糊、圓角半徑,以及影片四周的內距。","fitClipOne": "{{count}} 個片段",+ "formatAuto": "自動","formatOriginal": "原始","fitClipMany": "{{count}} 個片段","frame": "外框",diff --git a/src/lib/ai-edition/document/outputFormat.test.ts b/src/lib/ai-edition/document/outputFormat.test.tsindex c7e75ab40..de0977950 100644--- a/src/lib/ai-edition/document/outputFormat.test.ts+++ b/src/lib/ai-edition/document/outputFormat.test.ts@@ -298,3 +298,60 @@ describe("resolveAspectRatioValue", () => {expect(resolveAspectRatioValue(d, "64:27")).toBeCloseTo(64 / 27, 6);});});++describe("Auto", () => {+ const withEditor = (d: AxcutDocument, editor: Record<string, unknown>): AxcutDocument => ({+ ...d,+ legacyEditor: { aspectRatio: "auto", ...editor },+ });+ const withCamera = (a: AxcutAsset): AxcutAsset => ({+ ...a,+ cameraTrack: { sourcePath: "/tmp/cam.mp4", startMs: 0, offsetMs: 0, visible: true },+ });+ const auto = (d: AxcutDocument) => resolveAspectRatioValue(d, "auto");++ it("is the reference clip's cropped shape at 0% padding", () => {+ const d = withEditor(+ doc([asset("a1", 1920, 1080)], [clip("c1", "a1", { x: 0.25, y: 0, width: 0.5, height: 1 })]),+ { padding: 0 },+ );+ expect(auto(d)).toBeCloseTo(960 / 1080, 6);+ });++ it("pulls toward square as padding grows, so the border stays even", () => {+ const d = withEditor(doc([asset("a1", 1920, 1080)], [clip("c1", "a1")]), { padding: 50 });+ expect(auto(d)).toBeCloseTo(0.8 * (16 / 9) + 0.2, 6);+ });++ it("widens for side by side only when the reference clip carries a camera", () => {+ const editor = { padding: 0, webcamLayoutPreset: "dual-frame" };+ const h = 1080 / 1920;+ const withCam = withEditor(+ doc([withCamera(asset("a1", 1920, 1080))], [clip("c1", "a1")]),+ editor,+ );+ const without = withEditor(doc([asset("a1", 1920, 1080)], [clip("c1", "a1")]), editor);+ expect(auto(withCam)).toBeCloseTo((1 + 0.02 + h) / h, 6);+ expect(auto(without)).toBeCloseTo(16 / 9, 6);+ });++ it("lets the clip that sets the output size set its shape on a mixed timeline", () => {+ const d = withEditor(+ doc(+ [asset("small", 1280, 720), asset("big", 1080, 1920)],+ [clip("c1", "small"), clip("c2", "big")],+ ),+ { padding: 0 },+ );+ expect(auto(d)).toBeCloseTo(1080 / 1920, 6);+ });++ it("keeps the reference long side and even pixels for the output", () => {+ const d = withEditor(doc([asset("a1", 1920, 1080)], [clip("c1", "a1")]), { padding: 50 });+ expect(pickOutputDims(d, "auto")).toEqual({ width: 1920, height: 1184 });+ });++ it("falls back to 16:9 with no document to resolve against", () => {+ expect(resolveAspectRatioValue(null, "auto")).toBeCloseTo(16 / 9, 6);+ });+});diff --git a/src/lib/ai-edition/document/outputFormat.ts b/src/lib/ai-edition/document/outputFormat.tsindex 602db3aa5..e7b5db1c5 100644--- a/src/lib/ai-edition/document/outputFormat.ts+++ b/src/lib/ai-edition/document/outputFormat.ts@@ -14,6 +14,11 @@* which is then stored as a concrete `"W:H"` token and can no longer drift.*/+import {+ autoFrameAspect,+ resolveWebcamLayoutPreset,+ restingCompositionAspect,+} from "@/lib/compositeLayout";import { calculateEffectiveSourceDimensions } from "@/lib/exporter/mp4ExportSettings";import {type AspectRatio,@@ -22,6 +27,8 @@ import {toAspectRatioToken,} from "@/utils/aspectRatioUtils";import type { AxcutAsset, AxcutClip, AxcutDocument } from "../schema";+import { getEditorSettings } from "../store/editorSettings";+import { assetCameraSource } from "../timeline/camera";export interface Dims {width: number;@@ -162,11 +169,53 @@ export function referenceClipDims(probedAssetDims: Record<string, Dims> = {},): Dims {return (- pickExtremeDims(collectEffectiveClipDims(document, probedAssetDims), "largest") ??+ referenceClip(document, probedAssetDims)?.dims ??+ pickExtremeDims(collectUsedAssetDims(document, probedAssetDims), "largest") ??FALLBACK_OUTPUT_DIMS);}+/** The clip behind `referenceClipDims`, for the questions its dims alone can't answer+ * (does it carry a camera?). Same pick as `pickExtremeDims`: the first strictly largest. */+function referenceClip(+ document: AxcutDocument,+ probedAssetDims: Record<string, Dims>,+): { clip: AxcutClip; dims: Dims } | null {+ const assetById = new Map(document.assets.map((a) => [a.id, a]));+ let best: { clip: AxcutClip; dims: Dims } | null = null;+ for (const clip of document.timeline.clips) {+ const dims = clipEffectiveDims(clip, assetById, probedAssetDims);+ if (dims && (!best || dims.width * dims.height > best.dims.width * best.dims.height)) {+ best = { clip, dims };+ }+ }+ return best;+}++/**+ * What "Auto" resolves to: the frame shaped around the composition instead of the other way+ * round (`autoFrameAspect` over `restingCompositionAspect`).+ *+ * A video has one frame, so one clip has to answer for the timeline, and it is the clip that+ * already sets the output's size: `referenceClip`. Its cropped screen and its camera, laid out+ * with the project's camera layout, are the composition. Every other clip is contain-fitted into+ * that frame, exactly as it would be into a fixed format.+ *+ * Zoom, device frames, shadow and captions are left out on purpose: they happen inside the+ * frame, in every format alike, and would make the shape move with the playhead.+ */+function autoAspectRatioValue(document: AxcutDocument, probedAssetDims: Record<string, Dims>) {+ const settings = getEditorSettings(document);+ const reference = referenceClip(document, probedAssetDims);+ const asset = document.assets.find((a) => a.id === reference?.clip.assetId);+ const preset = resolveWebcamLayoutPreset(+ settings.webcamLayoutPreset,+ assetCameraSource(asset).path !== "",+ );+ const screen = reference?.dims ?? referenceClipDims(document, probedAssetDims);+ return autoFrameAspect(restingCompositionAspect(screen, preset), settings.padding);+}+/*** The distinct native shapes of the clips on the timeline, most-used first.*@@ -225,17 +274,18 @@ export function collectNativeFormats(}/**- * Numeric ratio for a stored selection, with the document available to resolve the legacy- * `"native"` value. Every consumer that frames or sizes the output must go through this rather- * than bare `getAspectRatioValue`, which has no document and falls back to 16/9.+ * Numeric ratio for a stored selection, with the document available to resolve `"auto"` and the+ * legacy `"native"` value. Every consumer that frames or sizes the output must go through this+ * rather than bare `getAspectRatioValue`, which has no document and falls back to 16/9.*/export function resolveAspectRatioValue(document: AxcutDocument | null | undefined,aspectRatio: AspectRatio,probedAssetDims: Record<string, Dims> = {},): number {- if (aspectRatio !== "native") return getAspectRatioValue(aspectRatio);- if (!document) return getAspectRatioValue("native");+ if (aspectRatio !== "native" && aspectRatio !== "auto") return getAspectRatioValue(aspectRatio);+ if (!document) return getAspectRatioValue(aspectRatio);+ if (aspectRatio === "auto") return autoAspectRatioValue(document, probedAssetDims);const reference = referenceClipDims(document, probedAssetDims);return getNativeAspectRatioValue(reference.width, reference.height);}diff --git a/src/lib/ai-edition/stylePresets.ts b/src/lib/ai-edition/stylePresets.tsindex d8de3b3f5..f15f1e191 100644--- a/src/lib/ai-edition/stylePresets.ts+++ b/src/lib/ai-edition/stylePresets.ts@@ -253,7 +253,7 @@ export function parseStylePresetAppearance(value: unknown): StylePresetAppearancthrow new TypeError("Style preset appearance must be an object.");}if (!isAspectRatio(value.aspectRatio)) {- throw new TypeError('Style preset aspectRatio must be "W:H" or "native".');+ throw new TypeError('Style preset aspectRatio must be "W:H", "auto" or "native".');}const cursor = value.cursor;if (!isRecord(cursor)) {diff --git a/src/lib/compositeLayout.test.ts b/src/lib/compositeLayout.test.tsindex 0a100a679..49a2346a4 100644--- a/src/lib/compositeLayout.test.ts+++ b/src/lib/compositeLayout.test.ts@@ -1,9 +1,13 @@import { describe, expect, it } from "vitest";import {+ autoFrameAspect,computeCameraFullscreenRect,computeCompositeLayout,isWebcamBlockLayout,+ paddedContentSize,+ paddingFit,resolveWebcamReactiveZoom,+ restingCompositionAspect,type StyledRenderRect,} from "./compositeLayout";@@ -447,6 +451,94 @@ describe("computeCompositeLayout", () => {});});+describe("Auto frame", () => {+ it("keeps the composition's shape at 0% padding and pulls it toward square as padding grows", () => {+ expect(autoFrameAspect(16 / 9, 0)).toBeCloseTo(16 / 9, 10);+ expect(autoFrameAspect(16 / 9, 50)).toBeCloseTo(0.8 * (16 / 9) + 0.2, 10);+ // Symmetric, and never flips orientation.+ expect(autoFrameAspect(9 / 16, 50)).toBeCloseTo(1 / (0.8 * (16 / 9) + 0.2), 10);+ expect(autoFrameAspect(1, 100)).toBe(1);+ });++ it("frames the block layouts with their camera at rest, square", () => {+ const screen = { width: 1920, height: 1080 };+ const h = 1080 / 1920;+ expect(restingCompositionAspect(screen, "picture-in-picture")).toBeCloseTo(16 / 9, 10);+ expect(restingCompositionAspect(screen, "no-webcam")).toBeCloseTo(16 / 9, 10);+ expect(restingCompositionAspect(screen, "dual-frame")).toBeCloseTo((1 + 0.02 + h) / h, 10);+ expect(restingCompositionAspect(screen, "vertical-stack")).toBeCloseTo(1 / (h + 0.02 + 1), 10);+ });++ it("leaves the fixed formats' padding exactly as it was", () => {+ expect(paddedContentSize({ width: 1920, height: 1080 }, 50, false)).toEqual({+ width: 1536,+ height: 864,+ });+ // The even border is the short axis' margin applied to all four sides …+ expect(paddedContentSize({ width: 1920, height: 1080 }, 50, true)).toEqual({+ width: 1704,+ height: 864,+ });+ // … so on a square frame the two rules are one.+ expect(paddedContentSize({ width: 1080, height: 1080 }, 50, true)).toEqual(+ paddedContentSize({ width: 1080, height: 1080 }, 50, false),+ );+ });++ // The whole contract: a frame shaped by `autoFrameAspect`, padded by `paddedContentSize`+ // and laid out by `computeCompositeLayout` gives the composition back, unbent, with the+ // same margin on all four sides. Preview and scene both go through exactly these three.+ const CASES = [+ { label: "16:9 screen", screen: { width: 1920, height: 1080 }, preset: "no-webcam" },+ {+ label: "16:9 screen + PiP",+ screen: { width: 1920, height: 1080 },+ preset: "picture-in-picture",+ },+ { label: "9:16 screen", screen: { width: 1080, height: 1920 }, preset: "no-webcam" },+ { label: "window crop", screen: { width: 1366, height: 911 }, preset: "no-webcam" },+ { label: "16:9 side by side", screen: { width: 1920, height: 1080 }, preset: "dual-frame" },+ { label: "16:9 top / bottom", screen: { width: 1920, height: 1080 }, preset: "vertical-stack" },+ { label: "9:16 side by side", screen: { width: 1080, height: 1920 }, preset: "dual-frame" },+ ] as const;+ for (const c of CASES) {+ for (const padding of [0, 30, 50, 100]) {+ it(`${c.label}, padding ${padding}%: even border, nothing bent`, () => {+ const aspect = autoFrameAspect(restingCompositionAspect(c.screen, c.preset), padding);+ const canvas =+ aspect >= 1+ ? { width: 1920, height: Math.round(1920 / aspect) }+ : { width: Math.round(1920 * aspect), height: 1920 };+ const layout = computeCompositeLayout({+ canvasSize: canvas,+ maxContentSize: paddedContentSize(canvas, padding, true),+ screenSize: c.screen,+ webcamSize: c.preset === "no-webcam" ? null : { width: 1280, height: 720 },+ layoutPreset: c.preset,+ })!;+ const block = isWebcamBlockLayout(c.preset);+ const rects = block ? [layout.screenRect, layout.webcamRect!] : [layout.screenRect];+ const border = ((1 - paddingFit(padding)) / 2) * Math.min(canvas.width, canvas.height);+ const sides = [+ Math.min(...rects.map((r) => r.x)),+ Math.min(...rects.map((r) => r.y)),+ canvas.width - Math.max(...rects.map((r) => r.x + r.width)),+ canvas.height - Math.max(...rects.map((r) => r.y + r.height)),+ ];+ for (const side of sides) expect(Math.abs(side - border)).toBeLessThanOrEqual(1.5);+ expect(layout.screenRect.width / layout.screenRect.height).toBeCloseTo(+ c.screen.width / c.screen.height,+ 1,+ );+ if (block) {+ const cam = layout.webcamRect!;+ expect(cam.width / cam.height).toBeCloseTo(1, 1);+ }+ });+ }+ }+});+describe("computeCameraFullscreenRect", () => {const CANVAS = { width: 1920, height: 1080 };const pip = (over: Partial<StyledRenderRect> = {}): StyledRenderRect => ({diff --git a/src/lib/compositeLayout.ts b/src/lib/compositeLayout.tsindex 11eb35a50..3de597a95 100644--- a/src/lib/compositeLayout.ts+++ b/src/lib/compositeLayout.ts@@ -284,6 +284,72 @@ export function getWebcamLayoutCssBoxShadow(: "none";}+/**+ * A block's footprint in UNIT space, where the screen is exactly 1 wide: the screen, the+ * gap, and a camera `cameraAlong` long on the split axis. One definition for the layout+ * below and for the resting shape Auto frames, so the two cannot disagree on it.+ */+function blockUnitSize(screenAspect: number, block: BlockTransform, cameraAlong: number): Size {+ const unitScreenHeight = 1 / screenAspect;+ return block.direction === "row"+ ? { width: 1 + block.gapFraction + cameraAlong, height: unitScreenHeight }+ : { width: 1, height: unitScreenHeight + block.gapFraction + cameraAlong };+}++/**+ * The composition's own shape (width / height) before any frame constrains it — what the+ * Auto format frames. Nothing is bent to fit: the screen keeps its ratio, and a block+ * layout's camera takes its resting shape, square, beside or under it. A picture-in-picture+ * bubble floats over the screen, so the composition is the screen alone.+ */+export function restingCompositionAspect(screenSize: Size, preset: WebcamLayoutPreset): number {+ const screenAspect = screenSize.width / screenSize.height;+ const transform = getWebcamLayoutPresetDefinition(preset).transform;+ if (transform.type !== "block") return screenAspect;+ const cameraCross = transform.direction === "row" ? 1 / screenAspect : 1;+ const block = blockUnitSize(screenAspect, transform, cameraCross);+ return block.width / block.height;+}++/** The share of the frame the composition keeps at `padding` (0–100): 1 at 0%, 0.6 at 100%. */+export function paddingFit(padding: number): number {+ return 1 - (Math.min(100, Math.max(0, padding)) / 100) * 0.4;+}++/**+ * The box the composition is contain-fitted into: the frame minus its padding.+ *+ * A fixed format keeps `paddingFit` of each axis. An Auto frame (`evenBorder`) is shaped+ * around the composition instead, so its padding is a border of one thickness on all four+ * sides — `(1 - fit) / 2` of the short side, which is what a fixed format leaves on the+ * short axis too. The two agree on a square frame, and on the short axis of any frame.+ */+export function paddedContentSize(canvas: Size, padding: number, evenBorder: boolean): Size {+ const fit = paddingFit(padding);+ if (!evenBorder) {+ return { width: Math.round(canvas.width * fit), height: Math.round(canvas.height * fit) };+ }+ const border = ((1 - fit) / 2) * Math.min(canvas.width, canvas.height);+ return {+ width: Math.round(canvas.width - 2 * border),+ height: Math.round(canvas.height - 2 * border),+ };+}++/**+ * The Auto frame's shape: the composition's resting shape plus an even padding border.+ *+ * With `paddedContentSize`'s border, the frame's elongation (long side / short side) is+ * `fit · e + (1 − fit)` for a composition of elongation `e`: the composition's own at 0%+ * padding, pulled toward square as the border grows. Orientation never flips.+ */+export function autoFrameAspect(compositionAspect: number, padding: number): number {+ const fit = paddingFit(padding);+ const elongation = Math.max(compositionAspect, 1 / compositionAspect);+ const framed = fit * elongation + (1 - fit);+ return compositionAspect >= 1 ? framed : 1 / framed;+}+export function computeCompositeLayout(params: {canvasSize: Size;maxContentSize?: Size;@@ -358,17 +424,24 @@ export function computeCompositeLayout(params: {// size ALONG the split axis is the one free dimension. Three constraints fix// it, in order:// 1. screen keeps its own aspect ratio → screen is 1 × h, untouched;- // 2. the block contain-fits the scene → pick `along` so the block's- // aspect equals the scene's (fills it, no bars) — see `alongForFill`;+ // 2. the block contain-fits the padded area → pick `along` so the block's+ // aspect equals that area's (fills it, no bars) — see `alongForFill`;// 3. the camera tends toward square → but clamp `along` so the// camera stays within `[1/T, T]` of square, so filling the scene only// nudges it slightly rectangular, never into a slice.// Square is `along === cameraCross`; the clamp is symmetric in both layouts.+ //+ // The target is the PADDED area, not the canvas: the block is fitted into the+ // former, so that is the shape it has to match. The two only differ under an+ // Auto frame's even border (`paddedContentSize`), which is exactly the shape of+ // the block at rest, so the camera comes out square there by construction.+ const contentWidth = Math.min(canvasWidth, Math.max(1, maxContentSize.width));+ const contentHeight = Math.min(canvasHeight, Math.max(1, maxContentSize.height));const cameraCross = isRow ? unitScreenHeight : 1;- const sceneAspect = canvasWidth / canvasHeight;+ const contentAspect = contentWidth / contentHeight;const alongForFill = isRow- ? sceneAspect * unitScreenHeight - 1 - gap // block width = 1 + gap + along- : 1 / sceneAspect - unitScreenHeight - gap; // block height = h + gap + along+ ? contentAspect * unitScreenHeight - 1 - gap // block width = 1 + gap + along+ : 1 / contentAspect - unitScreenHeight - gap; // block height = h + gap + alongconst cameraAlong = Math.min(cameraCross * BLOCK_CAMERA_ASPECT_TOLERANCE,Math.max(cameraCross / BLOCK_CAMERA_ASPECT_TOLERANCE, alongForFill),@@ -376,15 +449,16 @@ export function computeCompositeLayout(params: {const unitCameraWidth = isRow ? cameraAlong : 1;const unitCameraHeight = isRow ? unitScreenHeight : cameraAlong;- const blockWidth = isRow ? 1 + gap + cameraAlong : 1;- const blockHeight = isRow ? unitScreenHeight : unitScreenHeight + gap + cameraAlong;+ const { width: blockWidth, height: blockHeight } = blockUnitSize(+ screenAspect,+ block,+ cameraAlong,+ );- // Contain-fit the whole block into the padded content area. `maxContentSize`- // is `canvasSize × paddingFit`, so padding shrinks the BLOCK (not just the- // screen) and padding 0 leaves it flush against the two scene edges its own- // ratio makes it touch — bottom/top for a column, left/right for a row.- const contentWidth = Math.min(canvasWidth, Math.max(1, maxContentSize.width));- const contentHeight = Math.min(canvasHeight, Math.max(1, maxContentSize.height));+ // Contain-fit the whole block into the padded content area, so padding+ // shrinks the BLOCK (not just the screen) and padding 0 leaves it flush+ // against the two scene edges its own ratio makes it touch — bottom/top for a+ // column, left/right for a row.const scale = Math.min(contentWidth / blockWidth, contentHeight / blockHeight);const originX = (canvasWidth - blockWidth * scale) / 2;diff --git a/src/native/sceneDescription.test.ts b/src/native/sceneDescription.test.tsindex da4988650..f1edd4812 100644--- a/src/native/sceneDescription.test.ts+++ b/src/native/sceneDescription.test.ts@@ -1422,6 +1422,8 @@ describe("buildSceneDescription.output", () => {timelineEndSec: 2,}),],+ // Size is the point here; a fixed 16:9 keeps Auto's padding out of the numbers.+ legacyEditor: { aspectRatio: "16:9" },});const { output } = buildSceneDescription(doc);expect(output).toEqual({ width: 3840, height: 2160, fps: null });@@ -1441,6 +1443,8 @@ describe("buildSceneDescription.output", () => {timelineEndSec: 1,}),],+ // Size is the point here; a fixed 16:9 keeps Auto's padding out of the numbers.+ legacyEditor: { aspectRatio: "16:9" },});const { output } = buildSceneDescription(doc);expect(output).toEqual({ width: 1920, height: 1080, fps: null });@@ -1465,6 +1469,8 @@ describe("buildSceneDescription.output", () => {timelineEndSec: 1,}),],+ // Size is the point here; a fixed 16:9 keeps Auto's padding out of the numbers.+ legacyEditor: { aspectRatio: "16:9" },});const { output } = buildSceneDescription(doc);expect(output).toEqual({ width: 2560, height: 1440, fps: null });@@ -1503,6 +1509,43 @@ describe("buildSceneDescription.output", () => {});});+describe("buildSceneDescription with the Auto format", () => {+ // End to end through the scene the compositor draws: Auto shapes `output` around the+ // recording, and the screen rect sits in it with one margin on all four sides.+ it("frames the recording with an even border", () => {+ const asset = makeAsset({+ id: "a",+ originalPath: "/a.mp4",+ video: { codec: "h264", width: 1920, height: 1080, fps: 30 },+ });+ const clip = makeClip({+ id: "c1",+ assetId: "a",+ sourceStartSec: 0,+ sourceEndSec: 1,+ timelineStartSec: 0,+ timelineEndSec: 1,+ });+ const scene = buildSceneDescription(+ makeDoc({+ assets: [asset],+ clips: [clip],+ legacyEditor: { aspectRatio: "auto", padding: 50 },+ }),+ );+ const { width, height } = scene.output;+ expect({ width, height }).toEqual({ width: 1920, height: 1184 });+ const r = scene.layout.screenRect;+ if (!r) throw new Error("screenRect absent");+ const left = r.x * width;+ const top = r.y * height;+ const right = width - (r.x + r.width) * width;+ const bottom = height - (r.y + r.height) * height;+ for (const side of [left, right, bottom]) expect(Math.abs(side - top)).toBeLessThanOrEqual(1.5);+ expect(top).toBeCloseTo(0.1 * 1184, -1);+ });+});+// --- screenRect vs crop ------------------------------------------------------describe("buildSceneDescription.layout.screenRect", () => {@@ -1657,7 +1700,8 @@ describe("buildSceneDescription.layout.layoutByClip", () => {timelineEndSec: 8,}),],- legacyEditor: { webcamLayoutPreset: preset },+ // A fixed frame: under Auto the frame is shaped around the camera clip's block.+ legacyEditor: { webcamLayoutPreset: preset, aspectRatio: "16:9" },});};@@ -2040,7 +2084,12 @@ describe("buildSceneDescription.captions", () => {const base = docWithCaptions(true);const scene = buildSceneDescription({...base,- legacyEditor: { ...(base.legacyEditor as Record<string, unknown>), padding },+ // A fixed frame: under Auto the frame itself reshapes with the padding.+ legacyEditor: {+ ...(base.legacyEditor as Record<string, unknown>),+ padding,+ aspectRatio: "16:9",+ },} as AxcutDocument);const caption = scene.annotations[0];return {diff --git a/src/native/sceneDescription.ts b/src/native/sceneDescription.tsindex d14875d5d..5627ae84a 100644--- a/src/native/sceneDescription.ts+++ b/src/native/sceneDescription.ts@@ -48,6 +48,7 @@ import { takeProgramme } from "@/lib/ai-edition/timeline/take-programme";import { projectRegionsToSource } from "@/lib/ai-edition/timeline/timelineMap";import {computeCompositeLayout,+ paddedContentSize,type RenderRect,resolveWebcamLayoutPreset,resolveWebcamReactiveZoom,@@ -906,7 +907,11 @@ export function buildSceneDescription(// padded content area the preview uses — `compositor.rs` consumes an app-provided// `webcamRect` verbatim (it only scale_frame's the SCREEN by padding), so an// unpadded rect here would leave the camera behind while the screen moved.- const paddingFit = 1 - (Math.min(100, Math.max(0, settings.padding)) / 100) * 0.4;+ const maxContentSize = paddedContentSize(+ outputDims,+ settings.padding,+ settings.aspectRatio === "auto",+ );/*** The screen source SHAPE of a clip = its recording's own dimensions × its crop.*@@ -981,10 +986,7 @@ export function buildSceneDescription(const preset = resolveWebcamLayoutPreset(settings.webcamLayoutPreset, hasCamera);return computeCompositeLayout({canvasSize: outputDims,- maxContentSize: {- width: Math.round(outputDims.width * paddingFit),- height: Math.round(outputDims.height * paddingFit),- },+ maxContentSize,screenSize,webcamSize: preset === "no-webcam" ? null : camSize,layoutPreset: preset,diff --git a/src/utils/aspectRatioUtils.test.ts b/src/utils/aspectRatioUtils.test.tsindex e1d60181d..958c95685 100644--- a/src/utils/aspectRatioUtils.test.ts+++ b/src/utils/aspectRatioUtils.test.ts@@ -25,9 +25,11 @@ describe("parseAspectRatio", () => {});describe("isAspectRatio", () => {- it("accepts presets and free-form shapes", () => {+ it("accepts presets, free-form shapes and Auto", () => {expect(isAspectRatio("16:9")).toBe(true);expect(isAspectRatio("64:27")).toBe(true);+ // A style preset or a user preference saved on Auto must not reload as 16:9.+ expect(isAspectRatio("auto")).toBe(true);});it("rejects anything a project file could hold that isn't a ratio", () => {diff --git a/src/utils/aspectRatioUtils.ts b/src/utils/aspectRatioUtils.tsindex 07d98a207..b8aa49649 100644--- a/src/utils/aspectRatioUtils.ts+++ b/src/utils/aspectRatioUtils.ts@@ -16,12 +16,17 @@ export type AspectRatioPreset = (typeof ASPECT_RATIO_PRESETS)[number];* offers the clips' own native shapes ("Original"), which are stored the same way and can be* anything (`"64:27"` for an ultrawide, `"683:384"` for an odd capture size).*+ * `"auto"` is not a shape but a rule: the frame takes the shape of the composition plus an even+ * padding border, recomputed from the document (`resolveAspectRatioValue`, in+ * lib/ai-edition/document/outputFormat). The picker shows what it resolves to, so it adapts in+ * the open, unlike `"native"`.+ ** `"native"` is a LEGACY value kept only so projects saved before the shapes were enumerated* still open. It resolves to the timeline's reference asset (largest pixel area), which is* exactly the silent, drifting behaviour the enumeration replaced — nothing writes it any* more, so it can be dropped once old projects are assumed migrated.*/-export type AspectRatio = AspectRatioPreset | `${number}:${number}` | "native";+export type AspectRatio = AspectRatioPreset | `${number}:${number}` | "auto" | "native";const NATIVE_ASPECT_RATIO_FALLBACK = 16 / 9;@@ -40,7 +45,7 @@ export function parseAspectRatio(value: string): { width: number; height: number/** Validation gate for anything read back from disk (project files, user prefs). */export function isAspectRatio(value: unknown): value is AspectRatio {if (typeof value !== "string") return false;- return value === "native" || parseAspectRatio(value) !== null;+ return value === "auto" || value === "native" || parseAspectRatio(value) !== null;}function greatestCommonDivisor(a: number, b: number): number {@@ -71,10 +76,10 @@ export function toAspectRatioToken(width: number, height: number): AspectRatio |}/**- * Numeric value of an aspect ratio. Legacy `"native"` has no document context here so it- * returns the 16/9 fallback — callers holding a document must resolve it through+ * Numeric value of an aspect ratio. `"auto"` and legacy `"native"` have no document context+ * here so they return the 16/9 fallback — callers holding a document must resolve them through* `resolveAspectRatioValue` (lib/ai-edition/document/outputFormat) instead, or preview and- * output silently disagree on old projects.+ * output silently disagree.*/export function getAspectRatioValue(aspectRatio: AspectRatio): number {if (aspectRatio === "native") return NATIVE_ASPECT_RATIO_FALLBACK;diff --git a/technical-documentation/architecture/export-pipeline.md b/technical-documentation/architecture/export-pipeline.mdindex 6f44d3a9d..13c71511c 100644--- a/technical-documentation/architecture/export-pipeline.md+++ b/technical-documentation/architecture/export-pipeline.md@@ -133,6 +133,12 @@ and **one** encoder + muxer pair:width / height / bitrate, and passes `width` / `height` to `exportMulti`.Only "Source" quality targets those source dims; 720p / 1080p target afixed short side regardless.+ **Auto** resolves in that same function: the reference clip's cropped+ screen, laid out with the camera layout at rest (`restingCompositionAspect`),+ plus an even padding border (`autoFrameAspect`). The preview and the scene+ pad an Auto frame with the matching border (`paddedContentSize`,+ `compositeLayout.ts`), so the composition fills it with the same margin on+ all four sides.## Output formats and codecsdiff --git a/technical-documentation/testing/manual-e2e-checklist.md b/technical-documentation/testing/manual-e2e-checklist.mdindex dee209c2a..4c54e79e9 100644--- a/technical-documentation/testing/manual-e2e-checklist.md+++ b/technical-documentation/testing/manual-e2e-checklist.md@@ -436,6 +436,7 @@ The percentage is computed in the renderer against a predicted frame total, and- [ ] Open the top-bar language control by its `aria-label`, choose a non-English locale, and confirm visible UI strings change.- [ ] Switch back to English and confirm the top bar, transport, inspector, and export labels return to English.- [ ] Select a different aspect ratio from the timeline aspect-ratio menu and confirm the preview frame changes shape.+- [ ] Pick **Auto** in the Format menu, drag padding from 0 to 100, and confirm the frame reshapes live with one border thickness on all four sides; switch the camera layout to side by side, then top / bottom, and confirm the frame widens, then turns portrait, with a square camera. Export and confirm the file has the preview frame's shape and the same even border.- [ ] Press `Esc` or click outside an open menu, popover, or dialog and confirm it closes.### App menu, About, and updates