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
feat: footage projects fill Shorts, TikTok and Reels drafts from a recorded-aspect cut or a kit center-crop vertical encode (#10150)
Adam Eivyc6778e4d4beb
diff --git a/server/lib/musicVideoValidation.js b/server/lib/musicVideoValidation.jsindex b317e31571..e87f9e7a05 100644--- a/server/lib/musicVideoValidation.js+++ b/server/lib/musicVideoValidation.js@@ -682,6 +682,7 @@ export const musicVideoPublishPrepareSchema = z.object({pin: z.boolean(),prompt: kitText(25000),storyImage: z.string().min(1).max(300),+ cutId: z.string().min(1).max(100),}).partial().strict();export const musicVideoExcerptNoteSchema = z.object({diff --git a/server/services/musicVideo/excerptRender.js b/server/services/musicVideo/excerptRender.jsindex 8a1082e016..0bcb9da5c7 100644--- a/server/services/musicVideo/excerptRender.js+++ b/server/services/musicVideo/excerptRender.js@@ -291,7 +291,7 @@ export async function startExcerptRender(projectId, { startSec, endSec, aspect =await verifyCurrent?.(await getProject(projectId));const { excerpt } = await mutateProjectRecord(projectId, (current) => {if (pilotEvidence && musicVideoDependencyChanges(current, pilotEvidence).length) throw new ServerError('The selected pilot changed before rendering', { status: 409, code: 'COMPOSITION_DRAFT_STALE' });- const started = startExcerptOnProject(current, { startSec, endSec: endClamped, sections, performanceProject: stored, dependencies: pilotEvidence || captureMusicVideoEvidence(project, { sceneIds: sections.map((section) => section.sceneId), startSec, endSec: endClamped }), partialFilename: filename, renderingOn });+ const started = startExcerptOnProject(current, { startSec, endSec: endClamped, sections, performanceProject: stored, dependencies: pilotEvidence || captureMusicVideoEvidence(project, { sceneIds: sections.map((section) => section.sceneId), startSec, endSec: endClamped }), partialFilename: filename, renderingOn, aspect: musicVideoAspect(project) });return revisionId ? { ...started, project: markRevisionRendering(started.project, revisionId, started.excerpt.id) } : started;});const excerptId = excerpt.id;diff --git a/server/services/musicVideo/publish/payloads.js b/server/services/musicVideo/publish/payloads.jsindex 0d7a318421..79df551f84 100644--- a/server/services/musicVideo/publish/payloads.js+++ b/server/services/musicVideo/publish/payloads.js@@ -6,6 +6,7 @@*/import { ServerError } from '../../../lib/errorHandler.js';import { chaptersText } from '../publishKitText.js';+import { musicVideoDependencyChanges } from '../../../lib/musicVideoDependencies.js';const TITLE_LIMITS = { youtube: 100, shorts: 100, reddit: 300, stackerNews: 80 };const DEFAULT_SUBREDDIT = 'aivideo';@@ -20,10 +21,39 @@ function requireFreshKit(project, kit) {if ((kit.master?.renderHistoryId ?? null) !== (project?.renderHistoryId ?? null)) throw stale();}-/** The newest finished 9:16 social cut (#9280): what Shorts, TikTok and Reels upload. */-function latestVerticalCut(project) {- const cuts = (project?.excerpts || []).filter((e) => e?.status === 'complete' && e.aspect === '9:16' && e.filename);- return cuts.length ? cuts[cuts.length - 1] : null;+const VERTICAL_NEEDS = 'Render a 9:16 social cut on the Review stage (or rebuild the publishing kit for a 16:9 render) first';+const isVerticalCut = (e) => e?.status === 'complete' && e.aspect === '9:16' && e.filename;++/**+ * The vertical cuts a director can post (#10150), newest last: finished 9:16+ * excerpts flagged stale when the project changed since, plus the kit's+ * center-crop 9:16 encode (16:9 renders) while the kit is fresh.+ */+export function verticalCuts(project) {+ const kit = kitOf(project);+ const cuts = (project?.excerpts || []).filter(isVerticalCut)+ .map((e) => ({ id: e.id ?? null, filename: e.filename, startSec: e.startSec, endSec: e.endSec, stale: musicVideoDependencyChanges(project, e.dependencies).length > 0 }));+ const crop = (kit.exports || []).find((e) => e.kind === 'vertical-9x16' && e.filename);+ if (crop && (kit.master?.renderHistoryId ?? null) === (project?.renderHistoryId ?? null)) {+ cuts.unshift({ id: 'kit-vertical', filename: crop.filename, startSec: crop.startSec ?? 0, endSec: crop.endSec ?? 0, stale: false });+ }+ return cuts;+}++/** The cut the director picked (`options.cutId`), else the newest non-stale one; a stale pick is refused. */+function pickVerticalCut(project, options) {+ const cuts = verticalCuts(project);+ const wanted = text(options?.cutId);+ if (wanted) {+ const cut = cuts.find((c) => c.id === wanted);+ if (!cut) throw missing('That vertical cut no longer exists — pick another');+ if (cut.stale) throw new ServerError('That vertical cut was rendered before the project changed — render a fresh one', { status: 409, code: 'PUBLISH_CUT_STALE' });+ return cut;+ }+ const fresh = cuts.filter((c) => !c.stale);+ if (fresh.length) return fresh[fresh.length - 1];+ if (cuts.length) throw new ServerError('Every 9:16 cut was rendered before the project changed — render a fresh one', { status: 409, code: 'PUBLISH_CUT_STALE' });+ throw missing(VERTICAL_NEEDS);}/** The full video's public link: the recorded YouTube post, else the one the director gave the kit. */@@ -60,21 +90,18 @@ const BUILDERS = {captions: kit.captionsFilename ? { dir: 'videos', name: kit.captionsFilename } : null,};},- shorts: (project, kit) => {- const cut = latestVerticalCut(project);- if (!cut) throw missing('Render a 9:16 social cut on the Review stage first');+ shorts: (project, kit, options = {}) => {+ const cut = pickVerticalCut(project, options);const url = fullVideoUrl(kit);const description = [text(kit.copy?.shorts?.description), url && !text(kit.copy?.shorts?.description).includes(url) ? `Full video: ${url}` : ''].filter(Boolean).join('\n\n');return { video: { dir: 'videos', name: cut.filename }, title: requireTitle('shorts', text(kit.copy?.shorts?.title)), description, tags: [], thumbnail: null, captions: null };},- tiktok: (project, kit) => {- const cut = latestVerticalCut(project);- if (!cut) throw missing('Render a 9:16 social cut on the Review stage first');+ tiktok: (project, kit, options = {}) => {+ const cut = pickVerticalCut(project, options);return { video: { dir: 'videos', name: cut.filename }, caption: text(kit.copy?.tiktok?.caption), coverAtSec: Math.max(0, (cut.endSec - cut.startSec) / 2) };},- instagram: (project, kit) => {- const cut = latestVerticalCut(project);- if (!cut) throw missing('Render a 9:16 social cut on the Review stage first');+ instagram: (project, kit, options = {}) => {+ const cut = pickVerticalCut(project, options);return { video: { dir: 'videos', name: cut.filename }, caption: instagramSafe(text(kit.copy?.instagram?.caption)) };},x: (project, kit, options = {}) => {diff --git a/server/services/musicVideo/publish/payloads.test.js b/server/services/musicVideo/publish/payloads.test.jsindex acf55b096f..741182794c 100644--- a/server/services/musicVideo/publish/payloads.test.js+++ b/server/services/musicVideo/publish/payloads.test.js@@ -4,6 +4,7 @@*/import { describe, expect, it } from 'vitest';import { buildPublishPayload } from './payloads.js';+import { captureMusicVideoEvidence } from '../../../lib/musicVideoDependencies.js';const kit = (over = {}) => ({master: { filename: 'master.mp4' },@@ -23,7 +24,8 @@ const kit = (over = {}) => ({},...over,});-const project = (over = {}, excerpts = [{ status: 'complete', aspect: '9:16', filename: 'cut-a.mp4', startSec: 10, endSec: 30 }]) => ({ publishKit: kit(over), excerpts });+const evidence = () => captureMusicVideoEvidence({ scenes: [] }, { startSec: 0, endSec: 20 });+const project = (over = {}, excerpts = [{ status: 'complete', aspect: '9:16', filename: 'cut-a.mp4', startSec: 10, endSec: 30, dependencies: evidence() }]) => ({ scenes: [], publishKit: kit(over), excerpts });describe('buildPublishPayload (#9282)', () => {it('uploads the master to YouTube with chapters appended, thumbnail and captions', () => {@@ -57,9 +59,9 @@ describe('buildPublishPayload (#9282)', () => {it('sends the newest 9:16 cut to Shorts, TikTok and Reels, linking the full video from Shorts', () => {const excerpts = [- { status: 'complete', aspect: '9:16', filename: 'old.mp4', startSec: 0, endSec: 20 },- { status: 'complete', aspect: '16:9', filename: 'wide.mp4', startSec: 0, endSec: 20 },- { status: 'complete', aspect: '9:16', filename: 'new.mp4', startSec: 40, endSec: 60 },+ { status: 'complete', aspect: '9:16', filename: 'old.mp4', startSec: 0, endSec: 20, dependencies: evidence() },+ { status: 'complete', aspect: '16:9', filename: 'wide.mp4', startSec: 0, endSec: 20, dependencies: evidence() },+ { status: 'complete', aspect: '9:16', filename: 'new.mp4', startSec: 40, endSec: 60, dependencies: evidence() },{ status: 'running', aspect: '9:16', filename: 'partial.mp4' },];const shorts = buildPublishPayload('shorts', project({}, excerpts));@@ -70,6 +72,23 @@ describe('buildPublishPayload (#9282)', () => {expect(() => buildPublishPayload('tiktok', project({}, []))).toThrow(/9:16 social cut/);});+ it('uses the kit center-crop vertical encode for a 16:9 render with no social cut, and only while the kit is fresh (#10150)', () => {+ const exports = [{ kind: 'vertical-9x16', filename: 'vertical.mp4', startSec: 5, endSec: 35 }];+ const wide = { ...project({ exports, master: { filename: 'master.mp4', renderHistoryId: 'r1' } }, []), renderHistoryId: 'r1' };+ expect(buildPublishPayload('shorts', wide).video.name).toBe('vertical.mp4');+ expect(buildPublishPayload('tiktok', wide)).toMatchObject({ video: { name: 'vertical.mp4' }, coverAtSec: 15 });+ expect(() => buildPublishPayload('instagram', { ...wide, renderHistoryId: 'r2' })).toThrow(/9:16 social cut/);+ });++ it('lets the director pick a cut and refuses stale ones (#10150)', () => {+ const stale = { id: 'mve-stale', status: 'complete', aspect: '9:16', filename: 'stale.mp4', startSec: 0, endSec: 10, dependencies: { ...evidence(), references: [{ role: 'song', assetId: 'x', revision: 'old' }] } };+ const fresh = { id: 'mve-fresh', status: 'complete', aspect: '9:16', filename: 'fresh.mp4', startSec: 0, endSec: 10, dependencies: evidence() };+ expect(buildPublishPayload('shorts', project({}, [fresh, stale])).video.name).toBe('fresh.mp4');+ expect(buildPublishPayload('shorts', project({}, [fresh, stale]), { cutId: 'mve-fresh' }).video.name).toBe('fresh.mp4');+ expect(() => buildPublishPayload('shorts', project({}, [fresh, stale]), { cutId: 'mve-stale' })).toThrow(expect.objectContaining({ status: 409, code: 'PUBLISH_CUT_STALE' }));+ expect(() => buildPublishPayload('tiktok', project({}, [stale]))).toThrow(expect.objectContaining({ code: 'PUBLISH_CUT_STALE' }));+ });+it('threads X: hook with the 1080p encode, story, prompt, then links with the full video last', () => {const { posts } = buildPublishPayload('x', project(), { prompt: 'the prompt', storyImage: 'still.png' });expect(posts.map((p) => p.text)).toEqual(['Watch this', 'How it was made', 'the prompt', 'The song: https://suno.com/song/1234-abcd\nFull video: https://youtu.be/abc']);diff --git a/server/services/musicVideo/publishKit.js b/server/services/musicVideo/publishKit.jsindex 9fb3d51575..55add3bc49 100644--- a/server/services/musicVideo/publishKit.js+++ b/server/services/musicVideo/publishKit.js@@ -21,6 +21,7 @@ import { safeUnder, edgeFadeFilter } from '../../lib/ffmpeg.js';import { broadcastSse, attachSseClient as attachSse, closeJobAfterDelay } from '../../lib/sseUtils.js';import { getProject, listProjects, mutateProjectRecord } from './projects.js';import { suggestSocialCuts } from './socialCuts.js';+import { musicVideoAspect } from '../../lib/musicVideoAspect.js';import { buildChapters, buildSrt, buildPublishCopyPrompt, parsePublishCopy, PUBLISH_PLATFORMS } from './publishKitText.js';const jobs = new Map();@@ -133,6 +134,11 @@ 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 a center-crop of the hook window (no generation).+ ...(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,+ args: ['-ss', String(teaser.startSec), '-t', String(teaser.endSec - teaser.startSec), '-i', masterPath,+ '-vf', 'crop=trunc(ih*9/32)*2:ih,scale=1080:1920', ...X_VIDEO_ARGS,+ '-af', `asetpts=PTS-STARTPTS${edgeFadeFilter(teaser.endSec - teaser.startSec)}`, ...AUDIO_ARGS] }] : []),];const times = thumbnailTimes(project, durationSec);const total = encodes.length + times.length;diff --git a/server/services/musicVideo/publishKit.test.js b/server/services/musicVideo/publishKit.test.jsindex 3cb1d1652d..b686b6fcb1 100644--- a/server/services/musicVideo/publishKit.test.js+++ b/server/services/musicVideo/publishKit.test.js@@ -114,7 +114,7 @@ describe('publishing kit build (#9281)', () => {await kit.startPublishKitBuild(id);await vi.waitFor(async () => expect((await projects.getProject(id)).publishKit?.builtAt).toBeTruthy(), { timeout: 90000, interval: 250 });const first = (await projects.getProject(id)).publishKit;- expect(first.exports.map((e) => e.kind)).toEqual(['x-1080p', 'preview-720p', 'teaser']);+ expect(first.exports.map((e) => e.kind)).toEqual(['x-1080p', 'preview-720p', 'teaser', 'vertical-9x16']);for (const e of first.exports) expect(existsSync(join(PATHS.videos, e.filename))).toBe(true);expect(first.thumbnails).toHaveLength(2); // the two performance shotsexpect(first.thumbnail).toBe(first.thumbnails[0]);