Skip to content

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

refactor(scene): make sceneDescription the single source of truth

Etienne Lescot75242456eddc
diff --git a/src/components/ai-edition/ExportDialog.tsx b/src/components/ai-edition/ExportDialog.tsx
index 4002f06e1..8fcea5894 100644
--- a/src/components/ai-edition/ExportDialog.tsx
+++ b/src/components/ai-edition/ExportDialog.tsx
@@ -19,6 +19,7 @@ import {
exportAxcutDocument,
} from "@/lib/ai-edition/exporter/documentExporter";
import type { AxcutDocument } from "@/lib/ai-edition/schema";
+import { resolveClipSourceEndSec } from "@/lib/ai-edition/timeline/clipDuration";
import { probeVideoDimensions } from "@/lib/ai-edition/timeline/duration";
import {
type ExportFormat,
@@ -68,10 +69,10 @@ function buildNativeClipList(document: AxcutDocument): CompositorClipInput[] {
return [];
}
const cam = asset.cameraTrack;
- // sourceEndSec is optional in the schema (unknown until probed) — fall back to the
- // clip's timeline duration (speed 1).
- const sourceEndSec =
- clip.sourceEndSec ?? clip.sourceStartSec + (clip.timelineEndSec - clip.timelineStartSec);
+ // sourceEndSec is optional in the schema (unknown until probed) — fall back through
+ // the single canonical precedence used by every consumer (clip.probe → asset.duration
+ // → timeline-length guess). See `resolveClipSourceEndSec` for the full order.
+ const sourceEndSec = resolveClipSourceEndSec(clip, asset);
return [
{
screenPath: asset.originalPath,
diff --git a/src/lib/ai-edition/exporter/documentExporter.test.ts b/src/lib/ai-edition/exporter/documentExporter.test.ts
index 28f884c79..504a25e52 100644
--- a/src/lib/ai-edition/exporter/documentExporter.test.ts
+++ b/src/lib/ai-edition/exporter/documentExporter.test.ts
@@ -61,6 +61,17 @@ describe("computeExportTrimRegions", () => {
});
describe("computeCropSchedule", () => {
+ function assetA(durationSec?: number): AxcutAsset {
+ return {
+ kind: "video",
+ id: "a",
+ label: "Asset A",
+ originalPath: "/a.mp4",
+ cameraTrack: null,
+ ...(durationSec !== undefined ? { durationSec } : {}),
+ };
+ }
+
it("builds one schedule entry per clip, defaulting to the identity crop", () => {
const clips = [
clip({ id: "c1", sourceStartSec: 0, sourceEndSec: 3 }),
@@ -71,7 +82,7 @@ describe("computeCropSchedule", () => {
cropRegion: { x: 0.25, y: 0.25, width: 0.5, height: 0.5 },
}),
];
- expect(computeCropSchedule(clips, 6, "a")).toEqual([
+ expect(computeCropSchedule(clips, assetA(6))).toEqual([
{ startSec: 0, endSec: 3, cropRegion: { x: 0, y: 0, width: 1, height: 1 } },
{
startSec: 3,
@@ -81,9 +92,9 @@ describe("computeCropSchedule", () => {
]);
});
- it("falls back to sourceDurationSec when a clip's sourceEndSec is unset", () => {
+ it("falls back to asset.durationSec when a clip's sourceEndSec is unset", () => {
const clips = [clip({ id: "c1", sourceStartSec: 0, sourceEndSec: undefined })];
- expect(computeCropSchedule(clips, 12, "a")).toEqual([
+ expect(computeCropSchedule(clips, assetA(12))).toEqual([
{ startSec: 0, endSec: 12, cropRegion: { x: 0, y: 0, width: 1, height: 1 } },
]);
});
@@ -93,7 +104,7 @@ describe("computeCropSchedule", () => {
clip({ id: "c1", assetId: "a" }),
clip({ id: "c2", assetId: "other", cropRegion: { x: 0.1, y: 0.1, width: 0.5, height: 0.5 } }),
];
- expect(computeCropSchedule(clips, 10, "a")).toEqual([
+ expect(computeCropSchedule(clips, assetA(10))).toEqual([
{ startSec: 0, endSec: 10, cropRegion: { x: 0, y: 0, width: 1, height: 1 } },
]);
});
diff --git a/src/lib/ai-edition/exporter/documentExporter.ts b/src/lib/ai-edition/exporter/documentExporter.ts
index 67ca34df4..0bcfabcf2 100644
--- a/src/lib/ai-edition/exporter/documentExporter.ts
+++ b/src/lib/ai-edition/exporter/documentExporter.ts
@@ -41,7 +41,8 @@ import {
} from "@/utils/aspectRatioUtils";
import { createId } from "../document/ids";
import { type Interval, normalizeIntervals, primaryAssetDuration } from "../document/timeline";
-import type { AxcutDocument } from "../schema";
+import type { AxcutAsset, AxcutDocument } from "../schema";
+import { resolveClipSourceEndSec } from "../timeline/clipDuration";
import { projectRegionsToSourceTime } from "../timeline/region-ventilation";
import { buildRenderPlan, type RenderPlan } from "./renderPlan";
@@ -130,19 +131,19 @@ const IDENTITY_CROP: CropRegion = { x: 0, y: 0, width: 1, height: 1 };
// per-frame interpolation. The export renderer switches to whichever entry's
// [startSec, endSec) covers the current frame's SOURCE time right before
// rendering it (see VideoExporter/GifExporter + FrameRenderer.setCropRegion).
-// Only clips on `primaryAssetId` matter here — export renders one continuous
+// Only clips on `primaryAsset` matter here — export renders one continuous
// source video (the primary asset), so a clip pointing at a different asset
// has no meaningful source-time range against this one.
export function computeCropSchedule(
clips: AxcutDocument["timeline"]["clips"],
- sourceDurationSec: number,
- primaryAssetId: string,
+ primaryAsset: AxcutAsset,
): CropScheduleEntry[] {
+ const primaryAssetId = primaryAsset.id;
return clips
.filter((c) => c.assetId === primaryAssetId)
.map((c) => ({
startSec: c.sourceStartSec,
- endSec: c.sourceEndSec ?? sourceDurationSec,
+ endSec: resolveClipSourceEndSec(c, primaryAsset),
cropRegion: c.cropRegion ?? IDENTITY_CROP,
}));
}
@@ -231,7 +232,7 @@ export async function exportAxcutDocument(
const motionBlurAmount = extractLegacyField(legacy, "motionBlurAmount", 0);
const borderRadius = extractLegacyField(legacy, "borderRadius", 0);
const padding = extractLegacyField(legacy, "padding", 50);
- const cropSchedule = computeCropSchedule(clips, sourceDurationSec, asset.id);
+ const cropSchedule = computeCropSchedule(clips, asset);
const cropRegion: CropRegion = IDENTITY_CROP;
const webcamLayoutPreset = extractLegacyField(legacy, "webcamLayoutPreset", "picture-in-picture");
const webcamMaskShape = extractLegacyField(legacy, "webcamMaskShape", "rectangle");
diff --git a/src/lib/ai-edition/exporter/renderPlan.ts b/src/lib/ai-edition/exporter/renderPlan.ts
index 713ea462d..e6bf627d3 100644
--- a/src/lib/ai-edition/exporter/renderPlan.ts
+++ b/src/lib/ai-edition/exporter/renderPlan.ts
@@ -38,6 +38,7 @@ import {
} from "@/utils/aspectRatioUtils";
import { type Interval, normalizeIntervals } from "../document/timeline";
import type { AxcutDocument } from "../schema";
+import { resolveClipSourceEndSec } from "../timeline/clipDuration";
export type ExportVideoCodec = "h264" | "h265" | "vp9";
@@ -275,7 +276,7 @@ export function buildRenderPlan(
if (!asset) continue; // orphan clip — can't render, skip silently (matches today).
const sourceStartSec = clip.sourceStartSec;
- const sourceEndSec = clip.sourceEndSec ?? asset.durationSec ?? sourceStartSec;
+ const sourceEndSec = resolveClipSourceEndSec(clip, asset);
const sourceWidth = asset.video?.width || fallbackWidth || DEFAULT_FALLBACK_SOURCE_WIDTH;
const sourceHeight = asset.video?.height || fallbackHeight || DEFAULT_FALLBACK_SOURCE_HEIGHT;
const cameraTrack = asset.cameraTrack;
diff --git a/src/lib/ai-edition/timeline/clipDuration.ts b/src/lib/ai-edition/timeline/clipDuration.ts
new file mode 100644
index 000000000..08011f49e
--- /dev/null
+++ b/src/lib/ai-edition/timeline/clipDuration.ts
@@ -0,0 +1,28 @@
+// Single canonical helper for resolving a clip's effective `sourceEndSec`. The
+// four consumers (preview composer, scene serializer, render-plan builder, and
+// export trim/schedule builder) used to re-derive this each with a slightly
+// different formula; this file pins the precedence and keeps them in lock-step.
+
+import type { AxcutAsset, AxcutClip } from "../schema";
+
+/**
+ * Resolve the effective `sourceEndSec` for a clip, in seconds.
+ *
+ * Precedence (highest to lowest):
+ * 1. `clip.sourceEndSec` when probed/known — the most specific, per-clip
+ * authoritative value the renderer can trust.
+ * 2. `asset.durationSec` when the asset's own probed duration is known —
+ * more accurate than a timeline-duration guess, since speed edits can
+ * stretch or compress the timeline without changing the source length.
+ * 3. The timeline-duration formula
+ * `sourceStartSec + (timelineEndSec - timelineStartSec)` as a last resort
+ * (legacy/migrated documents before probing).
+ *
+ * `asset` may be `undefined` for orphan clips; the helper then degrades cleanly
+ * to the timeline-duration formula at step 3.
+ */
+export function resolveClipSourceEndSec(clip: AxcutClip, asset: AxcutAsset | undefined): number {
+ if (clip.sourceEndSec !== undefined) return clip.sourceEndSec;
+ if (asset?.durationSec !== undefined) return asset.durationSec;
+ return clip.sourceStartSec + (clip.timelineEndSec - clip.timelineStartSec);
+}
diff --git a/src/lib/compositeLayout.ts b/src/lib/compositeLayout.ts
index 4a99da975..9e61a0929 100644
--- a/src/lib/compositeLayout.ts
+++ b/src/lib/compositeLayout.ts
@@ -152,8 +152,8 @@ export interface WebcamCompositeLayout {
screenCover?: boolean;
}
-/** Convert a webcam size percentage (10–50) to a fraction of the reference dimension. */
-function webcamSizeToFraction(percent: number): number {
+/** Convert a webcam size percentage (10–50) to a fraction (0..1) of the reference dimension. */
+export function webcamSizeToFraction(percent: number): number {
const safe = Number.isFinite(percent) ? percent : 25;
const clamped = Math.max(10, Math.min(50, safe));
return clamped / 100;
diff --git a/src/native/sceneDescription.test.ts b/src/native/sceneDescription.test.ts
index 6d24f7b3b..03de4dd92 100644
--- a/src/native/sceneDescription.test.ts
+++ b/src/native/sceneDescription.test.ts
@@ -386,18 +386,112 @@ describe("buildSceneDescription.zoomRegions", () => {
});
});
-// --- crop ------------------------------------------------------------------
+// --- cameraFullscreenRegions -------------------------------------------------
-describe("buildSceneDescription.crop", () => {
- it("returns null for the identity (DEFAULT_CROP_REGION)", () => {
- const doc = makeDoc({ legacyEditor: { cropRegion: { ...DEFAULT_CROP_REGION } } });
- expect(buildSceneDescription(doc).crop).toBeNull();
+describe("buildSceneDescription.cameraFullscreenRegions", () => {
+ it("converts ms->sec for start/end", () => {
+ const doc = makeDoc({
+ legacyEditor: {
+ cameraFullscreenRegions: [{ id: "cf1", startMs: 2000, endMs: 5500 }],
+ },
+ });
+ const { cameraFullscreenRegions } = buildSceneDescription(doc);
+ expect(cameraFullscreenRegions).toEqual([{ startSec: 2, endSec: 5.5 }]);
});
- it("returns the region unchanged when non-identity", () => {
+ it("yields [] when legacyEditor.cameraFullscreenRegions is missing", () => {
+ const doc = makeDoc({ legacyEditor: {} });
+ expect(buildSceneDescription(doc).cameraFullscreenRegions).toEqual([]);
+ });
+
+ it("splits a region straddling two clips into one entry per clip's source time", () => {
+ const asset = makeAsset({ id: "a", originalPath: "/a.mp4" });
+ const clip1 = makeClip({
+ id: "c1",
+ assetId: "a",
+ sourceStartSec: 100,
+ sourceEndSec: 105,
+ timelineStartSec: 0,
+ timelineEndSec: 5,
+ });
+ const clip2 = makeClip({
+ id: "c2",
+ assetId: "a",
+ sourceStartSec: 200,
+ sourceEndSec: 205,
+ timelineStartSec: 5,
+ timelineEndSec: 10,
+ });
+ // Region spans timeline [3s, 7s) — 2s over clip1's tail, 2s over clip2's head.
+ const doc = makeDoc({
+ assets: [asset],
+ clips: [clip1, clip2],
+ legacyEditor: {
+ cameraFullscreenRegions: [{ id: "cf1", startMs: 3000, endMs: 7000 }],
+ },
+ });
+ const { cameraFullscreenRegions } = buildSceneDescription(doc);
+ expect(cameraFullscreenRegions).toEqual([
+ { startSec: 103, endSec: 105 },
+ { startSec: 200, endSec: 202 },
+ ]);
+ });
+});
+
+// --- cropByClip --------------------------------------------------------------
+
+describe("buildSceneDescription.cropByClip", () => {
+ it("is null for a clip without its own cropRegion", () => {
+ const asset = makeAsset({ id: "a", originalPath: "/a.mp4" });
+ const clip = makeClip({
+ id: "c1",
+ assetId: "a",
+ sourceStartSec: 0,
+ sourceEndSec: 4,
+ timelineStartSec: 0,
+ timelineEndSec: 4,
+ });
+ const doc = makeDoc({ assets: [asset], clips: [clip] });
+ expect(buildSceneDescription(doc).cropByClip).toEqual([null]);
+ });
+
+ it("is null for a clip whose cropRegion equals the identity (DEFAULT_CROP_REGION)", () => {
+ const asset = makeAsset({ id: "a", originalPath: "/a.mp4" });
+ const clip = makeClip({
+ id: "c1",
+ assetId: "a",
+ sourceStartSec: 0,
+ sourceEndSec: 4,
+ timelineStartSec: 0,
+ timelineEndSec: 4,
+ cropRegion: { ...DEFAULT_CROP_REGION },
+ });
+ const doc = makeDoc({ assets: [asset], clips: [clip] });
+ expect(buildSceneDescription(doc).cropByClip).toEqual([null]);
+ });
+
+ it("carries a non-identity per-clip cropRegion through, one entry per clip in clips[] order", () => {
+ const asset = makeAsset({ id: "a", originalPath: "/a.mp4" });
const region = { x: 0.1, y: 0.2, width: 0.5, height: 0.6 };
- const doc = makeDoc({ legacyEditor: { cropRegion: region } });
- expect(buildSceneDescription(doc).crop).toEqual(region);
+ const cropped = makeClip({
+ id: "c1",
+ assetId: "a",
+ sourceStartSec: 0,
+ sourceEndSec: 4,
+ timelineStartSec: 0,
+ timelineEndSec: 4,
+ cropRegion: region,
+ });
+ const plain = makeClip({
+ id: "c2",
+ assetId: "a",
+ sourceStartSec: 4,
+ sourceEndSec: 8,
+ timelineStartSec: 4,
+ timelineEndSec: 8,
+ });
+ const doc = makeDoc({ assets: [asset], clips: [cropped, plain] });
+ expect(buildSceneDescription(doc).cropByClip).toEqual([region, null]);
});
});
@@ -414,9 +508,16 @@ describe("buildSceneDescription.settings mapping", () => {
expect(buildSceneDescription(doc).effects.roundnessPx).toBe(12);
});
- it("webcamSize is webcamSizePreset / 16.7", () => {
+ it("webcamSize is webcamSizeToFraction(webcamSizePreset) — clamp(preset,10,50)/100", () => {
const doc = makeDoc({ legacyEditor: { webcamSizePreset: 33.4 } });
- expect(buildSceneDescription(doc).layout.webcamSize).toBeCloseTo(2, 5);
+ expect(buildSceneDescription(doc).layout.webcamSize).toBeCloseTo(0.334, 5);
+ });
+
+ it("webcamSize clamps below 10 and above 50", () => {
+ const low = makeDoc({ legacyEditor: { webcamSizePreset: 2 } });
+ const high = makeDoc({ legacyEditor: { webcamSizePreset: 90 } });
+ expect(buildSceneDescription(low).layout.webcamSize).toBeCloseTo(0.1, 5);
+ expect(buildSceneDescription(high).layout.webcamSize).toBeCloseTo(0.5, 5);
});
it("maps the cursor sub-settings", () => {
diff --git a/src/native/sceneDescription.ts b/src/native/sceneDescription.ts
index 078047d00..be93e09f5 100644
--- a/src/native/sceneDescription.ts
+++ b/src/native/sceneDescription.ts
@@ -15,9 +15,14 @@
* contract — do not change the exported types.
*/
+import type { CameraFullscreenRegion } from "@/components/video-editor/types";
import { DEFAULT_CROP_REGION } from "@/components/video-editor/types";
+import { createId } from "@/lib/ai-edition/document/ids";
import type { AxcutDocument } from "@/lib/ai-edition/schema";
import { getEditorSettings } from "@/lib/ai-edition/store/editorSettings";
+import { resolveClipSourceEndSec } from "@/lib/ai-edition/timeline/clipDuration";
+import { projectRegionsToSourceTime } from "@/lib/ai-edition/timeline/region-ventilation";
+import { webcamSizeToFraction } from "@/lib/compositeLayout";
import type { CompositorClipInput } from "./contracts";
/** Background behind the screen. Parsed from `settings.wallpaper`. */
@@ -43,10 +48,26 @@ export interface SceneZoomRegion {
rotation: "iso" | "left" | "right" | null;
}
+/** A "Full Camera" timeline region (from `legacyEditor.cameraFullscreenRegions`). Times in seconds. */
+export interface SceneCameraFullscreenRegion {
+ startSec: number;
+ endSec: number;
+}
+
/** Webcam layout, from the editor settings. */
export interface SceneLayout {
preset: "picture-in-picture" | "dual-frame" | "vertical-stack" | "no-webcam";
- /** Native size scale (1 = the compositor's default PiP webcam). */
+ /**
+ * Webcam size as a fraction (0..1) of the canvas reference dimension, derived from
+ * `webcamSizeToFraction(settings.webcamSizePreset)`. Matches the web's canonical
+ * composite-layout helper (0.10 = small, 0.25 ≈ default, 0.50 = max). The native
+ * compositor must consume this directly as a fraction of the reference dimension —
+ * an earlier revision emitted `settings.webcamSizePreset / 16.7` (a multiplier
+ * where ~1 ≈ default PiP size); that unit was incorrect vs. the web pipeline and has
+ * been replaced here. If you are touching the Rust consumer of this field, treat the
+ * incoming value as a 0..1 fraction of the canvas reference dimension, NOT as a
+ * size-multiplier.
+ */
webcamSize: number;
webcamShape: "rectangle" | "circle" | "square" | "rounded";
webcamMirror: boolean;
@@ -92,38 +113,24 @@ export interface SceneDescription {
effects: SceneEffects;
background: SceneBackground;
zoomRegions: SceneZoomRegion[];
+ /**
+ * "Full Camera" regions projected onto each clip's source time (one entry per
+ * source-time span after `projectRegionsToSourceTime`). Empty when none set.
+ */
+ cameraFullscreenRegions: SceneCameraFullscreenRegion[];
cursor: SceneCursor;
- /** Screen source crop (fractions of the frame), or null for the full frame. */
- crop: { x: number; y: number; width: number; height: number } | null;
+ /**
+ * Per-clip screen crop (fractions of the frame), or null for the identity
+ * (full-frame) crop. One entry per clip in the same order as `clips`, so a
+ * clip that owns its own cropRegion is rendered with that crop and a clip
+ * without one stays at the full frame. Replaces the old single global
+ * `crop` field, which lost per-clip crops on multi-clip documents.
+ */
+ cropByClip: Array<{ x: number; y: number; width: number; height: number } | null>;
/** Output frame. `fps` null = use the first clip's source fps. */
output: { width: number; height: number; fps: number | null };
}
-/** Mirror of `buildNativeClipList` in src/components/ai-edition/ExportDialog.tsx — keep these
- * two derivation paths in lock-step so the native multiclip export and the in-process preview
- * composer see the same clip stream. */
-function buildNativeClipList(document: AxcutDocument) {
- const assetById = new Map(document.assets.map((a) => [a.id, a]));
- return [...document.timeline.clips]
- .sort((a, b) => a.timelineStartSec - b.timelineStartSec)
- .flatMap((clip) => {
- const asset = assetById.get(clip.assetId);
- if (!asset?.originalPath) return [];
- const cam = asset.cameraTrack;
- const sourceEndSec =
- clip.sourceEndSec ?? clip.sourceStartSec + (clip.timelineEndSec - clip.timelineStartSec);
- return [
- {
- screenPath: asset.originalPath,
- webcamPath: cam?.sourcePath ?? asset.originalPath,
- sourceStartSec: clip.sourceStartSec,
- sourceEndSec,
- webcamOffsetSec: cam ? (cam.startMs + cam.offsetMs) / 1000 : 0,
- },
- ];
- });
-}
-
/** Strip a trailing position percentage (or any whitespace tail) from a gradient stop token,
* returning the colour piece. The presets never nest parens so a whitespace split is fine. */
function firstTokenOf(stop: string): string {
@@ -185,24 +192,76 @@ function pickOutputDims(document: AxcutDocument): { width: number; height: numbe
export function buildSceneDescription(document: AxcutDocument): SceneDescription {
const settings = getEditorSettings(document);
- const crop =
- settings.cropRegion.x === DEFAULT_CROP_REGION.x &&
- settings.cropRegion.y === DEFAULT_CROP_REGION.y &&
- settings.cropRegion.width === DEFAULT_CROP_REGION.width &&
- settings.cropRegion.height === DEFAULT_CROP_REGION.height
- ? null
- : {
- x: settings.cropRegion.x,
- y: settings.cropRegion.y,
- width: settings.cropRegion.width,
- height: settings.cropRegion.height,
- };
+ // Sort+filter the clips once, in the order they will appear in the scene's
+ // `clips[]` stream, so the per-clip `cropByClip[]` schedule stays aligned
+ // 1:1 with `clips[]` by index. Mirror of `buildNativeClipList` in
+ // src/components/ai-edition/ExportDialog.tsx — keep these two derivation
+ // paths in lock-step so the native multiclip export and the in-process
+ // preview composer see the same clip stream.
+ const assetById = new Map(document.assets.map((a) => [a.id, a]));
+ const visibleClips = [...document.timeline.clips]
+ .sort((a, b) => a.timelineStartSec - b.timelineStartSec)
+ .filter((clip) => assetById.get(clip.assetId)?.originalPath);
+ const clips: CompositorClipInput[] = visibleClips.flatMap((clip) => {
+ const asset = assetById.get(clip.assetId);
+ if (!asset?.originalPath) return [];
+ const cam = asset.cameraTrack;
+ return [
+ {
+ screenPath: asset.originalPath,
+ webcamPath: cam?.sourcePath ?? asset.originalPath,
+ sourceStartSec: clip.sourceStartSec,
+ sourceEndSec: resolveClipSourceEndSec(clip, asset),
+ webcamOffsetSec: cam ? (cam.startMs + cam.offsetMs) / 1000 : 0,
+ },
+ ];
+ });
+ const cropByClip = visibleClips.map(
+ (clip): { x: number; y: number; width: number; height: number } | null => {
+ const cropRegion = clip.cropRegion;
+ if (!cropRegion) return null;
+ if (
+ cropRegion.x === DEFAULT_CROP_REGION.x &&
+ cropRegion.y === DEFAULT_CROP_REGION.y &&
+ cropRegion.width === DEFAULT_CROP_REGION.width &&
+ cropRegion.height === DEFAULT_CROP_REGION.height
+ ) {
+ return null;
+ }
+ return {
+ x: cropRegion.x,
+ y: cropRegion.y,
+ width: cropRegion.width,
+ height: cropRegion.height,
+ };
+ },
+ );
+
+ // Zoom + Full Camera regions are authored in virtual (timeline) ms in the
+ // document, but the compositor matches them against each frame's SOURCE
+ // time the same way the web export's frame loop does. Project them onto the
+ // covered clips' source ranges (splitting any region that straddles a clip
+ // boundary) so the native side gets the same shape the export pipeline
+ // already proves correct.
+ const docClips = document.timeline.clips;
+ const projectedZoomRegions = projectRegionsToSourceTime(document.zoomRanges ?? [], docClips, () =>
+ createId("zoom"),
+ );
+ const projectedCameraFullscreenRegions = projectRegionsToSourceTime(
+ ((document.legacyEditor as Record<string, unknown> | null)?.cameraFullscreenRegions as
+ | CameraFullscreenRegion[]
+ | undefined) ?? [],
+ docClips,
+ () => createId("camfull"),
+ );
return {
- clips: buildNativeClipList(document),
+ clips,
layout: {
preset: settings.webcamLayoutPreset,
- webcamSize: settings.webcamSizePreset / 16.7,
+ // web-consistent 0..1 fraction of the canvas reference dimension
+ // (see `SceneLayout.webcamSize` for the consumer-facing semantics).
+ webcamSize: webcamSizeToFraction(settings.webcamSizePreset),
webcamShape: settings.webcamMaskShape,
webcamMirror: settings.webcamMirrored,
webcamPosition: settings.webcamPosition,
@@ -225,7 +284,7 @@ export function buildSceneDescription(document: AxcutDocument): SceneDescription
theme: settings.cursorTheme,
},
background: parseWallpaper(settings.wallpaper),
- zoomRegions: (document.zoomRanges ?? []).map((region) => ({
+ zoomRegions: projectedZoomRegions.map((region) => ({
id: region.id,
startSec: region.startMs / 1000,
endSec: region.endMs / 1000,
@@ -235,7 +294,11 @@ export function buildSceneDescription(document: AxcutDocument): SceneDescription
focusMode: region.focusMode ?? null,
rotation: region.rotationPreset ?? null,
})),
- crop,
+ cameraFullscreenRegions: projectedCameraFullscreenRegions.map((region) => ({
+ startSec: region.startMs / 1000,
+ endSec: region.endMs / 1000,
+ })),
+ cropByClip,
output: { ...pickOutputDims(document), fps: null },
};
}