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

let a code or document excerpt end up to one frame past the frame-quantized render

[._.]/ Adam Eivy5137c8711480
diff --git a/server/lib/musicVideoExcerptRange.js b/server/lib/musicVideoExcerptRange.js
new file mode 100644
index 0000000000..a46b5a98e5
--- /dev/null
+++ b/server/lib/musicVideoExcerptRange.js
@@ -0,0 +1,10 @@
+/**
+ * Whether an excerpt window fits a render of `totalSec` at `fps`. The end may run past the
+ * render by up to one frame: scene timings come from the analysed song length while a
+ * render's duration is frame-quantized, so the last scene's end (119.943s) can sit a
+ * fraction of a frame past a 24 fps document render (119.92s). Callers clamp the end.
+ */
+export function excerptRangeFits(startSec, endSec, totalSec, fps = 24) {
+ const frame = Number.isFinite(fps) && fps > 0 ? 1 / fps : 0;
+ return startSec >= 0 && endSec > startSec && endSec <= totalSec + frame + 1e-6;
+}
diff --git a/server/lib/musicVideoExcerptRange.test.js b/server/lib/musicVideoExcerptRange.test.js
new file mode 100644
index 0000000000..f0405ac2e2
--- /dev/null
+++ b/server/lib/musicVideoExcerptRange.test.js
@@ -0,0 +1,17 @@
+import { describe, expect, it } from 'vitest';
+import { excerptRangeFits } from './musicVideoExcerptRange.js';
+
+describe('excerptRangeFits', () => {
+ it('accepts an end up to one frame past a frame-quantized render', () => {
+ expect(excerptRangeFits(0, 119.943, 119.92, 24)).toBe(true);
+ expect(excerptRangeFits(0, 119.92 + 1 / 24, 119.92, 24)).toBe(true);
+ });
+ it('refuses an end more than a frame past the render, and empty or negative windows', () => {
+ expect(excerptRangeFits(0, 120, 119.92, 24)).toBe(false);
+ expect(excerptRangeFits(5, 5, 119.92, 24)).toBe(false);
+ expect(excerptRangeFits(-1, 4, 119.92, 24)).toBe(false);
+ });
+ it('allows no slack without a usable fps', () => {
+ expect(excerptRangeFits(0, 119.93, 119.92, 0)).toBe(false);
+ });
+});
diff --git a/server/services/musicVideo/excerptRender.js b/server/services/musicVideo/excerptRender.js
index 5fcb8c8e5c..d6b39d0efc 100644
--- a/server/services/musicVideo/excerptRender.js
+++ b/server/services/musicVideo/excerptRender.js
@@ -44,6 +44,7 @@ import { musicVideoAspect, musicVideoAtAspect } from '../../lib/musicVideoAspect
import { musicVideoEvents } from './events.js';
import { pilotDependencies, productionPilotRenderProject } from './productionPilot.js';
import { musicVideoDependencyChanges } from '../../lib/musicVideoDependencies.js';
+import { excerptRangeFits } from '../../lib/musicVideoExcerptRange.js';
const jobs = new Map();
const projectExcerptRenders = new Map();
@@ -148,7 +149,7 @@ async function launchSeekedExcerpt({ projectId, project: stored, startSec, endSe
await assertCurrentPerformanceTakes(project, audioPath);
}
const soundBed = renderer.soundBed ? await resolveSoundBedPath(project) : null;
- if (!(startSec >= 0) || !(endSec > startSec) || endSec > prepared.totalSec + 1e-6) {
+ if (!excerptRangeFits(startSec, endSec, prepared.totalSec, prepared.plan?.fps ?? prepared.full?.fps)) {
throw new ServerError(
`The excerpt range must fall within the project's ${prepared.totalSec.toFixed(2)}s song`,
{ status: 422, code: 'INVALID_EXCERPT_RANGE', context: { totalDuration: prepared.totalSec } },