@open-take/compositor 0.3.1 → 0.4.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- package/dist/index.d.ts +64 -7
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +211 -49
- package/dist/index.js.map +1 -1
- package/package.json +2 -2
- package/src/camera.ts +11 -1
- package/src/decode-guard.ts +35 -0
- package/src/ffmpeg.ts +41 -1
- package/src/math.ts +11 -8
- package/src/plan.ts +24 -0
- package/src/render.ts +193 -78
- package/src/scene/scene.tsx +170 -4
- package/src/types.ts +53 -4
- package/src/validate.ts +65 -1
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-take/compositor",
|
|
3
|
-
"version": "0.
|
|
3
|
+
"version": "0.4.1",
|
|
4
4
|
"description": "Polish compositor (D3) — event log + captured frames -> polished mp4 + editable revideo composition.",
|
|
5
5
|
"license": "MIT",
|
|
6
6
|
"funding": "https://ko-fi.com/pascal18663",
|
|
@@ -23,7 +23,7 @@
|
|
|
23
23
|
"@revideo/core": "0.11.0",
|
|
24
24
|
"@revideo/ui": "0.11.0",
|
|
25
25
|
"@revideo/vite-plugin": "0.11.0",
|
|
26
|
-
"@open-take/revideo-renderer": "0.
|
|
26
|
+
"@open-take/revideo-renderer": "0.4.1"
|
|
27
27
|
},
|
|
28
28
|
"devDependencies": {
|
|
29
29
|
"@types/node": "^22.10.1",
|
package/src/camera.ts
CHANGED
|
@@ -28,7 +28,7 @@ import type { BBox, CameraConfig, Pt, ZoomIntent } from "./types";
|
|
|
28
28
|
|
|
29
29
|
/** One action, already mapped into video-px, handed to the director. */
|
|
30
30
|
export type Beat = {
|
|
31
|
-
kind: "click" | "type" | "drag" | "scroll" | "hover" | "press" | "dropFiles";
|
|
31
|
+
kind: "click" | "type" | "drag" | "scroll" | "hover" | "look" | "press" | "dropFiles";
|
|
32
32
|
tMs: number;
|
|
33
33
|
durationMs: number;
|
|
34
34
|
/** element bbox (for a drag: the path's bbox), video-px — or undefined for a
|
|
@@ -93,6 +93,11 @@ function roiForBeat(b: Beat, video: { w: number; h: number }): BBox | undefined
|
|
|
93
93
|
// there the payoff usually lands AWAY from the element, which is the whole
|
|
94
94
|
// point of the frame-diff seam.
|
|
95
95
|
if (b.kind === "press" && b.intent === "always" && b.box) return b.box;
|
|
96
|
+
// A look names exactly what to frame — that IS the beat. Nothing happened on
|
|
97
|
+
// the page, so any effectBox is neighbouring noise (an animation, a ticking
|
|
98
|
+
// number), and preferring it would aim the "show the viewer this" camera at
|
|
99
|
+
// something else entirely.
|
|
100
|
+
if (b.kind === "look" && b.box) return b.box;
|
|
96
101
|
if (b.kind === "type" && b.box) {
|
|
97
102
|
// Bound the frame to "field + top of results": keep the effectBox's real
|
|
98
103
|
// reveal WIDTH, but cap the HEIGHT to growDown's result-sized window so an
|
|
@@ -321,6 +326,11 @@ export function directCamera(
|
|
|
321
326
|
// merges across a break (order: hard break → coalesce → min-hold).
|
|
322
327
|
segs.forEach((s, si) => {
|
|
323
328
|
if (s.kind !== "punch") return;
|
|
329
|
+
// A look segment is exempt: its hold length is the AUTHOR'S statement
|
|
330
|
+
// ("show the viewer this for durationMs"), not a derived gap — demoting it
|
|
331
|
+
// to full view would delete the beat's entire content. A tight look reads
|
|
332
|
+
// brisk, not flinchy, because nothing else competes for the frame.
|
|
333
|
+
if (s.idx.some((i) => beats[i]!.kind === "look")) return;
|
|
324
334
|
const firstT = beats[s.idx[0]!]!.tMs;
|
|
325
335
|
const next = segs[si + 1];
|
|
326
336
|
const heldUntil = next ? beats[next.idx[0]!]!.tMs : endMs;
|
|
@@ -0,0 +1,35 @@
|
|
|
1
|
+
// The decode guard's shared vocabulary — imported by BOTH sides of the
|
|
2
|
+
// browser/Node boundary. The scene (src/scene/scene.tsx, vite-compiled inside
|
|
3
|
+
// the render browser) probes the capture with a throwaway <video> and rejects
|
|
4
|
+
// with a message built here; render.ts (Node) recognises that rejection and
|
|
5
|
+
// retries with a VP9 intermediate. Only the message STRING survives the
|
|
6
|
+
// crossing — revideo forwards e.message through onRenderFailed — so the
|
|
7
|
+
// contract is a sentinel substring, not an error class.
|
|
8
|
+
//
|
|
9
|
+
// Keep this module dependency-free: the scene tree is copied verbatim into
|
|
10
|
+
// the render scratch and compiled for the browser, so a node:* import here
|
|
11
|
+
// would break the scene build.
|
|
12
|
+
|
|
13
|
+
export const CAPTURE_UNDECODABLE_MARK = "capture video is not decodable in the render browser";
|
|
14
|
+
|
|
15
|
+
/** Build the guard's rejection message. Both variants START with the mark so
|
|
16
|
+
* isCaptureUndecodable can match the forwarded string. */
|
|
17
|
+
export function buildUndecodableMessage(
|
|
18
|
+
kind: "media-error" | "timeout",
|
|
19
|
+
detail: string,
|
|
20
|
+
src: string,
|
|
21
|
+
): string {
|
|
22
|
+
const why =
|
|
23
|
+
kind === "media-error"
|
|
24
|
+
? `decode failed (${detail}) — this Chromium likely lacks the capture's codec`
|
|
25
|
+
: `no decode within 30s (${detail}) — the render browser may lack the capture's codec`;
|
|
26
|
+
return `${CAPTURE_UNDECODABLE_MARK}: ${why}; src=${src}`;
|
|
27
|
+
}
|
|
28
|
+
|
|
29
|
+
/** Did this render rejection come from the scene's decode guard? Substring
|
|
30
|
+
* match on the message — the Error identity does not survive the
|
|
31
|
+
* browser→Node crossing. */
|
|
32
|
+
export function isCaptureUndecodable(err: unknown): boolean {
|
|
33
|
+
const message = err instanceof Error ? err.message : String(err);
|
|
34
|
+
return message.includes(CAPTURE_UNDECODABLE_MARK);
|
|
35
|
+
}
|
package/src/ffmpeg.ts
CHANGED
|
@@ -5,7 +5,7 @@
|
|
|
5
5
|
// @revideo/ffmpeg — so the fallback costs consumers no extra download). Throw
|
|
6
6
|
// with an install hint only when neither exists.
|
|
7
7
|
|
|
8
|
-
import { spawnSync } from "node:child_process";
|
|
8
|
+
import { spawn, spawnSync } from "node:child_process";
|
|
9
9
|
import { chmod, stat } from "node:fs/promises";
|
|
10
10
|
|
|
11
11
|
let cachedFfmpeg: string | undefined;
|
|
@@ -69,6 +69,46 @@ export async function resolveFfmpeg(): Promise<string> {
|
|
|
69
69
|
);
|
|
70
70
|
}
|
|
71
71
|
|
|
72
|
+
/** True when an `ffmpeg -encoders` table has a video-encoder ROW named
|
|
73
|
+
* `encoder` (" V....D libx264 ..."), not merely the name as a substring
|
|
74
|
+
* somewhere — descriptions repeat encoder names constantly. */
|
|
75
|
+
export function parseEncoders(encodersText: string, encoder: string): boolean {
|
|
76
|
+
const escaped = encoder.replace(/[.*+?^${}()|[\]\\]/g, "\\$&");
|
|
77
|
+
return new RegExp(`^\\s*V\\S{5}\\s+${escaped}(?:\\s|$)`, "m").test(encodersText);
|
|
78
|
+
}
|
|
79
|
+
|
|
80
|
+
const encoderCache = new Map<string, Promise<boolean>>();
|
|
81
|
+
|
|
82
|
+
/** True when the RESOLVED ffmpeg (resolveFfmpeg — which may be a system
|
|
83
|
+
* binary lacking libvpx-vp9) offers the named video encoder. Cached per
|
|
84
|
+
* name; any failure is false, never a throw. */
|
|
85
|
+
export function ffmpegHasEncoder(name: string): Promise<boolean> {
|
|
86
|
+
let cached = encoderCache.get(name);
|
|
87
|
+
if (!cached) {
|
|
88
|
+
cached = hasEncoderOnce(name).catch(() => false);
|
|
89
|
+
encoderCache.set(name, cached);
|
|
90
|
+
}
|
|
91
|
+
return cached;
|
|
92
|
+
}
|
|
93
|
+
|
|
94
|
+
async function hasEncoderOnce(name: string): Promise<boolean> {
|
|
95
|
+
const ffmpeg = await resolveFfmpeg();
|
|
96
|
+
const text = await new Promise<string>((res, rej) => {
|
|
97
|
+
const child = spawn(ffmpeg, ["-hide_banner", "-encoders"], {
|
|
98
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
99
|
+
});
|
|
100
|
+
let out = "";
|
|
101
|
+
child.stdout.on("data", (d) => {
|
|
102
|
+
out += d;
|
|
103
|
+
});
|
|
104
|
+
child.on("error", rej);
|
|
105
|
+
child.on("close", (code) =>
|
|
106
|
+
code === 0 ? res(out) : rej(new Error(`ffmpeg -encoders exited ${code}`)),
|
|
107
|
+
);
|
|
108
|
+
});
|
|
109
|
+
return parseEncoders(text, name);
|
|
110
|
+
}
|
|
111
|
+
|
|
72
112
|
export async function resolveFfprobe(): Promise<string> {
|
|
73
113
|
if (cachedFfprobe) return cachedFfprobe;
|
|
74
114
|
if (runsOk("ffprobe")) {
|
package/src/math.ts
CHANGED
|
@@ -712,15 +712,18 @@ export function buildLegs(comp: TakeComposition): Leg[] {
|
|
|
712
712
|
return { sec: ms / 1000 };
|
|
713
713
|
};
|
|
714
714
|
for (const [evIdx, e] of comp.events.entries()) {
|
|
715
|
-
// scroll/press are not pointer-driven — the cursor holds where it was
|
|
716
|
-
// (the content pans / the keyboard acts
|
|
717
|
-
// so the between-legs parking logic keeps
|
|
715
|
+
// scroll/press/look are not pointer-driven — the cursor holds where it was
|
|
716
|
+
// (the content pans / the keyboard acts / the CAMERA does the moving). No
|
|
717
|
+
// travel leg; `cur` is untouched, so the between-legs parking logic keeps
|
|
718
|
+
// the cursor at its last anchor. For a look this parking IS the feature:
|
|
719
|
+
// cursor movement promises an action, and a look makes none — the camera
|
|
720
|
+
// frames the target while the cursor honestly stays put.
|
|
718
721
|
// They still OCCUPY the frame for durationMs, though: a scroll's duration IS
|
|
719
|
-
// the pan,
|
|
720
|
-
//
|
|
721
|
-
// cursor crossing it — so they push
|
|
722
|
-
// even though they contribute no leg.
|
|
723
|
-
if (e.kind === "scroll" || e.kind === "press") {
|
|
722
|
+
// the pan, a press's is the reveal animating in, a look's is the framed
|
|
723
|
+
// hold. A travel that departs into any of them puts two motions on screen
|
|
724
|
+
// at once — content sliding under a cursor crossing it — so they push
|
|
725
|
+
// `freeAt` exactly like a pointer beat even though they contribute no leg.
|
|
726
|
+
if (e.kind === "scroll" || e.kind === "press" || e.kind === "look") {
|
|
724
727
|
freeAt = Math.max(freeAt, (e.tMs + (e.durationMs ?? 0)) / 1000);
|
|
725
728
|
continue;
|
|
726
729
|
}
|
package/src/plan.ts
CHANGED
|
@@ -12,6 +12,7 @@ import { restStageScale } from "./math";
|
|
|
12
12
|
import {
|
|
13
13
|
type BBox,
|
|
14
14
|
type CameraConfig,
|
|
15
|
+
type Caption,
|
|
15
16
|
type CaptureLog,
|
|
16
17
|
type CompEvent,
|
|
17
18
|
type CursorConfig,
|
|
@@ -172,6 +173,28 @@ export function planComposition(log: CaptureLog, opts: PlanOpts = {}): TakeCompo
|
|
|
172
173
|
const start = log.start ? mapPt(log.start) : { x: vW * 0.25, y: vH * 0.9 };
|
|
173
174
|
const durationMs = Math.max(log.tEndMs ?? 0, lastEnd + cursor.holdMs + cursor.zoomOutMs + 400);
|
|
174
175
|
|
|
176
|
+
// --- captions: per-step caption strings → viewer-facing subtitle windows.
|
|
177
|
+
// Deterministic tiling ANCHORED AT ACTION INSTANTS: a caption lands exactly
|
|
178
|
+
// when its beat's action does — the camera has finished (or nearly finished)
|
|
179
|
+
// its move by then, so the swap happens over a settled frame. Anchoring at
|
|
180
|
+
// the zoom DEPARTURE (the first design) put every caption swap inside a
|
|
181
|
+
// camera ramp, and two simultaneous motions read as "the subtitle moves
|
|
182
|
+
// with the zoom" — the field complaint that moved the anchor here. A
|
|
183
|
+
// caption holds until the next beat's action (never narrating someone
|
|
184
|
+
// else's beat); the last one rides out to the end. All times
|
|
185
|
+
// untrimmed-timeline, editable afterwards like any composition field.
|
|
186
|
+
const captions: Caption[] = [];
|
|
187
|
+
log.events.forEach((c, i) => {
|
|
188
|
+
const text = c.caption?.trim();
|
|
189
|
+
if (!text) return;
|
|
190
|
+
const e = events[i]!;
|
|
191
|
+
const prevEnd = captions.length ? captions[captions.length - 1]!.toMs : 0;
|
|
192
|
+
const fromMs = Math.max(e.tMs, prevEnd);
|
|
193
|
+
const next = events[i + 1];
|
|
194
|
+
const toMs = Math.max(fromMs + 300, next ? next.tMs : durationMs);
|
|
195
|
+
captions.push({ fromMs, toMs, text });
|
|
196
|
+
});
|
|
197
|
+
|
|
175
198
|
return {
|
|
176
199
|
output: { width: oW, height: oH, fps },
|
|
177
200
|
source: { videoUrl: "/capture.mp4", videoWidth: vW, videoHeight: vH, viewport: log.viewport },
|
|
@@ -181,6 +204,7 @@ export function planComposition(log: CaptureLog, opts: PlanOpts = {}): TakeCompo
|
|
|
181
204
|
start,
|
|
182
205
|
events,
|
|
183
206
|
durationMs,
|
|
207
|
+
...(captions.length ? { captions } : {}),
|
|
184
208
|
};
|
|
185
209
|
}
|
|
186
210
|
|
package/src/render.ts
CHANGED
|
@@ -16,11 +16,10 @@
|
|
|
16
16
|
import { spawn } from "node:child_process";
|
|
17
17
|
import { existsSync, realpathSync } from "node:fs";
|
|
18
18
|
import {
|
|
19
|
-
copyFile,
|
|
20
19
|
mkdir,
|
|
21
20
|
mkdtemp,
|
|
22
|
-
readFile,
|
|
23
21
|
readdir,
|
|
22
|
+
readFile,
|
|
24
23
|
rm,
|
|
25
24
|
symlink,
|
|
26
25
|
unlink,
|
|
@@ -31,9 +30,15 @@ import { tmpdir } from "node:os";
|
|
|
31
30
|
import { dirname, join, resolve, sep } from "node:path";
|
|
32
31
|
import { fileURLToPath } from "node:url";
|
|
33
32
|
import { renderVideo } from "@open-take/revideo-renderer";
|
|
34
|
-
import {
|
|
33
|
+
import { isCaptureUndecodable } from "./decode-guard";
|
|
34
|
+
import { ffmpegHasEncoder, repairBundledMediaPermissions, resolveFfmpeg } from "./ffmpeg";
|
|
35
35
|
import { type PlanOpts, planComposition } from "./plan";
|
|
36
|
-
import {
|
|
36
|
+
import {
|
|
37
|
+
type CaptureLog,
|
|
38
|
+
type MotionBlurConfig,
|
|
39
|
+
motionBlurActive,
|
|
40
|
+
type TakeComposition,
|
|
41
|
+
} from "./types";
|
|
37
42
|
import { type CompositionIssue, formatIssues, validateComposition } from "./validate";
|
|
38
43
|
|
|
39
44
|
// dist/index.js -> package root
|
|
@@ -106,21 +111,37 @@ function run(cmd: string, args: string[]): Promise<void> {
|
|
|
106
111
|
|
|
107
112
|
/** Normalise the capture to a constant-fps mp4 the web decoder can read.
|
|
108
113
|
* fps follows the composition so a hi-fps capture can render at 60 (the
|
|
109
|
-
* render grid must match — a 30-grid would throw away the extra frames).
|
|
110
|
-
|
|
114
|
+
* render grid must match — a 30-grid would throw away the extra frames).
|
|
115
|
+
*
|
|
116
|
+
* `codec` is normally h264; "vp9" is the retry arm for render browsers
|
|
117
|
+
* WITHOUT H.264 decoding (Playwright-style Chromium builds ship no
|
|
118
|
+
* proprietary codecs). The scene's decode guard rejects in seconds when the
|
|
119
|
+
* capture can't decode there (see src/decode-guard.ts); renderTakeExclusive
|
|
120
|
+
* catches that rejection and re-encodes the scratch capture with this arm
|
|
121
|
+
* before one retry. The VP9 fallback must keep the .mp4 container AND the
|
|
122
|
+
* capture.mp4 name: revideo routes video decoding by file extension, so a
|
|
123
|
+
* .webm would take a different (and broken) decode path — VP9-in-MP4 (vp09
|
|
124
|
+
* track) is the shape that works. */
|
|
125
|
+
async function toMp4(
|
|
126
|
+
videoPath: string,
|
|
127
|
+
outMp4: string,
|
|
128
|
+
fps: number,
|
|
129
|
+
codec: "h264" | "vp9",
|
|
130
|
+
): Promise<void> {
|
|
111
131
|
await mkdir(dirname(outMp4), { recursive: true });
|
|
132
|
+
const codecArgs =
|
|
133
|
+
codec === "vp9"
|
|
134
|
+
? ["-c:v", "libvpx-vp9", "-b:v", "0", "-crf", "24", "-row-mt", "1", "-cpu-used", "4"]
|
|
135
|
+
: ["-c:v", "libx264", "-crf", "18"];
|
|
112
136
|
await run(await resolveFfmpeg(), [
|
|
113
137
|
"-y",
|
|
114
138
|
"-loglevel",
|
|
115
139
|
"error",
|
|
116
140
|
"-i",
|
|
117
141
|
resolve(videoPath),
|
|
118
|
-
|
|
119
|
-
"libx264",
|
|
142
|
+
...codecArgs,
|
|
120
143
|
"-pix_fmt",
|
|
121
144
|
"yuv420p",
|
|
122
|
-
"-crf",
|
|
123
|
-
"18",
|
|
124
145
|
"-r",
|
|
125
146
|
String(fps),
|
|
126
147
|
"-an",
|
|
@@ -128,37 +149,54 @@ async function toMp4(videoPath: string, outMp4: string, fps: number): Promise<vo
|
|
|
128
149
|
]);
|
|
129
150
|
}
|
|
130
151
|
|
|
131
|
-
/**
|
|
132
|
-
*
|
|
133
|
-
*
|
|
134
|
-
*
|
|
135
|
-
*
|
|
136
|
-
*
|
|
137
|
-
|
|
138
|
-
|
|
152
|
+
/** Delivery encode: the visually-lossless ProRes intermediate -> the postable
|
|
153
|
+
* H.264. The ONLY lossy generation in the pipeline, so its CRF is the
|
|
154
|
+
* master's quality — overlay text (captions/title card) used to look soft
|
|
155
|
+
* because it took TWO generations before this fix: revideo's default wasm
|
|
156
|
+
* exporter (WebCodecs H.264 at the browser's default bitrate, no knob, at
|
|
157
|
+
* fps·samples) and then this re-encode on top.
|
|
158
|
+
*
|
|
159
|
+
* Motion blur folds in here (temporal supersampling: the scene was rendered
|
|
160
|
+
* at fps·samples, project.ts): `tmix=frames=M` averages M consecutive
|
|
161
|
+
* sub-frames; `fps=baseFps` then decimates ≈every `samples`-th, so each
|
|
162
|
+
* output frame = the mean of the last M sub-frames of its interval (a
|
|
163
|
+
* trailing shutter).
|
|
164
|
+
*
|
|
165
|
+
* The scale step is a REAL conversion, not a re-tag: the ProRes encode
|
|
166
|
+
* converts the scene's RGB frames with swscale's default bt601 matrix, so
|
|
167
|
+
* the intermediate is 601-coded. Convert to bt709 and tag it — verified by
|
|
168
|
+
* round-tripping primaries (601-coded red merely tagged 709 decodes to
|
|
169
|
+
* rgb(255,24,0); converted it decodes to rgb(252,0,0)). */
|
|
170
|
+
async function deliverMp4(
|
|
171
|
+
inMov: string,
|
|
139
172
|
outMp4: string,
|
|
140
173
|
baseFps: number,
|
|
141
|
-
|
|
142
|
-
shutter: number,
|
|
174
|
+
blur: MotionBlurConfig | null,
|
|
143
175
|
): Promise<void> {
|
|
144
|
-
const
|
|
145
|
-
|
|
146
|
-
|
|
147
|
-
|
|
176
|
+
const vf: string[] = [];
|
|
177
|
+
if (blur) {
|
|
178
|
+
const M = Math.max(1, Math.min(blur.samples, Math.round(blur.shutter * blur.samples)));
|
|
179
|
+
vf.push(`tmix=frames=${M}`, `fps=${baseFps}`);
|
|
180
|
+
}
|
|
181
|
+
vf.push(
|
|
182
|
+
"scale=in_color_matrix=bt601:out_color_matrix=bt709",
|
|
183
|
+
"format=yuv420p",
|
|
184
|
+
"setparams=range=tv:colorspace=bt709:color_primaries=bt709:color_trc=bt709",
|
|
185
|
+
);
|
|
148
186
|
await run(await resolveFfmpeg(), [
|
|
149
187
|
"-y",
|
|
150
188
|
"-loglevel",
|
|
151
189
|
"error",
|
|
152
190
|
"-i",
|
|
153
|
-
resolve(
|
|
191
|
+
resolve(inMov),
|
|
154
192
|
"-vf",
|
|
155
|
-
vf,
|
|
193
|
+
vf.join(","),
|
|
156
194
|
"-c:v",
|
|
157
195
|
"libx264",
|
|
158
|
-
"-pix_fmt",
|
|
159
|
-
"yuv420p",
|
|
160
196
|
"-crf",
|
|
161
197
|
"18",
|
|
198
|
+
"-movflags",
|
|
199
|
+
"+faststart",
|
|
162
200
|
"-r",
|
|
163
201
|
String(baseFps),
|
|
164
202
|
"-an",
|
|
@@ -239,8 +277,10 @@ async function prepareScratch(composition: TakeComposition, videoPath: string):
|
|
|
239
277
|
// ignored on POSIX.
|
|
240
278
|
await symlink(nm, join(dir, "node_modules"), "junction");
|
|
241
279
|
// fps follows the composition: the render grid must match the source, or a
|
|
242
|
-
// hi-fps capture is decimated before the scene ever sees it.
|
|
243
|
-
|
|
280
|
+
// hi-fps capture is decimated before the scene ever sees it. Always H.264
|
|
281
|
+
// here — the happy path — the decode-guard retry re-encodes as VP9 in
|
|
282
|
+
// place when the render browser can't take it.
|
|
283
|
+
await toMp4(videoPath, join(dir, "public", "capture.mp4"), composition.output.fps, "h264");
|
|
244
284
|
return dir;
|
|
245
285
|
} catch (error) {
|
|
246
286
|
await cleanupScratch(dir);
|
|
@@ -317,71 +357,146 @@ async function renderTakeExclusive(opts: RenderTakeOpts): Promise<RenderTakeResu
|
|
|
317
357
|
// monorepo root's postinstall script.
|
|
318
358
|
await repairBundledMediaPermissions();
|
|
319
359
|
|
|
320
|
-
// 1. lay out this render's own directory (scene + composition + capture)
|
|
360
|
+
// 1. lay out this render's own directory (scene + composition + capture).
|
|
361
|
+
// The intermediate starts as H.264; the decode-guard retry below swaps
|
|
362
|
+
// it for VP9 when the render browser turns out not to decode it.
|
|
321
363
|
const scratch = await prepareScratch(composition, opts.videoPath);
|
|
322
364
|
const deps = depsRoot();
|
|
365
|
+
// Resolved BEFORE the chdir below: the retry re-encode runs while cwd is
|
|
366
|
+
// the scratch dir, where a relative videoPath would resolve wrongly.
|
|
367
|
+
const videoAbs = resolve(opts.videoPath);
|
|
323
368
|
try {
|
|
324
369
|
// 2. render headless, with cwd pinned to the scratch dir.
|
|
325
370
|
// revideo's @revideo/telemetry phones home to PostHog by default; this is an
|
|
326
371
|
// all-local tool, so default it OFF (an explicit user-set value still wins).
|
|
327
372
|
if (process.env.DISABLE_TELEMETRY === undefined) process.env.DISABLE_TELEMETRY = "true";
|
|
373
|
+
|
|
374
|
+
// One attempt = one renderVideo call with its own no-progress hint timer.
|
|
375
|
+
// A stuck render is SILENT: revideo's first progress tick fires only after
|
|
376
|
+
// the first frame fully renders, and legitimate pre-roll can take tens of
|
|
377
|
+
// seconds — so hint (never kill) when no tick has landed after 3 minutes.
|
|
378
|
+
const renderOnce = async (): Promise<string> => {
|
|
379
|
+
let noProgressTimer: ReturnType<typeof setTimeout> | undefined = setTimeout(() => {
|
|
380
|
+
process.stderr.write(
|
|
381
|
+
"open-take: no render progress after 3 minutes — if this never advances, the render browser may be stuck decoding the capture (see OPEN_TAKE_CHROME)\n",
|
|
382
|
+
);
|
|
383
|
+
}, 180_000);
|
|
384
|
+
try {
|
|
385
|
+
return await renderVideo({
|
|
386
|
+
projectFile: "/src/scene/project.ts",
|
|
387
|
+
settings: {
|
|
388
|
+
outFile: "take.mov",
|
|
389
|
+
outDir: RENDER_OUT,
|
|
390
|
+
workers: 1,
|
|
391
|
+
// ProRes 4444 intermediate, NOT revideo's default wasm exporter: the
|
|
392
|
+
// wasm path encodes H.264 in-browser via WebCodecs at the browser's
|
|
393
|
+
// default bitrate (mp4-wasm passes `bitrate: undefined`, and revideo
|
|
394
|
+
// 0.11 exposes no knob) — at fps·samples that visibly softens fine
|
|
395
|
+
// detail, screen-space caption/title text worst of all, before the
|
|
396
|
+
// delivery encode ever runs. The ffmpeg exporter is fed lossless PNG
|
|
397
|
+
// frames and prores_ks 4444 keeps them visually intact (4:4:4, no
|
|
398
|
+
// DCT mush), leaving deliverMp4's CRF 18 as the single lossy
|
|
399
|
+
// generation. Costs scratch disk (GBs at fps·samples for a long
|
|
400
|
+
// take) and slower frame handoff — accepted for the master's text.
|
|
401
|
+
projectSettings: {
|
|
402
|
+
exporter: { name: "@revideo/core/ffmpeg", options: { format: "proRes" } },
|
|
403
|
+
...(rangeSec ? { range: rangeSec } : {}),
|
|
404
|
+
},
|
|
405
|
+
logProgress: opts.logProgress ?? false,
|
|
406
|
+
// Wrapped even without opts.onProgress: the first tick proves the
|
|
407
|
+
// browser is decoding frames, which disarms the no-progress hint.
|
|
408
|
+
progressCallback: (_worker: number, progress: number) => {
|
|
409
|
+
if (noProgressTimer !== undefined) {
|
|
410
|
+
clearTimeout(noProgressTimer);
|
|
411
|
+
noProgressTimer = undefined;
|
|
412
|
+
}
|
|
413
|
+
opts.onProgress?.(progress);
|
|
414
|
+
},
|
|
415
|
+
// vite's dev server refuses to serve outside its root, and its root is
|
|
416
|
+
// now a tmp dir — so allow the dependency tree the scene imports
|
|
417
|
+
// through the node_modules link (vite resolves it to the realpath).
|
|
418
|
+
viteConfig: {
|
|
419
|
+
server: { fs: { allow: [scratch, ...(deps ? [deps] : [])] } },
|
|
420
|
+
},
|
|
421
|
+
// Reuse the capture-managed Chrome-for-Testing for both stages.
|
|
422
|
+
puppeteer: {
|
|
423
|
+
// --password-store/--use-mock-keychain: never touch the OS keychain, so
|
|
424
|
+
// macOS doesn't pop a "Chrome wants to use Chromium Safe Storage" prompt
|
|
425
|
+
// mid-render (matches the capture launch in runtime/cdp.ts).
|
|
426
|
+
args: [
|
|
427
|
+
"--no-sandbox",
|
|
428
|
+
"--disable-setuid-sandbox",
|
|
429
|
+
"--password-store=basic",
|
|
430
|
+
"--use-mock-keychain",
|
|
431
|
+
],
|
|
432
|
+
executablePath: opts.chromePath,
|
|
433
|
+
},
|
|
434
|
+
},
|
|
435
|
+
});
|
|
436
|
+
} finally {
|
|
437
|
+
if (noProgressTimer !== undefined) clearTimeout(noProgressTimer);
|
|
438
|
+
}
|
|
439
|
+
};
|
|
440
|
+
|
|
328
441
|
const prevCwd = process.cwd();
|
|
329
442
|
process.chdir(scratch);
|
|
330
443
|
let produced: string;
|
|
331
444
|
try {
|
|
332
|
-
|
|
333
|
-
|
|
334
|
-
|
|
335
|
-
|
|
336
|
-
|
|
337
|
-
|
|
338
|
-
|
|
339
|
-
|
|
340
|
-
|
|
341
|
-
|
|
342
|
-
|
|
343
|
-
|
|
344
|
-
|
|
345
|
-
|
|
346
|
-
|
|
347
|
-
|
|
348
|
-
|
|
349
|
-
|
|
350
|
-
|
|
351
|
-
|
|
352
|
-
|
|
353
|
-
|
|
354
|
-
|
|
355
|
-
|
|
356
|
-
|
|
357
|
-
|
|
358
|
-
|
|
359
|
-
|
|
360
|
-
|
|
361
|
-
|
|
362
|
-
|
|
363
|
-
|
|
364
|
-
|
|
365
|
-
|
|
445
|
+
try {
|
|
446
|
+
produced = await renderOnce();
|
|
447
|
+
} catch (error) {
|
|
448
|
+
// The scene's decode guard rejected: this browser cannot decode the
|
|
449
|
+
// H.264 intermediate (Playwright-style Chromium ships no proprietary
|
|
450
|
+
// codecs — before the guard, such a render hung forever; a real user
|
|
451
|
+
// lost ~20 minutes to that silence). Re-encode the scratch capture as
|
|
452
|
+
// VP9-in-MP4 and retry ONCE; without an ffmpeg that can, refuse with
|
|
453
|
+
// the fix. Any other rejection rethrows untouched.
|
|
454
|
+
if (!isCaptureUndecodable(error)) throw error;
|
|
455
|
+
const detail = error instanceof Error ? error.message : String(error);
|
|
456
|
+
if (!(await ffmpegHasEncoder("libvpx-vp9"))) {
|
|
457
|
+
throw new Error(
|
|
458
|
+
`render: the browser at ${opts.chromePath} cannot decode the capture (${detail}) — ` +
|
|
459
|
+
"point OPEN_TAKE_CHROME at a full Chrome/Chrome-for-Testing build, or install an " +
|
|
460
|
+
"ffmpeg with libvpx-vp9 to enable the VP9 fallback",
|
|
461
|
+
{ cause: error },
|
|
462
|
+
);
|
|
463
|
+
}
|
|
464
|
+
process.stderr.write(
|
|
465
|
+
"open-take: the render browser cannot decode the H.264 capture — retrying with a VP9 intermediate (output unchanged)\n",
|
|
466
|
+
);
|
|
467
|
+
await toMp4(
|
|
468
|
+
videoAbs,
|
|
469
|
+
join(scratch, "public", "capture.mp4"),
|
|
470
|
+
composition.output.fps,
|
|
471
|
+
"vp9",
|
|
472
|
+
);
|
|
473
|
+
try {
|
|
474
|
+
produced = await renderOnce();
|
|
475
|
+
} catch (retryError) {
|
|
476
|
+
if (!isCaptureUndecodable(retryError)) throw retryError;
|
|
477
|
+
const retryDetail = retryError instanceof Error ? retryError.message : String(retryError);
|
|
478
|
+
throw new Error(
|
|
479
|
+
`render: the browser at ${opts.chromePath} cannot decode the capture even as VP9 ` +
|
|
480
|
+
`(${retryDetail}) — point OPEN_TAKE_CHROME at a full Chrome/Chrome-for-Testing build`,
|
|
481
|
+
{ cause: retryError },
|
|
482
|
+
);
|
|
483
|
+
}
|
|
484
|
+
}
|
|
366
485
|
} finally {
|
|
367
486
|
process.chdir(prevCwd);
|
|
368
487
|
}
|
|
369
488
|
|
|
370
|
-
// 3. deliver
|
|
371
|
-
//
|
|
489
|
+
// 3. deliver the postable mp4 from the ProRes intermediate + the editable
|
|
490
|
+
// composition. Motion blur (when configured) and the 601→709 colour
|
|
491
|
+
// conversion both happen inside this single encode — see deliverMp4.
|
|
372
492
|
await mkdir(dirname(resolve(opts.outPath)), { recursive: true });
|
|
373
493
|
const producedAbs = resolve(scratch, produced);
|
|
374
|
-
|
|
375
|
-
|
|
376
|
-
|
|
377
|
-
|
|
378
|
-
|
|
379
|
-
|
|
380
|
-
composition.motionBlur.shutter,
|
|
381
|
-
);
|
|
382
|
-
} else {
|
|
383
|
-
await copyFile(producedAbs, resolve(opts.outPath));
|
|
384
|
-
}
|
|
494
|
+
await deliverMp4(
|
|
495
|
+
producedAbs,
|
|
496
|
+
resolve(opts.outPath),
|
|
497
|
+
composition.output.fps,
|
|
498
|
+
motionBlurActive(composition.motionBlur) ? composition.motionBlur : null,
|
|
499
|
+
);
|
|
385
500
|
const compositionPath = opts.compositionPath
|
|
386
501
|
? resolve(opts.compositionPath)
|
|
387
502
|
: `${resolve(opts.outPath).replace(/\.mp4$/i, "")}.composition.json`;
|