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

fix: preserve composition frame cadence with integer motion blur (#13427)

Adam Eivy76dd4df528f3
diff --git a/server/services/htmlComposition/encode.js b/server/services/htmlComposition/encode.js
index 236f92d8c2..a45b920b7f 100644
--- a/server/services/htmlComposition/encode.js
+++ b/server/services/htmlComposition/encode.js
@@ -91,6 +91,9 @@ export async function encodeComposition(page, contract, outputPath, { musicPath,
args.push('-map', '0:v', '-vf', [motionBlurFilter, videoFilter, 'scale=in_range=pc:out_range=tv:out_color_matrix=bt709', tag].filter(Boolean).join(','), ...H264_ENCODE_ARGS, ...BT709_CONTAINER_ARGS);
if (exactAudio) args.push('-map', '1:a', ...AAC_ENCODE_ARGS);
else if (musicPath) args.push('-map', '1:a', '-af', `${bedTrim}${mastering ? `,${mastering.filter}` : ''},afade=t=out:st=${durationSec - 0.5}:d=0.5`, ...AAC_ENCODE_ARGS);
+ // select drops subframes without changing the input's advertised rate.
+ // Pin the output cadence so ffmpeg cannot duplicate frames or shorten it.
+ if (sub > 1) args.push('-r', String(fps));
args.push('-frames:v', String(numFrames), '-t', String(durationSec), '-movflags', '+faststart', '-y', outputPath);
const proc = spawnProcess(ffmpeg, args, safeChildProcessOptions({ stdio: ['pipe', 'ignore', 'pipe'] }));
let currentFrame = null;
diff --git a/server/services/htmlComposition/index.test.js b/server/services/htmlComposition/index.test.js
index 3548f7b73f..15bbc1abe5 100644
--- a/server/services/htmlComposition/index.test.js
+++ b/server/services/htmlComposition/index.test.js
@@ -5,6 +5,7 @@ import { join } from 'node:path';
import { randomUUID } from 'node:crypto';
import { execFileSync, spawn } from 'node:child_process';
import { chromium } from 'playwright-core';
+import sharp from 'sharp';
import { cleanupTempDataRoots, lazyTempDataRoot, makePathsProxy } from '../../lib/mockPathsDataRoot.js';
import { findFfmpeg, probeVideoDuration, probeVideoStreamInfo } from '../../lib/ffmpeg.js';
import { PATHS } from '../../lib/fileUtils.js';
@@ -18,11 +19,24 @@ import { resolveTestChrome } from '../../lib/browserSuiteGate.js';
vi.mock('./encode.js', async importOriginal => {
const actual = await importOriginal();
const { _withTestCaptureDiagnostics } = await import('./testBrowserCleanup.js');
- return { ...actual, encodeComposition: _withTestCaptureDiagnostics(actual.encodeComposition, { getTestSignal: () => testSignal }) };
+ const encode = async (page, contract, ...args) => {
+ let capture = 0;
+ const observed = contract.motionBlur === 4 ? { ...page, send: async (method, ...params) => {
+ const result = await page.send(method, ...params);
+ if (method === 'Page.captureScreenshot') {
+ if (capture >= 24 && capture < 28) motionBlurCaptures.push(Buffer.from(result.data, 'base64'));
+ capture++;
+ }
+ return result;
+ } } : page;
+ return actual.encodeComposition(observed, contract, ...args);
+ };
+ return { ...actual, encodeComposition: _withTestCaptureDiagnostics(encode, { getTestSignal: () => testSignal }) };
});
let testSignal;
-beforeEach(({ signal }) => { testSignal = signal; });
+let motionBlurCaptures;
+beforeEach(({ signal }) => { testSignal = signal; motionBlurCaptures = []; });
let endpoint;
vi.mock('../browserService.js', () => ({ cdpRequest: path => fetch(`${endpoint}${path}`) }));
@@ -126,7 +140,17 @@ describe.skipIf(!chrome || !ffmpeg)('HTML composition with real Chrome and ffmpe
expect(await readFile(join(PATHS.videos, explicit.filename))).toEqual(await readFile(join(PATHS.videos, baseline.filename)));
const blurred = await renderComposition(await composition(fixture('', 'motionBlur:4')));
- const pixels = execFileSync(ffmpeg, ['-v', 'error', '-i', join(PATHS.videos, blurred.filename), '-f', 'rawvideo', '-pix_fmt', 'rgb24', '-'], { maxBuffer: 40 * 1024 * 1024 });
+ // Observe the renderer's actual PNG inputs before blaming tmix: a frozen
+ // compositor must name the capture failure instead of a decoded pixel.
+ const greens = await Promise.all(motionBlurCaptures.map(async png => {
+ const rgb = await sharp(png).extract({ left: 345, top: 110, width: 1, height: 1 }).removeAlpha().raw().toBuffer();
+ return rgb[1];
+ }));
+ expect(greens, 'Browser capture did not paint the requested subframe times (t=0.5..0.5625): check the capture environment clock/compositor').toEqual([255, 255, 255, 0]);
+ const output = join(PATHS.videos, blurred.filename);
+ expect(await probeVideoStreamInfo(output)).toMatchObject({ fps: 12, frameCount: 12 });
+ expect(await probeVideoDuration(output)).toBeCloseTo(1, 1);
+ const pixels = execFileSync(ffmpeg, ['-v', 'error', '-i', output, '-f', 'rawvideo', '-pix_fmt', 'rgb24', '-'], { maxBuffer: 40 * 1024 * 1024 });
const frameBytes = 1280 * 720 * 3;
expect(pixels.length / frameBytes).toBe(12); // frame count still durationSec * fps, unaffected by motionBlur
// Frame six spans t=0.5..0.5625s across 4 subframes. The block's trailing