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

Publishing kit renders the 9:16 cut natively when the composition lays itself out at that frame

[._.]/ Adam Eivy55832a23e904
diff --git a/server/services/musicVideo/excerptRender.js b/server/services/musicVideo/excerptRender.js
index dc540788e6..c02528d794 100644
--- a/server/services/musicVideo/excerptRender.js
+++ b/server/services/musicVideo/excerptRender.js
@@ -229,6 +229,30 @@ async function launchSeekedExcerpt({ projectId, project: stored, startSec, endSe
return { jobId, excerptId };
}
+/**
+ * Render [startSec, endSec) of a seekable composition (document, code, Eidoverse) at `aspect`
+ * straight to `outputPath`, with no excerpt record: the publishing kit's native 9:16 cut.
+ * 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".
+ */
+export async function renderSeekedWindow(stored, { startSec, endSec, aspect, fade = false, outputPath, jobId, signal, onProgress }) {
+ const renderer = SEEKED_EXCERPTS[stored?.composition?.mode];
+ if (!renderer) return null;
+ const project = musicVideoAtAspect(stored, aspect);
+ const prepared = await renderer.prepare(project);
+ const audioPath = await resolveMasterAudioPath(project);
+ if (renderer.performanceTakes) {
+ assertCurrentClipDependencies(project);
+ await assertCurrentPerformanceTakes(project, audioPath);
+ }
+ const soundBed = renderer.soundBed ? await resolveSoundBedPath(project) : null;
+ return renderer.encode({
+ prepared, project, projectId: project.id, jobId, audioPath, soundBed, outputPath, signal,
+ startSec, endSec: Math.min(endSec, prepared.totalSec), fade, onProgress,
+ });
+}
+
export async function startExcerptRender(projectId, { startSec, endSec, aspect = null, fade = false }, { revisionId = null, pilotSceneId = null, verifyCurrent = null } = {}) {
const stored = await getProject(projectId);
if (!stored) throw new ServerError('Project not found', { status: 404, code: 'NOT_FOUND' });
diff --git a/server/services/musicVideo/publishKit.js b/server/services/musicVideo/publishKit.js
index 3cf177cb8b..8ace7c0ae2 100644
--- a/server/services/musicVideo/publishKit.js
+++ b/server/services/musicVideo/publishKit.js
@@ -8,8 +8,9 @@
* field on the whole-record LWW body (same posture as `excerpts`), so an older
* peer carries it through untouched.
*
- * The build runs ffmpeg only; the copy is ONE user-triggered LLM call (AI
- * Provider Usage Policy) and every field stays editable afterwards.
+ * The build runs ffmpeg, plus one browser render of the 9:16 cut when the
+ * composition lays itself out at that frame; the copy is ONE user-triggered
+ * LLM call (AI Provider Usage Policy) and every field stays editable afterwards.
*/
import { randomUUID } from 'crypto';
import { existsSync } from 'fs';
@@ -137,9 +138,14 @@ async function beginPublishKitBuild(projectId, jobId) {
...(teaser ? [{ kind: 'teaser', label: `Teaser ${Math.round(teaser.endSec - teaser.startSec)}s`, filename: `${stem}-teaser.mp4`, window: teaser,
args: ['-ss', String(teaser.startSec), '-t', String(teaser.endSec - teaser.startSec), '-i', masterPath, ...X_VIDEO_ARGS,
'-af', `asetpts=PTS-STARTPTS${edgeFadeFilter(teaser.endSec - teaser.startSec)}`, ...AUDIO_ARGS] }] : []),
- // #10150: Shorts/TikTok/Reels need 9:16; a 16:9 render gets the whole frame fitted over a blurred fill
- // of itself (#10377) — a center-crop silently dropped off-center lyric/title text.
+ // #10150: Shorts/TikTok/Reels need 9:16. A composition that lays itself out at 9:16
+ // (portosComposition.formats) renders the window natively; otherwise the 16:9 master's whole
+ // 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,
+ }),
args: ['-ss', String(teaser.startSec), '-t', String(teaser.endSec - teaser.startSec), '-i', masterPath,
'-vf', VERTICAL_FIT_FILTER, ...X_VIDEO_ARGS,
'-af', `asetpts=PTS-STARTPTS${edgeFadeFilter(teaser.endSec - teaser.startSec)}`, ...AUDIO_ARGS] }] : []),
@@ -149,8 +155,25 @@ 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.
+ const renderNative = async (encode, out) => {
+ try {
+ if (await encode.native(out)) { encode.layout = 'native'; return true; }
+ } catch (error) {
+ if (job.abort.signal.aborted) throw error;
+ console.warn(`⚠️ Native ${encode.label} unavailable [${tag}], fitting the master instead: ${error.message}`);
+ }
+ await unlink(out).catch(() => {});
+ return false;
+ };
for (const encode of encodes) {
const out = join(PATHS.videos, encode.filename);
+ if (encode.native && await renderNative(encode, out)) {
+ written.push(encode.filename);
+ step();
+ continue;
+ }
const result = await runFfmpegProcess({ bin: ffmpeg, signal: job.abort.signal, args: ['-hide_banner', '-loglevel', 'error', ...encode.args, '-y', out] });
if (!result.ok) throw new Error(`${encode.label} encode failed: ${result.reason || 'ffmpeg error'}`);
written.push(encode.filename);
@@ -176,7 +199,7 @@ async function beginPublishKitBuild(projectId, jobId) {
...kit,
builtAt: new Date().toISOString(),
master: { filename: entry.filename, renderHistoryId: project.renderHistoryId },
- exports: encodes.map(({ kind, label, filename, window }) => ({ kind, label, filename, ...(window ? { startSec: window.startSec, endSec: window.endSec } : {}) })),
+ exports: encodes.map(({ kind, label, filename, window, layout }) => ({ kind, label, filename, ...(window ? { startSec: window.startSec, endSec: window.endSec } : {}), ...(layout ? { layout } : {}) })),
thumbnails,
thumbnail: thumbnails.includes(kit.thumbnail) ? kit.thumbnail : (thumbnails[0] || null),
captionsFilename,
diff --git a/server/services/musicVideo/publishKit.test.js b/server/services/musicVideo/publishKit.test.js
index a314625479..57696b860a 100644
--- a/server/services/musicVideo/publishKit.test.js
+++ b/server/services/musicVideo/publishKit.test.js
@@ -21,6 +21,7 @@ const { findFfmpeg, runFfmpegProcess } = ffmpegService;
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 ffmpeg = await findFfmpeg();
const watchedBuilds = new Set();
const startPublishKitBuild = kit.startPublishKitBuild.bind(kit);
@@ -176,6 +177,52 @@ describe('publishing kit build (#9281)', () => {
await vi.waitFor(async () => expect((await projects.getProject(id)).publishKit.builtAt).not.toBe(first.builtAt), { timeout: 90000, interval: 250 });
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 () => {
+ 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 }) => {
+ expect({ id: project.id, aspect, fade }).toEqual({ id, aspect: '9:16', fade: true });
+ expect(endSec).toBeGreaterThan(startSec);
+ await writeFile(outputPath, 'native 9:16 render');
+ return { width: 1080, height: 1920 };
+ });
+ const encode = vi.spyOn(ffmpegService, 'runFfmpegProcess');
+ try {
+ await kit.startPublishKitBuild(id);
+ await vi.waitFor(async () => expect((await projects.getProject(id)).publishKit?.builtAt).toBeTruthy(), { timeout: 90000, interval: 250 });
+ const vertical = (await projects.getProject(id)).publishKit.exports.find((e) => e.kind === 'vertical-9x16');
+ expect(vertical.layout).toBe('native');
+ expect(await readFile(join(PATHS.videos, vertical.filename), 'utf8')).toBe('native 9:16 render');
+ // the master was never squeezed into 9:16 for it
+ expect(encode.mock.calls.some(([o]) => o.args.includes(kit.VERTICAL_FIT_FILTER))).toBe(false);
+ } finally {
+ native.mockRestore();
+ encode.mockRestore();
+ }
+ });
+
+ 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 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' });
+ });
+ const warn = vi.spyOn(console, 'warn').mockImplementation(() => {});
+ try {
+ await kit.startPublishKitBuild(id);
+ await vi.waitFor(async () => expect((await projects.getProject(id)).publishKit?.builtAt).toBeTruthy(), { timeout: 90000, interval: 250 });
+ const vertical = (await projects.getProject(id)).publishKit.exports.find((e) => e.kind === 'vertical-9x16');
+ expect(vertical.layout).toBe('fit');
+ const probed = await runFfmpegProcess({ bin: ffmpeg, args: ['-hide_banner', '-i', join(PATHS.videos, vertical.filename), '-f', 'null', '-'] });
+ expect(probed.ok).toBe(true);
+ expect(warn.mock.calls.some(([m]) => /fitting the master/.test(m))).toBe(true);
+ } finally {
+ native.mockRestore();
+ warn.mockRestore();
+ }
+ });
});
const ALL_ON = Object.fromEntries(['youtube', 'shorts', 'x', 'tiktok', 'instagram', 'reddit', 'stackerNews', 'suno'].map((t) => [t, { enabled: true }]));