Self-hosted, Self-Improving, Federated Everything App — dev management, agent orchestration, persistent mind, digital twin, second brain, and creative pipeline from a single dashboard over Tailscale to port the user into the OS
JavaScript ai-agentsdashboarddeveloper-toolsdigital-twinquantified-selfsecond-brainself-hostedtailscale
compress a clamped overlay fade the same way in preview and export
[._.]/ Adam Eivyb4b330c7c214
diff --git a/client/src/lib/videoTimelineModel.js b/client/src/lib/videoTimelineModel.jsindex 55a663c79c..694563bd08 100644--- a/client/src/lib/videoTimelineModel.js+++ b/client/src/lib/videoTimelineModel.js@@ -75,6 +75,21 @@ export const fadeMultiplier = (fadeInSec, fadeOutSec, duration, within) => {return Math.min(1, Math.max(0, m));};+/**+ * Shrink a fade pair that no longer fits `duration`, scaling both+ * proportionally so the author's balance survives. Mirrors `fitFades` in+ * server/services/videoTimeline/segments.js — the export and the preview must+ * compress an over-long pair the same way or they ramp differently.+ */+export function fitFades(fadeInSec, fadeOutSec, duration) {+ const fin = Math.max(0, Number(fadeInSec) || 0);+ const fout = Math.max(0, Number(fadeOutSec) || 0);+ const span = fin + fout;+ if (span <= duration || span === 0) return { fadeInSec: fin, fadeOutSec: fout };+ const scale = Math.max(0, duration) / span;+ return { fadeInSec: fin * scale, fadeOutSec: fout * scale };+}+/*** Effective opacity of an overlay at project-time `t` — 0 outside its window,* its configured opacity inside, scaled by whichever alpha fade is active.@@ -91,7 +106,12 @@ export const overlayOpacityAt = (overlay, t, limitSec = Infinity) => {const dur = end - start;if (dur <= 0 || t < start || t > end) return 0;const base = overlay.opacity == null ? 1 : overlay.opacity;- return base * fadeMultiplier(overlay.fadeInSec || 0, overlay.fadeOutSec || 0, dur, t - start);+ // Refit against the VISIBLE span, exactly as the export does: a clamped+ // window can be shorter than the fades authored for the full one, and the+ // two sides must compress them the same way or the preview and the render+ // ramp differently over the overlay's last seconds.+ const { fadeInSec, fadeOutSec } = fitFades(overlay.fadeInSec || 0, overlay.fadeOutSec || 0, dur);+ return base * fadeMultiplier(fadeInSec, fadeOutSec, dur, t - start);};/**@@ -177,8 +197,7 @@ export function fitFadePatch(entry, patch, duration) {const fin = Math.max(0, merged.fadeInSec || 0);const fout = Math.max(0, merged.fadeOutSec || 0);if (fin + fout <= duration) return patch;- const scale = fin + fout > 0 ? Math.max(0, duration) / (fin + fout) : 0;- return { ...patch, fadeInSec: fin * scale, fadeOutSec: fout * scale };+ return { ...patch, ...fitFades(fin, fout, duration) };}/**@@ -202,6 +221,11 @@ export function clampTrim(segment, patch, sourceDur, fps) {* project's clip-audio multiplier, the segment's own trim, and its fade ramp,* exactly as the export composes them (`volume=` ahead of `afade` in the* segment's audio chain).+ *+ * Capped at 1: the server allows a multiplier up to MAX_VOLUME, but+ * HTMLMediaElement.volume cannot exceed 1, so a boosted mix auditions quieter+ * than it renders. The browser has no way to match that — the cap is the+ * honest ceiling, not a rule the export shares.*/export const segmentVolumeAt = (segment, clipVolume, within) => {if (!segment || segment.type === 'still') return 0;diff --git a/client/src/lib/videoTimelineModel.test.js b/client/src/lib/videoTimelineModel.test.jsindex 6b346f99f1..8fa3029388 100644--- a/client/src/lib/videoTimelineModel.test.js+++ b/client/src/lib/videoTimelineModel.test.js@@ -313,3 +313,24 @@ describe('canvasAspectRatio — the preview must match the export canvas', () =>.toBeCloseTo(1920 / 1080);});});++describe('overlay fade parity when the timeline clamps the window', () => {+ // 5s timeline, overlay starting at 4.5s with a 3s body and a 2s fade-out:+ // the window is cut to 0.5s, so the 2s fade cannot run as authored. Preview+ // and export must compress it identically or the render pops off on the+ // last frame while the editor showed it already gone.+ const overlay = { startSec: 4.5, durationSec: 3, opacity: 1, fadeInSec: 0, fadeOutSec: 2 };++ it('compresses the fade into the visible window, reaching zero exactly at the end', () => {+ expect(overlayOpacityAt(overlay, 4.5, 5)).toBe(1);+ expect(overlayOpacityAt(overlay, 4.75, 5)).toBeCloseTo(0.5);+ expect(overlayOpacityAt(overlay, 5, 5)).toBe(0);+ });++ it('leaves an unclamped overlay on its authored ramp', () => {+ // Window [4.5, 7.5]; the 2s ramp therefore runs 5.5s → 7.5s.+ expect(overlayOpacityAt(overlay, 5.5, 30)).toBe(1);+ expect(overlayOpacityAt(overlay, 6.5, 30)).toBeCloseTo(0.5);+ expect(overlayOpacityAt(overlay, 7.5, 30)).toBe(0);+ });+});diff --git a/client/src/pages/VideoTimelineEditor.jsx b/client/src/pages/VideoTimelineEditor.jsxindex bf2174378c..d849af99e9 100644--- a/client/src/pages/VideoTimelineEditor.jsx+++ b/client/src/pages/VideoTimelineEditor.jsx@@ -53,6 +53,13 @@ const DEFAULT_BED_SEC = 10;const MIN_ENTRY_SEC = 0.05;const MAX_ENTRY_SEC = 600;const MAX_VOLUME = 4;+// Mirrors MAX_SEGMENTS / MAX_OVERLAYS / MAX_AUDIO_TRACKS in+// server/services/videoTimeline/segments.js.+const LANE_CAPS = {+ segment: { max: 200, label: 'Video lane' },+ overlay: { max: 50, label: 'Overlay lane' },+ audio: { max: 20, label: 'Audio lane' },+};const LIBRARY_TABS = [{ id: 'clips', label: 'Clips', Icon: Film },@@ -285,8 +292,22 @@ export default function VideoTimelineEditor() {));}, [updateLanes]);+ // Refuse the add at the cap rather than letting it through: the server's Zod+ // gate 400s the whole PATCH, so one entry over the limit makes EVERY+ // subsequent debounced save fail with a message that names no lane, and the+ // user has to guess which one to trim.const addToLane = useCallback((lane, entry) => {- updateLanes((prev) => withLaneEntries(prev, lane, [...laneEntries(prev, lane), entry]));+ let added = false;+ updateLanes((prev) => {+ const entries = laneEntries(prev, lane);+ if (entries.length >= LANE_CAPS[lane].max) return prev;+ added = true;+ return withLaneEntries(prev, lane, [...entries, entry]);+ });+ if (!added) {+ toast.error(`${LANE_CAPS[lane].label} limit reached (${LANE_CAPS[lane].max}) — remove one first`);+ return;+ }setSelection({ lane, key: entry._key });}, [updateLanes]);diff --git a/server/services/videoTimeline/local.js b/server/services/videoTimeline/local.jsindex 808137b6f4..e25f7cce34 100644--- a/server/services/videoTimeline/local.js+++ b/server/services/videoTimeline/local.js@@ -295,7 +295,10 @@ export async function resolveTimeline(rawProject) {if (seg.type === 'still') {const assetPath = resolveAsset(seg.assetKind, seg.assetFile, { allowedKinds: IMAGE_ASSET_KINDS });if (!assetPath) { missingAssets.push(`${seg.assetKind}/${seg.assetFile}`); continue; }- prepared.push({ kind: 'still', i, seg, assetPath, duration: seg.durationSec });+ prepared.push({+ kind: 'still', i, seg, assetPath, duration: seg.durationSec,+ fades: fitFades(seg.fadeInSec, seg.fadeOutSec, seg.durationSec),+ });continue;}const entry = historyMap.get(seg.clipId);@@ -371,8 +374,8 @@ export async function resolveTimeline(rawProject) {assetFile: p.seg.assetFile,assetPath: p.assetPath,duration: p.duration,- fadeInSec: p.seg.fadeInSec,- fadeOutSec: p.seg.fadeOutSec,+ fadeInSec: p.fades.fadeInSec,+ fadeOutSec: p.fades.fadeOutSec,}: {type: 'clip',@@ -391,7 +394,14 @@ export async function resolveTimeline(rawProject) {volume: p.seg.volume,}));- const firstClip = resolvedSegments.find((seg) => seg.type === 'clip');+ // Pick the geometry off the first clip that actually HAS dimensions. An+ // uploaded or downloaded clip carries no width/height (videoUpload.js /+ // videoDownload.js write no dims), so taking the first clip unconditionally+ // would letterbox a whole project into the 720p fallback because of one+ // dims-less entry — and the editor's preview, which skips those, would then+ // show a different canvas than the render produces.+ const firstClip = resolvedSegments.find((seg) => seg.type === 'clip' && seg.width > 0 && seg.height > 0);+ const firstFps = resolvedSegments.find((seg) => seg.type === 'clip' && seg.fps > 0);return {segments: resolvedSegments,overlays,@@ -401,7 +411,7 @@ export async function resolveTimeline(rawProject) {// rather than letting scale/pad inherit `undefined` and fail the graph.canonW: firstClip?.width || DEFAULT_CANVAS.width,canonH: firstClip?.height || DEFAULT_CANVAS.height,- fps: firstClip?.fps || DEFAULT_CANVAS.fps,+ fps: firstFps?.fps || DEFAULT_CANVAS.fps,};}@@ -521,11 +531,17 @@ export function buildFfmpegArgs(timeline, outputPath, { colorTagFilter = null }const x = Math.round(ov.x * canonW);const y = Math.round(ov.y * canonH);const end = Math.min(totalDuration, ov.startSec + ov.durationSec);+ // An overlay running past the end of the video lane has its window cut+ // short, which can leave its fades longer than the window itself. Refit+ // them against the VISIBLE span — the same rule the preview applies — or+ // the ramp never completes before `enable` cuts the overlay off, and the+ // render pops from most-of-opaque to nothing on the last frame.+ const fades = fitFades(ov.fadeInSec, ov.fadeOutSec, end - ov.startSec);const chain = [`scale=${w}:-2`, `fps=${fps}`, 'format=rgba'];if (ov.opacity < 1) chain.push(`colorchannelmixer=aa=${fmt(ov.opacity)}`);- if (ov.fadeInSec > 0) chain.push(`fade=t=in:st=${fmt(ov.startSec)}:d=${fmt(ov.fadeInSec)}:alpha=1`);- if (ov.fadeOutSec > 0) {- chain.push(`fade=t=out:st=${fmt(Math.max(ov.startSec, end - ov.fadeOutSec))}:d=${fmt(ov.fadeOutSec)}:alpha=1`);+ if (fades.fadeInSec > 0) chain.push(`fade=t=in:st=${fmt(ov.startSec)}:d=${fmt(fades.fadeInSec)}:alpha=1`);+ if (fades.fadeOutSec > 0) {+ chain.push(`fade=t=out:st=${fmt(end - fades.fadeOutSec)}:d=${fmt(fades.fadeOutSec)}:alpha=1`);}filters.push(`[${oIdx}:v]${chain.join(',')}[ov${j}]`);const out = j === overlays.length - 1 ? videoOut : `[ovc${j}]`;diff --git a/server/services/videoTimeline/local.test.js b/server/services/videoTimeline/local.test.jsindex 47d5adae71..c71bb7fd45 100644--- a/server/services/videoTimeline/local.test.js+++ b/server/services/videoTimeline/local.test.js@@ -411,3 +411,42 @@ describe('buildFfmpegArgs — BT.709 frame tagging', () => {expect(args).toContain('-color_primaries');});});++describe('buildFfmpegArgs — an overlay clamped by the timeline end', () => {+ const clampedOverlay = {+ type: 'image', assetKind: 'images', assetFile: 'logo.png', assetPath: '/logo.png',+ startSec: 4.5, durationSec: 3, x: 0, y: 0, width: 0.5, opacity: 1, fadeInSec: 0, fadeOutSec: 2,+ };++ it('compresses the fade-out into the visible window so the ramp completes', () => {+ // The window is cut from 3s to 0.5s; keeping d=2 would leave the overlay+ // at ~75% when `enable` cuts it off — a pop on the final frame, and a+ // divergence from the preview, which ramps to zero at the end.+ const filter = filterOf(buildFfmpegArgs(lane([baseClip({ duration: 5, outSec: 5 })], {+ overlays: [clampedOverlay],+ }), '/out.mp4').args);++ expect(filter).toContain('fade=t=out:st=4.5:d=0.5:alpha=1');+ expect(filter).toContain("enable='between(t,4.5,5)'");+ });++ it('leaves an overlay that fits on its authored ramp', () => {+ const filter = filterOf(buildFfmpegArgs(lane([baseClip({ duration: 30, outSec: 30 })], {+ overlays: [clampedOverlay],+ }), '/out.mp4').args);+ expect(filter).toContain('fade=t=out:st=5.5:d=2:alpha=1');+ });+});++describe('buildFfmpegArgs — canonical geometry', () => {+ it('is taken from the timeline, which skips a clip carrying no dimensions', () => {+ // An uploaded or downloaded clip has no width/height in history; letting+ // it decide the canvas would letterbox the whole project into 720p and+ // disagree with the editor's preview, which skips those too.+ const { canonW, canonH } = buildFfmpegArgs({+ segments: [baseClip({ width: undefined, height: undefined }), baseClip({ width: 1080, height: 1920 })],+ canonW: 1080, canonH: 1920, fps: 24,+ }, '/out.mp4');+ expect([canonW, canonH]).toEqual([1080, 1920]);+ });+});diff --git a/server/services/videoTimeline/segments.js b/server/services/videoTimeline/segments.jsindex 70ac5473e7..ace8ca213e 100644--- a/server/services/videoTimeline/segments.js+++ b/server/services/videoTimeline/segments.js@@ -126,6 +126,14 @@ const clampFades = (fadeInSec, fadeOutSec, duration, label) => {return { fadeInSec: fin, fadeOutSec: fout };};+// `data/images` also holds `*.metadata.json` sidecars, and `data/music` holds+// whatever the user dropped there. Without an extension gate those are+// acceptable asset references that only fail at render time as a bare+// `ffmpeg exit 1`; refusing them here turns that into a 400 naming the field.+const IMAGE_EXTENSIONS = ['.png', '.jpg', '.jpeg', '.webp', '.gif', '.bmp'];+const AUDIO_EXTENSIONS = ['.mp3', '.wav', '.m4a', '.aac', '.flac', '.ogg', '.opus'];+const extensionsFor = (kinds) => (kinds === AUDIO_ASSET_KINDS ? AUDIO_EXTENSIONS : IMAGE_EXTENSIONS);+const assetFields = (raw, allowedKinds, label) => {const assetKind = String(raw.assetKind || '').trim();if (!allowedKinds.includes(assetKind)) {@@ -138,6 +146,10 @@ const assetFields = (raw, allowedKinds, label) => {if (!assetPathFor(assetKind, assetFile)) {throw bad(`${label}: assetFile must be a plain filename inside data/${assetKind}`);}+ const extensions = extensionsFor(allowedKinds);+ if (!extensions.some((ext) => assetFile.toLowerCase().endsWith(ext))) {+ throw bad(`${label}: assetFile must be one of ${extensions.join(', ')}`);+ }return { assetKind, assetFile };};diff --git a/server/services/videoTimeline/segments.test.js b/server/services/videoTimeline/segments.test.jsindex e836dfffe3..a8f20a1517 100644--- a/server/services/videoTimeline/segments.test.js+++ b/server/services/videoTimeline/segments.test.js@@ -276,3 +276,25 @@ describe('reconcileLegacyMirror — a legacy trim must not strand an over-long fexpect(() => validateSegments(v2.segments)).not.toThrow();});});++describe('asset extension gate', () => {+ it('refuses an image sidecar that lives in the same directory as the gallery', () => {+ // data/images also holds *.metadata.json; without this it is an acceptable+ // still that only fails at render as a bare `ffmpeg exit 1`.+ expect(() => validateSegments([{ type: 'still', assetKind: 'images', assetFile: 'shot.metadata.json', durationSec: 2 }]))+ .toThrow(/assetFile must be one of/);+ });++ it('refuses an image where an audio track is expected, and vice versa', () => {+ expect(() => validateAudio({ tracks: [{ assetKind: 'music', assetFile: 'cover.png', startSec: 0, durationSec: 2 }] }))+ .toThrow(/assetFile must be one of/);+ expect(() => validateOverlays([{ assetKind: 'images', assetFile: 'bed.mp3', startSec: 0, durationSec: 2 }]))+ .toThrow(/assetFile must be one of/);+ });++ it('accepts the formats each lane actually renders, case-insensitively', () => {+ expect(() => validateSegments([{ type: 'still', assetKind: 'images', assetFile: 'PLATE.PNG', durationSec: 2 }])).not.toThrow();+ expect(() => validateOverlays([{ assetKind: 'images', assetFile: 'logo.webp', startSec: 0, durationSec: 2 }])).not.toThrow();+ expect(() => validateAudio({ tracks: [{ assetKind: 'audio', assetFile: 'vo.wav', startSec: 0, durationSec: 2 }] })).not.toThrow();+ });+});