Skip to content

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

native 9:16 cut only when the master was rendered from this composition; progress, clean cancel, tests

[._.]/ Adam Eivyed9b69a28fb7
diff --git a/server/services/musicVideo/excerptRender.js b/server/services/musicVideo/excerptRender.js
index c02528d794..5fcb8c8e5c 100644
--- a/server/services/musicVideo/excerptRender.js
+++ b/server/services/musicVideo/excerptRender.js
@@ -235,13 +235,14 @@ async function launchSeekedExcerpt({ projectId, project: stored, startSec, endSe
* Resolves the encode's frame (`{ width, height, … }`), or null when the project has no
* seekable composition. A document that does not lay itself out at that frame throws
* COMPOSITION_DOCUMENT_FORMAT, which the caller takes as "not available".
+ * `deps` (tests): `renderers` stands in for the seeked renderers, `resolveAudio` for the master lookup.
*/
-export async function renderSeekedWindow(stored, { startSec, endSec, aspect, fade = false, outputPath, jobId, signal, onProgress }) {
- const renderer = SEEKED_EXCERPTS[stored?.composition?.mode];
+export async function renderSeekedWindow(stored, { startSec, endSec, aspect, fade = false, outputPath, jobId, signal, onProgress }, { renderers = SEEKED_EXCERPTS, resolveAudio = resolveMasterAudioPath } = {}) {
+ const renderer = renderers[stored?.composition?.mode];
if (!renderer) return null;
const project = musicVideoAtAspect(stored, aspect);
const prepared = await renderer.prepare(project);
- const audioPath = await resolveMasterAudioPath(project);
+ const audioPath = await resolveAudio(project);
if (renderer.performanceTakes) {
assertCurrentClipDependencies(project);
await assertCurrentPerformanceTakes(project, audioPath);
diff --git a/server/services/musicVideo/publishKit.js b/server/services/musicVideo/publishKit.js
index 8ace7c0ae2..ea312742c5 100644
--- a/server/services/musicVideo/publishKit.js
+++ b/server/services/musicVideo/publishKit.js
@@ -24,6 +24,7 @@ import { broadcastSse, attachSseClient as attachSse, closeJobAfterDelay } from '
import { getProject, listProjects, mutateProjectRecord } from './projects.js';
import { suggestSocialCuts } from './socialCuts.js';
import { musicVideoAspect } from '../../lib/musicVideoAspect.js';
+import { musicVideoDependencyChanges } from '../../lib/musicVideoDependencies.js';
import { buildChapters, buildSrt, buildPublishCopyPrompt, parsePublishCopy, normalizeCopyOptions, PUBLISH_PLATFORMS } from './publishKitText.js';
const jobs = new Map();
@@ -143,8 +144,8 @@ async function beginPublishKitBuild(projectId, jobId) {
// frame is fitted over a blurred fill of itself (#10377) — a center-crop dropped off-center text.
...(teaser && musicVideoAspect(project) === '16:9' ? [{ kind: 'vertical-9x16', label: `Vertical 9:16 ${Math.round(teaser.endSec - teaser.startSec)}s`, filename: `${stem}-vertical.mp4`, window: teaser,
layout: 'fit',
- native: async (outputPath) => (await import('./excerptRender.js')).renderSeekedWindow(project, {
- startSec: teaser.startSec, endSec: teaser.endSec, aspect: '9:16', fade: true, outputPath, jobId: `${jobId}-vertical`, signal: job.abort.signal,
+ native: async (outputPath, onProgress) => (await import('./excerptRender.js')).renderSeekedWindow(project, {
+ startSec: teaser.startSec, endSec: teaser.endSec, aspect: '9:16', fade: true, outputPath, jobId: `${jobId}-vertical`, signal: job.abort.signal, onProgress,
}),
args: ['-ss', String(teaser.startSec), '-t', String(teaser.endSec - teaser.startSec), '-i', masterPath,
'-vf', VERTICAL_FIT_FILTER, ...X_VIDEO_ARGS,
@@ -155,13 +156,26 @@ async function beginPublishKitBuild(projectId, jobId) {
const written = [];
let done = 0;
const step = () => broadcastSse(job, { type: 'progress', progress: Math.min(0.99, ++done / total) });
- // A native cut that isn't available (footage, a document without the 9:16 frame, a failed
- // render) falls back to the fitted master; a cancel still cancels.
+ // The native cut renders the composition as it is now; the rest of the kit is the master.
+ // Only when the master was rendered from exactly this composition do they match.
+ const matchesMaster = Boolean(project.renderDependencies) && !musicVideoDependencyChanges(project, project.renderDependencies).length;
+ // A native cut that isn't available (footage, a document without the 9:16 frame, a composition
+ // changed since the master, a failed render) falls back to the fitted master; a cancel still
+ // cancels and leaves no partial file behind.
const renderNative = async (encode, out) => {
+ if (!matchesMaster) {
+ console.log(`📐 ${encode.label} [${tag}]: the composition changed since the final render (or was never recorded), fitting the master`);
+ return false;
+ }
try {
- if (await encode.native(out)) { encode.layout = 'native'; return true; }
+ const slot = done;
+ const progress = (fraction) => broadcastSse(job, { type: 'progress', progress: Math.min(0.99, (slot + Math.max(0, Math.min(1, fraction))) / total) });
+ if (await encode.native(out, progress)) { encode.layout = 'native'; return true; }
} catch (error) {
- if (job.abort.signal.aborted) throw error;
+ if (job.abort.signal.aborted) {
+ await unlink(out).catch(() => {});
+ throw error;
+ }
console.warn(`⚠️ Native ${encode.label} unavailable [${tag}], fitting the master instead: ${error.message}`);
}
await unlink(out).catch(() => {});
diff --git a/server/services/musicVideo/publishKit.test.js b/server/services/musicVideo/publishKit.test.js
index 57696b860a..54d8c80d42 100644
--- a/server/services/musicVideo/publishKit.test.js
+++ b/server/services/musicVideo/publishKit.test.js
@@ -22,6 +22,7 @@ const projects = await import('./projects.js');
const { saveHistory } = await import('../videoGen/history.js');
const kit = await import('./publishKit.js');
const excerptRender = await import('./excerptRender.js');
+const { captureMusicVideoEvidence } = await import('../../lib/musicVideoDependencies.js');
const ffmpeg = await findFfmpeg();
const watchedBuilds = new Set();
const startPublishKitBuild = kit.startPublishKitBuild.bind(kit);
@@ -178,10 +179,22 @@ describe('publishing kit build (#9281)', () => {
await vi.waitFor(() => expect(existsSync(join(PATHS.videos, first.exports[0].filename))).toBe(false));
});
- it.skipIf(!ffmpeg)('renders the 9:16 cut natively when the composition lays itself out at that frame', { timeout: 120000 }, async () => {
+ // A document project whose final render was made from its current composition.
+ const documentRendered = async () => {
const id = await renderedProject();
- await projects.mutateProjectRecord(id, (current) => ({ project: { ...current, composition: { mode: 'document' } } }));
- const native = vi.spyOn(excerptRender, 'renderSeekedWindow').mockImplementation(async (project, { outputPath, aspect, startSec, endSec, fade }) => {
+ await projects.mutateProjectRecord(id, (current) => {
+ const next = { ...current, composition: { mode: 'document', version: 'v1' } };
+ return { project: { ...next, renderDependencies: captureMusicVideoEvidence(next) } };
+ });
+ return id;
+ };
+
+ it.skipIf(!ffmpeg)('renders the 9:16 cut natively when the composition lays itself out at that frame', { timeout: 120000 }, async () => {
+ const id = await documentRendered();
+ const progress = [];
+ const native = vi.spyOn(excerptRender, 'renderSeekedWindow').mockImplementation(async (project, { outputPath, aspect, startSec, endSec, fade, onProgress }) => {
+ onProgress(0.5);
+ progress.push(0.5);
expect({ id: project.id, aspect, fade }).toEqual({ id, aspect: '9:16', fade: true });
expect(endSec).toBeGreaterThan(startSec);
await writeFile(outputPath, 'native 9:16 render');
@@ -203,8 +216,7 @@ describe('publishing kit build (#9281)', () => {
});
it.skipIf(!ffmpeg)('fits the master when the composition has no 9:16 layout', { timeout: 120000 }, async () => {
- const id = await renderedProject();
- await projects.mutateProjectRecord(id, (current) => ({ project: { ...current, composition: { mode: 'document' } } }));
+ const id = await documentRendered();
const native = vi.spyOn(excerptRender, 'renderSeekedWindow').mockImplementation(async (_project, { outputPath }) => {
await writeFile(outputPath, 'partial');
throw Object.assign(new Error('The composition document is 1920x1080 and does not declare 1080x1920'), { code: 'COMPOSITION_DOCUMENT_FORMAT' });
@@ -223,6 +235,61 @@ describe('publishing kit build (#9281)', () => {
warn.mockRestore();
}
});
+
+ it.skipIf(!ffmpeg)('fits the master when the composition changed since the final render', { timeout: 120000 }, async () => {
+ const id = await documentRendered();
+ await projects.mutateProjectRecord(id, (current) => ({ project: { ...current, composition: { ...current.composition, version: 'v2' } } }));
+ const native = vi.spyOn(excerptRender, 'renderSeekedWindow');
+ try {
+ await kit.startPublishKitBuild(id);
+ await vi.waitFor(async () => expect((await projects.getProject(id)).publishKit?.builtAt).toBeTruthy(), { timeout: 90000, interval: 250 });
+ expect((await projects.getProject(id)).publishKit.exports.find((e) => e.kind === 'vertical-9x16').layout).toBe('fit');
+ expect(native).not.toHaveBeenCalled();
+ } finally {
+ native.mockRestore();
+ }
+ });
+
+ it.skipIf(!ffmpeg)('cancelling during the native cut cancels the build and leaves no partial file', { timeout: 120000 }, async () => {
+ const id = await documentRendered();
+ let partial = null;
+ const native = vi.spyOn(excerptRender, 'renderSeekedWindow').mockImplementation(async (_project, { outputPath, signal }) => {
+ partial = outputPath;
+ await writeFile(outputPath, 'partial');
+ await new Promise((_, reject) => signal.addEventListener('abort', () => reject(Object.assign(new Error('Render cancelled'), { code: 'CANCELED' })), { once: true }));
+ });
+ const encode = vi.spyOn(ffmpegService, 'runFfmpegProcess');
+ try {
+ await kit.startPublishKitBuild(id);
+ await vi.waitFor(() => expect(partial).toBeTruthy(), { timeout: 90000, interval: 50 });
+ const fitsBefore = encode.mock.calls.length;
+ kit.cancelPublishKitBuild(kit.getActivePublishKitBuild(id).jobId);
+ await vi.waitFor(() => expect(kit.getActivePublishKitBuild(id)).toBeNull(), { timeout: 15000, interval: 20 });
+ expect(existsSync(partial)).toBe(false);
+ expect(encode.mock.calls.slice(fitsBefore).some(([o]) => o.args.includes(kit.VERTICAL_FIT_FILTER))).toBe(false);
+ expect((await projects.getProject(id)).publishKit?.builtAt).toBeFalsy();
+ } finally {
+ native.mockRestore();
+ encode.mockRestore();
+ }
+ });
+});
+
+describe('renderSeekedWindow (the kit\'s native 9:16 cut)', () => {
+ it('has nothing to render for a footage project', async () => {
+ expect(await excerptRender.renderSeekedWindow({ id: 'mv-x', composition: { mode: 'footage' } }, { startSec: 0, endSec: 10, aspect: '9:16' }, { renderers: {} })).toBeNull();
+ });
+
+ it('renders the window at the asked aspect, clamped to the song', async () => {
+ const encode = vi.fn(async (input) => ({ width: 1080, height: 1920, input }));
+ const renderers = { document: { prepare: vi.fn(async (project) => ({ totalSec: 30, project })), encode } };
+ const stored = { id: 'mv-x', aspect: '16:9', composition: { mode: 'document' } };
+ const out = await excerptRender.renderSeekedWindow(stored, { startSec: 20, endSec: 45, aspect: '9:16', fade: true, outputPath: '/tmp/v.mp4', jobId: 'job' }, { renderers, resolveAudio: async () => '/tmp/song.wav' });
+ expect(out).toMatchObject({ width: 1080, height: 1920 });
+ const input = encode.mock.calls[0][0];
+ expect(input).toMatchObject({ startSec: 20, endSec: 30, fade: true, outputPath: '/tmp/v.mp4', audioPath: '/tmp/song.wav', soundBed: null });
+ expect(renderers.document.prepare.mock.calls[0][0]).not.toBe(stored); // re-framed view, the record untouched
+ });
});
const ALL_ON = Object.fromEntries(['youtube', 'shorts', 'x', 'tiktok', 'instagram', 'reddit', 'stackerNews', 'suno'].map((t) => [t, { enabled: true }]));