Open source CapCut alternative.
TypeScript
feat(site): clip box borders, crop-window pan, and preview region selection [rebuild]
David Le73abf9eb197a
diff --git a/site/src/cut/components/Inspector.tsx b/site/src/cut/components/Inspector.tsxindex 3e7d1536..bb491382 100644--- a/site/src/cut/components/Inspector.tsx+++ b/site/src/cut/components/Inspector.tsx@@ -83,6 +83,7 @@ import {SPEED_MIN,clampOverlayPos,type AudioClip,+ type BoxStyle,type ColorGrade,type FrameRect,type LayoutId,@@ -610,6 +611,7 @@ function ClipPanel({ clip }: { clip: VideoClip }) {onPick={(frame, fit) => updateClip(clip.id, { frame, fit })}/><ClipTransformSection clip={clip} />+ <ClipBorderSection clip={clip} /><ClipMaskSection clip={clip} /><ClipGeneratedAudio clip={clip} /></div>@@ -2231,6 +2233,85 @@ function OverlayMaskSection({ overlay: o }: { overlay: Overlay }) {/** The clip inspector's mask target, over the clip store actions. The clip's* timeline window comes through `clipWindow` (track-0 starts derive from the* span layout). */+/** Rounded corners and a border stroke on the clip's box. The section's+ * switch turns the style on with visible defaults; off returns the clip to a+ * plain box. */+function ClipBorderSection({ clip }: { clip: VideoClip }) {+ const widthCk = useSliderCheckpoint();+ const radiusCk = useSliderCheckpoint();+ const bs = clip.boxStyle;+ const st = () => useEditor.getState();+ const write = (patch: Partial<BoxStyle>) =>+ st().updateClipTransient(clip.id, { boxStyle: { ...st().clips.find((c) => c.id === clip.id)?.boxStyle, ...patch } });+ return (+ <Section+ title="Border"+ info="Round the clip's corners and stroke a border along its box edge. Sizes are design pixels, matched between preview and export."+ enabled={!!bs}+ onEnabledChange={(v) =>+ st().updateClip(clip.id, {+ boxStyle: v ? { radius: 16, borderWidth: 6, borderColor: "#FFFFFF" } : undefined,+ })+ }+ >+ {bs && (+ <>+ <Row label="Width">+ <ScrubValue+ label="Border width"+ className="w-9 text-muted-foreground"+ value={bs.borderWidth ?? 0}+ min={0}+ max={60}+ step={1}+ format={(v) => String(Math.round(v))}+ parse={parseNumberInput}+ onScrub={(v) => {+ widthCk.begin();+ write({ borderWidth: v });+ }}+ onCommit={(v) => {+ widthCk.begin();+ write({ borderWidth: v });+ widthCk.end();+ }}+ />+ </Row>+ <Row label="Radius">+ <ScrubValue+ label="Corner radius"+ className="w-9 text-muted-foreground"+ value={bs.radius ?? 0}+ min={0}+ max={200}+ step={1}+ format={(v) => String(Math.round(v))}+ parse={parseNumberInput}+ onScrub={(v) => {+ radiusCk.begin();+ write({ radius: v });+ }}+ onCommit={(v) => {+ radiusCk.begin();+ write({ radius: v });+ radiusCk.end();+ }}+ />+ </Row>+ <Row label="Color" grow>+ <ColorSwatches+ value={bs.borderColor ?? "#FFFFFF"}+ onBegin={() => st().pushHistory()}+ onLive={(c) => write({ borderColor: c })}+ onCommit={(c) => st().updateClip(clip.id, { boxStyle: { ...bs, borderColor: c } })}+ />+ </Row>+ </>+ )}+ </Section>+ );+}+function ClipMaskSection({ clip }: { clip: VideoClip }) {const clips = useEditor((s) => s.clips);const assets = useEditor((s) => s.assets);diff --git a/site/src/cut/components/Preview.tsx b/site/src/cut/components/Preview.tsxindex 09bdbd46..40bb358e 100644--- a/site/src/cut/components/Preview.tsx+++ b/site/src/cut/components/Preview.tsx@@ -160,6 +160,29 @@ export function Preview() {return true;};+ // The topmost regioned clip under a stage point at the playhead — clicking+ // its picture selects it, in the preview and the timeline alike. Full-frame+ // clips stay out: a click on the backdrop keeps playing and pausing.+ const clipAtPoint = (e: React.MouseEvent): string | null => {+ const rct = e.currentTarget.getBoundingClientRect();+ const px = (e.clientX - rct.left) / rct.width;+ const py = (e.clientY - rct.top) / rct.height;+ const s = useEditor.getState();+ const t = s.currentTime;+ let best: { id: string; track: number } | null = null;+ for (const c of s.clips) {+ if (c.hidden) continue;+ const r = rectOf(c);+ if (isFullRect(r)) continue;+ const speed = c.speed && c.speed > 0 ? c.speed : 1;+ const len = Math.max(0.1, (c.out - c.in) / speed);+ if (t < c.start || t >= c.start + len) continue;+ if (px < r.x || px > r.x + r.w || py < r.y || py > r.y + r.h) continue;+ if (!best || c.track > best.track) best = { id: c.id, track: c.track };+ }+ return best?.id ?? null;+ };+return (<section className="preview-pane flex min-h-0 min-w-0 flex-col bg-muted/40 select-none"><div@@ -184,6 +207,9 @@ export function Preview() {e.target === e.currentTarget ||(e.target as HTMLElement).tagName === "CANVAS") {+ // A press over a regioned clip belongs to the click handler+ // below (select it); a pan gesture here would swallow the click.+ if (clipAtPoint(e)) return;panDrag(e);}}}@@ -194,6 +220,11 @@ export function Preview() {e.target === e.currentTarget ||(e.target as HTMLElement).tagName === "CANVAS") {+ const hit = clipAtPoint(e);+ if (hit) {+ useEditor.getState().select({ kind: "clip", id: hit });+ return;+ }togglePlayback();}}}@@ -252,12 +283,49 @@ export function Preview() {* overlay clip, and only while that clip is live under the playhead so it lines* up with the compositor. A full-frame layer needs no handle.*/+/** How close (screen px) a box edge pulls onto a snap line while dragging. */+const SNAP_PX = 8;++/** Snap a moving box along one axis: its leading edge, center, and trailing+ * edge each pull to the frame's edges and centerline. Returns the snapped+ * position and the frame line it landed on, for the guide. */+function snapAxis(v: number, size: number, tol: number): { v: number; guide: number | null } {+ let best = { v, guide: null as number | null, d: tol };+ for (const offset of [0, size / 2, size]) {+ for (const target of [0, 0.5, 1]) {+ const d = Math.abs(v - (target - offset));+ if (d < best.d) best = { v: target - offset, guide: target, d };+ }+ }+ return best;+}++/** The frame line nearest a resized trailing edge, within tolerance. */+function snapEdge(v: number, tol: number): number | null {+ let best: number | null = null;+ let bd = tol;+ for (const target of [0.5, 1]) {+ const d = Math.abs(v - target);+ if (d < bd) {+ bd = d;+ best = target;+ }+ }+ return best;+}+function OverlayPipHandle({ stage }: { stage: { w: number; h: number } }) {const selection = useEditor((s) => s.selection);const clips = useEditor((s) => s.clips);+ const assets = useEditor((s) => s.assets);+ const aspect = useEditor((s) => s.aspect);const currentTime = useEditor((s) => s.currentTime);const skimTime = useEditor((s) => s.skimTime);const playing = useEditor((s) => s.playing);+ const [guides, setGuides] = useState<{ x: number | null; y: number | null }>({+ x: null,+ y: null,+ });// While hover-scrubbing the preview shows the skimmer's frame, where the// selected clip may not even be on screen — selection stays, the handle hides.if (!playing && skimTime !== null) return null;@@ -267,6 +335,10 @@ function OverlayPipHandle({ stage }: { stage: { w: number; h: number } }) {// every track.let rect: FrameRect | null = null;let apply: ((frame: FrameRect) => void) | null = null;+ // A fill clip whose content overflows the box can pan its crop window: how+ // far the scaled picture overhangs the box (frame px), and the pan to start+ // the gesture from.+ let pan: { id: string; ox: number; oy: number; panX0: number; panY0: number } | null = null;if (selection?.kind === "clip") {const clip = clips.find((c) => c.id === selection.id);if (clip && !clip.hidden) {@@ -275,6 +347,18 @@ function OverlayPipHandle({ stage }: { stage: { w: number; h: number } }) {if (currentTime >= clip.start && currentTime < clip.start + len) {rect = rectOf(clip);apply = (frame) => useEditor.getState().updateClipTransient(clip.id, { frame });+ const asset = assets.find((a) => a.id === clip.assetId);+ if (clip.fit === "fill" && asset?.width && asset?.height) {+ const fr = frameOf(aspect);+ const bw = rect.w * fr.w;+ const bh = rect.h * fr.h;+ const sc = Math.max(bw / asset.width, bh / asset.height);+ const ox = asset.width * sc - bw;+ const oy = asset.height * sc - bh;+ if (ox > 1 || oy > 1) {+ pan = { id: clip.id, ox, oy, panX0: clip.panX ?? 0, panY0: clip.panY ?? 0 };+ }+ }}}}@@ -288,12 +372,17 @@ function OverlayPipHandle({ stage }: { stage: { w: number; h: number } }) {e.stopPropagation();useEditor.getState().pushHistory();startDrag(e, {- onMove: (dx, dy) =>+ onMove: (dx, dy) => {+ const sx = snapAxis(r.x + dx / stage.w, r.w, SNAP_PX / stage.w);+ const sy = snapAxis(r.y + dy / stage.h, r.h, SNAP_PX / stage.h);+ setGuides({ x: sx.guide, y: sy.guide });patch({...r,- x: Math.max(0.05 - r.w, Math.min(0.95, r.x + dx / stage.w)),- y: Math.max(0.05 - r.h, Math.min(0.95, r.y + dy / stage.h)),- }),+ x: Math.max(0.05 - r.w, Math.min(0.95, sx.v)),+ y: Math.max(0.05 - r.h, Math.min(0.95, sy.v)),+ });+ },+ onUp: () => setGuides({ x: null, y: null }),});};@@ -301,12 +390,40 @@ function OverlayPipHandle({ stage }: { stage: { w: number; h: number } }) {e.stopPropagation();useEditor.getState().pushHistory();startDrag(e, {- onMove: (dx, dy) =>- patch({- ...r,- w: Math.max(0.1, Math.min(REGION_MAX_SCALE, r.w + dx / stage.w)),- h: Math.max(0.1, Math.min(REGION_MAX_SCALE, r.h + dy / stage.h)),- }),+ onMove: (dx, dy) => {+ let w = Math.max(0.1, Math.min(REGION_MAX_SCALE, r.w + dx / stage.w));+ let h = Math.max(0.1, Math.min(REGION_MAX_SCALE, r.h + dy / stage.h));+ const gx = snapEdge(r.x + w, SNAP_PX / stage.w);+ const gy = snapEdge(r.y + h, SNAP_PX / stage.h);+ if (gx !== null && gx - r.x >= 0.1) w = gx - r.x;+ if (gy !== null && gy - r.y >= 0.1) h = gy - r.y;+ setGuides({ x: gx !== null && gx - r.x >= 0.1 ? gx : null, y: gy !== null && gy - r.y >= 0.1 ? gy : null });+ patch({ ...r, w, h });+ },+ onUp: () => setGuides({ x: null, y: null }),+ });+ };++ const panContent = pan;+ const onPanContent = (e: React.PointerEvent) => {+ if (!panContent) return;+ e.stopPropagation();+ useEditor.getState().pushHistory();+ const toFrame = frameOf(aspect).w / stage.w; // screen px → frame px+ startDrag(e, {+ onMove: (dx, dy) => {+ // Content follows the pointer; pan is the crop-window position.+ useEditor.getState().updateClipTransient(panContent.id, {+ panX:+ panContent.ox > 1+ ? Math.max(-1, Math.min(1, panContent.panX0 - (dx * toFrame) / (panContent.ox / 2)))+ : 0,+ panY:+ panContent.oy > 1+ ? Math.max(-1, Math.min(1, panContent.panY0 - (dy * toFrame) / (panContent.oy / 2)))+ : 0,+ });+ },});};@@ -325,6 +442,14 @@ function OverlayPipHandle({ stage }: { stage: { w: number; h: number } }) {style={box}onPointerDown={onMove}>+ {/* Overflowing fill content pans from the interior; the ring at the+ border moves the box, the corner resizes it. */}+ {panContent && (+ <div+ className="absolute inset-2 cursor-grab active:cursor-grabbing"+ onPointerDown={onPanContent}+ />+ )}<spanclassName="absolute -right-1.5 -bottom-1.5 z-20 size-3 cursor-nwse-resize rounded-full bg-[#0a84ff] shadow-[0_0_0_2px_white]"onPointerDown={onResize}@@ -335,6 +460,12 @@ function OverlayPipHandle({ stage }: { stage: { w: number; h: number } }) {className="absolute rounded-[3px] shadow-[inset_0_0_0_2px_#0a84ff]"style={box}/>+ {guides.x !== null && (+ <div className="absolute inset-y-0 w-px bg-[#0a84ff]" style={{ left: guides.x * stage.w }} />+ )}+ {guides.y !== null && (+ <div className="absolute inset-x-0 h-px bg-[#0a84ff]" style={{ top: guides.y * stage.h }} />+ )}</div></>);diff --git a/site/src/cut/lib/composite.ts b/site/src/cut/lib/composite.tsindex db04dc60..24b6acd2 100644--- a/site/src/cut/lib/composite.ts+++ b/site/src/cut/lib/composite.ts@@ -467,21 +467,41 @@ export class FrameCompositor {const sc = (fill ? Math.max(rw / vw, rh / vh) : Math.min(rw / vw, rh / vh)) * zoom;const dw = vw * sc;const dh = vh * sc;- const dx = rx + (rw - dw) / 2;- const dy = ry + (rh - dh) / 2;+ let dx = rx + (rw - dw) / 2;+ let dy = ry + (rh - dh) / 2;+ if (fill) {+ // Pan the crop window across the overflow (matches the export crop).+ const kx = 0.5 + Math.max(-1, Math.min(1, clip?.panX ?? 0)) / 2;+ const ky = 0.5 + Math.max(-1, Math.min(1, clip?.panY ?? 0)) / 2;+ dx = rx - (dw - rw) * kx;+ dy = ry - (dh - rh) * ky;+ }const src = this.gradedSource(frame, clip);+ const bs = clip?.boxStyle;+ // Box style lengths are design px at the 1080 short side, like masks.+ const ds = Math.min(W, H) / 1080;+ const rad = Math.max(0, (bs?.radius ?? 0) * ds);const prevAlpha = ctx.globalAlpha;ctx.globalAlpha = Math.max(0, Math.min(1, alpha));- if (fill || zoom > 1) {+ if (fill || zoom > 1 || rad > 0) {ctx.save();ctx.beginPath();- ctx.rect(rx, ry, rw, rh);+ ctx.roundRect(rx, ry, rw, rh, rad);ctx.clip();ctx.drawImage(src, dx, dy, dw, dh);ctx.restore();} else {ctx.drawImage(src, dx, dy, dw, dh);}+ if (bs?.borderWidth) {+ // Stroke inside the box edge, so the border never widens the region.+ const bw = bs.borderWidth * ds;+ ctx.strokeStyle = bs.borderColor ?? "#ffffff";+ ctx.lineWidth = bw;+ ctx.beginPath();+ ctx.roundRect(rx + bw / 2, ry + bw / 2, rw - bw, rh - bw, Math.max(0, rad - bw / 2));+ ctx.stroke();+ }ctx.globalAlpha = prevAlpha;this.applyLookPost(clip, rx, ry, rw, rh, alpha, at);}@@ -540,9 +560,11 @@ export class FrameCompositor {ctx.translate(Math.round(fx.dx ?? 0), Math.round(fx.dy ?? 0));}// A regioned track-0 clip (split-screen half) draws into its rect over the- // black frame; the full-frame path below keeps the pan-crop behavior.+ // black frame; the full-frame path below keeps the pan-crop behavior. A+ // styled box (rounded corners, border) also routes through the rect path,+ // which knows how to draw the style at full frame too.const rect = rectOf(clip ?? {});- if (!isFullRect(rect)) {+ if (!isFullRect(rect) || clip?.boxStyle) {this.drawIntoRect(frame, rect, clip?.fit === "fill", alpha, at, zoom, clip);if (hasFx) ctx.restore();return;diff --git a/site/src/cut/lib/exportClient.ts b/site/src/cut/lib/exportClient.tsindex e2826e96..1bf26ebd 100644--- a/site/src/cut/lib/exportClient.ts+++ b/site/src/cut/lib/exportClient.ts@@ -215,15 +215,31 @@ async function renderClipMaskPictures(): Promise<SpecMask | undefined> {const m = clip.mask && clip.mask.kind !== "subject" ? clip.mask : undefined;const opacityVaries = (clip.kf ?? []).some((k) => Math.abs(k.opacity - 1) > 1e-3);- if (!m && !opacityVaries) return undefined;+ const radius = clip.boxStyle?.radius ?? 0;+ if (!m && !opacityVaries && radius <= 0) return undefined;const rect = rectOf(clip);const anchor = { x: rect.x + rect.w / 2, y: rect.y + rect.h / 2 };const frame = { width: W, height: H, scale: Math.min(W, H) / 1080 };+ // Rounded corners trim coverage at the clip's box: outside the rounded box+ // everything drops, and inside it the mask keeps deciding.+ const rp = regionPx(clip.frame, W, H);+ const rb = rp+ ? { x: rp.rx - box.x, y: rp.ry - box.y, w: rp.rw, h: rp.rh }+ : { x: -box.x, y: -box.y, w: W, h: H };const canvas = document.createElement("canvas");canvas.width = box.w;canvas.height = box.h;const blobAt = (tLocal: number) => {const ctx = canvas.getContext("2d")!;+ if (radius > 0) {+ ctx.globalCompositeOperation = "source-over";+ ctx.fillStyle = "#000000";+ ctx.fillRect(0, 0, canvas.width, canvas.height);+ ctx.save();+ ctx.beginPath();+ ctx.roundRect(rb.x, rb.y, rb.w, rb.h, radius * frame.scale);+ ctx.clip();+ }if (m) {paintMaskLuma(canvas, m, tLocal, frame, anchor, box.x, box.y);} else {@@ -231,6 +247,7 @@ async function renderClipMaskPictures(ctx.fillStyle = "#ffffff";ctx.fillRect(0, 0, canvas.width, canvas.height);}+ if (radius > 0) ctx.restore();if (opacityVaries) {const v = Math.round(255 * Math.max(0, Math.min(1, clipPoseAt(clip, tLocal).opacity))@@ -260,6 +277,37 @@ async function renderClipMaskPictures(return { frames };}+/** Paint the clip's border ring — a stroked rounded rect along its box edge,+ * transparent everywhere else — sized to the segment the graph frames (the+ * full frame for track 0, the region box for overlays). The engine overlays+ * it onto the segment before fades, masks and pose, so the ring rides the+ * clip like the preview's stroke does. Null without a border. */+function renderClipBorderPng(+ clip: VideoClip,+ seg: { w: number; h: number },+ ring: { x: number; y: number; w: number; h: number },+ W: number,+ H: number+): Promise<Blob> | null {+ const bs = clip.boxStyle;+ if (!bs?.borderWidth) return null;+ const scale = Math.min(W, H) / 1080;+ const bw = bs.borderWidth * scale;+ const rad = Math.max(0, (bs.radius ?? 0) * scale);+ const canvas = document.createElement("canvas");+ canvas.width = seg.w;+ canvas.height = seg.h;+ const ctx = canvas.getContext("2d")!;+ ctx.strokeStyle = bs.borderColor ?? "#ffffff";+ ctx.lineWidth = bw;+ ctx.beginPath();+ ctx.roundRect(ring.x + bw / 2, ring.y + bw / 2, ring.w - bw, ring.h - bw, Math.max(0, rad - bw / 2));+ ctx.stroke();+ return new Promise((resolve, reject) =>+ canvas.toBlob((b) => (b ? resolve(b) : reject(new Error("Could not render the border."))), "image/png")+ );+}+/** Build the export spec + overlay PNGs from the cut. Media already lives in* the project folder — the spec references it by file name; only overlay PNGs* travel with the request. Shared by full exports and the low-res hover proxy. */@@ -341,6 +389,7 @@ async function buildExportPayload(grade: normalizeGrade(sp.clip.grade),mask: undefined as SpecMask | undefined,kf: sp.clip.kf,+ border: undefined as string | undefined,}));// Track-0 segments render at the full output frame (regioned clips pad out// to it), so their masks paint full-frame. A subject mask rides the shared@@ -362,6 +411,22 @@ async function buildExportPayload(if (pictures || subject) {clipEntries[i].mask = { ...(pictures ?? {}), ...(subject ? { subject } : {}) };}+ const rp = regionPx(c.frame, settings.width, settings.height);+ const ring = rp+ ? { x: rp.rx, y: rp.ry, w: rp.rw, h: rp.rh }+ : { x: 0, y: 0, w: settings.width, h: settings.height };+ const borderBlob = renderClipBorderPng(+ c,+ { w: settings.width, h: settings.height },+ ring,+ settings.width,+ settings.height+ );+ if (borderBlob) {+ const name = `border_c${i}.png`;+ pngs.push({ name, blob: await borderBlob });+ clipEntries[i].border = name;+ }}// The server's video graph is a sequential fold, so gaps between the@@ -444,6 +509,8 @@ async function buildExportPayload(// Pass `fit` through unset so the server's "default full-frame overlay// covers what's below" branch fires — normalizing to "fit" defeated it.fit: c.fit,+ panX: c.panX ?? 0,+ panY: c.panY ?? 0,muted: c.muted,volume: c.volume,speed: c.speed,@@ -453,6 +520,7 @@ async function buildExportPayload(lookAmount: c.lookAmount,mask: undefined as SpecMask | undefined,kf: c.kf,+ border: undefined as string | undefined,...ramp,};overlayClipOf.set(entry, c);@@ -485,6 +553,18 @@ async function buildExportPayload(if (pictures || subject) {entry.mask = { ...(pictures ?? {}), ...(subject ? { subject } : {}) };}+ const borderBlob = renderClipBorderPng(+ c,+ { w: box.w, h: box.h },+ { x: 0, y: 0, w: box.w, h: box.h },+ settings.width,+ settings.height+ );+ if (borderBlob) {+ const name = `border_ov${i}.png`;+ pngs.push({ name, blob: await borderBlob });+ entry.border = name;+ }}const audio = doc.audioClipsdiff --git a/site/src/cut/lib/types.ts b/site/src/cut/lib/types.tsindex a3497124..225ba40b 100644--- a/site/src/cut/lib/types.ts+++ b/site/src/cut/lib/types.ts@@ -214,6 +214,18 @@ export interface FrameRect {export const FULL_FRAME: FrameRect = { x: 0, y: 0, w: 1, h: 1 };+/** Decorative styling on a clip's box, off until the user turns it on:+ * rounded corners trim the picture, and a stroke draws along the box edge.+ * Lengths are design px at the 1080 short side, like mask feather/radius. */+export interface BoxStyle {+ /** Corner radius, design px. */+ radius?: number;+ /** Border stroke width, design px; 0/absent draws no stroke. */+ borderWidth?: number;+ /** Border stroke color (hex). */+ borderColor?: string;+}+/** How far a region box may oversize the frame on each axis. Oversizing is* the zoom-into-an-area move; the ceiling keeps export scale targets and* mask canvases within what ffmpeg and browser canvases handle. */@@ -378,6 +390,8 @@ export interface VideoClip {* multiplies its fitted size, rotation turns it about its center, opacity* fades it. Absent = the clip sits in its region untransformed. */kf?: OverlayKey[];+ /** Rounded corners and a border stroke on the clip's box; absent = plain. */+ boxStyle?: BoxStyle;}// Color grading (the dual-renderer math) lives in the effects kit; the modeldiff --git a/site/src/cut/server/exportPipeline.ts b/site/src/cut/server/exportPipeline.tsindex d0c72acd..f009e8b6 100644--- a/site/src/cut/server/exportPipeline.ts+++ b/site/src/cut/server/exportPipeline.ts@@ -35,7 +35,7 @@ export interface ExportSpec {volume?: number;/** "fit" letterboxes (default); "fill" covers the region and crops. */fit?: "fit" | "fill";- panX?: number; // crop-window pan -1..1 (fill mode, full frame)+ panX?: number; // crop-window pan -1..1 (fill mode)panY?: number;/** Region of the frame this clip fills; absent = full frame. */frame?: { x: number; y: number; w: number; h: number };@@ -78,6 +78,10 @@ export interface ExportSpec {* turns it. Opacity keys ride the painted mask's luma, so the graph* never needs an animatable alpha filter. */kf?: { t: number; x: number; y: number; scale: number; rotation: number; opacity: number }[];+ /** Client-painted border ring (a stroked rounded rect along the clip's+ * box, transparent elsewhere), full-frame sized; overlaid onto the+ * segment before fades, masks and pose so it rides the clip. */+ border?: string;}[];/** Video tracks composited over the track-0 `clips`, lowest track first. */overlayVideos?: {@@ -89,6 +93,8 @@ export interface ExportSpec {/** Region of the frame this overlay fills; absent = full frame. */frame?: { x: number; y: number; w: number; h: number };fit?: "fit" | "fill";+ panX?: number; // crop-window pan -1..1 (fill mode)+ panY?: number;muted: boolean;/** Gain on the clip's own audio, 0..1.5; absent = 1 (unchanged). */volume?: number;@@ -121,6 +127,10 @@ export interface ExportSpec {};/** Keyframed pose track, seconds from this overlay's start. */kf?: { t: number; x: number; y: number; scale: number; rotation: number; opacity: number }[];+ /** Client-painted border ring, box-sized (a letterboxed segment pads out+ * to its box when bordered); overlaid onto the segment so it rides the+ * clip through fades, masks and pose. */+ border?: string;}[];audio: {file: string;@@ -513,6 +523,26 @@ export async function runExport(const idx = await maskInput(oc.mask, olen, `mask_ovl_${k}`);if (idx !== undefined) overlayMaskInput.set(oc, idx);}+ // Border rings loop as stills for their segment's length, like mask files.+ const borderStill = (file: string, dur: number): number => {+ const idx = nInputs++;+ inputs.push("-loop", "1", "-t", num(dur), "-framerate", String(fps), "-i", path.join(job.tmpDir, path.basename(file)));+ return idx;+ };+ const clipBorderInput = new Map<number, number>();+ for (let j = 0; j < spec.clips.length; j++) {+ const c = spec.clips[j];+ if (!c.border) continue;+ const dur = c.file ? Math.max(0.1, (c.out - c.in) / clipRate(c)) : Math.max(0, c.out - c.in);+ clipBorderInput.set(j, borderStill(c.border, dur));+ }+ const overlayBorderInput = new Map<(typeof overlayVideos)[number], number>();+ for (const oc of overlayVideos) {+ if (!oc.border) continue;+ const ospeed = oc.speed && oc.speed > 0 ? oc.speed : 1;+ const olen = Math.max(0.1, (oc.out - oc.in) / ospeed);+ overlayBorderInput.set(oc, borderStill(oc.border, olen));+ }// One concat-demuxer input per subtitle track: within a track cues never// overlap, so each plays as a slideshow with transparent filler@@ -910,7 +940,9 @@ export async function runExport(const win = bw > W || bh > H ? `,crop=${W}:${H}:${-bx}:${-by}` : "";frame =c.fit === "fill"- ? `scale=${rw}:${rh}:force_original_aspect_ratio=increase,crop=${rw}:${rh},` ++ ? `scale=${rw}:${rh}:force_original_aspect_ratio=increase,` ++ `crop=${rw}:${rh}:(iw-ow)*${num(0.5 + Math.max(-1, Math.min(1, c.panX ?? 0)) / 2)}` ++ `:(ih-oh)*${num(0.5 + Math.max(-1, Math.min(1, c.panY ?? 0)) / 2)},` +`pad=${bw}:${bh}:${rx - bx}:${ry - by}:color=${padColor}${win}`: `scale=${rw}:${rh}:force_original_aspect_ratio=decrease:force_divisible_by=2,` +`pad=${bw}:${bh}:${rx - bx}+(${rw}-iw)/2:${ry - by}+(${rh}-ih)/2:color=${padColor}${win}`;@@ -939,6 +971,14 @@ export async function runExport(core = `[lko${j}]null`;}}+ // The border ring lands after the look (true stroke color) and before+ // the fades, so it fades and masks with the clip like the preview.+ const brIdx = clipBorderInput.get(j);+ if (brIdx !== undefined) {+ filters.push(`${core}[cbi${j}]`);+ filters.push(`[cbi${j}][${brIdx}:v]overlay=0:0:eof_action=pass,format=${clipFmt}[cbo${j}]`);+ core = `[cbo${j}]null`;+ }const fades =(hf > 0.01 ? `,fade=t=in:st=0:d=${num(hf)}` : "") +(tf > 0.01 ? `,fade=t=out:st=${num(Math.max(0, dur - tf))}:d=${num(tf)}` : "");@@ -1183,15 +1223,20 @@ export async function runExport(const boxH = region ? region.rh : H;let framing: string;let pos: string;+ // A fill overlay's crop window follows the clip's pan, matching the+ // preview compositor.+ const panCrop =+ `:(iw-ow)*${num(0.5 + Math.max(-1, Math.min(1, oc.panX ?? 0)) / 2)}` ++ `:(ih-oh)*${num(0.5 + Math.max(-1, Math.min(1, oc.panY ?? 0)) / 2)}`;if (!region) {framing = cover- ? `scale=${W}:${H}:force_original_aspect_ratio=increase,crop=${W}:${H}`+ ? `scale=${W}:${H}:force_original_aspect_ratio=increase,crop=${W}:${H}${panCrop}`: `scale=${W}:${H}:force_original_aspect_ratio=decrease:force_divisible_by=2`;pos = cover ? "0:0" : `x=(${W}-w)/2:y=(${H}-h)/2`;} else {const { rx, ry, rw, rh } = region;framing = cover- ? `scale=${rw}:${rh}:force_original_aspect_ratio=increase,crop=${rw}:${rh}`+ ? `scale=${rw}:${rh}:force_original_aspect_ratio=increase,crop=${rw}:${rh}${panCrop}`: `scale=${rw}:${rh}:force_original_aspect_ratio=decrease:force_divisible_by=2`;pos = cover ? `${rx}:${ry}` : `x=${rx}+(${rw}-w)/2:y=${ry}+(${rh}-h)/2`;}@@ -1201,7 +1246,10 @@ export async function runExport(// overlay at the box origin. The pad joins the chain after the look// bakes in, so the look grades the opaque scaled picture and never// flattens the transparent margins.- const boxed = (ramped || maskIdx !== undefined || !!subjMask || keyed) && !cover;+ // A bordered letterboxed segment also pads to its box: the ring strokes+ // the box edge, so the segment must span the box to carry it.+ const boxed =+ (ramped || maskIdx !== undefined || !!subjMask || keyed || !!oc.border) && !cover;const boxPad = boxed? `,format=yuva420p,pad=${boxW}:${boxH}:(ow-iw)/2:(oh-ih)/2:[email protected]`: "";@@ -1232,6 +1280,14 @@ export async function runExport(}}if (boxPad) core += boxPad;+ // The border ring lands after the look and box pad, before the edge+ // ramps, so it fades and masks with the clip like the preview.+ const obIdx = overlayBorderInput.get(oc);+ if (obIdx !== undefined) {+ filters.push(`${core}[obi${k}]`);+ filters.push(`[obi${k}][${obIdx}:v]overlay=0:0:eof_action=pass,format=${fmt}[obo${k}]`);+ core = `[obo${k}]null`;+ }const pre = `ovp${k}`;pushEdgeFx(core,