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
Add film and camera effects to music video cuts and shots (#11470)
[._.]/75156b2ff84f
diff --git a/client/src/components/musicVideo/SceneCard.test.jsx b/client/src/components/musicVideo/SceneCard.test.jsxindex 8e0337ba8a..885436ab3f 100644--- a/client/src/components/musicVideo/SceneCard.test.jsx+++ b/client/src/components/musicVideo/SceneCard.test.jsx@@ -503,13 +503,13 @@ describe('VHS glitch transitions', () => {return <SceneCard scene={scene} index={0} onEditLocal={(_id, patch) => setScene((current) => ({ ...current, ...patch }))} onSave={onSave} />;}render(<Harness />);- const out = screen.getByLabelText('Glitch out');+ const out = screen.getByLabelText('Effect out');fireEvent.change(out, { target: { value: 'vhs-glitch' } });expect(onSave).toHaveBeenLastCalledWith('s1', { transitionOut: 'vhs-glitch' });expect(out.value).toBe('vhs-glitch');fireEvent.change(out, { target: { value: '' } });expect(onSave).toHaveBeenLastCalledWith('s1', { transitionOut: null });- expect(screen.getByLabelText('Glitch in').value).toBe('');+ expect(screen.getByLabelText('Effect in').value).toBe('');});});@@ -523,15 +523,15 @@ describe('In-shot glitches', () => {return <SceneCard scene={scene} index={0} onEditLocal={(_id, patch) => setScene((current) => ({ ...current, ...patch }))} onSave={onSave} />;}render(<Harness />);- fireEvent.click(screen.getByRole('button', { name: /Add glitch/ }));+ fireEvent.click(screen.getByRole('button', { name: /Add effect/ }));expect(onSave).toHaveBeenLastCalledWith('s1', { glitches: [{ atSec: 2, style: 'color-block' }] });const slider = screen.getByLabelText(/^at /);fireEvent.change(slider, { target: { value: '2.5' } });fireEvent.pointerUp(slider);expect(onSave).toHaveBeenLastCalledWith('s1', { glitches: [{ atSec: 2.5, style: 'color-block' }] });- fireEvent.change(screen.getByLabelText('Glitch 1 length'), { target: { value: '0.5' } });+ fireEvent.change(screen.getByLabelText('Effect 1 length'), { target: { value: '0.5' } });expect(onSave).toHaveBeenLastCalledWith('s1', { glitches: [{ atSec: 2.5, style: 'color-block', lengthSec: 0.5 }] });- fireEvent.click(screen.getByRole('button', { name: 'Remove glitch 1' }));+ fireEvent.click(screen.getByRole('button', { name: 'Remove effect 1' }));expect(onSave).toHaveBeenLastCalledWith('s1', { glitches: null });});});diff --git a/client/src/components/musicVideo/SceneGlitches.jsx b/client/src/components/musicVideo/SceneGlitches.jsxindex 30be48e63a..947ab5cda1 100644--- a/client/src/components/musicVideo/SceneGlitches.jsx+++ b/client/src/components/musicVideo/SceneGlitches.jsx@@ -18,7 +18,7 @@ function GlitchRow({ fieldId, index, glitch, spanSec, onCommit, onRemove, disablconst id = (name) => fieldId(`glitch-${index}-${name}`);return (<li className="flex flex-wrap items-center gap-x-2 gap-y-1">- <label htmlFor={id('style')} className="sr-only">Glitch {index + 1} style</label>+ <label htmlFor={id('style')} className="sr-only">Effect {index + 1} style</label><select id={id('style')} value={glitch.style} disabled={disabled}onChange={(e) => onCommit({ style: e.target.value })}className="min-w-0 bg-port-bg border border-port-border rounded px-1 py-1 text-xs min-h-[44px] sm:min-h-0 disabled:opacity-50">@@ -31,14 +31,14 @@ function GlitchRow({ fieldId, index, glitch, spanSec, onCommit, onRemove, disablonPointerUp={commitTime} onKeyUp={commitTime} onBlur={commitTime}className="min-w-0 flex-1 accent-port-accent min-h-[44px] sm:min-h-0" /></span>- <label htmlFor={id('length')} className="sr-only">Glitch {index + 1} length</label>- <select id={id('length')} value={glitch.lengthSec ?? ''} disabled={disabled} title="How long the glitch lasts"+ <label htmlFor={id('length')} className="sr-only">Effect {index + 1} length</label>+ <select id={id('length')} value={glitch.lengthSec ?? ''} disabled={disabled} title="How long the effect lasts"onChange={(e) => onCommit({ lengthSec: e.target.value === '' ? null : Number(e.target.value) })}className="bg-port-bg border border-port-border rounded px-1 py-1 text-xs min-h-[44px] sm:min-h-0 disabled:opacity-50"><option value="">Short</option>{MUSIC_VIDEO_GLITCH_LENGTHS.map((sec) => <option key={sec} value={sec}>{LENGTH_LABELS[sec] || `${sec} s`}</option>)}</select>- <button type="button" onClick={onRemove} disabled={disabled} aria-label={`Remove glitch ${index + 1}`}+ <button type="button" onClick={onRemove} disabled={disabled} aria-label={`Remove effect ${index + 1}`}className="inline-flex min-h-[44px] min-w-[44px] items-center justify-center rounded text-port-text-muted hover:text-port-error sm:min-h-[28px] sm:min-w-[28px] disabled:opacity-50"><X size={14} aria-hidden="true" /></button>@@ -61,11 +61,11 @@ export default function SceneGlitches({ fieldId, scene, onChange, disabled = falreturn (<div className="space-y-1 text-xs" data-testid="scene-glitches"><div className="flex items-center gap-2">- <span className={glitches.length ? 'text-port-accent' : 'text-port-text-muted'}>Glitches</span>+ <span className={glitches.length ? 'text-port-accent' : 'text-port-text-muted'}>Effects</span>{glitches.length < MUSIC_VIDEO_SHOT_GLITCH_LIMIT && (<button type="button" onClick={add} disabled={disabled}className="inline-flex min-h-[44px] items-center gap-1 rounded border border-port-border px-2 text-port-text-muted hover:text-port-text sm:min-h-[28px] disabled:opacity-50">- <Plus size={12} aria-hidden="true" /> Add glitch+ <Plus size={12} aria-hidden="true" /> Add effect</button>)}</div>diff --git a/client/src/components/musicVideo/SceneTransitions.jsx b/client/src/components/musicVideo/SceneTransitions.jsxindex 1e5c25b37d..e25674a3c4 100644--- a/client/src/components/musicVideo/SceneTransitions.jsx+++ b/client/src/components/musicVideo/SceneTransitions.jsx@@ -1,12 +1,12 @@import { MUSIC_VIDEO_TRANSITIONS, MUSIC_VIDEO_TRANSITION_LABELS } from '../../lib/musicVideoTransitions.js';const SIDES = Object.freeze([- ['transitionIn', 'Glitch in', 'in', 'A VHS glitch over the cut into this shot. It adds no time: the cut stays where it is.'],- ['transitionOut', 'Glitch out', 'out', 'A VHS glitch over the cut to the next shot. It adds no time: the cut stays where it is.'],+ ['transitionIn', 'Effect in', 'in', 'A glitch, film or camera effect over the cut into this shot. It adds no time: the cut stays where it is.'],+ ['transitionOut', 'Effect out', 'out', 'A glitch, film or camera effect over the cut to the next shot. It adds no time: the cut stays where it is.'],]);/**- * The VHS glitch over the cut into and out of a shot, Off by default. It rides+ * The effect over the cut into and out of a shot (a VHS glitch, a film or camera look), Off by default. It rides* on the cut in the animatic and the final render alike, and never moves a cut* or changes a lock.*/diff --git a/client/src/components/musicVideo/TransitionGlitch.jsx b/client/src/components/musicVideo/TransitionGlitch.jsxindex 24dfcaa516..dc8ff572ac 100644--- a/client/src/components/musicVideo/TransitionGlitch.jsx+++ b/client/src/components/musicVideo/TransitionGlitch.jsx@@ -1,6 +1,6 @@import { useCallback, useEffect, useMemo, useRef } from 'react';import {- blockBox, mergeGlitchFrames, sceneImageEffectGlitchFrames, sceneShotGlitchFrames, sceneTransitionSections, transitionFrameAt, transitionGlitchFrames,+ blockBox, edgeGlows, mergeGlitchFrames, sceneImageEffectGlitchFrames, sceneShotGlitchFrames, sceneTransitionSections, transitionFrameAt, transitionGlitchFrames,} from '../../lib/musicVideoTransitions.js';// The canvas paints at most this wide; a glitch lasts a few frames, so detail past it is never seen.@@ -205,6 +205,17 @@ function paintGlitch(canvas, figure, params, frame) {out.fillStyle = `#${b.color}`;out.fillRect(box.x, box.y, box.w, box.h);}+ for (const glow of edgeGlows(params.glows)) {+ const reach = glow.size * (glow.side === 'left' || glow.side === 'right' ? width : height);+ const [x0, y0, x1, y1] = glow.side === 'left' ? [0, 0, reach, 0] : glow.side === 'right' ? [width, 0, width - reach, 0]+ : glow.side === 'top' ? [0, 0, 0, reach] : [0, height, 0, height - reach];+ const ramp = out.createLinearGradient(x0, y0, x1, y1);+ ramp.addColorStop(0, `#${glow.color}`);+ ramp.addColorStop(1, `#${glow.color}00`);+ out.globalAlpha = glow.alpha;+ out.fillStyle = ramp;+ out.fillRect(0, 0, width, height);+ }out.globalAlpha = 1;for (const bar of [...(params.bar ? [params.bar] : []), ...(params.bars || [])]) {out.fillStyle = `rgba(255,255,255,${bar.alpha})`;diff --git a/client/src/lib/README.md b/client/src/lib/README.mdindex 9772984877..e58bbf6974 100644--- a/client/src/lib/README.md+++ b/client/src/lib/README.md@@ -319,4 +319,4 @@ grep -i "what you want to do" client/src/lib/README.md| `musicVideoNarrativeEvents.js` | Named narrative event kinds, absolute onset/word/frame resolution and deterministic silence/reactive state for composition documents. || `musicVideoImageEffects.js` | Music-video image effects (a camera flash that develops over a still shot), re-exported from `server/lib/musicVideoImageEffects.js`: the effects, labels and develop lengths, `sceneImageEffect`, `imageEffectState`. Used by `components/musicVideo/SceneImageEffect.jsx` and the storyboard animatic. || `musicVideoCutEffects.js` | Music-video cut effects (the beat toggle across a cut), re-exported from `server/lib/musicVideoCutEffects.js`: settings, labels, `sceneCutEffect`, `sceneBeatToggles`. Used by `components/musicVideo/SceneCutEffect.jsx` and the storyboard animatic. |-| `musicVideoTransitions.js` | Music-video cut transitions (VHS glitches over a cut), re-exported from `server/lib/musicVideoTransitions.js`: the styles and labels, `sceneTransitionSections`, `transitionGlitchFrames`, `transitionFrameAt`, in-shot glitches (`sceneShotGlitchFrames`). Used by `components/musicVideo/SceneTransitions.jsx`, `SceneGlitches.jsx` and the storyboard animatic. |+| `musicVideoTransitions.js` | Music-video cut transitions (VHS glitches over a cut), re-exported from `server/lib/musicVideoTransitions.js`: the styles and labels, `sceneTransitionSections`, `transitionGlitchFrames`, `transitionFrameAt`, in-shot glitches (`sceneShotGlitchFrames`), `blockBox` and `edgeGlows` for painting. Used by `components/musicVideo/SceneTransitions.jsx`, `SceneGlitches.jsx` and the storyboard animatic. |diff --git a/client/src/lib/musicVideoTransitions.js b/client/src/lib/musicVideoTransitions.jsindex c72de13ecc..15fad2362b 100644--- a/client/src/lib/musicVideoTransitions.js+++ b/client/src/lib/musicVideoTransitions.js@@ -11,6 +11,7 @@ export {MUSIC_VIDEO_TRANSITION_STYLES,mergeGlitchFrames,blockBox,+ edgeGlows,sceneImageEffectGlitchFrames,sceneShotGlitchFrames,sceneTransitions,diff --git a/server/lib/README.md b/server/lib/README.mdindex be0a2ae13d..7f76ede35f 100644--- a/server/lib/README.md+++ b/server/lib/README.md@@ -439,6 +439,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub| `httpCompression.js` | `httpCompression` negotiates Brotli/gzip for API and static responses while preserving streaming, ranges, existing encodings, and `no-transform`. || `execGit.js` | `execGit(args, cwd, options)` and `execGitSafe(args, cwd, options)` shared process boundary for Git operations, worktrees, and `services/forgeAuth.js` credential resolution. The safe variant converts rejections into `{ exitCode: 1, stdout: '', stderr }`; `services/git.js` re-exports both for compatibility. `cwd` is REQUIRED — it rejects on a missing/blank one rather than letting `spawn` fall back to `process.cwd()` and run git against PortOS's own checkout (#4554). || `ffmpeg.js` | Shared ffmpeg helpers (videoGen + videoTimeline). `probeVideoGeometry(videoPath)` measures a finished clip's `{ width, height, fps, numFrames, durationSec }` (null when any axis is unreadable) for hosted renders that record no frame count. `generateThumbnail(videoPath, jobId, { atSec } = {})` accepts a clamped poster seek while preserving the single-clip default. Includes `probeFrameCount(videoPath)` (metadata `nb_frames`, falling back to a real `-count_frames` pass — expensive, so call it once per file) and `trimVideoFromFrame(videoPath, outPath, {startFrame, fps})` — a frame-EXACT head cut via the `trim` filter (an `-ss` seek can drift a frame, which reads as a stutter at a stitch seam), keeping audio in sync with `atrim` when the clip has a soundtrack and taking `-an` when it doesn't. Re-encodes by necessity, so a later concat must re-encode too; `outPath` may equal the input (temp-file + rename install). Used by the chained-render context window — see `videoContinuity.js`. `buildTrimConcatArgs({inputs, outPath, width, height, fps, withAudio})` builds the argv for the other half of that job: a concat that drops leading frames from some of its inputs inside a `filter_complex` graph, so the cuts ride along with the timeline encode instead of costing one pre-encode per clip (pass `withAudio` only when EVERY input has an audio stream — check with `hasAudioStream`). `buildExtendSpliceArgs({sourcePath, generatedPath, outPath, keepFrames, newStartFrame, width, height, fps, audio, sourceAudioPath, masterOutPath})` is the plain-Extend counterpart: source frames `[0, keep)` + render frames from `newStartFrame`, one encode, audio crossfaded (~40 ms linear) at the seam; `sourceAudioPath` swaps the source span's audio for a lossless master and `masterOutPath` also writes the mix as a 24-bit FLAC master, so the delivered AAC is encoded once from PCM. Its stream-copy sibling is `buildExtendNewSpanArgs` (encode only the render's new span) + `buildExtendConcatList` + `buildExtendCopyArgs` (join it to the untouched source with `-c:v copy`); `probeVideoCodecSignature` gates it and `videoFrameHashes` (per-frame MD5) proves the join before anything is replaced; `audioFingerprint` / `sealAudioMaster` / `readAudioMasterFingerprint` bind a master to the exact decoded soundtrack it was mixed for so a replaced soundtrack invalidates it — driven by `services/videoGen/extendSplice.js`. `H264_ENCODE_ARGS` / `AAC_ENCODE_ARGS` are the shared encode profile: clips produced by different paths here get concatenated together, so a mismatch shows up as one segment graded differently from its neighbours — spread these rather than re-typing the flags. Every re-encode here also pins BT.709: `BT709_CONTAINER_ARGS` (the `colr` atom, always emitted) plus `bt709TagFilter()` → the `BT709_TAG_FILTER` `setparams=…` string, or `null` on an ffmpeg without that filter (`supportsSetparamsFilter()` probes `-filters` once per process; `null` = not probed, and a probe that couldn't run stays uncached). Both halves are required — from ffmpeg 8 the encoder reads color properties off the FRAMES, silently overriding the container flags, so a flags-only output decodes washed-out. `buildTrimConcatArgs` takes the filter as its `colorTagFilter` option rather than probing, to stay pure. `installEncodedVideo(tmpPath, targetPath, label)` is the shared in-place install: move the original aside to a `.bak` on Windows (where `fs.rename` refuses an existing destination), rename the new file over it, and restore the backup — plus unlink the temp — on any failure, returning `{ok:true,outPath}` / `{ok:false,reason}` so the worst case is "skipped", never "the video is gone". Use it for EVERY replace-a-video-with-its-re-encode path; `pipeline/audioMux.js` is the out-of-module caller. `edgeFadeFilter(durationSec)` is the `-af` fade-in/fade-out fragment a mid-song clip (a social cut) appends to its trim. Loudness mastering (#10249): `MASTER_LOUDNESS` (-14 LUFS / -1.5 dBTP / LRA 11), `planLoudnessMaster` (measure then build the linear apply filter; throws on a silent source), `reportMasteredLoudness` (post-encode before/after numbers). |+| `ffmpegFilterGraph.js` | `filterGraphViaFile(bin, args, path)` moves a `-filter_complex` graph over `FILTER_GRAPH_ARG_LIMIT` into a file (`-/filter_complex`, or `-filter_complex_script` before ffmpeg 7), since Linux and Windows cap argument length. Used by the music video render and excerpt encodes. || `forgeAccessErrors.js` | `isForgeNoAccessError(err)` / `isForgeNoAccessMessage(text)` / `logForgeNoAccessOnce(scope, repoSpec, detail)` / `forgeNoAccessRemedy(repoSpec)` — tells a PERMANENT `gh` no-access 404 (`Could not resolve to a Repository`, `HTTP 404`) apart from a transient blip. `execGh` stamps `ghNoAccess` on the rejection and keeps it OUT of the consecutive-failure backoff (which caps at 15 min and then re-fires forever), and the polling jobs (`branchReconcile`, `prWatcher`) narrate it exactly once per scope+repo per process with a remedy line instead of once per tick. `__resetForgeNoAccessLog()` is the test seam. || `forkHead.js` | `normalizeForkHead(value)` / `forkRemoteName(ownerLogin)` / `resolveTaskForkHead(metadata)` — the validated `{remoteUrl, ownerLogin}` address of a cross-repository PR's head branch, which has no `origin/<branch>` to attach to. Fail-closed: anything that isn't a usable pair (or that starts with `-`, which git would read as an option) is `null`, so every caller falls back to origin-only behavior instead of guessing. `forkRemoteName` is the deterministic `fork-<owner>` remote name that makes a re-attach reuse the remote it already added. Shared by `appPullRequests.js` (produces), `agentWorktreeCleanup.js`/`prRemediationFollowUp.js` (persist in task metadata), `agentWorkspacePrep.js` (threads), and `worktreeManager.js` (consumes — it has no forge client of its own). `resolveTaskForkHead` is the single reader of the generic `forkHead` task-metadata key, the fork-side counterpart to `taskTargetBranch.js`. || `frameQuality.js` | Scores decoded video frames so a chained render can CHOOSE its continuation anchor instead of taking whatever an end-seek lands on. `scoreFrame({width,height,data},{recency})` combines three terms over a raw single-channel buffer: log-compressed `gradientVariance` (focus), distance of `meanLuma` from mid-grey (exposure penalty, which rejects a fade-to-black or a blown highlight), and a small linear recency bonus that keeps the anchor near the cut when candidates are comparably clean. Usability and ranking are deliberately separate: `usable` gates on raw gradient variance against `MIN_SIGNAL_VARIANCE` alone, so only a mathematically degenerate frame is rejected and a legitimately dark low-key tail still qualifies — the same contract `imageFrameStats.js` keeps. Gating on the composite score instead would reject every night scene on the exposure term. `TAIL_WINDOW_SECONDS` is capped at the reach of the single `-sseof -1.0` seek this replaces: focus is systematically highest at the OLDEST candidate, so a wider window would widen the backward jump at each chain seam rather than tightening it. `pickBestFrame(paths)` decodes each candidate through `sharp` and returns the winner (or `null` when nothing decodes or every candidate is degenerate, so the caller degrades rather than failing a render); its `index` is the position in the array AS PASSED, because the caller turns that into the anchor's time offset. `MAX_CANDIDATES` is derived from the window, never set independently — the ffmpeg-side `-frames:v` cap truncates from the NEWEST end, exactly the frames recency prefers. `TAIL_WINDOW_SECONDS` / `CANDIDATE_FPS` / `MAX_CANDIDATES` define the window the caller decodes from. Consumer: `services/videoGen/local.js#extractLastFrame`. |@@ -566,7 +567,7 @@ The barrel `server/lib/index.js` is a machine-checkable enumeration of every pub| `musicVideoLayers.js` | Music Video per-scene visual layers (#8985): `MUSIC_VIDEO_VISUAL_LAYERS` (`footage`/`still`/`card`/`code`), `MUSIC_VIDEO_STILL_MOVES` (`hold`/`push`/`pan`), `MUSIC_VIDEO_FRAME_FITS` (`fill`/`still`/`vhs`/`black`: how an off-shape clip fills the frame), `sceneVisualLayer(scene, { layered })` (only a composed render honors a still/card), `sceneHasAuthoredSpan`, and `sceneRenderReady(scene, { layered })`. `clipSpeedRate(scene)` / `clipOffsetSec(scene)` / `clipReversed(scene)` read a footage shot's hand-set `speedFps`, `offsetFrames` and `reverse` on the 24 fps grid (`CLIP_TIMING_FPS`, `CLIP_SPEED_FPS_RANGE`, `CLIP_OFFSET_FRAMES_RANGE`). Pure leaf shared by `services/musicVideo/render.js` and the client board (`client/src/lib/musicVideoLayers.js`). || `musicVideoLyricAnchors.js` | Music Video lyric anchors: `cuesSungWithin(cues, startSec, endSec)`, the lines a shot's span anchors, each counted from its first sung word to its last when it has word timing, else its line window. Shared by the storyboard anchor check and the retime anchor sync. || `musicVideoImageEffects.js` | Music Video image effects: a code-drawn effect a still shot plays instead of a generated clip (`imageEffect`: `flash-develop`, a camera flash then the picture develops like an instant photo over `imageEffectSec`; or a fade, flash or glitch from the start frame to the end frame). `sceneImageEffect(scene, { layered })`, `imageEffectState` (the effect at a time into the shot, painted by the storyboard animatic) and `musicVideoImageEffectFilter` (the same curves as ffmpeg filters for the final render). Browser-safe and import-free: document videos ship it as is. |-| `musicVideoTransitions.js` | Music Video cut transitions: VHS glitch styles a shot sets on the cut into (`transitionIn`) or out of (`transitionOut`) it, `transitionGlitchFrames` (the glitched frames of a cut timeline, never moving a cut), `transitionFrameAt`, `sceneTransitionSections`, `imageEffectGlitchFrames`/`mergeGlitchFrames` (end-frame glitch effects in the same shape), `shotGlitchFrames`/`sceneShotGlitchFrames` (glitches a shot sets at moments inside it, `scene.glitches`), `blockBox` and `musicVideoTransitionFilter` (per-frame ffmpeg filters for the final render). Browser-safe; the storyboard animatic paints the same frames. |+| `musicVideoTransitions.js` | Music Video cut transitions: VHS glitch styles a shot sets on the cut into (`transitionIn`) or out of (`transitionOut`) it, `transitionGlitchFrames` (the glitched frames of a cut timeline, never moving a cut), `transitionFrameAt`, `sceneTransitionSections`, `imageEffectGlitchFrames`/`mergeGlitchFrames` (end-frame glitch effects in the same shape), `shotGlitchFrames`/`sceneShotGlitchFrames` (glitches a shot sets at moments inside it, `scene.glitches`), `blockBox`, `edgeGlows` (an effect's edge glows as fading ramps) and `musicVideoTransitionFilter` (per-frame ffmpeg filters for the final render). Styles span VHS, film and camera looks. Browser-safe; the storyboard animatic paints the same frames. || `pitchMath.js` | Dependency-free scientific-pitch math shared by the LLM-authored music formats on both runtimes: `pitchToMidi("C4")` → 60 (null when unparseable) and `midiToFreq(69)` → 440. || `wavAudioFile.js` | `writeWavAudioFile(wav, dir, basename)` — land a synthesized WAV Buffer as `<basename>.ogg` via the system ffmpeg, falling back to `<basename>.wav` (and dropping a stale `.ogg`) when ffmpeg is missing or the encode fails; resolves to the filename used. Shared by the chiptune and drawn-waveform renderers and the code-engine take upload. `wavDurationMs(buffer)` reads a PCM WAV's duration from its RIFF header (0 for anything that is not a parseable WAV). `measureWavAudio(buffer)` decodes PCM 16/24/32-bit or float 32/64 (EXTENSIBLE included) into `{ channels, sampleRate, frames, durationMs, peak, rms, nonFinite }` so native renders are judged by their samples (null when undecodable). || `superColliderRuntime.js` | Managed SuperCollider runtime contract (#9412), pure: image/runtime/policy version constants, `buildSuperColliderRunArgs` (the one contained `docker run` for untrusted `sclang` source: no network/caps, read-only root, limits, ro input, private output), `buildSuperColliderBuildArgs`, the shipped synthetic probe, `evaluateSuperColliderStatus` (docker-missing … ready, with stale image/evidence invalidation), and the render contract (#9413): `SUPERCOLLIDER_RENDER` bounds, the trusted NRT `SUPERCOLLIDER_RENDER_WRAPPER_SOURCE`, `classifySuperColliderRenderLog` (syntax/source/pattern/score/synthesis failures) and `parseDockerContainerList` for orphan sweeps. I/O lives in `services/superColliderRuntime.js`. |diff --git a/server/lib/ffmpegFilterGraph.js b/server/lib/ffmpegFilterGraph.jsnew file mode 100644index 0000000000..6b41eaa03b--- /dev/null+++ b/server/lib/ffmpegFilterGraph.js@@ -0,0 +1,40 @@+/**+ * Passing a long ffmpeg filter graph by file instead of on the command line.+ */+import { writeFile } from 'fs/promises';+import { promisify } from 'util';+import { execFile } from './childProcess.js';+import { safeChildProcessOptions } from './processEnv.js';++// Linux refuses any one argument over 128 KiB and Windows a whole command line+// over 32K characters, so a filter graph longer than this goes to ffmpeg in a file.+export const FILTER_GRAPH_ARG_LIMIT = 16 * 1024;++// ffmpeg 7 reads an option's value from a file with `-/filter_complex <file>`;+// older builds only have `-filter_complex_script`, which later builds drop.+// `null` = not probed; a probe that couldn't run stays uncached.+let filterGraphFileFlag = null;++const probeFilterGraphFileFlag = async (bin) => {+ if (filterGraphFileFlag) return filterGraphFileFlag;+ const out = await promisify(execFile)(bin, ['-hide_banner', '-version'], safeChildProcessOptions({}))+ .then((r) => String(r.stdout || ''), () => null);+ // A git build ("ffmpeg version N-…") is newer than any release.+ const major = /ffmpeg version n?(\d+)\./.exec(out || '')?.[1];+ const flag = major && Number(major) < 7 ? '-filter_complex_script' : '-/filter_complex';+ if (out !== null) filterGraphFileFlag = flag;+ return flag;+};++/**+ * `args` with a `-filter_complex` graph over `FILTER_GRAPH_ARG_LIMIT` written to+ * `path` and passed by file instead, as `{ args, file }` (`file` is null when the+ * graph stays inline). The caller removes `file` once ffmpeg has exited.+ */+export async function filterGraphViaFile(bin, args, path) {+ const at = args.indexOf('-filter_complex');+ if (at < 0 || Buffer.byteLength(args[at + 1]) <= FILTER_GRAPH_ARG_LIMIT) return { args, file: null };+ const flag = await probeFilterGraphFileFlag(bin);+ await writeFile(path, args[at + 1]);+ return { args: [...args.slice(0, at), flag, path, ...args.slice(at + 2)], file: path };+}diff --git a/server/lib/index.js b/server/lib/index.jsindex 672646e26c..44cdda5af4 100644--- a/server/lib/index.js+++ b/server/lib/index.js@@ -402,6 +402,7 @@ export * from './hostShutdown.js';export * from './httpDrain.js';export * from './execGit.js';export * from './ffmpeg.js';+export * from './ffmpegFilterGraph.js';export * from './forgeAccessErrors.js';export * from './forkHead.js';export * from './ffmpegRenderGuard.js';diff --git a/server/lib/musicVideoTransitions.js b/server/lib/musicVideoTransitions.jsindex 5f91041969..825521fbcf 100644--- a/server/lib/musicVideoTransitions.js+++ b/server/lib/musicVideoTransitions.js@@ -18,7 +18,8 @@import { IMAGE_EFFECT_GLITCH_STYLE, imageEffectChangeFrame, sceneImageEffect } from './musicVideoImageEffects.js';-export const MUSIC_VIDEO_TRANSITIONS = Object.freeze(['vhs-glitch', 'channel-change', 'vhs-tracking', 'vhs-dropout', 'camera-flash', 'color-block', 'vhs-rewind']);+export const MUSIC_VIDEO_TRANSITIONS = Object.freeze(['vhs-glitch', 'channel-change', 'vhs-tracking', 'vhs-dropout', 'camera-flash', 'color-block', 'vhs-rewind',+ 'film-burn', 'light-leak', 'gate-jump', 'shutter', 'film-scratches', 'color-split']);export const MUSIC_VIDEO_TRANSITION_LABELS = Object.freeze({'vhs-glitch': 'VHS glitch',@@ -28,6 +29,12 @@ export const MUSIC_VIDEO_TRANSITION_LABELS = Object.freeze({'camera-flash': 'Camera flash','color-block': 'Color blocks','vhs-rewind': 'Rewind / fast-forward',+ 'film-burn': 'Film burn',+ 'light-leak': 'Light leak',+ 'gate-jump': 'Gate jump',+ 'shutter': 'Shutter',+ 'film-scratches': 'Film scratches',+ 'color-split': 'Color split',});// A shot also carries glitches at any moment inside it (`scene.glitches`):@@ -50,6 +57,8 @@ export const MUSIC_VIDEO_GLITCH_LENGTHS = Object.freeze([0.125, 0.25, 0.5, 1, 2]// shift of width, blur the horizontal smear (a fraction of width)// swaps macroblocks traded places: { x1, y1, x2, y2, w, h } fractions of the frame// blocks solid colour macroblocks: { x, y, w, h } fractions, color 'rrggbb', alpha+// glows light washing in from an edge: { side: left|right|top|bottom, size }+// (fraction of the frame), color 'rrggbb', alpha at the edge fading to noneexport const MUSIC_VIDEO_TRANSITION_STYLES = Object.freeze({'vhs-glitch': {lead: 1,@@ -143,6 +152,74 @@ export const MUSIC_VIDEO_TRANSITION_STYLES = Object.freeze({{ smears: [{ y: 0.52, h: 0.04, shift: -0.02, blur: 0.005 }], chroma: 0.003, noise: 0.15, lines: 0.2 },],},+ // Film burning in the gate: a hot orange glow floods in from one side, whites+ // the frame out on the cut and burns away off the other.+ 'film-burn': {+ lead: 4,+ frames: [+ { glows: [{ side: 'right', size: 0.2, color: 'ff8a2a', alpha: 0.35 }], bright: 1.05 },+ { glows: [{ side: 'right', size: 0.35, color: 'ff7a1a', alpha: 0.55 }], bright: 1.1, sat: 1.1 },+ { glows: [{ side: 'right', size: 0.55, color: 'ff9a3a', alpha: 0.75 }, { side: 'left', size: 0.15, color: 'ffd27a', alpha: 0.3 }], bright: 1.2, sat: 1.1 },+ { glows: [{ side: 'right', size: 0.8, color: 'ffb050', alpha: 0.9 }], bright: 1.35 },+ { glows: [{ side: 'right', size: 1, color: 'ffc070', alpha: 0.9 }], bar: { y: 0, h: 1, alpha: 0.6 }, bright: 1.4 },+ { glows: [{ side: 'left', size: 0.8, color: 'ffb050', alpha: 0.85 }], bright: 1.3 },+ { glows: [{ side: 'left', size: 0.55, color: 'ff8a2a', alpha: 0.6 }], bright: 1.15 },+ { glows: [{ side: 'left', size: 0.3, color: 'ff6a1a', alpha: 0.4 }], bright: 1.05 },+ { glows: [{ side: 'left', size: 0.12, color: 'ff5a10', alpha: 0.2 }] },+ ],+ },+ // Stray light on the film: a soft amber and rose wash from the top corner swells and fades.+ 'light-leak': {+ lead: 5,+ frames: [0.12, 0.22, 0.32, 0.42, 0.5, 0.5, 0.44, 0.36, 0.26, 0.16, 0.08].map((alpha) => ({+ glows: [{ side: 'left', size: 0.6, color: 'ff4f8a', alpha }, { side: 'top', size: 0.5, color: 'ffb347', alpha: alpha * 0.9 }],+ bright: 1 + alpha * 0.3, sat: 1.05,+ })),+ },+ // The film slipping in a projector gate: the picture jumps up a frame line,+ // its black frame bar showing, and drops back into place.+ 'gate-jump': {+ lead: 2,+ frames: [+ { roll: 0.06, bright: 0.95 },+ { roll: 0.45, blocks: [{ x: 0, y: 0.43, w: 1, h: 0.05, color: '000000', alpha: 1 }], bright: 0.9, noise: 0.1 },+ { roll: -0.25, blocks: [{ x: 0, y: 0.73, w: 1, h: 0.05, color: '000000', alpha: 1 }], bright: 0.95 },+ { roll: 0.05 },+ { bright: 1.05, chroma: 0.002 },+ ],+ },+ // A camera shutter blinking over the cut: black closes in from top and bottom and opens again.+ shutter: {+ lead: 3,+ frames: [0.18, 0.38, 0.5, 0.5, 0.32, 0.12].map((v) => ({+ blocks: [{ x: 0, y: 0, w: 1, h: v, color: '000000', alpha: 1 }, { x: 0, y: 1 - v, w: 1, h: v, color: '000000', alpha: 1 }],+ })),+ },+ // Worn print: thin scratches run down the frame, dust specks flash and the exposure flickers.+ 'film-scratches': {+ lead: 2,+ frames: [+ { blocks: [{ x: 0.23, y: 0, w: 0.003, h: 1, color: 'ffffff', alpha: 0.55 }, { x: 0.61, y: 0.3, w: 0.008, h: 0.012, color: '000000', alpha: 0.8 }], bright: 1.08, sat: 0.9 },+ { blocks: [{ x: 0.24, y: 0, w: 0.003, h: 1, color: 'ffffff', alpha: 0.45 }, { x: 0.71, y: 0, w: 0.002, h: 1, color: '000000', alpha: 0.5 },+ { x: 0.38, y: 0.66, w: 0.01, h: 0.014, color: 'ffffff', alpha: 0.8 }], bright: 0.93, sat: 0.9 },+ { blocks: [{ x: 0.72, y: 0, w: 0.002, h: 1, color: '000000', alpha: 0.45 }, { x: 0.15, y: 0.2, w: 0.006, h: 0.01, color: '000000', alpha: 0.8 },+ { x: 0.82, y: 0.78, w: 0.008, h: 0.012, color: '000000', alpha: 0.75 }], bright: 1.06, sat: 0.9 },+ { blocks: [{ x: 0.46, y: 0, w: 0.003, h: 1, color: 'ffffff', alpha: 0.5 }, { x: 0.55, y: 0.45, w: 0.012, h: 0.016, color: 'ffffff', alpha: 0.75 }], bright: 0.95, sat: 0.9 },+ { blocks: [{ x: 0.47, y: 0, w: 0.002, h: 1, color: 'ffffff', alpha: 0.35 }, { x: 0.3, y: 0.86, w: 0.007, h: 0.01, color: '000000', alpha: 0.7 }], bright: 1.04, sat: 0.95 },+ { blocks: [{ x: 0.66, y: 0.12, w: 0.006, h: 0.01, color: '000000', alpha: 0.7 }], bright: 0.98 },+ ],+ },+ // A tube camera losing convergence: red and blue pull apart and snap back.+ 'color-split': {+ lead: 2,+ frames: [+ { chroma: 0.03, shift: 0.004, bright: 1.03 },+ { chroma: 0.055, shift: -0.008, bright: 1.06, sat: 1.15 },+ { chroma: 0.04, shift: 0.006, bright: 1.04, sat: 1.1 },+ { chroma: 0.02, bright: 1.02 },+ { chroma: 0.008 },+ ],+ },});const isTransition = (value) => MUSIC_VIDEO_TRANSITIONS.includes(value);@@ -265,6 +342,32 @@ export function blockBox(x, y, w, h, width, height) {return { x: px, y: py, w: Math.max(0, Math.min(width - px, even(w * width))), h: Math.max(0, Math.min(height - py, even(h * height))) };}+/**+ * A style frame's glows, `{ side, size, color, alpha }`: light at `alpha` on its+ * `side` edge that fades evenly to nothing `size` (a fraction of the frame) in.+ * Both players paint each as one smooth ramp, so a glow looks the same in each.+ */+export function edgeGlows(glows) {+ return (Array.isArray(glows) ? glows : [])+ .map((g) => ({ side: g.side, size: Math.min(1, Math.max(0, g.size || 0)), color: g.color, alpha: Math.min(1, Math.max(0, g.alpha || 0)) }))+ .filter((g) => g.size > 0 && g.alpha > 0);+}++// One `geq` per glow: each pixel moves toward the glow's color by the ramp's strength there.+// The color goes in as limited-range BT.601 YUV, as drawbox paints it.+function glowFilter({ side, size, color, alpha }) {+ const [r, g, b] = [0, 2, 4].map((i) => parseInt(color.slice(i, i + 2), 16) / 255);+ const yuv = [+ 16 + 65.481 * r + 128.553 * g + 24.966 * b,+ 128 - 37.797 * r - 74.203 * g + 112 * b,+ 128 + 112 * r - 93.786 * g - 18.214 * b,+ ].map((v) => Math.round(v));+ const from = side === 'left' ? 'X/W' : side === 'right' ? '(W-1-X)/W' : side === 'top' ? 'Y/H' : '(H-1-Y)/H';+ const strength = `${num(alpha)}*max(0,1-${from}/${num(size)})`;+ const [lum, cb, cr] = yuv.map((v) => `'p(X,Y)+(${v}-p(X,Y))*${strength}'`);+ return `geq=lum=${lum}:cb=${cb}:cr=${cr}`;+}+/** Inclusive frame runs as a timeline expression: `between(n,4,6)+between(n,90,90)`. */function framesExpr(frames) {const sorted = [...new Set(frames)].sort((a, b) => a - b);@@ -335,6 +438,7 @@ export function musicVideoTransitionFilter(glitches, { width, height }) {const box = blockBox(b.x, b.y, b.w, b.h, width, height);if (box.w >= 2 && box.h >= 2) add(`drawbox=x=${box.x}:y=${box.y}:w=${box.w}:h=${box.h}:color=0x${b.color}@${num(b.alpha)}:t=fill`);}+ for (const glow of edgeGlows(p.glows)) add(glowFilter(glow));for (const bar of [...(p.bar ? [p.bar] : []), ...(p.bars || [])]) {add(`drawbox=x=0:y=${rows(bar.y)}:w=iw:h=${Math.max(2, rows(bar.h))}:color=white@${num(bar.alpha)}:t=fill`);}diff --git a/server/services/musicVideo/excerptRender.js b/server/services/musicVideo/excerptRender.jsindex cc490978f5..f893fc2bbb 100644--- a/server/services/musicVideo/excerptRender.js+++ b/server/services/musicVideo/excerptRender.js@@ -22,6 +22,7 @@ import { captureMusicVideoEvidence } from '../../lib/musicVideoDependencies.js';import { withBackupAssetPublication } from '../../lib/backupSnapshotBoundary.js';import { unlink } from 'fs/promises';import { join } from 'path';+import { tmpdir } from 'os';import { ensureDir, PATHS } from '../../lib/fileUtils.js';import { ServerError } from '../../lib/errorHandler.js';import { spawn } from '../../lib/childProcess.js';@@ -30,6 +31,7 @@ import { broadcastSse, attachSseClient as attachSse, closeJobAfterDelay } from 'import { attachFfmpegRenderGuard } from '../../lib/ffmpegRenderGuard.js';import { cancelMusicVideoRenderJob, isMusicVideoRenderCanceled } from './renderCancellation.js';import { safeUnder } from '../../lib/ffmpeg.js';+import { filterGraphViaFile } from '../../lib/ffmpegFilterGraph.js';import { encodeFileContactSheetAtTimes } from '../htmlComposition/encode.js';import { getProject, listProjects, mutateProjectRecord } from './projects.js';import { assertCurrentPerformanceTakes, withDraftPerformanceFallbacks } from './performanceShot.js';@@ -327,6 +329,9 @@ export async function startExcerptRender(projectId, { startSec, endSec, aspect =const composition = cues.length > 0 ? project.composition : null;const totalDuration = endClamped - startSec;+ // A long filter graph goes to ffmpeg in this file, removed once ffmpeg exits.+ const graphPath = join(tmpdir(), `portos-music-video-${jobId}.filtergraph`);+ const plainEncode = composition ? null : await filterGraphViaFile(ffmpeg, buildMusicVideoFfmpegArgs(clips, audioPath, outputPath, { audioDurationSec, frameGrid: composed, excerpt: { startSec, endSec: endClamped }, soundBed, grade: composed ? project.composition?.grade : null, beats: project.audioAnalysis?.beats, aspect: canvasAspect }).args, graphPath);const job = { id: jobId, projectId, excerptId, status: 'running', clients: [], process: null, totalDuration };jobs.set(jobId, job);projectExcerptRenders.set(projectId, jobId);@@ -386,10 +391,11 @@ export async function startExcerptRender(projectId, { startSec, endSec, aspect =// the look after ffmpeg (filmLookFinish.js), on song time so the grain// matches the final render's frames.const finishing = filmLookFinishNeeded(project);- const startEncode = (encodeArgs, progressBase = 0) => {+ const startEncode = (encode, progressBase = 0) => {const encodeTop = finishing ? progressBase + (1 - progressBase) / 2 : 1;const encodeProgress = (fraction) => progressBase + (encodeTop - progressBase) * fraction;- const proc = spawn(ffmpeg, encodeArgs, safeChildProcessOptions({ stdio: ['ignore', 'ignore', 'pipe'] }));+ const dropGraphFile = () => (encode.file ? unlink(encode.file).catch(() => {}) : null);+ const proc = spawn(ffmpeg, encode.args, safeChildProcessOptions({ stdio: ['ignore', 'ignore', 'pipe'] }));job.process = proc;let stderrBuf = '';@@ -421,6 +427,7 @@ export async function startExcerptRender(projectId, { startSec, endSec, aspect =console.log(`⚠️ Music-video excerpt render post-spawn error [${jobId.slice(4, 12)}]: ${err.message}`);},onSpawnError: async (err) => {+ await dropGraphFile();job.process = null;job.status = 'error';const reason = `Failed to spawn ffmpeg: ${err.message}`;@@ -434,6 +441,7 @@ export async function startExcerptRender(projectId, { startSec, endSec, aspect =},onClose: async (code, signal) => {job.process = null;+ await dropGraphFile();if (code !== 0) {const canceled = isMusicVideoRenderCanceled(job, signal);await settleFailure(canceled, canceled ? 'Render cancelled' : signal ? `Killed by signal ${signal}` : `ffmpeg exit ${code}`);@@ -478,8 +486,7 @@ export async function startExcerptRender(projectId, { startSec, endSec, aspect =};if (!composition) {- const { args } = buildMusicVideoFfmpegArgs(clips, audioPath, outputPath, { audioDurationSec, frameGrid: composed, excerpt: { startSec, endSec: endClamped }, soundBed, grade: composed ? project.composition?.grade : null, beats: project.audioAnalysis?.beats, aspect: canvasAspect });- startEncode(args);+ startEncode(plainEncode);return { jobId, excerptId };}@@ -494,11 +501,11 @@ export async function startExcerptRender(projectId, { startSec, endSec, aspect =renderTypographyOverlays({jobId, cues: captureCues, style, width: probe.canonW, height: probe.canonH, fps: probe.fps, durationSec: endClamped, signal,onProgress: (fraction) => broadcastSse(job, { type: 'progress', progress: 0.5 * fraction }),- }).then((overlays) => {+ }).then(async (overlays) => {signal.throwIfAborted();job.overlayAbort = null;const layered = buildMusicVideoFfmpegArgs(clips, audioPath, outputPath, { audioDurationSec, overlays, frameGrid: true, excerpt: { startSec, endSec: endClamped }, soundBed, grade: composed ? project.composition?.grade : null, beats: project.audioAnalysis?.beats, aspect: canvasAspect });- startEncode(layered.args, 0.5);+ startEncode(await filterGraphViaFile(ffmpeg, layered.args, graphPath), 0.5);}).catch(async (err) => {const canceled = signal.aborted;job.status = canceled ? 'canceled' : 'error';diff --git a/server/services/musicVideo/render.js b/server/services/musicVideo/render.jsindex 03f8710854..1355eee969 100644--- a/server/services/musicVideo/render.js+++ b/server/services/musicVideo/render.js@@ -29,11 +29,13 @@ import { spawn } from '../../lib/childProcess.js';import { existsSync } from 'fs';import { unlink } from 'fs/promises';import { join } from 'path';+import { tmpdir } from 'os';import { randomUUID } from 'crypto';import { ensureDir, PATHS } from '../../lib/fileUtils.js';import { ServerError } from '../../lib/errorHandler.js';import { broadcastSse, attachSseClient as attachSse, closeJobAfterDelay } from '../../lib/sseUtils.js';import { findFfmpeg, safeUnder, generateThumbnail, probeVideoDuration, probeVideoGeometry } from '../../lib/ffmpeg.js';+import { filterGraphViaFile } from '../../lib/ffmpegFilterGraph.js';import { safeChildProcessOptions } from '../../lib/processEnv.js';import { cancelMusicVideoRenderJob, isMusicVideoRenderCanceled } from './renderCancellation.js';import { attachFfmpegRenderGuard } from '../../lib/ffmpegRenderGuard.js';@@ -991,6 +993,9 @@ async function renderAdmittedMusicVideo(projectId, options, permit) {const composition = cues.length > 0 ? project.composition : null;await assertCurrentRenderApproval(projectId, project, options);+ // A long filter graph goes to ffmpeg in this file, removed once ffmpeg exits.+ const graphPath = join(tmpdir(), `portos-music-video-${jobId}.filtergraph`);+ const plainEncode = composition ? null : await filterGraphViaFile(ffmpeg, args, graphPath);const job = { id: jobId, projectId, status: 'running', clients: [], process: null, totalDuration };jobs.set(jobId, job);projectRenders.set(projectId, jobId);@@ -1049,10 +1054,11 @@ async function renderAdmittedMusicVideo(projectId, options, permit) {const outroSec = statsOutroSeconds(project.statsOutro);// A composed render first captures its overlay (progress 0–50%), then// encodes (50–100%); a plain render encodes across the whole bar.- const startEncode = (encodeArgs, progressBase = 0) => {+ const startEncode = (encode, progressBase = 0) => {const encodeTop = finishing ? progressBase + (1 - progressBase) / 2 : 1;const encodeProgress = (fraction) => progressBase + (encodeTop - progressBase) * fraction;- const proc = spawn(ffmpeg, encodeArgs, safeChildProcessOptions({ stdio: ['ignore', 'ignore', 'pipe'] }));+ const dropGraphFile = () => (encode.file ? unlink(encode.file).catch(() => {}) : null);+ const proc = spawn(ffmpeg, encode.args, safeChildProcessOptions({ stdio: ['ignore', 'ignore', 'pipe'] }));job.process = proc;let stderrBuf = '';@@ -1092,6 +1098,7 @@ async function renderAdmittedMusicVideo(projectId, options, permit) {},onSpawnError: async (err) => {// Pre-spawn failure: the child never started, so 'close' won't follow.+ await dropGraphFile();job.process = null;job.status = 'error';const reason = `Failed to spawn ffmpeg: ${err.message}`;@@ -1110,6 +1117,7 @@ async function renderAdmittedMusicVideo(projectId, options, permit) {},onClose: async (code, signal) => {job.process = null;+ await dropGraphFile();if (code !== 0) {const canceled = isMusicVideoRenderCanceled(job, signal);await settleFailure(canceled, canceled ? 'Render cancelled' : signal ? `Killed by signal ${signal}` : `ffmpeg exit ${code}`);@@ -1205,7 +1213,7 @@ async function renderAdmittedMusicVideo(projectId, options, permit) {};if (!composition) {- startEncode(args);+ startEncode(plainEncode);return { jobId };}@@ -1224,7 +1232,7 @@ async function renderAdmittedMusicVideo(projectId, options, permit) {// Capture is over: from here a cancel kills the encode (job.process).job.overlayAbort = null;const layered = buildMusicVideoFfmpegArgs(clips, audioPath, outputPath, { audioDurationSec, overlays, frameGrid: true, soundBed, grade: project.composition?.grade, beats: project.audioAnalysis?.beats });- startEncode(layered.args, 0.5);+ startEncode(await filterGraphViaFile(ffmpeg, layered.args, graphPath), 0.5);}).catch(async (err) => {const canceled = signal.aborted;await settleFailure(canceled, canceled ? 'Render cancelled' : `Typography overlay failed: ${err.message}`);diff --git a/server/services/musicVideo/transitions.test.js b/server/services/musicVideo/transitions.test.jsindex ab1340b96e..583f2b54c5 100644--- a/server/services/musicVideo/transitions.test.js+++ b/server/services/musicVideo/transitions.test.js@@ -1,10 +1,11 @@import { afterAll, describe, expect, it } from 'vitest';import { execFileSync } from 'node:child_process';-import { mkdtempSync, rmSync } from 'node:fs';+import { mkdtempSync, readFileSync, rmSync } from 'node:fs';import { tmpdir } from 'node:os';import { join } from 'node:path';import { findFfmpeg } from '../../lib/ffmpeg.js';-import { sceneTransitions, shotGlitchFrames, transitionGlitchFrames } from '../../lib/musicVideoTransitions.js';+import { FILTER_GRAPH_ARG_LIMIT, filterGraphViaFile } from '../../lib/ffmpegFilterGraph.js';+import { MUSIC_VIDEO_TRANSITION_STYLES, sceneTransitions, shotGlitchFrames, transitionGlitchFrames } from '../../lib/musicVideoTransitions.js';import { buildMusicVideoFfmpegArgs } from './render.js';import { applySceneUpdate } from './projectsLogic.js';@@ -109,6 +110,64 @@ describe.skipIf(!ffmpeg)('a VHS glitch on a cut in the final render', () => {});});+// Uniquely catches a film or camera effect's filters failing in ffmpeg, adding+// time, or painting outside its frames around the cut.+describe.skipIf(!ffmpeg)('film and camera effects on a cut in the final render', () => {+ const renderRgb = (name, transitionOut) => {+ const song = join(dir, 'song.wav');+ run(['-f', 'lavfi', '-i', 'sine=frequency=440:duration=2', '-y', song]);+ const clips = ['0x2050a0', '0xa05020'].map((color, i) => {+ const videoPath = join(dir, `fx${i}.mp4`);+ run(['-f', 'lavfi', '-i', `color=${color}:s=${W}x${H}:r=${FPS}:d=1`, '-pix_fmt', 'yuv420p', '-y', videoPath]);+ return { sceneId: `s${i}`, videoPath, width: W, height: H, fps: FPS, duration: 1, sourceSec: 1, loop: false, inSec: 0, outSec: 1, frameFit: 'fill' };+ });+ if (transitionOut) clips[0].transitionOut = transitionOut;+ const output = join(dir, `${name}.mp4`);+ const plan = buildMusicVideoFfmpegArgs(clips, song, output, { audioDurationSec: 2, frameGrid: true });+ run(plan.args.filter((arg, i) => !(arg === '-progress' || plan.args[i - 1] === '-progress')));+ expect(plan.totalDuration).toBe(2);+ return run(['-i', output, '-f', 'rawvideo', '-pix_fmt', 'rgb24', '-']);+ };+ it.each(['film-burn', 'light-leak', 'gate-jump', 'shutter', 'film-scratches', 'color-split'])('%s repaints only its frames around the cut', (style) => {+ const clean = renderRgb('fx-clean', null);+ const fx = renderRgb(`fx-${style}`, style);+ expect(fx.length).toBe(clean.length);+ const size = W * H * 3;+ const changed = Array.from({ length: fx.length / size }, (_, f) => f)+ .filter((f) => fx.subarray(f * size, (f + 1) * size).some((v, i) => Math.abs(v - clean[f * size + i]) > 6));+ const { lead, frames } = MUSIC_VIDEO_TRANSITION_STYLES[style];+ expect(changed.length).toBeGreaterThan(0);+ expect(changed.every((f) => f >= FPS - lead && f < FPS - lead + frames.length)).toBe(true);+ });+});++// Uniquely catches a long edit's filter graph reaching ffmpeg as one argument+// Linux refuses over 128 KiB (E2BIG): the graph must go by file and still render.+describe.skipIf(!ffmpeg)('effects on every cut of a long edit', () => {+ it('passes the filter graph to ffmpeg in a file and renders every frame', async () => {+ const song = join(dir, 'long-song.wav');+ run(['-f', 'lavfi', '-i', 'sine=frequency=440:duration=30', '-y', song]);+ const videoPath = join(dir, 'long-clip.mp4');+ run(['-f', 'lavfi', '-i', `testsrc2=s=${W}x${H}:r=${FPS}:d=1`, '-pix_fmt', 'yuv420p', '-y', videoPath]);+ const styles = ['light-leak', 'vhs-rewind', 'film-burn'];+ const clips = Array.from({ length: 30 }, (_, i) => ({+ videoPath, width: W, height: H, fps: FPS, duration: 1, sourceSec: 1, loop: false, inSec: 0, outSec: 1, frameFit: 'fill',+ ...sceneTransitions({ sceneId: `s${i}`, startSec: i, endSec: i + 1, transitionIn: styles[i % 3], transitionOut: styles[(i + 1) % 3], glitches: [{ atSec: 0.5, style: styles[(i + 2) % 3] }] }),+ sceneId: `s${i}`,+ }));+ const output = join(dir, 'long-edit.mp4');+ const plan = buildMusicVideoFfmpegArgs(clips, song, output, { audioDurationSec: 30, frameGrid: true });+ const graph = plan.args[plan.args.indexOf('-filter_complex') + 1];+ expect(Buffer.byteLength(graph)).toBeGreaterThan(FILTER_GRAPH_ARG_LIMIT);+ const encode = await filterGraphViaFile(ffmpeg, plan.args, join(dir, 'long-edit.filtergraph'));+ expect(encode.args).not.toContain('-filter_complex');+ expect(encode.args).not.toContain(graph);+ expect(readFileSync(encode.file, 'utf8')).toBe(graph);+ run(encode.args.filter((arg, i) => !(arg === '-progress' || encode.args[i - 1] === '-progress')));+ expect(frameSpreads(output)).toHaveLength(30 * FPS);+ });+});+// Uniquely catches the in-shot glitch filters failing in ffmpeg, landing on// the wrong frames, or adding time to the edit.describe.skipIf(!ffmpeg)('a color block glitch inside a shot in the final render', () => {