8000 feat(editor): stage-based output + per-element viewport transform by johannboehme · Pull Request #21 · johannboehme/tk-1 · GitHub
[go: up one dir, main page]

Skip to content
Merged
Show file tree
Hide file tree
Changes from all commits
Commits
File filter

Filter by extension

Filter by extension

Conversations
Failed to load comments.
Loading
Jump to
Jump to file
Failed to load files.
Loading
Diff view
Diff view
29 changes: 29 additions & 0 deletions frontend/src/editor/components/AspectPicker.tsx
Original file line number Diff line number Diff line change
@@ -0,0 +1,29 @@
// Aspect-ratio picker — five preset chips (16:9, 9:16, 1:1, 4:3, 21:9).
// "custom" is implicit: typing W/H by hand in the ResolutionPicker
// switches the panel into custom mode and de-selects all chips here.
// (Keeping "custom" in the chip group made the segment overflow on
// narrow side-panels and the bottom-sheet on phones.)
import type { AspectRatio } from "../types";
import { ASPECT_RATIO_PRESETS } from "../exportPresets";
import { SegmentedControl } from "./SegmentedControl";

interface Props {
value: AspectRatio | undefined;
onChange: (a: AspectRatio) => void;
}

export function AspectPicker({ value, onChange }: Props) {
const options = ASPECT_RATIO_PRESETS.map((p) => ({ value: p, label: p }));
// When the active spec is "custom" the value won't match any chip and
// the SegmentedControl just shows none active — exactly what we want.
return (
<SegmentedControl
label="Aspect"
value={(value ?? "custom") as Exclude<AspectRatio, "custom">}
options={options}
>
size="sm"
fullWidth
/>
);
}
2 changes: 2 additions & 0 deletions frontend/src/editor/components/Compositor.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -20,6 +20,7 @@ import { getCapabilities } from "../../local/capabilities";
import { MasterAudio } from "./MasterAudio";
import { TestPattern } from "./TestPattern";
import { OutputFrameBox } from "./OutputFrameBox";
import { StageInteractionOverlay } from "./StageInteractionOverlay";
import { PreviewRuntime, type ClipUrlMap } from "../render/preview-runtime";
import { COMPOSITOR_INITIAL_SCALE } from "../render/feature-flag";

Expand Down Expand Up @@ -49,6 +50,7 @@ export function Compositor({ cams, audioUrl }: Props) {

<OutputFrameBox>
<CompositorCanvas cams={cams} />
<StageInteractionOverlay />
</OutputFrameBox>
</div>
);
Expand Down
33 changes: 19 additions & 14 deletions frontend/src/editor/components/ExportPanel.test.tsx
8000
Original file line number Diff line number Diff line change
Expand Up @@ -22,44 +22,49 @@ describe("<ExportPanel />", () => {
mountAt(1920, 1080);
});

test("default preset is web with H.264 and the Good-quality bitrate at 1080p", () => {
test("default preset is custom — Stage shape derives from the first clip", () => {
render(<ExportPanel => undefined} submitting={false} />);
const ex = useEditorStore.getState().exportSpec;
expect(ex.preset).toBe("web");
expect(ex.preset).toBe("custom");
expect(ex.video_codec).toBe("h264");
// Good @ 1080p = 3500 kbps (see exportPresets.qualityToBitrates).
expect(ex.video_bitrate_kbps).toBe(3500);
});

test("MOBILE preset preserves aspect for portrait sources (the bug fix)", async () => {
test("WEB preset always sets 16:9 1920×1080 + H.264 + Good", async () => {
mountAt(1080, 1920);
render(<ExportPanel => undefined} submitting={false} />);
const mobileTab = screen.getByRole("tab", { name: /MOBILE/i });
await userEvent.click(mobileTab);
const webTab = screen.getByRole("tab", { name: /WEB/i });
await userEvent.click(webTab);
const ex = useEditorStore.getState().exportSpec;
expect(ex.preset).toBe("mobile");
// Portrait source within the long-side cap stays 1080×1920 — the old
// hardcoded 1280×720 was wrong for portrait phone footage.
expect(ex.resolution).toEqual({ w: 1080, h: 1920 });
expect(ex.preset).toBe("web");
expect(ex.aspectRatio).toBe("16:9");
expect(ex.resolution).toEqual({ w: 1920, h: 1080 });
expect(ex.video_codec).toBe("h264");
expect(ex.video_bitrate_kbps).toBe(3500);
});

test("MOBILE preset caps a 4K landscape source on its long side", async () => {
test("MOBILE preset always sets 9:16 1080×1920 + H.264 + Low", async () => {
mountAt(3840, 2160);
render(<ExportPanel => undefined} submitting={false} />);
const mobileTab = screen.getByRole("tab", { name: /MOBILE/i });
await userEvent.click(mobileTab);
const ex = useEditorStore.getState().exportSpec;
expect(ex.resolution).toEqual({ w: 1920, h: 1080 });
expect(ex.preset).toBe("mobile");
expect(ex.aspectRatio).toBe("9:16");
expect(ex.resolution).toEqual({ w: 1080, h: 1920 });
expect(ex.video_codec).toBe("h264");
expect(ex.quality).toBe("low");
});

test("ARCHIVE preset switches to H.265 and keeps source dimensions", async () => {
test("ARCHIVE preset keeps the user's aspect + dims, switches to H.265", async () => {
mountAt(3840, 2160);
render(<ExportPanel => undefined} submitting={false} />);
// Without prior aspect/dims set, archive falls back to 16:9 4K.
const archiveTab = screen.getByRole("tab", { name: /ARCHIVE/i });
await userEvent.click(archiveTab);
const ex = useEditorStore.getState().exportSpec;
expect(ex.preset).toBe("archive");
expect(ex.video_codec).toBe("h265");
expect(ex.aspectRatio).toBe("16:9");
expect(ex.resolution).toEqual({ w: 3840, h: 2160 });
});

Expand Down
95 changes: 74 additions & 21 deletions frontend/src/editor/components/ExportPanel.tsx
Original file line number Diff line number Diff line change
@@ -1,10 +1,16 @@
// Studio-Console export dialog. Source → Output is the hero element; the
// rest are modifiers.
// Studio-Console export dialog.
//
// Three orthogonal axes a user might want to touch:
// 1. WHERE — destination preset (Web / Archive / Mobile / Custom).
// 2. HOW MUCH — Quality slider, mapped to bitrate via `qualityToBitrates`.
// 3. WHAT KIND — Advanced drawer: resolution, codec, bitrate, audio codec.
// V2 layout (post Stage redesign — see plan file):
// 1. ASPECT picker — picks Stage shape independently of pixels.
// 2. RESOLUTION picker — long-side presets, derived from aspect.
// 3. Big mono LCD readout — "1920 × 1080" so the user always sees
// the concrete pixels they will get.
// 4. PRESET (Web/Archive/Mobile/Custom) — bitrate + codec recipe.
// 5. QUALITY slider — bitrate ladder.
// 6. Advanced drawer — codecs, bitrates, filename.
//
// IOReadout (Source vs Output) is gone. There's no single "source" in
// a multi-clip edit — the Stage shape is what the user picks here.
//
// Everything reads/writes through the editor store's `exportSpec`. The
// onSubmit handler in `Editor.tsx` translates the spec to the renderer's
Expand All @@ -13,16 +19,18 @@
import { useEffect, useMemo } from "react";
import {
applyPreset,
classifyAspectRatio,
deriveResolution,
estimateFileSizeBytes,
qualityToBitrates,
resolveResolution,
} from "../exportPresets";
import { useEditorStore } from "../store";
import type { ExportPreset, ExportSpec, QualityStep } from "../types";
import type { AspectRatio, ExportPreset, ExportSpec, QualityStep } from "../types";
import { AdvancedDrawer } from "./AdvancedDrawer";
import { AspectPicker } from "./AspectPicker";
import { ChunkyButton } from "./ChunkyButton";
import { FilenameInput } from "./FilenameInput";
import { IOReadout } from "./IOReadout";
import { QualitySlider } from "./QualitySlider";
import { ResolutionPicker } from "./ResolutionPicker";
import { SegmentedControl } from "./SegmentedControl";
Expand All @@ -39,6 +47,10 @@ export function ExportPanel({ onSubmit, submitting }: Props) {
const setExport = useEditorStore((s) => s.setExport);
const jobMeta = useEditorStore((s) => s.jobMeta);

// Source dims are still needed for `applyPreset` (preset's bitrate
// ladder scales with output area, and a "source pass-through" preset
// needs *some* concrete fallback dims). When no clip has reported its
// dims yet we fall back to the legacy job meta — typically 1920×1080.
const source = useMemo(
() => ({
w: jobMeta?.width ?? 1920,
Expand Down Expand Up @@ -89,7 +101,7 @@ export function ExportPanel({ onSubmit, submitting }: Props) {
});

function selectPreset(p: ExportPreset) {
setExport(applyPreset(p, source));
setExport(applyPreset(p, exportSpec));
}

function selectQuality(q: Exclude<QualityStep, "custom">) {
Expand All @@ -101,8 +113,47 @@ export function ExportPanel({ onSubmit, submitting }: Props) {
});
}

function setResolution(dims: { w: number; h: number }) {
setExport({ resolution: dims, preset: "custom" });
// Aspect change: keep the existing long-side, derive new {w,h}.
function pickAspect(a: AspectRatio) {
if (a === "custom") {
// Custom means: use whatever {w,h} is currently set. Just flip
// the picker state — don't touch resolution.
setExport({ aspectRatio: "custom", preset: "custom" });
return;
}
const longSide =
exportSpec.resolutionLongSide ?? Math.max(output.w, output.h);
const dims = deriveResolution(a, longSide);
setExport({
aspectRatio: a,
resolutionLongSide: longSide,
resolution: dims,
preset: "custom",
});
}

// Long-side change: re-derive {w,h} from active aspect.
function pickLongSide(longSide: number) {
const aspect = exportSpec.aspectRatio;
if (!aspect || aspect === "custom") return;
const dims = deriveResolution(aspect, longSide);
setExport({
resolutionLongSide: longSide,
resolution: dims,
preset: "custom",
});
}

// Manual W/H: flips aspect to "custom" because the dims may not match
// any preset.
function setCustomDims(dims: { w: number; h: number }) {
const matched = classifyAspectRatio(dims);
setExport({
resolution: dims,
aspectRatio: matched,
resolutionLongSide: Math.max(dims.w, dims.h),
preset: "custom",
});
}

function setVideoCodec(c: ExportSpec["video_codec"]) {
Expand Down Expand Up @@ -130,14 +181,12 @@ export function ExportPanel({ onSubmit, submitting }: Props) {
<header>
<h2 className="font-display text-lg leading-none">Export</h2>
<p className="text-xs text-ink-2 mt-1">
Pick a destination, dial in the quality, hit render.
Pick the Stage shape, dial in the size, hit render.
</p>
</header>

<IOReadout source={source} output={output} />

<SegmentedControl
label="Destination"
label="Preset"
value={exportSpec.preset}
options={[
{ value: "web", label: "WEB" },
Expand All @@ -149,6 +198,15 @@ export function ExportPanel({ onSubmit, submitting }: Props) {
fullWidth
/>

<AspectPicker value={exportSpec.aspectRatio} />

<ResolutionPicker
aspect={exportSpec.aspectRatio}
value={output}
>
>
/>

<QualitySlider
value={exportSpec.quality ?? "good"}
>
Expand All @@ -163,12 +221,6 @@ export function ExportPanel({ onSubmit, submitting }: Props) {
/>

<AdvancedDrawer>
<ResolutionPicker
source={source}
value={output}
>
/>

<FormField label="Video codec">
<SegmentedControl
value={exportSpec.video_codec ?? "h264"}
Expand Down Expand Up @@ -248,3 +300,4 @@ function FormField({ label, children }: { label: string; children: React.ReactNo
</div>
);
}

79 changes: 71 additions & 8 deletions frontend/src/editor/components/OutputFrameBox.tsx
Original file line number Diff line number Diff line change
Expand Up @@ -84,17 +84,80 @@ export function OutputFrameBox({ children, showIndicator = true }: Props) {
}}
>
{showIndicator && boxResolved && (
<div
aria-hidden
className="absolute inset-0 pointer-events-none"
style={{
outline: "1px dashed rgba(255,255,255,0.18)",
outlineOffset: -1,
}}
/>
<>
<div
aria-hidden
className="absolute inset-0 pointer-events-none"
style={{
outline: "1px dashed rgba(255,255,255,0.18)",
outlineOffset: -1,
}}
/>
<StageCornerMarks />
</>
)}
{children}
</div>
</div>
);
}

/**
* Subtle white L-shaped corner marks anchored to the Stage corners. TE-
* spirit: like the registration marks on a print template — they say
* "this is the frame" without screaming it. Active-element corners get
* the orange treatment in `StageInteractionOverlay` instead.
*/
function StageCornerMarks() {
const SIZE = 10; // px schenkel
const W = 1.5; // px stroke
const COLOR = "rgba(255,255,255,0.45)";
const corners: Array<{ pos: React.CSSProperties; lines: [string, string] }> = [
{
pos: { left: 0, top: 0 },
lines: [
// horizontal arm (top edge)
`width:${SIZE}px;height:${W}px;left:0;top:0`,
// vertical arm (left edge)
`width:${W}px;height:${SIZE}px;left:0;top:0`,
],
},
{
pos: { right: 0, top: 0 },
lines: [
`width:${SIZE}px;height:${W}px;right:0;top:0`,
`width:${W}px;height:${SIZE}px;right:0;top:0`,
],
},
{
pos: { left: 0, bottom: 0 },
lines: [
`width:${SIZE}px;height:${W}px;left:0;bottom:0`,
`width:${W}px;height:${SIZE}px;left:0;bottom:0`,
],
},
{
pos: { right: 0, bottom: 0 },
lines: [
`width:${SIZE}px;height:${W}px;right:0;bottom:0`,
`width:${W}px;height:${SIZE}px;right:0;bottom:0`,
],
},
];
return (
<div aria-hidden className="absolute inset-0 pointer-events-none">
{corners.map((c, i) => (
<div key={i} className="absolute" style={c.pos}>
{c.lines.map((s, j) => {
const styleObj: Record<string, string> = { backgroundColor: COLOR, position: "absolute" };
for (const part of s.split(";")) {
const [k, v] = part.split(":");
styleObj[k.trim()] = v.trim();
}
return <div key={j} style={styleObj as React.CSSProperties} />;
})}
</div>
))}
</div>
);
}
Loading
Loading
0