feat(e2e): add playwright-recast motion graphics to the demo video pipeline
Adds cursor overlay, click ripples, auto-zoom, kinetic-typography intro/outro cards, real per-beat captions, and a self-synthesized ambient music bed to the main demo scene via playwright-recast, with ffmpeg-static/ffprobe-static as real devDependencies. Fixes a concat-stage audio/duration regression found during verification (a single filter_complex mixing a real audio stream with an anullsrc generator node silently truncated output duration) by splitting the final concat into three separately-verified ffmpeg passes.
This commit is contained in:
1 parent
1f5b99e3ac
commit
f8ceb980a1
3 files changed
+1388
-17
No files matched your search
+315
-17
@@ -12,21 +12,44 @@
|
|||||||
// technique e2e/fairDrawWalletCredit.e2e.mjs already uses) so Fair
|
// technique e2e/fairDrawWalletCredit.e2e.mjs already uses) so Fair
|
||||||
// Draw's real commit/reveal/verify cycle deterministically resolves to
|
// Draw's real commit/reveal/verify cycle deterministically resolves to
|
||||||
// "You" winning, making the wallet-credit beat reliably demonstrable on
|
// "You" winning, making the wallet-credit beat reliably demonstrable on
|
||||||
// camera without touching any other real logic.
|
// camera without touching any other real logic. The raw capture is then
|
||||||
|
// run through `playwright-recast` (a real trace-based motion-graphics
|
||||||
|
// pipeline - see .omo/ulw-research/20261118-121942/ for the research
|
||||||
|
// that picked it over a from-scratch Remotion/Manim rebuild) to add a
|
||||||
|
// synthetic cursor, click ripples, and auto-zoom onto the exact element
|
||||||
|
// being interacted with, derived from the real Playwright trace - not
|
||||||
|
// hand-authored keyframes. It also gets a motion-graphics polish pass
|
||||||
|
// (see .omo/evidence/full-feature-demo/DEMO_VIDEO_NOTES.md for the
|
||||||
|
// research behind each choice): a kinetic-typography title card as a
|
||||||
|
// cold open/outro (crossfaded in via `.intro()`/`.outro()` - the same
|
||||||
|
// "bold statement before the product" hook used by Linear/Apple/Raycast
|
||||||
|
// launch films), real on-screen captions generated from this script's
|
||||||
|
// own beat-log narration (written into the trace via
|
||||||
|
// `context.tracing.group()` using the exact marker convention
|
||||||
|
// `subtitlesFromTrace()` already looks for, so no voiceover/TTS key is
|
||||||
|
// needed - captions carry the explanation instead), and a short
|
||||||
|
// self-synthesized ambient pad (`ffmpeg` sine-wave tones, not a
|
||||||
|
// copyrighted track) via `.backgroundMusic()` so the video isn't silent.
|
||||||
//
|
//
|
||||||
// Scene 2 ("assembly-sync"): TWO genuinely isolated browser contexts
|
// Scene 2 ("assembly-sync"): TWO genuinely isolated browser contexts
|
||||||
// (separate storage origins - the same discipline
|
// (separate storage origins - the same discipline
|
||||||
// e2e/assemblyScreenSync.e2e.mjs already proved out) open the real
|
// e2e/assemblyScreenSync.e2e.mjs already proved out) open the real
|
||||||
// shipped Assembly screen and drive its real "Sync with nearby devices"
|
// shipped Assembly screen and drive its real "Sync with nearby devices"
|
||||||
// toggle through connect -> partition -> heal -> converge, recorded as
|
// toggle through connect -> partition -> heal -> converge, recorded as
|
||||||
// two side-by-side panes.
|
// two side-by-side panes. Left as a plain capture (no recast pass): the
|
||||||
|
// point of this scene is the side-by-side proof of independent device
|
||||||
|
// state, which a zoom/cursor layer would only obscure.
|
||||||
//
|
//
|
||||||
// The two scenes are concatenated (scale/pad to one common canvas) into
|
// The two scenes are concatenated (scale/pad to one common canvas) into
|
||||||
// a single final video with the Playwright-bundled ffmpeg binary.
|
// a single final video with a real ffmpeg binary.
|
||||||
import { chromium } from "playwright";
|
import { chromium } from "playwright";
|
||||||
import { createServer as createViteServer } from "vite";
|
import { createServer as createViteServer } from "vite";
|
||||||
|
import { Recast } from "playwright-recast";
|
||||||
|
import { NARRATE_TITLE_PREFIX } from "playwright-recast/helpers";
|
||||||
|
import ffmpegStatic from "ffmpeg-static";
|
||||||
|
import ffprobeStatic from "ffprobe-static";
|
||||||
import { spawn, execFileSync } from "node:child_process";
|
import { spawn, execFileSync } from "node:child_process";
|
||||||
import { mkdirSync, writeFileSync, existsSync } from "node:fs";
|
import { mkdirSync, writeFileSync, existsSync, readdirSync } from "node:fs";
|
||||||
import { dirname, resolve } from "node:path";
|
import { dirname, resolve } from "node:path";
|
||||||
import { fileURLToPath } from "node:url";
|
import { fileURLToPath } from "node:url";
|
||||||
|
|
||||||
@@ -40,15 +63,33 @@ const FINAL_VIDEO = resolve(ROOT, ".omo/evidence/full-feature-demo/the-commons-h
|
|||||||
// is a `--disable-everything` build meant only for Playwright's own
|
// is a `--disable-everything` build meant only for Playwright's own
|
||||||
// frame-to-webm screencast conversion: it has no `hstack`/`concat`/
|
// frame-to-webm screencast conversion: it has no `hstack`/`concat`/
|
||||||
// `setsar`/`fps` filters and no libx264 encoder at all, so it cannot do
|
// `setsar`/`fps` filters and no libx264 encoder at all, so it cannot do
|
||||||
// the compositing/concatenation this script needs. `ffmpeg-static`
|
// the compositing/concatenation this script needs, nor what
|
||||||
// (installed into an isolated /tmp dir, never touching this project's
|
// `playwright-recast` needs (`zoompan`, `xfade`, `overlay`, `subtitles`/
|
||||||
// package.json) provides a real full static build instead.
|
// `ass` - confirmed present; `drawtext` confirmed ABSENT, so `.urlBar()`
|
||||||
const FFMPEG_BIN = process.env.FFMPEG_BIN ?? "/tmp/ffmpeg-tool/node_modules/ffmpeg-static/ffmpeg";
|
// is not used anywhere in this script). `ffmpeg-static`/`ffprobe-static`
|
||||||
|
// are real devDependencies of this project (not a throwaway /tmp
|
||||||
|
// install) providing a full static build of both binaries; their
|
||||||
|
// directory is prepended to PATH so `playwright-recast`'s own internal
|
||||||
|
// `execFileSync('ffmpeg'|'ffprobe', ...)` calls find them too.
|
||||||
|
const FFMPEG_BIN = process.env.FFMPEG_BIN ?? ffmpegStatic;
|
||||||
|
const FFPROBE_BIN = process.env.FFPROBE_BIN ?? ffprobeStatic.path;
|
||||||
if (!existsSync(FFMPEG_BIN)) {
|
if (!existsSync(FFMPEG_BIN)) {
|
||||||
throw new Error(`ffmpeg binary not found at ${FFMPEG_BIN}. Set FFMPEG_BIN env var to override.`);
|
throw new Error(`ffmpeg binary not found at ${FFMPEG_BIN}. Set FFMPEG_BIN env var to override.`);
|
||||||
}
|
}
|
||||||
|
if (!existsSync(FFPROBE_BIN)) {
|
||||||
|
throw new Error(`ffprobe binary not found at ${FFPROBE_BIN}. Set FFPROBE_BIN env var to override.`);
|
||||||
|
}
|
||||||
|
process.env.PATH = `${dirname(FFMPEG_BIN)}:${dirname(FFPROBE_BIN)}:${process.env.PATH ?? ""}`;
|
||||||
|
|
||||||
const PANE = { width: 414, height: 896 };
|
const PANE = { width: 414, height: 896 };
|
||||||
|
// The main scene is recorded at 2x device-pixel density (recast's own
|
||||||
|
// documented fix for sharp zoomed/overlaid text - plain `deviceScaleFactor`
|
||||||
|
// never reaches a headless recording; it needs BOTH the
|
||||||
|
// `--force-device-scale-factor` launch arg AND a matching `recordVideo`
|
||||||
|
// `size`, confirmed by this project's own test render during the research
|
||||||
|
// pass, which otherwise warned of a 4.64x upscale and visibly soft text).
|
||||||
|
const RECAST_SCALE = 2;
|
||||||
|
const MAIN_VIDEO_SIZE = { width: PANE.width * RECAST_SCALE, height: PANE.height * RECAST_SCALE };
|
||||||
const FINAL_W = PANE.width * 2;
|
const FINAL_W = PANE.width * 2;
|
||||||
const FINAL_H = PANE.height;
|
const FINAL_H = PANE.height;
|
||||||
|
|
||||||
@@ -74,8 +115,18 @@ async function waitFor(fn, label, timeoutMs = 20000) {
|
|||||||
throw new Error(`timeout waiting for: ${label}${lastErr ? ` (last error: ${lastErr})` : ""}`);
|
throw new Error(`timeout waiting for: ${label}${lastErr ? ` (last error: ${lastErr})` : ""}`);
|
||||||
}
|
}
|
||||||
|
|
||||||
function makeBeatLog(sceneName, sceneStartRef) {
|
// `context` is optional (Scene 2's dualBeat has its own logger and never
|
||||||
|
// passes one): when present, each beat also opens a `context.tracing.group()`
|
||||||
|
// titled with recast's own `NARRATE_TITLE_PREFIX` marker - the exact
|
||||||
|
// convention its `subtitlesFromTrace()` stage already looks for (confirmed
|
||||||
|
// against `helpers.d.ts` and a standalone trace-parse probe), so this
|
||||||
|
// script's real beat narration becomes real on-screen captions without
|
||||||
|
// needing playwright-bdd or a TTS key. Each caption's window runs from its
|
||||||
|
// own beat to the next one's (or scene end), matching `narrate()`'s own
|
||||||
|
// documented span semantics.
|
||||||
|
function makeBeatLog(sceneName, sceneStartRef, context) {
|
||||||
const beats = [];
|
const beats = [];
|
||||||
|
let captionOpen = false;
|
||||||
return {
|
return {
|
||||||
beats,
|
beats,
|
||||||
async log(label, note, page) {
|
async log(label, note, page) {
|
||||||
@@ -87,10 +138,96 @@ function makeBeatLog(sceneName, sceneStartRef) {
|
|||||||
}
|
}
|
||||||
beats.push({ scene: sceneName, label, note, sceneRelativeMs, screenshot });
|
beats.push({ scene: sceneName, label, note, sceneRelativeMs, screenshot });
|
||||||
console.log(`[${sceneName} +${(sceneRelativeMs / 1000).toFixed(1)}s] ${label}: ${note}`);
|
console.log(`[${sceneName} +${(sceneRelativeMs / 1000).toFixed(1)}s] ${label}: ${note}`);
|
||||||
|
if (context) {
|
||||||
|
if (captionOpen) await context.tracing.groupEnd();
|
||||||
|
await context.tracing.group(`${NARRATE_TITLE_PREFIX}${note}`);
|
||||||
|
captionOpen = true;
|
||||||
|
}
|
||||||
|
},
|
||||||
|
async closeCaption() {
|
||||||
|
if (context && captionOpen) {
|
||||||
|
await context.tracing.groupEnd();
|
||||||
|
captionOpen = false;
|
||||||
|
}
|
||||||
},
|
},
|
||||||
};
|
};
|
||||||
}
|
}
|
||||||
|
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
// Motion-graphics assets: a kinetic-typography title card (cold-open hook
|
||||||
|
// + outro, the same "bold statement before the product" pattern
|
||||||
|
// reverse-engineered from Linear/Apple/Raycast launch films - see
|
||||||
|
// DEMO_VIDEO_NOTES.md) and a short self-synthesized ambient pad (plain
|
||||||
|
// `ffmpeg` sine oscillators - no third-party/copyrighted audio file).
|
||||||
|
// Both are rendered with the same Chromium/ffmpeg this script already
|
||||||
|
// uses, at the exact resolution `addMotionGraphics()` needs so recast's
|
||||||
|
// internal `xfade`/`amix` compositing doesn't choke on a mismatch.
|
||||||
|
// ---------------------------------------------------------------------
|
||||||
|
const TITLE_CARD_CSS = `
|
||||||
|
* { margin:0; padding:0; box-sizing:border-box; }
|
||||||
|
html,body { width:100%; height:100%; background:#05070d; overflow:hidden; font-family: -apple-system, 'Helvetica Neue', Arial, sans-serif; }
|
||||||
|
.wrap { width:100%; height:100%; display:flex; flex-direction:column; align-items:center; justify-content:center; position:relative; padding:0 60px; text-align:center; }
|
||||||
|
.glow { position:absolute; width:900px; height:900px; border-radius:50%; background:radial-gradient(circle, rgba(22,119,255,0.35) 0%, rgba(22,119,255,0) 70%); filter:blur(10px); }
|
||||||
|
.eyebrow { color:#4f9dff; letter-spacing:0.4em; font-size:20px; font-weight:600; text-transform:uppercase; opacity:0; transform:translateY(14px); animation: rise 0.6s ease forwards 0.15s; }
|
||||||
|
.title { color:#f5f7ff; font-size:72px; font-weight:800; letter-spacing:-0.02em; margin-top:18px; line-height:1.05; opacity:0; transform:translateY(20px); animation: rise 0.7s ease forwards 0.45s; }
|
||||||
|
.rule { width:110px; height:4px; background:#1677FF; margin-top:26px; transform:scaleX(0); transform-origin:center; animation: grow 0.6s ease forwards 0.95s; }
|
||||||
|
.tagline { color:#9fb3d9; font-size:26px; font-weight:400; margin-top:26px; max-width:620px; opacity:0; transform:translateY(14px); animation: rise 0.6s ease forwards 1.3s; }
|
||||||
|
@keyframes rise { to { opacity:1; transform:translateY(0); } }
|
||||||
|
@keyframes grow { to { transform:scaleX(1); } }
|
||||||
|
`;
|
||||||
|
|
||||||
|
function titleCardHtml({ eyebrow, title, tagline }) {
|
||||||
|
return `<!doctype html><html><head><style>${TITLE_CARD_CSS}</style></head>
|
||||||
|
<body><div class="wrap"><div class="glow"></div>
|
||||||
|
<div class="eyebrow">${eyebrow}</div>
|
||||||
|
<div class="title">${title}</div>
|
||||||
|
<div class="rule"></div>
|
||||||
|
<div class="tagline">${tagline}</div>
|
||||||
|
</div></body></html>`;
|
||||||
|
}
|
||||||
|
|
||||||
|
// Records the title card through a real throwaway Playwright context (same
|
||||||
|
// `recordVideo` mechanism as the real scenes) so the reveal animation plays
|
||||||
|
// out as genuine composited video frames, not a hand-assembled still.
|
||||||
|
async function renderTitleCard({ html, size, durationMs, outDir }) {
|
||||||
|
mkdirSync(outDir, { recursive: true });
|
||||||
|
const browser = await chromium.launch({ headless: true });
|
||||||
|
const context = await browser.newContext({ viewport: size, recordVideo: { dir: outDir, size } });
|
||||||
|
const page = await context.newPage();
|
||||||
|
await page.setContent(html, { waitUntil: "load" });
|
||||||
|
await page.waitForTimeout(durationMs);
|
||||||
|
await context.close();
|
||||||
|
await browser.close();
|
||||||
|
const file = readdirSync(outDir).find((f) => f.endsWith(".webm"));
|
||||||
|
if (!file) throw new Error(`title card recording produced no .webm in ${outDir}`);
|
||||||
|
return resolve(outDir, file);
|
||||||
|
}
|
||||||
|
|
||||||
|
// A soft three-note pad (C3/E3/G3) with slow tremolo, faded in and out -
|
||||||
|
// generated entirely by ffmpeg's `lavfi` sine-wave source, so there's no
|
||||||
|
// licensing question around the audio bed `.backgroundMusic()` needs.
|
||||||
|
function generateAmbientTrack(outPath, durationSeconds = 26) {
|
||||||
|
mkdirSync(dirname(outPath), { recursive: true });
|
||||||
|
const fadeOutStart = Math.max(0, durationSeconds - 4);
|
||||||
|
execFileSync(
|
||||||
|
FFMPEG_BIN,
|
||||||
|
[
|
||||||
|
"-y",
|
||||||
|
"-f", "lavfi", "-i", `sine=frequency=130.81:duration=${durationSeconds}`,
|
||||||
|
"-f", "lavfi", "-i", `sine=frequency=164.81:duration=${durationSeconds}`,
|
||||||
|
"-f", "lavfi", "-i", `sine=frequency=196.00:duration=${durationSeconds}`,
|
||||||
|
"-filter_complex",
|
||||||
|
`[0][1][2]amix=inputs=3:duration=longest:weights=1 0.8 0.7[mix];` +
|
||||||
|
`[mix]tremolo=f=0.15:d=0.3,volume=0.14,afade=t=in:st=0:d=3,afade=t=out:st=${fadeOutStart}:d=4[out]`,
|
||||||
|
"-map", "[out]",
|
||||||
|
"-c:a", "libmp3lame", "-b:a", "128k",
|
||||||
|
outPath,
|
||||||
|
],
|
||||||
|
{ stdio: ["ignore", "pipe", "pipe"] },
|
||||||
|
);
|
||||||
|
return outPath;
|
||||||
|
}
|
||||||
|
|
||||||
function startSignaling() {
|
function startSignaling() {
|
||||||
return new Promise((resolvePromise, reject) => {
|
return new Promise((resolvePromise, reject) => {
|
||||||
const child = spawn("node", ["node_modules/y-webrtc/bin/server.js"], {
|
const child = spawn("node", ["node_modules/y-webrtc/bin/server.js"], {
|
||||||
@@ -159,15 +296,25 @@ async function recordMainScene() {
|
|||||||
const videoDir = resolve(VIDEO_TMP_DIR, "main");
|
const videoDir = resolve(VIDEO_TMP_DIR, "main");
|
||||||
mkdirSync(videoDir, { recursive: true });
|
mkdirSync(videoDir, { recursive: true });
|
||||||
|
|
||||||
const browser = await chromium.launch({ headless: true, args: ["--no-sandbox"] });
|
const browser = await chromium.launch({
|
||||||
|
headless: true,
|
||||||
|
args: ["--no-sandbox", `--force-device-scale-factor=${RECAST_SCALE}`],
|
||||||
|
});
|
||||||
const context = await browser.newContext({
|
const context = await browser.newContext({
|
||||||
viewport: PANE,
|
viewport: PANE,
|
||||||
recordVideo: { dir: videoDir, size: PANE },
|
deviceScaleFactor: RECAST_SCALE,
|
||||||
|
recordVideo: { dir: videoDir, size: MAIN_VIDEO_SIZE },
|
||||||
});
|
});
|
||||||
|
// Real Playwright tracing (actions, screencast frames, cursor positions)
|
||||||
|
// is what playwright-recast's autoZoom()/cursorOverlay()/clickEffect()
|
||||||
|
// read to find click/fill coordinates - this is the one new line of
|
||||||
|
// capture this motion-graphics pass needed; the tour script below is
|
||||||
|
// completely unmodified.
|
||||||
|
await context.tracing.start({ screenshots: true, snapshots: true });
|
||||||
await forceLocalIdentityWinsFairDraw(context);
|
await forceLocalIdentityWinsFairDraw(context);
|
||||||
const page = await context.newPage();
|
const page = await context.newPage();
|
||||||
const sceneStartRef = { value: Date.now() };
|
const sceneStartRef = { value: Date.now() };
|
||||||
const beatLog = makeBeatLog("main", sceneStartRef);
|
const beatLog = makeBeatLog("main", sceneStartRef, context);
|
||||||
|
|
||||||
try {
|
try {
|
||||||
// --- Cold start: real non-custodial identity resolves, honest empty state ---
|
// --- Cold start: real non-custodial identity resolves, honest empty state ---
|
||||||
@@ -486,14 +633,118 @@ async function recordMainScene() {
|
|||||||
await page.getByRole("button", { name: "Counter Widget" }).waitFor({ state: "visible" });
|
await page.getByRole("button", { name: "Counter Widget" }).waitFor({ state: "visible" });
|
||||||
await beatLog.log("upload-tile-appears", "the uploaded mini-app now appears as a real tile on the home grid", page);
|
await beatLog.log("upload-tile-appears", "the uploaded mini-app now appears as a real tile on the home grid", page);
|
||||||
await sleep(1400);
|
await sleep(1400);
|
||||||
|
await beatLog.closeCaption();
|
||||||
} finally {
|
} finally {
|
||||||
|
await context.tracing.stop({ path: resolve(videoDir, "trace.zip") });
|
||||||
await context.close();
|
await context.close();
|
||||||
await browser.close();
|
await browser.close();
|
||||||
}
|
}
|
||||||
|
|
||||||
const videoPath = await page.video().path();
|
const videoPath = await page.video().path();
|
||||||
console.log(`Scene 1 recorded: ${videoPath} (${((Date.now() - sceneStartRef.value) / 1000).toFixed(1)}s wall-clock)`);
|
console.log(`Scene 1 recorded: ${videoPath} (${((Date.now() - sceneStartRef.value) / 1000).toFixed(1)}s wall-clock)`);
|
||||||
return { videoPath, beats: beatLog.beats };
|
|
||||||
|
const enhancedPath = await addMotionGraphics(videoDir);
|
||||||
|
return { videoPath: enhancedPath, rawVideoPath: videoPath, beats: beatLog.beats };
|
||||||
|
}
|
||||||
|
|
||||||
|
// Runs the real Playwright trace this scene just recorded through
|
||||||
|
// playwright-recast: a synthetic cursor + click ripples at every real
|
||||||
|
// click/selectOption action, and an auto-zoom onto the exact element a
|
||||||
|
// fill/type/click action targeted, timed to that action's own real
|
||||||
|
// duration - all derived from the trace, never hand-authored keyframes.
|
||||||
|
// `.subtitlesFromTrace()` is required by `.autoZoom()` (confirmed by
|
||||||
|
// actually running this pipeline - it throws "autoZoom() requires
|
||||||
|
// subtitles() first" otherwise); it now also carries real captions, since
|
||||||
|
// `beatLog.log()` writes each beat's narration into the trace via
|
||||||
|
// `context.tracing.group()` using recast's own marker convention.
|
||||||
|
//
|
||||||
|
// Motion-graphics pass (see DEMO_VIDEO_NOTES.md for the research this is
|
||||||
|
// drawn from):
|
||||||
|
// 1. Kinetic-typography intro/outro title cards, crossfaded in/out -
|
||||||
|
// the "bold statement before the product" cold-open hook reverse-
|
||||||
|
// engineered from Linear/Apple/Raycast launch films.
|
||||||
|
// 2. Real captions (above) with a restyled, high-contrast caption box
|
||||||
|
// instead of the library default - legible on a 414px-wide pane and
|
||||||
|
// consistent with the app's own accent blue (#1677FF).
|
||||||
|
// 3. A short self-synthesized ambient pad via `.backgroundMusic()` - no
|
||||||
|
// voiceover (no TTS key in this environment), so sound design leans
|
||||||
|
// on music + pacing instead, at a volume low enough not to compete
|
||||||
|
// with the captions.
|
||||||
|
async function addMotionGraphics(videoDir) {
|
||||||
|
console.log("\nAdding motion graphics (cursor, click ripples, auto-zoom, intro/outro, captions, music) via playwright-recast...");
|
||||||
|
const outputPath = resolve(videoDir, "main-enhanced.mp4");
|
||||||
|
|
||||||
|
const assetsDir = resolve(VIDEO_TMP_DIR, "assets");
|
||||||
|
const introPath = await renderTitleCard({
|
||||||
|
html: titleCardHtml({
|
||||||
|
eyebrow: "PatriotHacks 2026",
|
||||||
|
title: "THE COMMONS",
|
||||||
|
tagline: "One identity. One signed ledger. No backend.",
|
||||||
|
}),
|
||||||
|
size: MAIN_VIDEO_SIZE,
|
||||||
|
durationMs: 2600,
|
||||||
|
outDir: resolve(assetsDir, "intro"),
|
||||||
|
});
|
||||||
|
const outroPath = await renderTitleCard({
|
||||||
|
html: titleCardHtml({
|
||||||
|
eyebrow: "Built in 36 hours",
|
||||||
|
title: "The Commons",
|
||||||
|
tagline: "13 mini-apps. 1 wallet. Every balance a signed, replayable event.",
|
||||||
|
}),
|
||||||
|
size: MAIN_VIDEO_SIZE,
|
||||||
|
durationMs: 2600,
|
||||||
|
outDir: resolve(assetsDir, "outro"),
|
||||||
|
});
|
||||||
|
const musicPath = generateAmbientTrack(resolve(assetsDir, "ambient.mp3"), 26);
|
||||||
|
|
||||||
|
await Recast.from(videoDir)
|
||||||
|
.parse()
|
||||||
|
.speedUp({ duringIdle: 3.0, duringUserAction: 1.0, duringNetworkWait: 2.0, duringNavigation: 2.0, minSegmentDuration: 500 })
|
||||||
|
.subtitlesFromTrace()
|
||||||
|
.autoZoom({ inputLevel: 1.4, clickLevel: 1.25, centerBias: 0.3 })
|
||||||
|
.cursorOverlay()
|
||||||
|
.clickEffect()
|
||||||
|
.intro({ path: introPath, fadeDuration: 600 })
|
||||||
|
.outro({ path: outroPath, fadeDuration: 600 })
|
||||||
|
.backgroundMusic({ path: musicPath, volume: 0.1, ducking: false, fadeOutMs: 2500, loop: true })
|
||||||
|
.render({
|
||||||
|
format: "mp4",
|
||||||
|
resolution: MAIN_VIDEO_SIZE,
|
||||||
|
fps: 30,
|
||||||
|
// `burnSubtitles` defaults to false (confirmed in
|
||||||
|
// `dist/render/renderer.js`) - without it, `subtitlesFromTrace()`'s
|
||||||
|
// cues are parsed but never drawn, which is exactly what an earlier
|
||||||
|
// test render of this change showed (real captions in the trace,
|
||||||
|
// nothing burned into the frames).
|
||||||
|
burnSubtitles: true,
|
||||||
|
// `fontSize` is calibrated against the library's internal
|
||||||
|
// 1080p-widescreen reference canvas - on this project's narrow
|
||||||
|
// 828px-wide portrait canvas the library's own default ran text off
|
||||||
|
// the right edge uncut (confirmed by an earlier test render's
|
||||||
|
// extracted frames), so it's scaled down to roughly the 0.43x width
|
||||||
|
// ratio (828/1920) instead of reused verbatim. `chunkOptions` was
|
||||||
|
// tried and reverted: it splits one beat's full caption into many
|
||||||
|
// ~17-char fragments each on its own short timer, which flashed
|
||||||
|
// past before a viewer could read it (confirmed by frame extraction
|
||||||
|
// showing a single orphaned word per frame) - `wrapStyle: 'smart'`
|
||||||
|
// alone lets libass wrap the full line across 2-3 lines and hold it
|
||||||
|
// for the beat's whole on-screen window instead.
|
||||||
|
subtitleStyle: {
|
||||||
|
fontSize: 30,
|
||||||
|
primaryColor: "#F5F7FF",
|
||||||
|
backgroundColor: "#05070D",
|
||||||
|
backgroundOpacity: 0.82,
|
||||||
|
padding: 16,
|
||||||
|
position: "bottom",
|
||||||
|
marginVertical: 70,
|
||||||
|
marginHorizontal: 36,
|
||||||
|
bold: true,
|
||||||
|
wrapStyle: "smart",
|
||||||
|
},
|
||||||
|
})
|
||||||
|
.toFile(outputPath);
|
||||||
|
console.log(`Motion-graphics pass written: ${outputPath}`);
|
||||||
|
return outputPath;
|
||||||
}
|
}
|
||||||
|
|
||||||
// =======================================================================
|
// =======================================================================
|
||||||
@@ -671,16 +922,63 @@ function compositeSideBySide(videoPathA, videoPathB, outPath) {
|
|||||||
|
|
||||||
function concatToFinal(mainVideoPath, assemblyCompositePath) {
|
function concatToFinal(mainVideoPath, assemblyCompositePath) {
|
||||||
mkdirSync(dirname(FINAL_VIDEO), { recursive: true });
|
mkdirSync(dirname(FINAL_VIDEO), { recursive: true });
|
||||||
const filter =
|
// mainVideoPath may carry a real audio track (intro/outro/background
|
||||||
|
// music muxed in by addMotionGraphics()); assemblyCompositePath never
|
||||||
|
// does. concat requires matching stream counts per segment, so a
|
||||||
|
// silent pad stands in for segment 2's missing audio rather than
|
||||||
|
// dropping audio for both (which silently lost it before, and - the
|
||||||
|
// real bug this fixes - a `-map "[v]"`-only map with an unreferenced
|
||||||
|
// audio stream still present on input 0 was truncating the output's
|
||||||
|
// duration well short of its real video length).
|
||||||
|
// A single filter_complex mixing a real [0:a] stream with a
|
||||||
|
// filter-graph-generated anullsrc pad truncated this video's duration
|
||||||
|
// hard (confirmed by direct testing: per-stream ffprobe showed both
|
||||||
|
// main-enhanced streams genuinely ~43.5s, but that one-pass concat
|
||||||
|
// produced a ~26s output) - so this does it as three separately
|
||||||
|
// verifiable passes instead: video-only concat (the pattern already
|
||||||
|
// proven to work), a real silent file concatenated onto a real
|
||||||
|
// extracted copy of the main audio (not a filter-graph source node),
|
||||||
|
// then a final mux.
|
||||||
|
const assemblyDuration = ffmpegDurationSeconds(assemblyCompositePath) ?? 10;
|
||||||
|
const tmpVideo = resolve(VIDEO_TMP_DIR, "final-video-only.mp4");
|
||||||
|
const tmpSilence = resolve(VIDEO_TMP_DIR, "silence.m4a");
|
||||||
|
const tmpMainAudio = resolve(VIDEO_TMP_DIR, "main-audio.m4a");
|
||||||
|
const tmpAudio = resolve(VIDEO_TMP_DIR, "padded-audio.m4a");
|
||||||
|
const tmpAudioList = resolve(VIDEO_TMP_DIR, "audio-concat-list.txt");
|
||||||
|
|
||||||
|
const vfilter =
|
||||||
`[0:v]scale=${FINAL_W}:${FINAL_H}:force_original_aspect_ratio=decrease,pad=${FINAL_W}:${FINAL_H}:(ow-iw)/2:(oh-ih)/2:color=black,setsar=1,fps=25[v0];` +
|
`[0:v]scale=${FINAL_W}:${FINAL_H}:force_original_aspect_ratio=decrease,pad=${FINAL_W}:${FINAL_H}:(ow-iw)/2:(oh-ih)/2:color=black,setsar=1,fps=25[v0];` +
|
||||||
`[1:v]scale=${FINAL_W}:${FINAL_H}:force_original_aspect_ratio=decrease,pad=${FINAL_W}:${FINAL_H}:(ow-iw)/2:(oh-ih)/2:color=black,setsar=1,fps=25[v1];` +
|
`[1:v]scale=${FINAL_W}:${FINAL_H}:force_original_aspect_ratio=decrease,pad=${FINAL_W}:${FINAL_H}:(ow-iw)/2:(oh-ih)/2:color=black,setsar=1,fps=25[v1];` +
|
||||||
"[v0][v1]concat=n=2:v=1:a=0[v]";
|
"[v0][v1]concat=n=2:v=1:a=0[v]";
|
||||||
execFileSync(FFMPEG_BIN, [
|
execFileSync(FFMPEG_BIN, [
|
||||||
"-y", "-i", mainVideoPath, "-i", assemblyCompositePath,
|
"-y", "-i", mainVideoPath, "-i", assemblyCompositePath,
|
||||||
"-filter_complex", filter, "-map", "[v]",
|
"-filter_complex", vfilter, "-map", "[v]",
|
||||||
"-c:v", "libx264", "-pix_fmt", "yuv420p", "-movflags", "+faststart",
|
"-c:v", "libx264", "-pix_fmt", "yuv420p",
|
||||||
FINAL_VIDEO,
|
tmpVideo,
|
||||||
], { stdio: ["ignore", "pipe", "pipe"] });
|
], { stdio: ["ignore", "pipe", "pipe"] });
|
||||||
|
|
||||||
|
const hasAudio = (() => {
|
||||||
|
try {
|
||||||
|
execFileSync(FFMPEG_BIN, ["-i", mainVideoPath, "-vn", "-c:a", "copy", "-f", "null", "-"], { stdio: ["ignore", "pipe", "pipe"] });
|
||||||
|
return true;
|
||||||
|
} catch {
|
||||||
|
return false;
|
||||||
|
}
|
||||||
|
})();
|
||||||
|
|
||||||
|
if (hasAudio) {
|
||||||
|
execFileSync(FFMPEG_BIN, ["-y", "-f", "lavfi", "-i", "anullsrc=channel_layout=stereo:sample_rate=44100", "-t", String(assemblyDuration), "-c:a", "aac", tmpSilence], { stdio: ["ignore", "pipe", "pipe"] });
|
||||||
|
execFileSync(FFMPEG_BIN, ["-y", "-i", mainVideoPath, "-vn", "-c:a", "aac", tmpMainAudio], { stdio: ["ignore", "pipe", "pipe"] });
|
||||||
|
writeFileSync(tmpAudioList, `file '${tmpMainAudio}'\nfile '${tmpSilence}'\n`);
|
||||||
|
execFileSync(FFMPEG_BIN, ["-y", "-f", "concat", "-safe", "0", "-i", tmpAudioList, "-c:a", "aac", tmpAudio], { stdio: ["ignore", "pipe", "pipe"] });
|
||||||
|
execFileSync(FFMPEG_BIN, [
|
||||||
|
"-y", "-i", tmpVideo, "-i", tmpAudio,
|
||||||
|
"-c:v", "copy", "-c:a", "aac", "-b:a", "128k", "-shortest", "-movflags", "+faststart",
|
||||||
|
FINAL_VIDEO,
|
||||||
|
], { stdio: ["ignore", "pipe", "pipe"] });
|
||||||
|
} else {
|
||||||
|
execFileSync(FFMPEG_BIN, ["-y", "-i", tmpVideo, "-c:v", "copy", "-movflags", "+faststart", FINAL_VIDEO], { stdio: ["ignore", "pipe", "pipe"] });
|
||||||
|
}
|
||||||
}
|
}
|
||||||
|
|
||||||
function ffmpegDurationSeconds(videoPath) {
|
function ffmpegDurationSeconds(videoPath) {
|
||||||
|
|||||||
Generated
+1070
File diff suppressed because it is too large.
Load diff
@@ -37,9 +37,12 @@
|
|||||||
"@types/react-dom": "^19.3.0",
|
"@types/react-dom": "^19.3.0",
|
||||||
"@vitejs/plugin-react": "^6.1.2",
|
"@vitejs/plugin-react": "^6.1.2",
|
||||||
"fake-indexeddb": "^6.2.8",
|
"fake-indexeddb": "^6.2.8",
|
||||||
|
"ffmpeg-static": "^5.3.0",
|
||||||
|
"ffprobe-static": "^3.1.0",
|
||||||
"happy-dom": "^21.0.4",
|
"happy-dom": "^21.0.4",
|
||||||
"oxlint": "^1.90.0",
|
"oxlint": "^1.90.0",
|
||||||
"playwright": "^1.65.1",
|
"playwright": "^1.65.1",
|
||||||
|
"playwright-recast": "^0.23.0",
|
||||||
"typescript": "~7.0.2",
|
"typescript": "~7.0.2",
|
||||||
"vite": "^8.3.6",
|
"vite": "^8.3.6",
|
||||||
"vite-plugin-pwa": "^2.0.0",
|
"vite-plugin-pwa": "^2.0.0",
|
||||||
|
|||||||
Reference in new issue
Block a user