Skip to content

AI media harness for planning, generating, and editing locally

TypeScript

Rebuild the resolution ladder on multiples of 32

Bitti33c7f2494a05
diff --git a/src-tauri/src/lib.rs b/src-tauri/src/lib.rs
index 089bbc3..9d33363 100644
--- a/src-tauri/src/lib.rs
+++ b/src-tauri/src/lib.rs
@@ -405,8 +405,19 @@ fn is_supported_aspect_ratio(value: &str) -> bool {
matches!(value, "16:9" | "9:16" | "1:1" | "4:5")
}
+/// The same nine names `resolutionSchema` in src/lib/project.ts accepts, and no
+/// others in either direction — this layer writes the file the frontend then
+/// has to parse. The first six are the ladder a new project is created at, every
+/// rung a multiple of 32 on both edges because that is what MiniMax H3
+/// generates at; the last three are names already on disk, kept so a project
+/// saved before the ladder was rebuilt still opens at the pixels it always had.
+/// The pixels themselves live in `outputDimensions` (src/lib/export.ts) — this
+/// side validates the name and never needs the geometry.
fn is_supported_resolution(value: &str) -> bool {
- matches!(value, "720p" | "1080p" | "4k")
+ matches!(
+ value,
+ "416p" | "544p" | "640p" | "768p" | "1088p" | "1344p" | "720p" | "1080p" | "4k"
+ )
}
fn days_in_month(year: u32, month: u32) -> u32 {
@@ -3593,7 +3604,9 @@ mod tests {
"rejected valid aspect ratio {aspect_ratio}"
);
}
- for resolution in ["720p", "1080p", "4k"] {
+ for resolution in [
+ "416p", "544p", "640p", "768p", "1088p", "1344p", "720p", "1080p", "4k",
+ ] {
let mut config = fixture();
config.settings.resolution = resolution.into();
config.brief.resolution = resolution.into();
diff --git a/src/App.test.tsx b/src/App.test.tsx
index 6d7d116..bc78ee9 100644
--- a/src/App.test.tsx
+++ b/src/App.test.tsx
@@ -91,6 +91,36 @@ describe("project library controls", () => {
await waitFor(() => expect(screen.getByRole("menuitem", { name: "Open project" })).not.toBeNull());
});
+ it("offers frame sizes MiniMax H3 can generate, relabelled when the shape changes", async () => {
+ render(<App />);
+ await screen.findByText("Northern Light — Brand Film");
+ const shape = screen.getByRole("combobox", { name: /Video shape/ }) as HTMLSelectElement;
+ const size = screen.getByRole("combobox", { name: /Frame size/ }) as HTMLSelectElement;
+
+ // The ladder the user asked for, in pixels rather than a name for them.
+ expect([...size.options].map((option) => option.textContent)).toEqual([
+ "736 × 416", "960 × 544", "1152 × 640", "1376 × 768 (default)", "1920 × 1088", "2432 × 1344",
+ ]);
+ // Every edge a multiple of 32 — the whole reason the old 720p/1080p/4K
+ // ladder was replaced.
+ for (const option of [...size.options]) {
+ const [width, height] = option.textContent!.split(" (")[0].split(" × ").map(Number);
+ expect([width % 32, height % 32]).toEqual([0, 0]);
+ }
+
+ /* A frame size is two numbers, and one of them changes with the shape. The
+ old labels ("1080p HD") could sit above either and say nothing. */
+ fireEvent.change(shape, { target: { value: "9:16" } });
+ expect([...size.options].map((option) => option.textContent)).toEqual([
+ "416 × 736", "544 × 960", "640 × 1152", "768 × 1376 (default)", "1088 × 1920", "1344 × 2432",
+ ]);
+
+ // And the summary line beside the collapsed panel says the same numbers.
+ fireEvent.change(size, { target: { value: "544p" } });
+ expect(document.querySelector(".composer__options-value")!.textContent)
+ .toBe("Vertical 9:16 · 544 × 960 · 30 seconds");
+ });
+
it("opens a prompt-created project in Generator with its initial draft selected", async () => {
render(<App />);
await screen.findByText("Northern Light — Brand Film");
diff --git a/src/components/ProjectCard.tsx b/src/components/ProjectCard.tsx
index 70b27e0..4ab99d4 100644
--- a/src/components/ProjectCard.tsx
+++ b/src/components/ProjectCard.tsx
@@ -1,5 +1,6 @@
import { Clock3, Folder, MoreHorizontal, Play, Ratio, Sparkles } from "lucide-react";
import { useEffect, useRef, useState } from "react";
+import { resolutionLabel } from "../lib/export";
import type { ProjectRecord } from "../lib/project";
interface ProjectCardProps {
@@ -66,7 +67,7 @@ export function ProjectCard({ project, index, onOpen }: ProjectCardProps) {
<button className="project-card__art-button" onClick={() => onOpen(project)} aria-label={`Open ${config.name}`}>
<div className={`project-card__art project-card__art--${artwork[index % artwork.length]}`} style={style}>
<span className="project-card__format"><Ratio size={13} /> {config.settings.aspectRatio}</span>
- <span className="project-card__quality">{config.settings.resolution.toUpperCase()}</span>
+ <span className="project-card__quality">{resolutionLabel(config.settings.resolution, config.settings.aspectRatio)}</span>
<span className="project-card__play"><Play size={18} fill="currentColor" /></span>
<div className="project-card__art-copy"><Sparkles size={15} /><span>{config.brief.prompt}</span></div>
</div>
diff --git a/src/components/ProjectWorkspace.test.ts b/src/components/ProjectWorkspace.test.ts
index 18eadad..b38edf1 100644
--- a/src/components/ProjectWorkspace.test.ts
+++ b/src/components/ProjectWorkspace.test.ts
@@ -561,7 +561,8 @@ describe("project workspace timecode", () => {
// the playhead time is printed once. The toolbar used to print it beside
// the heading while the monitor printed it again, which reads as two clocks.
expect(container.textContent!.match(/\d\d:\d\d:\d\d:\d\d/g)).toHaveLength(1);
- expect(container.querySelector(".transport-format")!.textContent).toBe("1080P · 30 fps");
+ // Pixels, not the id: "1080p" names one edge and leaves the other a guess.
+ expect(container.querySelector(".transport-format")!.textContent).toBe("1920 × 1080 · 30 fps");
// An empty timeline has nothing to play, and every control says so rather
// than only going grey.
diff --git a/src/components/PromptComposer.tsx b/src/components/PromptComposer.tsx
index 20144f9..6e14818 100644
--- a/src/components/PromptComposer.tsx
+++ b/src/components/PromptComposer.tsx
@@ -1,8 +1,9 @@
import { ChevronDown, Clapperboard, Clock3, ImagePlus, Monitor, Sparkles, Undo2, WandSparkles, X } from "lucide-react";
import { useEffect, useRef, useState } from "react";
import { chooseInitialReferenceImages, isTauri } from "../lib/persistence";
+import { outputDimensions, resolutionLabel } from "../lib/export";
import type { AspectRatio, CreateProjectInput, Resolution } from "../lib/project";
-import { projectNameFromPrompt } from "../lib/project";
+import { projectNameFromPrompt, PROJECT_RESOLUTIONS } from "../lib/project";
import { PolStudioLogo } from "./PolStudioLogo";
interface PromptComposerProps {
@@ -24,11 +25,10 @@ const aspectRatioLabels: Record<AspectRatio, string> = {
"4:5": "Portrait 4:5",
};
-const resolutionLabels: Record<Resolution, string> = {
- "720p": "720p",
- "1080p": "1080p HD",
- "4k": "4K",
-};
+/* Chosen because it is the closest rung to the canvas vidfab actually plans a
+ 16:9 scene onto (1344×768), so a project made without opening this panel is
+ not one that has to be rescaled the moment a scene is generated. */
+const DEFAULT_RESOLUTION: Resolution = "768p";
const durationOptions: { value: number; label: string }[] = [
{ value: 15, label: "15 seconds" },
@@ -47,7 +47,7 @@ export function PromptComposer({ busy, onCreate }: PromptComposerProps) {
const [open, setOpen] = useState(false);
const [prompt, setPrompt] = useState("");
const [aspectRatio, setAspectRatio] = useState<AspectRatio>("16:9");
- const [resolution, setResolution] = useState<Resolution>("720p");
+ const [resolution, setResolution] = useState<Resolution>(DEFAULT_RESOLUTION);
const [duration, setDuration] = useState(30);
const [referenceImages, setReferenceImages] = useState<NonNullable<CreateProjectInput["referenceImages"]>>([]);
const [referenceError, setReferenceError] = useState<string | null>(null);
@@ -149,7 +149,7 @@ export function PromptComposer({ busy, onCreate }: PromptComposerProps) {
<details className="composer__options">
<summary>
<span className="composer__options-title">Video settings</span>
- <span className="composer__options-value">{aspectRatioLabels[aspectRatio]} · {resolutionLabels[resolution]} · {durationLabel(duration)}</span>
+ <span className="composer__options-value">{aspectRatioLabels[aspectRatio]} · {resolutionLabel(resolution, aspectRatio)} · {durationLabel(duration)}</span>
<ChevronDown className="composer__options-chevron" size={17} />
</summary>
<div className="composer__options-body">
@@ -164,12 +164,17 @@ export function PromptComposer({ busy, onCreate }: PromptComposerProps) {
<option value="4:5">Portrait 4:5</option>
</select>
</label>
+ {/* The real pixels, not a name for them. Every rung is a multiple
+ of 32 on both edges — what MiniMax H3 generates at — and they
+ are relabelled when the shape above changes, because 768p is
+ 1376×768 widescreen and 768×1376 vertical. */}
<label>
- <span><Clapperboard size={15} /> Picture quality</span>
+ <span><Clapperboard size={15} /> Frame size</span>
<select value={resolution} onChange={(event) => setResolution(event.target.value as Resolution)}>
- <option value="720p">720p</option>
- <option value="1080p">1080p HD</option>
- <option value="4k">4K</option>
+ {PROJECT_RESOLUTIONS.map((option) => {
+ const { width, height } = outputDimensions(option, aspectRatio);
+ return <option key={option} value={option}>{width} × {height}{option === DEFAULT_RESOLUTION ? " (default)" : ""}</option>;
+ })}
</select>
</label>
<label>
diff --git a/src/components/workspace/ExportView.tsx b/src/components/workspace/ExportView.tsx
index 9605d4b..c1081a4 100644
--- a/src/components/workspace/ExportView.tsx
+++ b/src/components/workspace/ExportView.tsx
@@ -34,9 +34,17 @@ import {
type CompositorProbe,
type ExportProgress,
} from "../../lib/exportPipeline";
-import type { ProjectConfig, Resolution } from "../../lib/project";
-
-const RESOLUTIONS: Resolution[] = ["720p", "1080p", "4k"];
+import { PROJECT_RESOLUTIONS, type ProjectConfig, type Resolution } from "../../lib/project";
+
+/* The ladder a project can be created at, plus the project's own size when that
+ is one of the names from before the ladder was rebuilt. Dropping the legacy
+ rung outright would leave a 1080p project looking at a select that does not
+ contain what the project IS, and the first touch of any other field would
+ have quietly resized the export. */
+const resolutionChoices = (current: Resolution): Resolution[] =>
+ PROJECT_RESOLUTIONS.includes(current as (typeof PROJECT_RESOLUTIONS)[number])
+ ? [...PROJECT_RESOLUTIONS]
+ : [...PROJECT_RESOLUTIONS, current];
const FRAME_RATES: FrameRate[] = [24, 25, 30, 60];
/* The preview is a picture, not a deliverable: 480px on the long edge is
enough to judge framing and costs a fraction of a full-size decode. */
@@ -355,9 +363,12 @@ export function ExportView({ config, folderPath }: { config: ProjectConfig; fold
disabled={running}
onChange={(event) => setSettings({ ...settings, resolution: event.target.value as Resolution })}
>
- {RESOLUTIONS.map((resolution) => {
+ {resolutionChoices(config.settings.resolution).map((resolution) => {
const size = outputDimensions(resolution, config.settings.aspectRatio);
- return <option key={resolution} value={resolution}>{resolution} · {size.width} × {size.height}</option>;
+ const legacy = !PROJECT_RESOLUTIONS.includes(resolution as (typeof PROJECT_RESOLUTIONS)[number]);
+ return <option key={resolution} value={resolution}>
+ {size.width} × {size.height}{legacy ? " · this project’s original size" : ""}
+ </option>;
})}
</select>
</label>
diff --git a/src/components/workspace/GeneratorView.tsx b/src/components/workspace/GeneratorView.tsx
index 7ab6c62..8404757 100644
--- a/src/components/workspace/GeneratorView.tsx
+++ b/src/components/workspace/GeneratorView.tsx
@@ -1,6 +1,7 @@
import { listen } from "@tauri-apps/api/event";
import { AlertCircle, Ban, Check, ChevronRight, Clock3, FileText, Image as ImageIcon, Info, LoaderCircle, Music2, Play, Plus, RefreshCw, Sparkles, Square, Video, WandSparkles, X } from "lucide-react";
import { useEffect, useMemo, useRef, useState } from "react";
+import { resolutionLabel } from "../../lib/export";
import { isTauri } from "../../lib/persistence";
import { actionReferenceIds, compileGenerationJobPrompt, compileGenerationJobSegments, createDraftGenerationJob, danglingReferenceTokens, sceneDurationSeconds, sceneShots, STORY_TRACK_ID, isReferenceDescribed, isReferenceUsable, isVisualReference, projectItemPath, usableImageReferences, type GenerationJob, type ProjectAsset, type ProjectConfig, type ProjectReference, type PromptSegment, type TimelineClip, type TimelineTrack } from "../../lib/project";
import { cancelVidfabGeneration, enqueueVidfabGeneration, resolveVidfabPlan, type VidfabGenerationRequest, type VidfabStatus } from "../../lib/runtime";
@@ -312,11 +313,12 @@ export function GeneratorView({ config, folderPath, runtime = null, onChange, on
<dl className="job-meta">
<div><dt>Video model</dt><dd>MiniMax H3</dd></div>
<div><dt>Scene length</dt><dd>{sceneDurationSeconds(selected).toFixed(1)} seconds, {sceneShots(selected).length === 1 ? "one shot" : `${sceneShots(selected).length} shots`}</dd></div>
- {/* Project settings, not this scene's — but they decide the frame
- every scene is rendered into, and the composer's chips were the
- only place on this screen that said so. */}
+ {/* The project's own settings, not this scene's. The frame size is
+ what the edit is exported at; the engine picks its own canvas
+ from the shape alone (set_aspect is the only geometry vidfab
+ takes), and the plan note above reports the one it picked. */}
<div><dt>Shape</dt><dd>{config.settings.aspectRatio}</dd></div>
- <div><dt>Size</dt><dd>{config.settings.resolution.toUpperCase()}</dd></div>
+ <div><dt>Frame size</dt><dd>{resolutionLabel(config.settings.resolution, config.settings.aspectRatio)}</dd></div>
<div><dt>Where it is</dt><dd>{STATUS_WORD[selected.status]}</dd></div>
<div><dt>Saved to</dt><dd>{selected.outputRelativePath ?? "Nothing saved to disk"}</dd></div>
</dl>
diff --git a/src/components/workspace/TimelineView.tsx b/src/components/workspace/TimelineView.tsx
index 008bd7f..1f60bae 100644
--- a/src/components/workspace/TimelineView.tsx
+++ b/src/components/workspace/TimelineView.tsx
@@ -4,6 +4,7 @@ import {
Volume2, VolumeX,
} from "lucide-react";
import { useEffect, useMemo, useRef, useState } from "react";
+import { resolutionLabel } from "../../lib/export";
import { importMediaFiles, isTauri } from "../../lib/persistence";
import { loadMediaLayout, saveMediaLayout, type MediaLayout } from "../../lib/settings";
import type { ProjectAsset, ProjectConfig, TimelineClip } from "../../lib/project";
@@ -518,7 +519,7 @@ export function TimelineView({ config, folderPath, onChange, onMeasured, onOpenG
<div className="timeline-toolbar__lead">
<h2>Timeline</h2>
<strong className="transport-time" title="Playhead position">{timecode(playhead)}</strong>
- <span className="transport-format">{config.settings.resolution.toUpperCase()} · {config.settings.frameRate} fps</span>
+ <span className="transport-format">{resolutionLabel(config.settings.resolution, config.settings.aspectRatio)} · {config.settings.frameRate} fps</span>
</div>
{/* The transport belongs to the timeline, not to the picture: it drives
the playhead, and the playhead is drawn a few pixels below this row.
diff --git a/src/lib/export.test.ts b/src/lib/export.test.ts
index eb8e581..81089c9 100644
--- a/src/lib/export.test.ts
+++ b/src/lib/export.test.ts
@@ -8,6 +8,7 @@ import {
formatBytes,
formatDuration,
outputDimensions,
+ resolutionLabel,
sourceTimeMsForFrame,
suggestedFileName,
videoDurationMs,
@@ -15,7 +16,7 @@ import {
type ExportSegment,
type ExportSettings,
} from "./export";
-import { createProjectConfig, type ProjectAsset, type ProjectConfig, type TimelineClip } from "./project";
+import { createProjectConfig, LEGACY_RESOLUTIONS, PROJECT_RESOLUTIONS, type ProjectAsset, type ProjectConfig, type TimelineClip } from "./project";
const asset = (id: string, overrides: Partial<ProjectAsset> = {}): ProjectAsset => ({
id,
@@ -68,7 +69,49 @@ const settings = (overrides: Partial<ExportSettings> = {}): ExportSettings => ({
const clipSegments = (segments: ExportSegment[]) => segments.flatMap((segment) => (segment.kind === "clip" ? [segment] : []));
describe("output geometry", () => {
- it("gives every aspect ratio the same short edge", () => {
+ it("offers the widescreen sizes MiniMax H3 actually generates at", () => {
+ // The ladder, verbatim. These are not 16:9 rounded off — 2432×1344 is 1.810
+ // against 16:9's 1.778 — so they are pinned here rather than recomputed by
+ // the same arithmetic the table deliberately does not use.
+ expect(PROJECT_RESOLUTIONS.map((resolution) => outputDimensions(resolution, "16:9"))).toEqual([
+ { width: 736, height: 416 },
+ { width: 960, height: 544 },
+ { width: 1152, height: 640 },
+ { width: 1376, height: 768 },
+ { width: 1920, height: 1088 },
+ { width: 2432, height: 1344 },
+ ]);
+ });
+
+ it("keeps both edges on a multiple of 32 in every shape a project can be", () => {
+ // The whole point of the ladder: a frame the engine cannot generate is a
+ // frame the project would have to rescale to fill.
+ for (const resolution of PROJECT_RESOLUTIONS) {
+ for (const ratio of ["16:9", "9:16", "1:1", "4:5"] as const) {
+ const { width, height } = outputDimensions(resolution, ratio);
+ expect({ resolution, ratio, width: width % 32, height: height % 32 })
+ .toEqual({ resolution, ratio, width: 0, height: 0 });
+ }
+ }
+ });
+
+ it("gives every aspect ratio the same short edge, and 9:16 the 16:9 frame turned over", () => {
+ expect(outputDimensions("768p", "16:9")).toEqual({ width: 1376, height: 768 });
+ expect(outputDimensions("768p", "9:16")).toEqual({ width: 768, height: 1376 });
+ expect(outputDimensions("768p", "1:1")).toEqual({ width: 768, height: 768 });
+ expect(outputDimensions("768p", "4:5")).toEqual({ width: 768, height: 960 });
+ for (const resolution of PROJECT_RESOLUTIONS) {
+ const wide = outputDimensions(resolution, "16:9");
+ expect(outputDimensions(resolution, "9:16")).toEqual({ width: wide.height, height: wide.width });
+ expect(outputDimensions(resolution, "1:1")).toEqual({ width: wide.height, height: wide.height });
+ expect(outputDimensions(resolution, "4:5").width).toBe(wide.height);
+ }
+ });
+
+ it("opens a project saved before the ladder at the pixels it always had", () => {
+ /* Nobody's export is resized behind their back. These are exactly what the
+ old short-edge formula produced, which is why 1080 and 2160 are still
+ here despite not being multiples of 32. */
expect(outputDimensions("1080p", "16:9")).toEqual({ width: 1920, height: 1080 });
expect(outputDimensions("1080p", "9:16")).toEqual({ width: 1080, height: 1920 });
expect(outputDimensions("1080p", "1:1")).toEqual({ width: 1080, height: 1080 });
@@ -77,8 +120,14 @@ describe("output geometry", () => {
expect(outputDimensions("4k", "16:9")).toEqual({ width: 3840, height: 2160 });
});
+ it("names a frame size in pixels, because the id only names one of its edges", () => {
+ // "768p" at 16:9 is 1376 wide, not the 1365 the name invites you to derive.
+ expect(resolutionLabel("768p", "16:9")).toBe("1376 × 768");
+ expect(resolutionLabel("768p", "9:16")).toBe("768 × 1376");
+ });
+
it("never produces an odd edge, which a 4:2:0 encoder refuses", () => {
- for (const resolution of ["720p", "1080p", "4k"] as const) {
+ for (const resolution of [...PROJECT_RESOLUTIONS, ...LEGACY_RESOLUTIONS]) {
for (const ratio of ["16:9", "9:16", "1:1", "4:5"] as const) {
const { width, height } = outputDimensions(resolution, ratio);
expect(width % 2).toBe(0);
diff --git a/src/lib/export.ts b/src/lib/export.ts
index 0d2dc7a..e5e1eca 100644
--- a/src/lib/export.ts
+++ b/src/lib/export.ts
@@ -103,26 +103,47 @@ export function qualityPreset(id: QualityId): QualityPreset {
return preset;
}
-/* The resolution names the SHORT edge, so one setting means the same amount of
- picture in every aspect ratio the project offers: 1080p is 1920×1080 wide,
- 1080×1920 tall, 1080×1080 square and 1080×1350 at 4:5. */
-const SHORT_EDGE: Record<Resolution, number> = { "720p": 720, "1080p": 1080, "4k": 2160 };
-const RATIO: Record<AspectRatio, readonly [number, number]> = {
- "16:9": [16, 9],
- "9:16": [9, 16],
- "1:1": [1, 1],
- "4:5": [4, 5],
+/* Every frame size the app knows, written out rather than derived.
+
+ The resolution names the SHORT edge, so one setting means the same height of
+ picture in every aspect ratio the project offers: 768p is 1376×768 wide,
+ 768×1376 tall, 768×768 square and 768×960 at 4:5.
+
+ These are a TABLE and not a formula because the sizes MiniMax H3 generates at
+ are not the ones arithmetic would pick. Both edges have to be a multiple of
+ 32, and the nearest such pair is not the ratio rounded off: 16:9 at 1344 is
+ 2432×1344, which no expression of 1344 and 16/9 produces. Deriving these
+ would mean deriving the wrong numbers precisely.
+
+ So the ratios here are approximate — 736×416 is 1.769 against 16:9's 1.778 —
+ and that is the trade the multiple of 32 buys. The four legacy rows keep the
+ exact pixels the old short-edge formula produced, because a project saved at
+ 1080p must open at 1920×1080 and not one pixel else. */
+const FRAME_SIZES: Record<Resolution, Record<AspectRatio, readonly [number, number]>> = {
+ "416p": { "16:9": [736, 416], "9:16": [416, 736], "1:1": [416, 416], "4:5": [416, 512] },
+ "544p": { "16:9": [960, 544], "9:16": [544, 960], "1:1": [544, 544], "4:5": [544, 672] },
+ "640p": { "16:9": [1152, 640], "9:16": [640, 1152], "1:1": [640, 640], "4:5": [640, 800] },
+ "768p": { "16:9": [1376, 768], "9:16": [768, 1376], "1:1": [768, 768], "4:5": [768, 960] },
+ "1088p": { "16:9": [1920, 1088], "9:16": [1088, 1920], "1:1": [1088, 1088], "4:5": [1088, 1376] },
+ "1344p": { "16:9": [2432, 1344], "9:16": [1344, 2432], "1:1": [1344, 1344], "4:5": [1344, 1696] },
+ // Not offered for a new project; see LEGACY_RESOLUTIONS in project.ts.
+ "720p": { "16:9": [1280, 720], "9:16": [720, 1280], "1:1": [720, 720], "4:5": [720, 900] },
+ "1080p": { "16:9": [1920, 1080], "9:16": [1080, 1920], "1:1": [1080, 1080], "4:5": [1080, 1350] },
+ "4k": { "16:9": [3840, 2160], "9:16": [2160, 3840], "1:1": [2160, 2160], "4:5": [2160, 2700] },
};
-/** Encoders reject odd dimensions in 4:2:0, so both edges land on an even number. */
-const even = (value: number) => Math.max(2, Math.round(value / 2) * 2);
-
export function outputDimensions(resolution: Resolution, aspectRatio: AspectRatio): { width: number; height: number } {
- const base = SHORT_EDGE[resolution];
- const [ratioWidth, ratioHeight] = RATIO[aspectRatio];
- return ratioWidth >= ratioHeight
- ? { width: even((base * ratioWidth) / ratioHeight), height: even(base) }
- : { width: even(base), height: even((base * ratioHeight) / ratioWidth) };
+ const [width, height] = FRAME_SIZES[resolution][aspectRatio];
+ return { width, height };
+}
+
+/** A frame size in the only terms that mean anything to the person choosing it.
+ * Everywhere a resolution is SHOWN uses this rather than the id: "416p" names
+ * the short edge and leaves the other one a guess, and at 16:9 the guess is
+ * wrong by 24 pixels. */
+export function resolutionLabel(resolution: Resolution, aspectRatio: AspectRatio): string {
+ const { width, height } = outputDimensions(resolution, aspectRatio);
+ return `${width} × ${height}`;
}
/** The export starts as the project already describes itself. Nothing here is
diff --git a/src/lib/project.test.ts b/src/lib/project.test.ts
index da44c06..65049c7 100644
--- a/src/lib/project.test.ts
+++ b/src/lib/project.test.ts
@@ -9,6 +9,7 @@ import initialReferenceWire from "../../fixtures/rust-serialized-initial-referen
import sceneFixture from "../../fixtures/project-v1-scene.json";
import wireScene from "../../fixtures/rust-serialized-scene.json";
+import { outputDimensions } from "./export";
import {
compileMiniMaxH3Prompt,
createProjectConfig,
@@ -21,7 +22,10 @@ import {
projectItemPath,
projectNameFromPrompt,
projectReferenceSchema,
+ resolutionSchema,
seedProjectWorkspace,
+ LEGACY_RESOLUTIONS,
+ PROJECT_RESOLUTIONS,
STORY_TRACK_ID,
usableImageReferences,
actionReferenceIds,
@@ -530,6 +534,46 @@ describe("project schema", () => {
});
});
+describe("the frame sizes a project can be", () => {
+ it("accepts exactly the ladder plus the names already on disk, and nothing else", () => {
+ /* `is_supported_resolution` in src-tauri/src/lib.rs spells the same nine
+ names. They have to agree in BOTH directions: Rust writes the settings
+ file before the frontend ever parses it, so a name Rust accepts and zod
+ refuses is saved and then fails to open (see CLAUDE.md). */
+ expect(resolutionSchema.options).toEqual([...PROJECT_RESOLUTIONS, ...LEGACY_RESOLUTIONS]);
+ expect(resolutionSchema.options).toEqual([
+ "416p", "544p", "640p", "768p", "1088p", "1344p", "720p", "1080p", "4k",
+ ]);
+ for (const rejected of ["8k", "480p", "1080P", "768", ""]) {
+ expect(resolutionSchema.safeParse(rejected).success).toBe(false);
+ }
+ });
+
+ it("gives every name the schema accepts a frame size in every shape", () => {
+ /* The two lists live in different files — the names in project.ts, the
+ pixels in export.ts — and TypeScript only pins the table's KEYS to the
+ type. A name added to the schema alone would reach `outputDimensions` as
+ an undefined row and throw on the export screen, not here. */
+ for (const resolution of resolutionSchema.options) {
+ for (const ratio of ["16:9", "9:16", "1:1", "4:5"] as const) {
+ const { width, height } = outputDimensions(resolution, ratio);
+ expect(Number.isInteger(width) && width > 0).toBe(true);
+ expect(Number.isInteger(height) && height > 0).toBe(true);
+ }
+ }
+ });
+
+ it("creates a project at the size it was asked for, with the brief agreeing", () => {
+ const config = createProjectConfig({
+ name: "Ladder", prompt: "A quiet product film", aspectRatio: "9:16", resolution: "416p", targetDurationSeconds: 15,
+ });
+ expect(config.settings.resolution).toBe("416p");
+ // The brief carries its own copy and the two must not drift apart.
+ expect(config.brief.resolution).toBe("416p");
+ expect(outputDimensions(config.settings.resolution, config.settings.aspectRatio)).toEqual({ width: 416, height: 736 });
+ });
+});
+
describe("scenes and the shots inside them", () => {
const now = "2026-02-01T00:00:00.000Z";
const scene = () => parseProjectConfig(sceneFixture);
diff --git a/src/lib/project.ts b/src/lib/project.ts
index 31a4420..e6cb4bc 100644
--- a/src/lib/project.ts
+++ b/src/lib/project.ts
@@ -86,7 +86,25 @@ function checkOneLocation(value: StoredLocation, context: z.RefinementCtx, label
}
export const aspectRatioSchema = z.enum(["16:9", "9:16", "1:1", "4:5"]);
-export const resolutionSchema = z.enum(["720p", "1080p", "4k"]);
+
+/** The frame sizes a NEW project can be created at, smallest first. Every one
+ * of them is a multiple of 32 on both edges in every aspect ratio, because
+ * that is what MiniMax H3 generates at — a frame the engine cannot produce is
+ * a frame the project would have to rescale to fill.
+ *
+ * The id names the SHORT edge, the way "1080p" always has: 768p is 1376×768
+ * wide and 768×1376 tall. `outputDimensions` in export.ts holds the pixels
+ * themselves; a test pins the two lists together so neither can grow a member
+ * the other has never heard of. */
+export const PROJECT_RESOLUTIONS = ["416p", "544p", "640p", "768p", "1088p", "1344p"] as const;
+
+/** Names still on disk, from before the ladder was rebuilt on multiples of 32.
+ * They keep their exact old pixels (1080p is still 1920×1080) and they are not
+ * offered for a new project — a project is not resized behind its owner's
+ * back, and 1080 is not a multiple of 32. */
+export const LEGACY_RESOLUTIONS = ["720p", "1080p", "4k"] as const;
+
+export const resolutionSchema = z.enum([...PROJECT_RESOLUTIONS, ...LEGACY_RESOLUTIONS]);
export const projectAssetSchema = z.object({
id: idSchema,