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

Trim a shot's clip to a later start frame as a new take (#11262)

[._.]/b4d8f5f148ad
diff --git a/client/src/components/musicVideo/SceneCard.jsx b/client/src/components/musicVideo/SceneCard.jsx
index 4ecaeb00af..e6a6c3062e 100644
--- a/client/src/components/musicVideo/SceneCard.jsx
+++ b/client/src/components/musicVideo/SceneCard.jsx
@@ -6,6 +6,7 @@ import { useEffect, useRef, useState } from 'react';
import { Trash2, Activity, ArrowUp, ArrowDown, ChevronRight, Image as ImageIcon, Video, Maximize2, AlertTriangle, ImagePlus, Clapperboard, SkipForward, Shuffle, ArrowRight } from 'lucide-react';
import OverflowMenu from '../ui/OverflowMenu.jsx';
import SceneTakePicker from './SceneTakePicker.jsx';
+import VideoStartTrimControl from '../media/VideoStartTrimControl.jsx';
import { formatDurationSec } from '../../utils/formatters.js';
import { useVideoFileSrc } from '../../hooks/useVideoFileSrc.js';
import PerformanceEvidence from './PerformanceEvidence.jsx';
@@ -123,7 +124,7 @@ export default function SceneCard({
settingsSaving, videoBlockedReason, videoBlockedReasonFor = null, canContinueShot,
onMove, onDelete, onEditLocal, onSave,
onGenerateFrame, onGenerateVideo, onContinueVideo, onGenerateEndFrame, generatingEndFrame = false, onContinueFromPrevious, previousHasClip = false,
- onOpenPreview, onSelectTake, onReviewTake, onImportTake, onImportClipTake, onPlacePoolItem, projectId = null, videoModels = [], defaultVideoModel = '', shotNumbers = undefined, takeBusy = false, layered = false, documentComposition = false,
+ onOpenPreview, onSelectTake, onReviewTake, onImportTake, onImportClipTake, onPlacePoolItem, onTrimClip, projectId = null, videoModels = [], defaultVideoModel = '', shotNumbers = undefined, takeBusy = false, layered = false, documentComposition = false,
lipSyncBackend = '', songDurationSec = null, onSplit, onMergeNext, nextEndSec = null, falVideoSettings = null, onSeek, performanceReview = null, onRepairPerformance, repairBusy = false,
expanded, onToggleExpand, footageOptional = false, failedScenes = null, songReview = null,
}) {
@@ -459,6 +460,12 @@ export default function SceneCard({
</button>
</div>
)}
+ {/* Step to a later frame and keep the clip from there, as a new take of this shot. */}
+ {scene.videoHistoryId && !performance && onTrimClip && (
+ <VideoStartTrimControl videoRef={clipPlayerRef} sourceKey={scene.videoHistoryId}
+ disabled={takeBusy || !!generatingVideo || shotLock?.clip === 'locked'}
+ onTrim={(startSec) => onTrimClip(scene, startSec)} />
+ )}
{!scene.videoHistoryId && layer === 'footage' && (
<div className="flex aspect-video w-full items-center justify-center rounded border border-dashed border-port-border text-xs text-port-text-muted">No clip yet</div>
)}
diff --git a/client/src/components/musicVideo/stages/BoardStage.jsx b/client/src/components/musicVideo/stages/BoardStage.jsx
index d0425e0622..2dd0a5af87 100644
--- a/client/src/components/musicVideo/stages/BoardStage.jsx
+++ b/client/src/components/musicVideo/stages/BoardStage.jsx
@@ -228,6 +228,7 @@ export default function BoardStage({ board }) {
onImportTake={(target) => board.setPickerTarget({ type: 'take', sceneId: target.sceneId })}
onImportClipTake={(target) => board.setPickerTarget({ type: 'clip', sceneId: target.sceneId })}
onPlacePoolItem={takes.placePoolItem}
+ onTrimClip={takes.trimClipTake}
projectId={project.id}
shotNumbers={numbers}
layered={layered}
diff --git a/client/src/hooks/useMusicVideoTakes.js b/client/src/hooks/useMusicVideoTakes.js
index 5d525d0396..86023381d5 100644
--- a/client/src/hooks/useMusicVideoTakes.js
+++ b/client/src/hooks/useMusicVideoTakes.js
@@ -11,7 +11,7 @@ import {
importMusicVideoHandoff,
} from '../services/apiMusicVideo.js';
import { uploadGalleryImage } from '../services/apiSystem.js';
-import { uploadGalleryVideo } from '../services/apiImageVideo.js';
+import { trimVideoStart, uploadGalleryVideo } from '../services/apiImageVideo.js';
import { downloadBlob } from '../lib/downloadBlob.js';
import { validateImageFile } from '../utils/fileUpload.js';
@@ -77,6 +77,23 @@ export default function useMusicVideoTakes({ project, applyScenePatch }) {
'Failed to use that take',
);
+ // "Start clip here": the shot's clip from a later frame becomes a new clip take, and the selected one.
+ // It keeps the cut clip's still and provider, so a still change still marks it stale and the pool pairs it.
+ const trimClipTake = (scene, startSec) => {
+ const origin = scene.takes?.find((take) => take.kind === 'video' && take.assetId === scene.videoHistoryId);
+ const provenance = {
+ ...(origin?.sourceImageId ? { sourceImageId: origin.sourceImageId } : {}),
+ // Only a slug the take route accepts; an older free-form label is left off rather than failing the trim.
+ ...(/^[a-z0-9][a-z0-9._-]{0,39}$/i.test(origin?.provider || '') ? { provider: origin.provider } : {}),
+ };
+ return runTakeOp(
+ (projectId) => trimVideoStart(scene.videoHistoryId, startSec, { silent: true })
+ .then(({ video }) => addMusicVideoSceneTake(projectId, scene.sceneId, { kind: 'video', assetId: video.id, source: 'trimmed', ...provenance }, { silent: true }))
+ .then(({ take }) => selectMusicVideoSceneTake(projectId, scene.sceneId, take.takeId, { silent: true })),
+ 'Failed to trim the clip',
+ );
+ };
+
// Continuing shot: the previous shot's last on-screen frame becomes this
// scene's start frame; `keepStillAsEnd` keeps the current one as its end frame.
const continueFromPrevious = (scene, { keepStillAsEnd = false } = {}) => runTakeOp(
@@ -162,5 +179,5 @@ export default function useMusicVideoTakes({ project, applyScenePatch }) {
if (failures.length) toast.error(failures.slice(0, 3).join(' · '));
};
- return { busy, selectTake, placePoolItem, reviewTake, continueFromPrevious, importTake, importClipTake, exportHandoff, exportHandoffBundle, importHandoffFiles };
+ return { busy, selectTake, placePoolItem, trimClipTake, reviewTake, continueFromPrevious, importTake, importClipTake, exportHandoff, exportHandoffBundle, importHandoffFiles };
}
diff --git a/client/src/pages/MusicVideo.test.jsx b/client/src/pages/MusicVideo.test.jsx
index b605fc539a..d878f840f0 100644
--- a/client/src/pages/MusicVideo.test.jsx
+++ b/client/src/pages/MusicVideo.test.jsx
@@ -216,6 +216,7 @@ vi.mock('../services/apiImageVideo.js', () => ({
getVideoGenModelContext: vi.fn(async () => null),
generateVideo: vi.fn(),
uploadGalleryVideo: vi.fn(),
+ trimVideoStart: vi.fn(),
listLorasFull: vi.fn(async () => [{
filename: 'audio-reactive.safetensors',
name: 'Audio Reactive',
@@ -289,7 +290,7 @@ import {
} from '../services/apiMusicVideo.js';
import { generateImage, uploadGalleryImage } from '../services/apiSystem.js';
import { importTrackFromYoutube, importTrackFromSuno, trackImportEventsUrl, listTracks } from '../services/apiTracks.js';
-import { generateVideo, getVideoGenStatus, getVideoHistoryItem } from '../services/apiImageVideo.js';
+import { generateVideo, getVideoGenStatus, getVideoHistoryItem, trimVideoStart } from '../services/apiImageVideo.js';
import { getUniverse } from '../services/apiUniverseBuilder.js';
import { downloadBlob } from '../lib/downloadBlob.js';
@@ -2499,6 +2500,23 @@ describe('MusicVideo visual spec, takes and handoff (#8965)', () => {
}), { silent: true }));
});
+ // Uniquely catches a trimmed clip landing only in Video Gen history, never as this shot's take, or not becoming the shot's clip.
+ it('trims the shot clip to a later start frame and makes it the shot\'s selected clip take', async () => {
+ const scene = { sceneId: 's1', order: 0, prompt: 'waves', referenceImageId: 'img1', videoHistoryId: 'h1',
+ takes: [{ takeId: 't-v', kind: 'video', assetId: 'h1', source: 'generated', provider: 'portos', sourceImageId: 'img1', status: 'selected', note: null }] };
+ const trimmedTake = { takeId: 't-trim', kind: 'video', assetId: 'h1-trim', source: 'trimmed', provider: null, status: 'candidate', note: null };
+ trimVideoStart.mockResolvedValueOnce({ video: { id: 'h1-trim' } });
+ addMusicVideoSceneTake.mockResolvedValueOnce({ scene: { ...scene, takes: [...scene.takes, trimmedTake] }, take: trimmedTake });
+ selectMusicVideoSceneTake.mockResolvedValueOnce({ ...scene, videoHistoryId: 'h1-trim', takes: [{ ...scene.takes[0], status: 'candidate' }, { ...trimmedTake, status: 'selected' }] });
+ await openProject({ ...PROJECT_WITH_CLIP, id: 'mv-trim', scenes: [scene] }, 'produce');
+ const render = within(await screen.findByRole('region', { name: 'Render' }));
+ for (let i = 0; i < 12; i += 1) fireEvent.click(render.getByRole('button', { name: 'Next frame' }));
+ fireEvent.click(render.getByRole('button', { name: /Start clip here/ }));
+ await waitFor(() => expect(selectMusicVideoSceneTake).toHaveBeenCalledWith('mv-trim', 's1', 't-trim', { silent: true }));
+ expect(trimVideoStart).toHaveBeenCalledWith('h1', 0.5, { silent: true });
+ expect(addMusicVideoSceneTake).toHaveBeenCalledWith('mv-trim', 's1', { kind: 'video', assetId: 'h1-trim', source: 'trimmed', sourceImageId: 'img1', provider: 'portos' }, { silent: true });
+ });
+
it('keeps a new render as a candidate and lets the director explicitly pick and reject takes', async () => {
const scene = {
sceneId: 's1', order: 0, prompt: 'waves', referenceImageId: 'take-a.png', videoHistoryId: null,
diff --git a/server/lib/musicVideoValidation.js b/server/lib/musicVideoValidation.js
index b6f0f72bc0..cedf24f42b 100644
--- a/server/lib/musicVideoValidation.js
+++ b/server/lib/musicVideoValidation.js
@@ -306,7 +306,8 @@ const providerSlug = z.string().min(1).max(40).regex(/^[a-z0-9][a-z0-9._-]*$/i,
export const musicVideoTakeInputSchema = z.object({
kind: z.enum(MUSIC_VIDEO_TAKE_KINDS),
assetId: z.string().min(1).max(256),
- source: z.enum(['generated', 'imported']).optional(),
+ // `trimmed`: a clip take cut from a later start frame of another (the shot card's "Start clip here").
+ source: z.enum(['generated', 'imported', 'trimmed']).optional(),
provider: providerSlug.optional(),
originalName: z.string().max(255).optional(),
sourceImageId: galleryImageName.optional(),
diff --git a/server/routes/musicVideoTakes.test.js b/server/routes/musicVideoTakes.test.js
index 16e3d84c22..38d137e369 100644
--- a/server/routes/musicVideoTakes.test.js
+++ b/server/routes/musicVideoTakes.test.js
@@ -228,7 +228,7 @@ describe('swapping a shot from unused takes', () => {
// Uniquely catches a cut shot's takes vanishing from the picker, a clip losing its still, and a used take offered as unused.
it('lists every unused still and clip, keeps a cut shot\'s takes on the floor, and puts a still with its clip on a shot', async () => {
for (const name of ['a-1.png', 'a-2.png', 'b-1.png', 'b-2.png']) seedImage(name);
- seedVideoHistory([{ id: 'clip-b2', prompt: 'waves in slow motion' }, { id: 'clip-a1' }]);
+ seedVideoHistory([{ id: 'clip-b2', prompt: 'waves in slow motion' }, { id: 'clip-a1' }, { id: 'clip-a1-trim' }]);
await addTake(sceneA.sceneId, { kind: 'image', assetId: 'a-1.png', source: 'generated' });
await addTake(sceneA.sceneId, { kind: 'image', assetId: 'a-2.png', source: 'generated' });
await addTake(sceneA.sceneId, { kind: 'video', assetId: 'clip-a1', source: 'generated', sourceImageId: 'a-1.png' });
@@ -256,11 +256,16 @@ describe('swapping a shot from unused takes', () => {
expect(used.body.scene.takes.find((take) => take.assetId === 'clip-b2')).toMatchObject({ source: 'reused', sourceImageId: 'b-2.png' });
expect((await pool()).map((item) => item.assetId).sort()).toEqual(['a-1.png', 'a-2.png', 'b-1.png', 'clip-a1']);
+ // A clip cut from a later start frame ("Start clip here") lands as a trimmed take.
+ const trimmed = await addTake(sceneA.sceneId, { kind: 'video', assetId: 'clip-a1-trim', source: 'trimmed' });
+ expect(trimmed.status).toBe(201);
+ expect(trimmed.body.take).toMatchObject({ kind: 'video', assetId: 'clip-a1-trim', source: 'trimmed' });
+
// Any unused still can become the shot's end frame, and leaves the pool.
const end = await request(app).post(`${base()}/scenes/${sceneA.sceneId}/takes/use`).send({ kind: 'endImage', assetId: 'b-1.png' });
expect(end.status).toBe(200);
expect(end.body.scene).toMatchObject({ referenceImageId: 'b-2.png', endImageId: 'b-1.png' });
- expect((await pool()).map((item) => item.assetId).sort()).toEqual(['a-1.png', 'a-2.png', 'clip-a1']);
+ expect((await pool()).map((item) => item.assetId).sort()).toEqual(['a-1.png', 'a-2.png', 'clip-a1', 'clip-a1-trim']);
expect((await request(app).post(`${base()}/scenes/${sceneA.sceneId}/takes/use`).send({ kind: 'image', assetId: 'missing.png' })).status).toBe(400);
expect((await request(app).post(`${base()}/scenes/${sceneA.sceneId}/takes/use`).send({ kind: 'endImage', assetId: 'a-1.png', withAssetId: 'clip-a1' })).status).toBe(400);