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

Run a beat toggle's incoming clip on the song's clock (#11411)

[._.]/7a3fa40bdd9d
diff --git a/client/src/components/musicVideo/StoryboardAnimatic.jsx b/client/src/components/musicVideo/StoryboardAnimatic.jsx
index 6c0b6fe838..5c3587a67c 100644
--- a/client/src/components/musicVideo/StoryboardAnimatic.jsx
+++ b/client/src/components/musicVideo/StoryboardAnimatic.jsx
@@ -167,24 +167,26 @@ const CLIP_PAUSED_DRIFT_SEC = 0.01;
* them: the offset moves the in-point by whole frames, a negative one past the
* clip's start holds its first frame that long, and the speed runs the clip faster
* or slower, looping round the whole file as the render's looped input does.
+ * `early` follows the song's clock before the shot starts too (a beat toggle
+ * into it), reading the footage before its in-point back to the clip's start.
*/
-export function clipTimeAt(scene, t, clipSec = null) {
+export function clipTimeAt(scene, t, clipSec = null, { early = false } = {}) {
const inSec = selectedPerformanceInstruction(scene)?.edit?.inSec ?? 0;
- const local = Math.max(0, t - (scene.startSec || 0));
+ const local = early ? t - (scene.startSec || 0) : Math.max(0, t - (scene.startSec || 0));
const rate = clipSpeedRate(scene);
const start = inSec + clipOffsetSec(scene);
+ // A negative offset holds the first frame before the clip runs; otherwise it runs from `start`.
+ const at = start >= 0 ? Math.max(0, start + local * rate) : Math.max(0, local + start) * rate;
if (clipReversed(scene)) {
// Backwards from the file's end, as the render reads it once: past its start it holds the first frame shown last.
if (!(clipSec > 0)) return 0;
- const at = Math.max(0, start) + Math.max(0, local + Math.min(0, start)) * rate;
return Math.min(clipSec - 0.05, Math.max(0, clipSec - at));
}
if (rate !== 1 || start !== inSec) {
- const sourceIn = Math.max(0, start);
- const at = sourceIn + Math.max(0, local + Math.min(0, start)) * rate;
if (!(clipSec > 0) || at < clipSec) return at;
return scene.loop !== false && !(inSec > 0) ? at % clipSec : Math.max(0, clipSec - 0.05);
}
+ if (local < 0) return at;
if (!(clipSec > inSec)) return inSec + local;
const span = clipSec - inSec;
if (local < span) return inSec + local;
@@ -206,10 +208,8 @@ const ANIMATIC_LOOK_KEY = 'portos-mv-animatic-look';
* come waits paused on its first frame. The clip stays transparent until it has
* a frame to show, so the shot's still underneath covers the load and the seek.
*/
-function ShotClip({ scene, audioRef, time, current, leadSec = 0 }) {
+function ShotClip({ scene, audioRef, time, current }) {
const videoRef = useRef(null);
- // A beat toggle into this shot started its clip early: it carries on from there.
- const timing = useMemo(() => (leadSec > 0 ? { ...scene, startSec: (scene.startSec || 0) - leadSec } : scene), [scene, leadSec]);
const [ready, setReady] = useState(false);
const file = useVideoFileSrc(scene.videoHistoryId);
const src = file.src || (file.resolving ? null : `/data/videos/${scene.videoHistoryId}.mp4`);
@@ -218,17 +218,17 @@ function ShotClip({ scene, audioRef, time, current, leadSec = 0 }) {
const audio = audioRef.current;
if (!video || !audio || video.readyState < 1) return;
const duration = Number.isFinite(video.duration) ? video.duration : null;
- const target = clipTimeAt(timing, current ? audio.currentTime || 0 : scene.startSec || 0, duration);
+ const target = clipTimeAt(scene, current ? audio.currentTime || 0 : scene.startSec || 0, duration);
// A browser cannot play a clip backwards, so a reversed clip stays paused and is stepped to each frame.
const reversed = clipReversed(scene);
const tolerance = current && (audio.paused || reversed) ? CLIP_PAUSED_DRIFT_SEC : CLIP_DRIFT_SEC;
if (Math.abs((video.currentTime || 0) - target) > tolerance && !(reversed && video.seeking)) video.currentTime = target;
// The shot's hand-set speed; a negative offset's lead holds the first frame.
video.playbackRate = clipSpeedRate(scene);
- const leading = (timing.startSec || 0) - clipOffsetSec(scene) - (selectedPerformanceInstruction(scene)?.edit?.inSec ?? 0) > (audio.currentTime || 0);
+ const leading = (scene.startSec || 0) - clipOffsetSec(scene) - (selectedPerformanceInstruction(scene)?.edit?.inSec ?? 0) > (audio.currentTime || 0);
if (!current || audio.paused || leading || reversed) video.pause?.();
else if (video.paused) video.play?.()?.catch?.(() => {});
- }, [scene, timing, audioRef, current]);
+ }, [scene, audioRef, current]);
// Shown once a frame is decoded where the clip should be; kept from then on, since a
// drift re-seek holds the last frame rather than going blank.
const markReady = useCallback(() => {
@@ -276,8 +276,8 @@ function ShotClip({ scene, audioRef, time, current, leadSec = 0 }) {
/**
* The incoming shot of a beat toggle (lib/musicVideoCutEffects.js) over the
- * outgoing one: its clip plays from where the toggle starts it and shows only
- * on the toggle's frames, as the final render overlays it. Playback flips it on
+ * outgoing one: its clip runs on the song's clock, reading the footage before
+ * its in-point, and shows only on the toggle's frames, as the final render overlays it. Playback flips it on
* animation frames, since the song's timeupdate is far too coarse for a beat.
* A shot without a clip shows its still.
*/
@@ -285,7 +285,6 @@ function ToggleClip({ scene, toggle, audioRef, time }) {
const mediaRef = useRef(null);
const file = useVideoFileSrc(scene.videoHistoryId || null);
const src = scene.videoHistoryId ? file.src || (file.resolving ? null : `/data/videos/${scene.videoHistoryId}.mp4`) : null;
- const timing = useMemo(() => ({ ...scene, startSec: toggle.windowStartSec }), [scene, toggle.windowStartSec]);
const apply = useCallback((t) => {
const el = mediaRef.current;
const audio = audioRef.current;
@@ -293,13 +292,13 @@ function ToggleClip({ scene, toggle, audioRef, time }) {
el.style.opacity = toggle.incoming.some(([a, b]) => t >= a && t < b) ? '1' : '0';
if (el.tagName !== 'VIDEO' || el.readyState < 1) return;
const duration = Number.isFinite(el.duration) ? el.duration : null;
- const target = clipTimeAt(timing, Math.max(t, toggle.windowStartSec), duration);
+ const target = clipTimeAt(scene, Math.min(Math.max(t, toggle.windowStartSec), toggle.cutSec), duration, { early: true });
const tolerance = audio?.paused ? CLIP_PAUSED_DRIFT_SEC : CLIP_DRIFT_SEC;
if (Math.abs((el.currentTime || 0) - target) > tolerance) el.currentTime = target;
const running = !!audio && !audio.paused && t >= toggle.windowStartSec && t < toggle.cutSec;
if (!running) el.pause?.();
else if (el.paused) el.play?.()?.catch?.(() => {});
- }, [toggle, timing, audioRef]);
+ }, [toggle, scene, audioRef]);
useEffect(() => { apply(time); }, [time, apply]);
useEffect(() => {
const audio = audioRef.current;
@@ -431,9 +430,7 @@ export default function StoryboardAnimatic({ project, audioUrl, seekRequest, col
};
// Beat toggles across cuts, on the frames the final render flips (lib/musicVideoCutEffects.js).
const beats = project.audioAnalysis?.beats;
- const toggles = useMemo(() => sceneBeatToggles(scenes, { fps: ANIMATIC_FPS, beats, endSec: songEndSec || null,
- isPerformance: (scene) => !!selectedPerformanceInstruction(scene)?.edit }), [scenes, beats, songEndSec]);
- const leadOf = (scene) => toggles.find((t) => t.toSceneId === scene.sceneId)?.leadSec || 0;
+ const toggles = useMemo(() => sceneBeatToggles(scenes, { fps: ANIMATIC_FPS, beats, endSec: songEndSec || null }), [scenes, beats, songEndSec]);
// A toggle mounts its incoming clip a little ahead, so it has loaded when the flips start.
const nearToggles = toggles.filter((t) => time >= t.windowStartSec - 3 && time < t.cutSec);
const shot = shotAt(scenes, time);
@@ -474,7 +471,7 @@ export default function StoryboardAnimatic({ project, audioUrl, seekRequest, col
</div>
) : null}
{clipShots.map((scene) => (
- <ShotClip key={`${scene.sceneId}:${scene.videoHistoryId}`} scene={scene} audioRef={audioRef} time={time} current={scene === shot} leadSec={leadOf(scene)} />
+ <ShotClip key={`${scene.sceneId}:${scene.videoHistoryId}`} scene={scene} audioRef={audioRef} time={time} current={scene === shot} />
))}
{nearToggles.map((toggle) => {
const incoming = scenes.find((scene) => scene.sceneId === toggle.toSceneId);
diff --git a/client/src/components/musicVideo/StoryboardAnimatic.test.jsx b/client/src/components/musicVideo/StoryboardAnimatic.test.jsx
index 4bc0e1b20d..ffcdc146d8 100644
--- a/client/src/components/musicVideo/StoryboardAnimatic.test.jsx
+++ b/client/src/components/musicVideo/StoryboardAnimatic.test.jsx
@@ -122,11 +122,12 @@ describe('StoryboardAnimatic clips', () => {
});
// Uniquely catches the animatic's beat toggle showing the incoming shot on the wrong frames,
- // starting its clip in the wrong place, or the incoming shot jumping back to its start at the cut.
- it('flips to the next shot on the beats before a beat toggle cut and carries its clip on through the cut', async () => {
+ // or its clip leaving the song's clock (ignoring the shot's offset or speed) before or after the cut.
+ it('flips to the next shot on the beats before a beat toggle cut, its clip on the song\'s clock', async () => {
const scenes = [
{ sceneId: 'a', label: 'One', startSec: 0, endSec: 4, videoHistoryId: 'clip-a', cutEffect: { style: 'beat-toggle', enabled: true, overlapSec: 1, rate: 'beat' } },
- { sceneId: 'b', label: 'Two', startSec: 4, endSec: 8, videoHistoryId: 'clip-b' },
+ // 1.5 s in, half again as fast.
+ { sceneId: 'b', label: 'Two', startSec: 4, endSec: 8, videoHistoryId: 'clip-b', offsetFrames: 36, speedFps: 12 },
];
const project = { id: 'p', scenes, audioAnalysis: { beats: [3, 3.5, 4, 4.5] } };
render(<StoryboardAnimatic project={project} audioUrl="/song.mp3" />);
@@ -139,16 +140,16 @@ describe('StoryboardAnimatic clips', () => {
expect(toggle.style.opacity).toBe('0');
at(3.2);
expect(toggle.style.opacity).toBe('1');
- // The incoming clip started on the first beat.
- expect(toggle.currentTime).toBeCloseTo(0.2, 2);
+ // 0.8 s before the shot starts: 1.2 s of clip before its 1.5 s in-point.
+ expect(toggle.currentTime).toBeCloseTo(0.3, 2);
at(3.7);
expect(toggle.style.opacity).toBe('0');
- // Past the cut the incoming shot's own clip runs on from where the toggle took it.
+ // Past the cut the incoming shot's own clip starts where it would without the toggle.
const clipB = screen.getByLabelText('Clip for Two');
Object.defineProperty(clipB, 'readyState', { value: 4, configurable: true });
Object.defineProperty(audio, 'paused', { value: true, configurable: true });
at(4.25);
- expect(clipB.currentTime).toBeCloseTo(1.25, 2);
+ expect(clipB.currentTime).toBeCloseTo(1.875, 2);
});
it('loads the next shots\' clips ahead and cuts to the same loaded clip', async () => {
diff --git a/server/lib/musicVideoCutEffects.js b/server/lib/musicVideoCutEffects.js
index 4cf42badd3..dcaac0c7d0 100644
--- a/server/lib/musicVideoCutEffects.js
+++ b/server/lib/musicVideoCutEffects.js
@@ -7,9 +7,10 @@
* `beat-toggle`: over the last moments of the outgoing shot both clips play and
* the picture flips between them on the song's beats, incoming first
* (incoming, outgoing, incoming, …), then the incoming shot carries on. Its
- * clip keeps running from where the toggle started it, so the cut lands mid-
- * motion; a lip-synced (performance) shot instead starts from its in-point at
- * the cut, so its mouth stays on the words.
+ * clip runs on the song's clock: during the flips it shows the footage just
+ * before its in-point (as its speed and offset place it), so beat-timed motion
+ * and a lip-sync stay on the song, and the shot itself starts exactly where it
+ * would without the toggle.
*
* One definition serves both players: the final render overlays the incoming
* clip on exactly the frames `beatToggleCuts` names, and the storyboard
@@ -76,15 +77,13 @@ export function beatToggleSwitches({ cutSec, overlapSec, rate = 'beat', beats =
/**
* The beat toggles on a cut timeline. `pieces` are its sections in order,
- * `{ sceneId, startFrame, endFrame, partner?, cutEffect?, performance? }` on one
+ * `{ sceneId, startFrame, endFrame, partner?, cutEffect? }` on one
* frame grid (`cutEffect` as `sceneCutEffect` returns it). A toggle plays on the
* cut out of a shot's last piece into the next shot's first; an intercut
* partner piece on either side carries none. Returns, per toggle:
- * `{ index, cutFrame, windowFrames, incoming: [[from, to)], leadFrames }` with
- * `index` the outgoing piece, `incoming` the frames (on the timeline) that show
- * the incoming clip, `windowFrames` how many frames before the cut the incoming
- * clip starts playing, and `leadFrames` how far its clip has run by the cut
- * (0 for a performance shot, which starts again at its in-point).
+ * `{ index, cutFrame, windowFrames, incoming: [[from, to)] }` with `index` the
+ * outgoing piece, `incoming` the frames (on the timeline) that show the incoming
+ * clip, and `windowFrames` how many frames before the cut its clip is read.
*/
export function beatToggleCuts(pieces, { fps, beats = [] }) {
const list = Array.isArray(pieces) ? pieces : [];
@@ -111,7 +110,7 @@ export function beatToggleCuts(pieces, { fps, beats = [] }) {
const incoming = [];
for (let k = 0; k < switches.length; k += 2) incoming.push([switches[k], k + 1 < switches.length ? switches[k + 1] : cutFrame]);
const windowFrames = cutFrame - switches[0];
- out.push({ index: i, cutFrame, windowFrames, incoming, leadFrames: to.performance ? 0 : windowFrames });
+ out.push({ index: i, cutFrame, windowFrames, incoming });
}
return out;
}
@@ -119,17 +118,16 @@ export function beatToggleCuts(pieces, { fps, beats = [] }) {
/**
* The storyboard's beat toggles in song seconds (the animatic's counterpart of
* the render's): `[{ fromSceneId, toSceneId, windowStartSec, cutSec, incoming:
- * [[fromSec, toSec)], leadSec }]`. `isPerformance(scene)` says whether a shot
- * plays a lip-synced edit.
+ * [[fromSec, toSec)] }]`.
*/
-export function sceneBeatToggles(scenes, { fps, beats = [], endSec = null, isPerformance = () => false }) {
+export function sceneBeatToggles(scenes, { fps, beats = [], endSec = null }) {
const timed = (Array.isArray(scenes) ? scenes : []).filter((s) => Number.isFinite(s?.startSec)).sort((a, b) => a.startSec - b.startSec);
const pieces = timed.map((scene, i) => {
const next = timed[i + 1];
const stop = next ? next.startSec : (Number.isFinite(endSec) ? endSec : scene.endSec);
return {
sceneId: scene.sceneId, startFrame: Math.round(scene.startSec * fps), endFrame: Math.round((stop ?? scene.startSec) * fps),
- cutEffect: sceneCutEffect(scene), performance: !!isPerformance(scene),
+ cutEffect: sceneCutEffect(scene),
};
});
return beatToggleCuts(pieces, { fps, beats }).map((t) => ({
@@ -138,6 +136,5 @@ export function sceneBeatToggles(scenes, { fps, beats = [], endSec = null, isPer
windowStartSec: (t.cutFrame - t.windowFrames) / fps,
cutSec: t.cutFrame / fps,
incoming: t.incoming.map(([a, b]) => [a / fps, b / fps]),
- leadSec: t.leadFrames / fps,
}));
}
diff --git a/server/services/musicVideo/cutEffects.test.js b/server/services/musicVideo/cutEffects.test.js
index da294e32ff..ebd0b9a318 100644
--- a/server/services/musicVideo/cutEffects.test.js
+++ b/server/services/musicVideo/cutEffects.test.js
@@ -18,16 +18,15 @@ const H = 48;
const toggle = (extra = {}) => sceneCutEffect({ cutEffect: { style: 'beat-toggle', overlapSec: 0.5, ...extra } });
// Uniquely catches where a beat toggle flips: which beats (or half beats) in the
-// overlap, the even fallback with no beat grid, which cuts carry one, and a
-// lip-synced shot restarting at its cut rather than running on.
+// overlap, the even fallback with no beat grid, and which cuts carry one.
describe('beatToggleCuts', () => {
const piece = (sceneId, startFrame, endFrame, extra = {}) => ({ sceneId, startFrame, endFrame, ...extra });
it('flips to the incoming shot on each beat in the overlap before the cut, incoming first', () => {
const [cut] = beatToggleCuts([piece('a', 0, 24, { cutEffect: toggle() }), piece('b', 24, 48)], { fps: 24, beats: [0.25, 0.5, 0.75, 1] });
- expect(cut).toEqual({ index: 0, cutFrame: 24, windowFrames: 12, incoming: [[12, 18]], leadFrames: 12 });
- const [half] = beatToggleCuts([piece('a', 0, 24, { cutEffect: toggle({ rate: 'half' }) }), piece('b', 24, 48, { performance: true })], { fps: 24, beats: [0.25, 0.5, 0.75, 1] });
- expect(half).toMatchObject({ incoming: [[12, 15], [18, 21]], leadFrames: 0 });
+ expect(cut).toEqual({ index: 0, cutFrame: 24, windowFrames: 12, incoming: [[12, 18]] });
+ const [half] = beatToggleCuts([piece('a', 0, 24, { cutEffect: toggle({ rate: 'half' }) }), piece('b', 24, 48)], { fps: 24, beats: [0.25, 0.5, 0.75, 1] });
+ expect(half).toMatchObject({ incoming: [[12, 15], [18, 21]] });
const [even] = beatToggleCuts([piece('a', 0, 24, { cutEffect: toggle() }), piece('b', 24, 48)], { fps: 24 });
expect(even.incoming).toEqual([[12, 15], [18, 21]]);
});
@@ -47,44 +46,53 @@ function frameMeans(path) {
}
// Uniquely catches the toggle's filters failing in ffmpeg, flipping on the wrong
-// frames, adding time, or the incoming clip jumping back to its start at the cut.
+// frames, adding time, or the incoming clip leaving the song's clock: ignoring its
+// in-point (a performance edit or hand-set offset) or speed, or moving the shot itself.
describe.skipIf(!ffmpeg)('a beat toggle across a cut in the final render', () => {
- const render = (incomingExtra = {}) => {
- const song = join(dir, 'song.wav');
+ const song = join(dir, 'song.wav');
+ const outgoing = join(dir, 'outgoing.mp4');
+ const incoming = join(dir, 'incoming.mp4');
+ const render = (incomingTiming) => {
run(['-f', 'lavfi', '-i', 'sine=frequency=440:duration=2', '-y', song]);
- const outgoing = join(dir, 'outgoing.mp4');
- const incoming = join(dir, 'incoming.mp4');
run(['-f', 'lavfi', '-i', `color=white:s=${W}x${H}:r=${FPS}:d=1`, '-pix_fmt', 'yuv420p', '-y', outgoing]);
- // Its brightness climbs 8 levels a frame, so a frame's luma names its place in the clip.
- run(['-f', 'lavfi', '-i', `color=black:s=${W}x${H}:r=${FPS}:d=2,geq=lum='40+8*N':cb=128:cr=128`, '-pix_fmt', 'yuv420p', '-y', incoming]);
- const clip = (videoPath, i, extra = {}) => ({ sceneId: `s${i}`, videoPath, width: W, height: H, fps: FPS, duration: i ? 2 : 1, sourceSec: i ? 2 : 1, loop: false, inSec: 0, outSec: 1, frameFit: 'fill', ...extra });
+ // Its brightness climbs 4 levels a frame, so a frame's luma names its place in the clip.
+ run(['-f', 'lavfi', '-i', `color=black:s=${W}x${H}:r=${FPS}:d=4,geq=lum='40+4*N':cb=128:cr=128`, '-pix_fmt', 'yuv420p', '-y', incoming]);
+ const clip = (videoPath, i, extra = {}) => ({ sceneId: `s${i}`, videoPath, width: W, height: H, fps: FPS, duration: 1, sourceSec: 1, loop: false, inSec: 0, outSec: 1, frameFit: 'fill', ...extra });
const output = join(dir, 'toggle.mp4');
- const plan = buildMusicVideoFfmpegArgs([clip(outgoing, 0, { cutEffect: toggle() }), clip(incoming, 1, incomingExtra)], song, output,
+ const plan = buildMusicVideoFfmpegArgs([clip(outgoing, 0, { cutEffect: toggle() }), clip(incoming, 1, incomingTiming)], song, output,
{ audioDurationSec: 2, frameGrid: true, beats: [0.5, 0.75, 1, 1.25] });
run(plan.args.filter((arg, i) => !(arg === '-progress' || plan.args[i - 1] === '-progress')));
expect(plan.totalDuration).toBe(2);
- return frameMeans(output);
+ const means = frameMeans(output);
+ expect(means).toHaveLength(2 * FPS);
+ // Outgoing until the first beat (frame 6) and again on frames 9-11, between the flips.
+ expect([0, 5, 9, 11].every((f) => means[f] > 200)).toBe(true);
+ return means;
};
// The clip's Y levels read back as full-range gray.
- const clipFrame = (n) => ((40 + 8 * n - 16) * 255) / 219;
+ const showsClipFrame = (means, f, n) => expect(Math.abs(means[f] - ((40 + 4 * n - 16) * 255) / 219)).toBeLessThan(2.5);
- it('shows the incoming clip on its beats, keeps every frame and carries the clip on through the cut', () => {
- const means = render();
- expect(means).toHaveLength(2 * FPS);
- const white = (f) => means[f] > 200;
- // Outgoing until the first beat, the incoming clip from its start on frames 6-8, outgoing again on 9-11.
- expect([0, 5, 9, 11].every(white)).toBe(true);
- [6, 7, 8].forEach((f, k) => expect(Math.abs(means[f] - clipFrame(k))).toBeLessThan(4));
- // At the cut the incoming clip is 6 frames in, as far as the toggle ran it.
- expect(Math.abs(means[12] - clipFrame(6))).toBeLessThan(4);
+ it('reads the footage before an in-point, so the shot still starts at its in-point', () => {
+ // In 0.5 s: the half second before it plays under the flips.
+ const means = render({ inSec: 0.5, outSec: 1.5, sourceSec: 3.5, duration: 1 });
+ [6, 7, 8].forEach((f, k) => showsClipFrame(means, f, k));
+ showsClipFrame(means, 12, 6);
+ showsClipFrame(means, 23, 17);
+ });
+
+ it('holds the first frame where the clip has no footage before its in-point', () => {
+ const means = render({ sourceSec: 4 });
+ [6, 7, 8].forEach((f) => showsClipFrame(means, f, 0));
+ showsClipFrame(means, 12, 0);
+ showsClipFrame(means, 23, 11);
});
- // Uniquely catches a non-looping clip with no spare footage running out before its shot ends.
- it('starts a clip with no footage to spare from its in-point at the cut', () => {
- const means = render({ duration: 1, sourceSec: 1 });
- [6, 7, 8].forEach((f, k) => expect(Math.abs(means[f] - clipFrame(k))).toBeLessThan(4));
- expect(Math.abs(means[12] - clipFrame(0))).toBeLessThan(4);
- expect(Math.abs(means[23] - clipFrame(11))).toBeLessThan(4);
+ it('plays the footage before the in-point at the shot\'s speed', () => {
+ // Twice as fast from 1 s into the clip: on the output timebase it starts at 0.5 s.
+ const means = render({ rate: 2, inSec: 0.5, outSec: 1.5, sourceSec: 1.5, duration: 1 });
+ [6, 7, 8].forEach((f, k) => showsClipFrame(means, f, 2 * k));
+ showsClipFrame(means, 12, 12);
+ showsClipFrame(means, 23, 34);
});
});
diff --git a/server/services/musicVideo/render.js b/server/services/musicVideo/render.js
index 98ced9d018..03f8710854 100644
--- a/server/services/musicVideo/render.js
+++ b/server/services/musicVideo/render.js
@@ -321,9 +321,8 @@ export async function resolveSceneClips(project, { layered = false, stillForMiss
...footageFrameFit(scene),
// VHS glitches on its cuts (musicVideoTransitions.js) ride over the edit without moving it.
...sceneTransitions(scene),
- // So does a beat toggle on its cut out (musicVideoCutEffects.js); a lip-synced shot restarts at its cut.
+ // So does a beat toggle on its cut out (musicVideoCutEffects.js).
...cutEffectOf(scene),
- ...(edit ? { performance: true } : {}),
});
}
if (missing.length > 0) {
@@ -582,25 +581,26 @@ export function buildMusicVideoFfmpegArgs(clips, audioPath, outputPath, { audioD
return clipInput;
};
// A beat toggle (musicVideoCutEffects.js) flips the picture to the next shot's clip
- // on the beats before a cut. That clip plays from where the toggle starts it, read
- // from an input of its own, and its own section picks up where it left off.
+ // on the beats before a cut. That clip runs on the song's clock, read from an input
+ // of its own, so its own section starts exactly where it would without the toggle.
const sectionFrame = (sec) => Math.round(sec * fps);
const toggles = beatToggleCuts(plan.map(({ c, startSec, endSec }) => ({
sceneId: c.sceneId, startFrame: sectionFrame(startSec), endFrame: sectionFrame(endSec),
- partner: !!c.intercutOf, cutEffect: c.cutEffect, performance: !!c.performance,
+ partner: !!c.intercutOf, cutEffect: c.cutEffect,
})), { fps, beats });
const prerolls = toggles.map((t) => {
- const incoming = plan[t.index + 1];
- const clip = { ...incoming.c, outSec: incoming.c.inSec + t.windowFrames / fps };
- // A clip that doesn't loop only runs on as far as its spare footage allows, so
- // the shot never runs out early and freezes on its last frame.
- const spare = incoming.c.loop === false
- ? Math.max(0, (incoming.c.sourceSec ?? incoming.c.duration) - (incoming.c.outSec - incoming.c.inSec))
- : Infinity;
- const lead = Math.min(t.leadFrames / fps, spare);
- if (lead > 0 && !incoming.c.layer) {
- incoming.c = { ...incoming.c, inSec: incoming.c.inSec + lead, outSec: incoming.c.outSec + lead, sourceSec: (incoming.c.sourceSec ?? incoming.c.duration) - lead };
- }
+ const { c } = plan[t.index + 1];
+ // The footage just before the incoming shot's in-point, on the output timebase
+ // its speed and offset already set; any part before the clip starts holds its first frame.
+ const windowSec = t.windowFrames / fps;
+ const shortSec = Math.max(0, windowSec - c.inSec);
+ const clip = c.layer ? { ...c, outSec: c.inSec + windowSec } : {
+ ...c,
+ inSec: Math.max(0, c.inSec - windowSec),
+ outSec: c.inSec + shortSec,
+ sourceSec: (c.sourceSec ?? c.duration) + windowSec,
+ ...(shortSec > 0 ? { leadSec: round3((c.leadSec || 0) + shortSec) } : {}),
+ };
return { ...t, clip };
});
for (const { c } of plan) inputOf.push(addInput(c));