@open-take/compositor 0.5.0 → 0.5.2
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 +37 -12
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +274 -70
- package/dist/index.js.map +1 -1
- package/package.json +3 -5
- package/src/camera.ts +42 -12
- package/src/ffmpeg.ts +341 -63
- package/src/index.ts +8 -1
- package/src/launch-evaluate.ts +18 -0
- package/src/launch-render.ts +5 -2
- package/src/render.ts +6 -6
- package/src/scene/launch-scene.tsx +14 -3
- package/src/scene/motion-layers.tsx +4 -1
- package/src/types.ts +7 -4
package/package.json
CHANGED
|
@@ -1,6 +1,6 @@
|
|
|
1
1
|
{
|
|
2
2
|
"name": "@open-take/compositor",
|
|
3
|
-
"version": "0.5.
|
|
3
|
+
"version": "0.5.2",
|
|
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",
|
|
@@ -17,13 +17,11 @@
|
|
|
17
17
|
"src/scene/tsconfig.json"
|
|
18
18
|
],
|
|
19
19
|
"dependencies": {
|
|
20
|
-
"@ffmpeg-installer/ffmpeg": "^1.1.0",
|
|
21
|
-
"@ffprobe-installer/ffprobe": "^2.1.2",
|
|
22
20
|
"@revideo/2d": "0.11.0",
|
|
23
21
|
"@revideo/core": "0.11.0",
|
|
24
22
|
"@revideo/ui": "0.11.0",
|
|
25
23
|
"@revideo/vite-plugin": "0.11.0",
|
|
26
|
-
"@open-take/revideo-renderer": "0.5.
|
|
24
|
+
"@open-take/revideo-renderer": "0.5.2"
|
|
27
25
|
},
|
|
28
26
|
"devDependencies": {
|
|
29
27
|
"@types/node": "^22.10.1",
|
|
@@ -58,7 +56,7 @@
|
|
|
58
56
|
"build": "tsdown",
|
|
59
57
|
"typecheck": "tsc --noEmit",
|
|
60
58
|
"test": "node --test --import tsx/esm test/*.test.ts",
|
|
61
|
-
"test:render-smoke": "node --test --import tsx/esm e2e/render-smoke.test.ts",
|
|
59
|
+
"test:render-smoke": "node --test --test-force-exit --import tsx/esm e2e/render-smoke.test.ts",
|
|
62
60
|
"clean": "rm -rf dist"
|
|
63
61
|
}
|
|
64
62
|
}
|
package/src/camera.ts
CHANGED
|
@@ -34,7 +34,7 @@ export type Beat = {
|
|
|
34
34
|
/** element bbox (for a drag: the path's bbox), video-px — or undefined for a
|
|
35
35
|
* bare press (no located element). */
|
|
36
36
|
box?: BBox;
|
|
37
|
-
/** the region that
|
|
37
|
+
/** the dominant region that changed after the action (frame-diff seam),
|
|
38
38
|
* video-px. Framed over `box` when present. */
|
|
39
39
|
effectBox?: BBox;
|
|
40
40
|
/** fraction of the frame that changed after the action, 0..1. */
|
|
@@ -80,10 +80,19 @@ function growDown(box: BBox, video: { w: number; h: number }): BBox {
|
|
|
80
80
|
return { x: box.x, y: box.y, w: box.w, h };
|
|
81
81
|
}
|
|
82
82
|
|
|
83
|
+
const intersects = (a: BBox, b: BBox): boolean =>
|
|
84
|
+
a.x < b.x + b.w && b.x < a.x + a.w && a.y < b.y + b.h && b.y < a.y + a.h;
|
|
85
|
+
|
|
83
86
|
/** The region a beat is "about" — what the camera should frame. A type is
|
|
84
87
|
* field-anchored and height-capped (its reveal is open-ended); every other
|
|
85
|
-
* kind trusts the captured effect region, else shapes one from the bbox.
|
|
86
|
-
|
|
88
|
+
* kind trusts the captured effect region, else shapes one from the bbox.
|
|
89
|
+
* `fillsFrame` says whether a region is big enough to be a shot of its own
|
|
90
|
+
* (see the effectBox branch). */
|
|
91
|
+
function roiForBeat(
|
|
92
|
+
b: Beat,
|
|
93
|
+
video: { w: number; h: number },
|
|
94
|
+
fillsFrame: (roi: BBox) => boolean,
|
|
95
|
+
): { roi?: BBox; note?: string } {
|
|
87
96
|
// A press with an EXPLICIT zoom=always + a located reveal element: the
|
|
88
97
|
// author named exactly what to frame — that box outranks the frame-diff
|
|
89
98
|
// effectBox. A press payoff behind a scrim (modal / command palette) diffs
|
|
@@ -92,12 +101,12 @@ function roiForBeat(b: Beat, video: { w: number; h: number }): BBox | undefined
|
|
|
92
101
|
// somewhere else entirely (issue #8). click/hover keep effectBox preference:
|
|
93
102
|
// there the payoff usually lands AWAY from the element, which is the whole
|
|
94
103
|
// point of the frame-diff seam.
|
|
95
|
-
if (b.kind === "press" && b.intent === "always" && b.box) return b.box;
|
|
104
|
+
if (b.kind === "press" && b.intent === "always" && b.box) return { roi: b.box };
|
|
96
105
|
// A look names exactly what to frame — that IS the beat. Nothing happened on
|
|
97
106
|
// the page, so any effectBox is neighbouring noise (an animation, a ticking
|
|
98
107
|
// number), and preferring it would aim the "show the viewer this" camera at
|
|
99
108
|
// something else entirely.
|
|
100
|
-
if (b.kind === "look" && b.box) return b.box;
|
|
109
|
+
if (b.kind === "look" && b.box) return { roi: b.box };
|
|
101
110
|
if (b.kind === "type" && b.box) {
|
|
102
111
|
// Bound the frame to "field + top of results": keep the effectBox's real
|
|
103
112
|
// reveal WIDTH, but cap the HEIGHT to growDown's result-sized window so an
|
|
@@ -111,13 +120,27 @@ function roiForBeat(b: Beat, video: { w: number; h: number }): BBox | undefined
|
|
|
111
120
|
// (a rare upward-opening autocomplete) can't yield a zero/negative ROI —
|
|
112
121
|
// we then simply frame the field, never punch into the vacated space above.
|
|
113
122
|
const h = Math.max(b.box.h, Math.min(capH, bottom - b.box.y));
|
|
114
|
-
return { x, y: b.box.y, w: right - x, h };
|
|
123
|
+
return { roi: { x, y: b.box.y, w: right - x, h } };
|
|
115
124
|
}
|
|
116
|
-
return growDown(b.box, video);
|
|
125
|
+
return { roi: growDown(b.box, video) };
|
|
126
|
+
}
|
|
127
|
+
if (b.effectBox) {
|
|
128
|
+
// A change too small to fill the frame even at the camera's tightest zoom
|
|
129
|
+
// is not a shot of its own — a hint line, a badge, a toast. When it also
|
|
130
|
+
// lies away from the control, framing it would swing the camera onto a
|
|
131
|
+
// sliver of the page and leave the click itself off-frame; the control is
|
|
132
|
+
// the honest subject, exactly as for the tiny incidental effectBox on a
|
|
133
|
+
// press (issue #8). A change that touches the control (its own active
|
|
134
|
+
// state, a menu opening under it) or that is large enough to be a shot
|
|
135
|
+
// (a modal, a results panel) is the payoff and is framed as before.
|
|
136
|
+
if (b.box && !intersects(b.effectBox, b.box) && !fillsFrame(b.effectBox))
|
|
137
|
+
return {
|
|
138
|
+
roi: b.box,
|
|
139
|
+
note: "effect region is a far sliver (fills no frame at maxScale) → framed the control",
|
|
140
|
+
};
|
|
141
|
+
return { roi: b.effectBox };
|
|
117
142
|
}
|
|
118
|
-
|
|
119
|
-
if (!b.box) return undefined;
|
|
120
|
-
return b.box;
|
|
143
|
+
return { roi: b.box };
|
|
121
144
|
}
|
|
122
145
|
|
|
123
146
|
function clusterLabel(beats: Beat[], idx: number[]): string {
|
|
@@ -159,10 +182,17 @@ export function directCamera(
|
|
|
159
182
|
): Framing[] {
|
|
160
183
|
const restC: Pt = { x: video.w / 2, y: video.h / 2 };
|
|
161
184
|
const fit = (roi: BBox) => bboxFitScale(roi, out.w, out.h, cam.fillFrac, cam.maxScale, rest);
|
|
185
|
+
// a region is a shot when, at the tightest zoom the camera takes, it still
|
|
186
|
+
// fills the frame's fillFrac in at least one dimension
|
|
187
|
+
const fillsFrame = (roi: BBox) =>
|
|
188
|
+
Math.min(
|
|
189
|
+
(out.w * cam.fillFrac) / Math.max(1, roi.w),
|
|
190
|
+
(out.h * cam.fillFrac) / Math.max(1, roi.h),
|
|
191
|
+
) <= cam.maxScale;
|
|
162
192
|
|
|
163
193
|
// --- phase 1: per-beat ROI + hard-break classification ---------------------
|
|
164
194
|
const nodes: Node[] = beats.map((b, i) => {
|
|
165
|
-
const roi = roiForBeat(b, video);
|
|
195
|
+
const { roi, note } = roiForBeat(b, video, fillsFrame);
|
|
166
196
|
const scale = roi ? fit(roi) : rest;
|
|
167
197
|
const gapBreak =
|
|
168
198
|
i > 0 && b.tMs - (beats[i - 1]!.tMs + beats[i - 1]!.durationMs) > cam.coalesceWindowMs;
|
|
@@ -279,7 +309,7 @@ export function directCamera(
|
|
|
279
309
|
forceFull: false,
|
|
280
310
|
forcePunch: false,
|
|
281
311
|
boundary: gapBreak,
|
|
282
|
-
reason: `punch ${scale.toFixed(2)}× (ROI-fit)`,
|
|
312
|
+
reason: `punch ${scale.toFixed(2)}× (ROI-fit)${note ? ` · ${note}` : ""}`,
|
|
283
313
|
};
|
|
284
314
|
});
|
|
285
315
|
|
package/src/ffmpeg.ts
CHANGED
|
@@ -1,74 +1,369 @@
|
|
|
1
|
-
// ffmpeg/ffprobe resolution — zero-config
|
|
2
|
-
// system
|
|
3
|
-
//
|
|
4
|
-
//
|
|
5
|
-
//
|
|
6
|
-
//
|
|
1
|
+
// ffmpeg/ffprobe resolution — zero-config, the way Chrome is handled
|
|
2
|
+
// (runtime/src/cdp.ts ensureChrome): a system binary on PATH is used when it
|
|
3
|
+
// is at least as new as the builds we test on; otherwise a pinned static build
|
|
4
|
+
// is fetched once into ~/.open-take/ffmpeg and reused. Nothing is bundled in
|
|
5
|
+
// the npm package any more: the @ffmpeg-installer binaries it used to carry
|
|
6
|
+
// were ffmpeg 4.4 on macOS and 2018/2019 git snapshots on Linux and Windows,
|
|
7
|
+
// only ever ran on machines without a system ffmpeg, and that is where 0.5.0
|
|
8
|
+
// and 0.5.1 rendered nothing.
|
|
9
|
+
//
|
|
10
|
+
// The builds come from eugeneware/ffmpeg-static's GitHub release (the assets
|
|
11
|
+
// its npm package downloads at install time — used here without the package,
|
|
12
|
+
// so no postinstall script and nothing pnpm has to approve), pinned by tag
|
|
13
|
+
// and sha256. Overrides: OPEN_TAKE_FFMPEG / OPEN_TAKE_FFPROBE name a binary
|
|
14
|
+
// to use as is.
|
|
7
15
|
|
|
8
16
|
import { spawn, spawnSync } from "node:child_process";
|
|
9
|
-
import {
|
|
17
|
+
import { createHash } from "node:crypto";
|
|
18
|
+
import { createWriteStream, existsSync } from "node:fs";
|
|
19
|
+
import { chmod, mkdir, readdir, rename, rm, stat } from "node:fs/promises";
|
|
20
|
+
import { homedir } from "node:os";
|
|
21
|
+
import { join, resolve } from "node:path";
|
|
22
|
+
import { Readable, Transform } from "node:stream";
|
|
23
|
+
import { pipeline } from "node:stream/promises";
|
|
24
|
+
import { createGunzip } from "node:zlib";
|
|
10
25
|
|
|
11
|
-
|
|
12
|
-
|
|
26
|
+
/** The ffmpeg-static release the managed builds come from. */
|
|
27
|
+
export const FFMPEG_RELEASE = "b6.1.1";
|
|
28
|
+
const RELEASE_URL = `https://github.com/eugeneware/ffmpeg-static/releases/download/${FFMPEG_RELEASE}/`;
|
|
13
29
|
|
|
14
|
-
|
|
15
|
-
|
|
16
|
-
|
|
17
|
-
|
|
18
|
-
|
|
19
|
-
|
|
30
|
+
/** The oldest ffmpeg among the managed builds. A system ffmpeg older than
|
|
31
|
+
* this is passed over: the managed builds are what the tests run on, and
|
|
32
|
+
* nothing older ever is. The pinned binaries' own `-version` banners (not the
|
|
33
|
+
* release's README assets, one of which is wrong) say: darwin-arm64 6.0,
|
|
34
|
+
* darwin-x64 6.1.1, linux 7.0.2, win32-x64 6.1.1. */
|
|
35
|
+
export const FFMPEG_FLOOR: readonly [number, number] = [6, 0];
|
|
36
|
+
|
|
37
|
+
/** sha256 and byte size of each gzipped asset, as published on the release
|
|
38
|
+
* (the GitHub release API reports both). The size bounds what a download
|
|
39
|
+
* may stream before the hash can be checked.
|
|
40
|
+
*
|
|
41
|
+
* Licensing: these are GPLv3 static builds (johnvansickle for Linux, gyan for
|
|
42
|
+
* Windows; the macOS builds from osxexperts/evermeet are configured with
|
|
43
|
+
* `--enable-nonfree` although no nonfree library is linked, so their `-L`
|
|
44
|
+
* banner calls them non-redistributable). open-take (MIT) never ships them:
|
|
45
|
+
* the user's machine fetches them at first use and runs them as a separate
|
|
46
|
+
* process, which carries no GPL obligation. They must stay out of the npm
|
|
47
|
+
* tarball and out of anything a user redistributes — ~/.open-take/ffmpeg is
|
|
48
|
+
* a per-machine cache. */
|
|
49
|
+
type Asset = { sha256: string; size: number };
|
|
50
|
+
const ASSETS: Record<string, { ffmpeg: Asset; ffprobe: Asset }> = {
|
|
51
|
+
"darwin-arm64": {
|
|
52
|
+
ffmpeg: {
|
|
53
|
+
sha256: "8923876afa8db5585022d7860ec7e589af192f441c56793971276d450ed3bbfa",
|
|
54
|
+
size: 19246198,
|
|
55
|
+
},
|
|
56
|
+
ffprobe: {
|
|
57
|
+
sha256: "d986a8ec7b030899fe66a8a288ed809a3543338705a3ce178cfb85869c5d80be",
|
|
58
|
+
size: 19207077,
|
|
59
|
+
},
|
|
60
|
+
},
|
|
61
|
+
"darwin-x64": {
|
|
62
|
+
ffmpeg: {
|
|
63
|
+
sha256: "929b375c1182d956c51f7ac25e0b2b0411fb01f6f407aa15c9758efeb4242106",
|
|
64
|
+
size: 25296431,
|
|
65
|
+
},
|
|
66
|
+
ffprobe: {
|
|
67
|
+
sha256: "d4da574d6e2e197bd259b47d69cf262df9e312af24ad960444f6d806d3d4c186",
|
|
68
|
+
size: 25239438,
|
|
69
|
+
},
|
|
70
|
+
},
|
|
71
|
+
"linux-x64": {
|
|
72
|
+
ffmpeg: {
|
|
73
|
+
sha256: "bfe8a8fc511530457b528c48d77b5737527b504a3797a9bc4866aeca69c2dffa",
|
|
74
|
+
size: 29354986,
|
|
75
|
+
},
|
|
76
|
+
ffprobe: {
|
|
77
|
+
sha256: "25d9b6ccb05e3d9de9e04e31e2506d8dd7f9f0418981965ac6df12e8d3afd067",
|
|
78
|
+
size: 29276839,
|
|
79
|
+
},
|
|
80
|
+
},
|
|
81
|
+
"linux-arm64": {
|
|
82
|
+
ffmpeg: {
|
|
83
|
+
sha256: "754a678672298bc68156adff58aa7385a592c2b30b1d0ae8750c45c915c4bac0",
|
|
84
|
+
size: 25568691,
|
|
85
|
+
},
|
|
86
|
+
ffprobe: {
|
|
87
|
+
sha256: "2ab6aba60ee84412dff9188720703376cb4e7aaf7e0b5e43aa8249f2acae5bf8",
|
|
88
|
+
size: 25493573,
|
|
89
|
+
},
|
|
90
|
+
},
|
|
91
|
+
"linux-arm": {
|
|
92
|
+
ffmpeg: {
|
|
93
|
+
sha256: "64b115a12f0ab77c277e3c418aae8b40ef881e75e746a0e2d066a206b9bc5172",
|
|
94
|
+
size: 19167563,
|
|
95
|
+
},
|
|
96
|
+
ffprobe: {
|
|
97
|
+
sha256: "2471169c19fea00018413eebf188703c19ae5ab614477465146d4cdc7458b55d",
|
|
98
|
+
size: 19084901,
|
|
99
|
+
},
|
|
100
|
+
},
|
|
101
|
+
"linux-ia32": {
|
|
102
|
+
ffmpeg: {
|
|
103
|
+
sha256: "169b27c078a8ecedb814cac67afccf15a9868d63e9d74ef86088adefaa500d00",
|
|
104
|
+
size: 22184031,
|
|
105
|
+
},
|
|
106
|
+
ffprobe: {
|
|
107
|
+
sha256: "a75c55bcaad1b0e79f2201d82b9cc43903d950857615f91baaea5ce92d756e63",
|
|
108
|
+
size: 22093495,
|
|
109
|
+
},
|
|
110
|
+
},
|
|
111
|
+
"win32-x64": {
|
|
112
|
+
ffmpeg: {
|
|
113
|
+
sha256: "8883a3dffbd0a16cf4ef95206ea05283f78908dbfb118f73c83f4951dcc06d77",
|
|
114
|
+
size: 29581307,
|
|
115
|
+
},
|
|
116
|
+
ffprobe: {
|
|
117
|
+
sha256: "f309e6223ad89d2fe54bccd420a7709b66fd27540674e92309578ed491a43c8d",
|
|
118
|
+
size: 29521644,
|
|
119
|
+
},
|
|
120
|
+
},
|
|
121
|
+
};
|
|
122
|
+
|
|
123
|
+
type Tool = "ffmpeg" | "ffprobe";
|
|
124
|
+
|
|
125
|
+
/** The release's asset key for this machine, or null when it ships none.
|
|
126
|
+
* Windows on ARM runs the x64 build under emulation. */
|
|
127
|
+
export function managedPlatform(
|
|
128
|
+
platform: string = process.platform,
|
|
129
|
+
arch: string = process.arch,
|
|
130
|
+
): string | null {
|
|
131
|
+
const key = platform === "win32" && arch === "arm64" ? "win32-x64" : `${platform}-${arch}`;
|
|
132
|
+
return key in ASSETS ? key : null;
|
|
133
|
+
}
|
|
134
|
+
|
|
135
|
+
/** Where the managed builds live: ~/.open-take/ffmpeg/<release>/<platform>. */
|
|
136
|
+
export function managedDir(): string {
|
|
137
|
+
return join(
|
|
138
|
+
homedir(),
|
|
139
|
+
".open-take",
|
|
140
|
+
"ffmpeg",
|
|
141
|
+
FFMPEG_RELEASE,
|
|
142
|
+
managedPlatform() ?? "unsupported",
|
|
143
|
+
);
|
|
144
|
+
}
|
|
145
|
+
|
|
146
|
+
const exeName = (tool: Tool): string => (process.platform === "win32" ? `${tool}.exe` : tool);
|
|
147
|
+
|
|
148
|
+
/** `[major, minor]` from an ffmpeg/ffprobe `-version` banner, or null when
|
|
149
|
+
* the build carries no release number (a git snapshot such as
|
|
150
|
+
* "N-47683-g0e8eb07980" or "2024-05-02-git-…") — treated as below the floor. */
|
|
151
|
+
export function parseFfmpegVersion(banner: string): [number, number] | null {
|
|
152
|
+
const m = /^ff(?:mpeg|probe) version (?:n|v)?(\d+)\.(\d+)/m.exec(banner);
|
|
153
|
+
return m ? [Number(m[1]), Number(m[2])] : null;
|
|
20
154
|
}
|
|
21
155
|
|
|
22
|
-
|
|
156
|
+
export const meetsFloor = (v: [number, number] | null): boolean =>
|
|
157
|
+
!!v && (v[0] > FFMPEG_FLOOR[0] || (v[0] === FFMPEG_FLOOR[0] && v[1] >= FFMPEG_FLOOR[1]));
|
|
158
|
+
|
|
159
|
+
/** The `-version` banner of a binary, or null when it does not run. */
|
|
160
|
+
function versionBanner(bin: string): string | null {
|
|
23
161
|
try {
|
|
24
|
-
const
|
|
25
|
-
|
|
162
|
+
const r = spawnSync(bin, ["-version"], {
|
|
163
|
+
encoding: "utf8",
|
|
164
|
+
stdio: ["ignore", "pipe", "ignore"],
|
|
165
|
+
});
|
|
166
|
+
return r.status === 0 ? r.stdout : null;
|
|
26
167
|
} catch {
|
|
27
168
|
return null;
|
|
28
169
|
}
|
|
29
170
|
}
|
|
30
171
|
|
|
31
|
-
|
|
32
|
-
|
|
33
|
-
|
|
34
|
-
*
|
|
35
|
-
|
|
36
|
-
|
|
172
|
+
const runsOk = (bin: string): boolean => versionBanner(bin) !== null;
|
|
173
|
+
|
|
174
|
+
/** Runs, and its banner names a release at or above the floor — what the
|
|
175
|
+
* managed cache must hold; anything else there is foreign. */
|
|
176
|
+
const clearsFloor = (bin: string): boolean => {
|
|
177
|
+
const banner = versionBanner(bin);
|
|
178
|
+
return banner !== null && meetsFloor(parseFfmpegVersion(banner));
|
|
179
|
+
};
|
|
180
|
+
|
|
181
|
+
/** Some downloads land without an executable bit; repair at the point of
|
|
182
|
+
* use. Windows does not use POSIX execute bits. */
|
|
183
|
+
async function ensureExecutable(path: string): Promise<void> {
|
|
184
|
+
if (process.platform === "win32") return;
|
|
37
185
|
try {
|
|
38
186
|
const info = await stat(path);
|
|
39
187
|
if ((info.mode & 0o111) === 0) await chmod(path, info.mode | 0o111);
|
|
40
188
|
} catch {
|
|
41
|
-
// Best effort. The normal spawn
|
|
189
|
+
// Best effort. The normal spawn still returns the useful failure.
|
|
190
|
+
}
|
|
191
|
+
}
|
|
192
|
+
|
|
193
|
+
export type ManagedOpts = {
|
|
194
|
+
/** where to keep the build (tests point this at a temp dir) */
|
|
195
|
+
cacheDir?: string;
|
|
196
|
+
/** the fetch to download with (tests substitute a local one) */
|
|
197
|
+
fetchImpl?: typeof fetch;
|
|
198
|
+
/** progress lines go here (default: process.stderr) */
|
|
199
|
+
log?: (line: string) => void;
|
|
200
|
+
};
|
|
201
|
+
|
|
202
|
+
/** Fetch one gzipped asset, verifying the published sha256 of the gz bytes
|
|
203
|
+
* while they stream, and land the executable atomically. */
|
|
204
|
+
async function download(
|
|
205
|
+
tool: Tool,
|
|
206
|
+
platform: string,
|
|
207
|
+
dest: string,
|
|
208
|
+
opts: ManagedOpts,
|
|
209
|
+
): Promise<void> {
|
|
210
|
+
const url = `${RELEASE_URL}${tool}-${platform}.gz`;
|
|
211
|
+
const expected = ASSETS[platform]![tool];
|
|
212
|
+
const log = opts.log ?? ((line: string) => process.stderr.write(`${line}\n`));
|
|
213
|
+
const dir = join(dest, "..");
|
|
214
|
+
await mkdir(dir, { recursive: true });
|
|
215
|
+
// an earlier attempt cut short (Ctrl-C during the fetch) leaves its .part;
|
|
216
|
+
// nothing else sweeps this directory
|
|
217
|
+
for (const stale of await readdir(dir)) {
|
|
218
|
+
if (stale.startsWith(`${exeName(tool)}.`) && stale.endsWith(".part"))
|
|
219
|
+
await rm(join(dir, stale), { force: true });
|
|
220
|
+
}
|
|
221
|
+
const res = await (opts.fetchImpl ?? fetch)(url, { redirect: "follow" });
|
|
222
|
+
if (!res.ok) throw new Error(`${url}: HTTP ${res.status}`);
|
|
223
|
+
if (!res.body) throw new Error(`${url}: HTTP ${res.status} with no body`);
|
|
224
|
+
const total = Number(res.headers.get("content-length") ?? 0) || expected.size;
|
|
225
|
+
// First run on this machine: a one-time ~20–30 MB fetch. Say so (and show
|
|
226
|
+
// coarse progress) so `make` doesn't look like a silent stall.
|
|
227
|
+
log(
|
|
228
|
+
`open-take: downloading ${tool} (${FFMPEG_RELEASE}, one-time, ${Math.round(total / 1e6)} MB) → ${dest}`,
|
|
229
|
+
);
|
|
230
|
+
const hash = createHash("sha256");
|
|
231
|
+
let received = 0;
|
|
232
|
+
let lastPct = -1;
|
|
233
|
+
const meter = new Transform({
|
|
234
|
+
transform(chunk: Buffer, _enc, cb) {
|
|
235
|
+
// A 200 that is not the asset — a rate-limit or login page, a captive
|
|
236
|
+
// portal, a proxy that unpacked the gzip — is a network problem, not a
|
|
237
|
+
// missing ffmpeg; say so instead of surfacing zlib's "incorrect header".
|
|
238
|
+
if (received === 0 && chunk.length >= 2 && !(chunk[0] === 0x1f && chunk[1] === 0x8b)) {
|
|
239
|
+
const type = res.headers.get("content-type") ?? "unknown content type";
|
|
240
|
+
return cb(
|
|
241
|
+
new Error(
|
|
242
|
+
`${url} did not return the release asset (got ${type}) — check network/proxy access to github.com`,
|
|
243
|
+
),
|
|
244
|
+
);
|
|
245
|
+
}
|
|
246
|
+
hash.update(chunk);
|
|
247
|
+
received += chunk.length;
|
|
248
|
+
// the pinned size bounds what is written before the hash can be checked
|
|
249
|
+
if (received > expected.size) {
|
|
250
|
+
return cb(new Error(`${url}: more than the pinned ${expected.size} bytes — refusing it`));
|
|
251
|
+
}
|
|
252
|
+
const pct = Math.floor((received / total) * 100);
|
|
253
|
+
// throttle to whole-ten-percent steps to keep the log quiet
|
|
254
|
+
if (pct >= lastPct + 10 || pct === 100) {
|
|
255
|
+
lastPct = pct;
|
|
256
|
+
log(`open-take: …${tool} download ${pct}%`);
|
|
257
|
+
}
|
|
258
|
+
cb(null, chunk);
|
|
259
|
+
},
|
|
260
|
+
});
|
|
261
|
+
const part = `${dest}.${process.pid}.part`;
|
|
262
|
+
try {
|
|
263
|
+
await pipeline(
|
|
264
|
+
// the fetch body is a WHATWG stream typed for the DOM; Node's is the same thing
|
|
265
|
+
Readable.fromWeb(res.body as unknown as import("node:stream/web").ReadableStream),
|
|
266
|
+
meter,
|
|
267
|
+
createGunzip(),
|
|
268
|
+
createWriteStream(part),
|
|
269
|
+
);
|
|
270
|
+
const digest = hash.digest("hex");
|
|
271
|
+
if (digest !== expected.sha256) {
|
|
272
|
+
throw new Error(
|
|
273
|
+
`${url}: sha256 ${digest} is not the pinned ${expected.sha256} — refusing to run it`,
|
|
274
|
+
);
|
|
275
|
+
}
|
|
276
|
+
await chmod(part, 0o755);
|
|
277
|
+
await rename(part, dest);
|
|
278
|
+
} catch (e) {
|
|
279
|
+
await rm(part, { force: true });
|
|
280
|
+
// Two processes fetching at once: if the other one already landed the
|
|
281
|
+
// same pinned bytes, ours losing the rename (Windows refuses to replace a
|
|
282
|
+
// running image) is no failure.
|
|
283
|
+
if (clearsFloor(dest)) {
|
|
284
|
+
log(`open-take: ${tool} ready (another process fetched it).`);
|
|
285
|
+
return;
|
|
286
|
+
}
|
|
287
|
+
throw e;
|
|
288
|
+
}
|
|
289
|
+
log(`open-take: ${tool} ready.`);
|
|
290
|
+
}
|
|
291
|
+
|
|
292
|
+
/** The managed build of a tool: on disk already, or fetched now. */
|
|
293
|
+
async function ensureManaged(tool: Tool, opts: ManagedOpts = {}): Promise<string> {
|
|
294
|
+
const platform = managedPlatform();
|
|
295
|
+
if (!platform) {
|
|
296
|
+
throw new Error(`no ${tool} build is published for ${process.platform}-${process.arch}`);
|
|
42
297
|
}
|
|
298
|
+
const dir = opts.cacheDir ?? managedDir();
|
|
299
|
+
const dest = join(dir, exeName(tool));
|
|
300
|
+
if (existsSync(dest)) {
|
|
301
|
+
await ensureExecutable(dest);
|
|
302
|
+
if (clearsFloor(dest)) return dest;
|
|
303
|
+
// a cut-short or foreign file, or a directory someone put there: fetch again
|
|
304
|
+
await rm(dest, { force: true, recursive: true });
|
|
305
|
+
}
|
|
306
|
+
await download(tool, platform, dest, opts);
|
|
307
|
+
if (!clearsFloor(dest))
|
|
308
|
+
throw new Error(`${dest} downloaded but does not run as ffmpeg ≥ ${FFMPEG_FLOOR.join(".")}`);
|
|
309
|
+
return dest;
|
|
43
310
|
}
|
|
44
311
|
|
|
45
|
-
/**
|
|
46
|
-
*
|
|
47
|
-
export
|
|
48
|
-
|
|
49
|
-
|
|
50
|
-
|
|
51
|
-
|
|
52
|
-
|
|
312
|
+
/** The managed ffmpeg regardless of what is on PATH — the build every
|
|
313
|
+
* zero-config install runs, so tests run against it too. */
|
|
314
|
+
export const resolveManagedFfmpeg = (opts?: ManagedOpts): Promise<string> =>
|
|
315
|
+
ensureManaged("ffmpeg", opts);
|
|
316
|
+
export const resolveManagedFfprobe = (opts?: ManagedOpts): Promise<string> =>
|
|
317
|
+
ensureManaged("ffprobe", opts);
|
|
318
|
+
|
|
319
|
+
/** A binary named by OPEN_TAKE_FFMPEG / OPEN_TAKE_FFPROBE, taken as is once
|
|
320
|
+
* it runs. Renders chdir into their scratch dir before spawning, so a
|
|
321
|
+
* relative path is pinned now; a bare name keeps resolving through PATH. */
|
|
322
|
+
export function explicitBinary(tool: Tool, value: string): string {
|
|
323
|
+
if (!runsOk(value)) throw new Error(`${tool} at ${value} (from the environment) does not run`);
|
|
324
|
+
return /[\\/]/.test(value) ? resolve(value) : value;
|
|
53
325
|
}
|
|
54
326
|
|
|
55
|
-
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
59
|
-
|
|
327
|
+
const cached: Partial<Record<Tool, Promise<string>>> = {};
|
|
328
|
+
|
|
329
|
+
async function resolveTool(tool: Tool): Promise<string> {
|
|
330
|
+
const explicit = process.env[tool === "ffmpeg" ? "OPEN_TAKE_FFMPEG" : "OPEN_TAKE_FFPROBE"];
|
|
331
|
+
if (explicit) return explicitBinary(tool, explicit);
|
|
332
|
+
const banner = versionBanner(tool);
|
|
333
|
+
if (banner) {
|
|
334
|
+
const version = parseFfmpegVersion(banner);
|
|
335
|
+
if (meetsFloor(version)) return tool;
|
|
336
|
+
process.stderr.write(
|
|
337
|
+
version
|
|
338
|
+
? `open-take: the ${tool} on PATH (${version.join(".")}) is older than ${FFMPEG_FLOOR.join(".")} — using the managed build\n`
|
|
339
|
+
: `open-take: the ${tool} on PATH reports no release number, so it cannot be trusted to be ≥ ${FFMPEG_FLOOR.join(".")} — using the managed build\n`,
|
|
340
|
+
);
|
|
60
341
|
}
|
|
61
|
-
|
|
62
|
-
|
|
63
|
-
|
|
64
|
-
|
|
65
|
-
|
|
342
|
+
try {
|
|
343
|
+
return await ensureManaged(tool);
|
|
344
|
+
} catch (e) {
|
|
345
|
+
throw new Error(
|
|
346
|
+
`open-take: no ${tool} ≥ ${FFMPEG_FLOOR.join(".")} on PATH and the managed download failed (${(e as Error).message}). ` +
|
|
347
|
+
`Install ffmpeg (brew install ffmpeg / apt install ffmpeg) or set OPEN_TAKE_${tool.toUpperCase()} to a binary.`,
|
|
348
|
+
);
|
|
66
349
|
}
|
|
67
|
-
throw new Error(
|
|
68
|
-
"ffmpeg not found — install it (e.g. `brew install ffmpeg`) or `npm install` so the bundled @ffmpeg-installer binary resolves for this platform",
|
|
69
|
-
);
|
|
70
350
|
}
|
|
71
351
|
|
|
352
|
+
function resolveCached(tool: Tool): Promise<string> {
|
|
353
|
+
let p = cached[tool];
|
|
354
|
+
if (!p) {
|
|
355
|
+
p = resolveTool(tool).catch((e) => {
|
|
356
|
+
cached[tool] = undefined; // a failed download may succeed next time
|
|
357
|
+
throw e;
|
|
358
|
+
});
|
|
359
|
+
cached[tool] = p;
|
|
360
|
+
}
|
|
361
|
+
return p;
|
|
362
|
+
}
|
|
363
|
+
|
|
364
|
+
export const resolveFfmpeg = (): Promise<string> => resolveCached("ffmpeg");
|
|
365
|
+
export const resolveFfprobe = (): Promise<string> => resolveCached("ffprobe");
|
|
366
|
+
|
|
72
367
|
/** True when an `ffmpeg -encoders` table has a video-encoder ROW named
|
|
73
368
|
* `encoder` (" V....D libx264 ..."), not merely the name as a substring
|
|
74
369
|
* somewhere — descriptions repeat encoder names constantly. */
|
|
@@ -108,20 +403,3 @@ async function hasEncoderOnce(name: string): Promise<boolean> {
|
|
|
108
403
|
});
|
|
109
404
|
return parseEncoders(text, name);
|
|
110
405
|
}
|
|
111
|
-
|
|
112
|
-
export async function resolveFfprobe(): Promise<string> {
|
|
113
|
-
if (cachedFfprobe) return cachedFfprobe;
|
|
114
|
-
if (runsOk("ffprobe")) {
|
|
115
|
-
cachedFfprobe = "ffprobe";
|
|
116
|
-
return cachedFfprobe;
|
|
117
|
-
}
|
|
118
|
-
const p = await installerPath("@ffprobe-installer/ffprobe");
|
|
119
|
-
await ensureExecutable(p);
|
|
120
|
-
if (p && runsOk(p)) {
|
|
121
|
-
cachedFfprobe = p;
|
|
122
|
-
return p;
|
|
123
|
-
}
|
|
124
|
-
throw new Error(
|
|
125
|
-
"ffprobe not found — install ffmpeg (e.g. `brew install ffmpeg`) or `npm install` so the bundled @ffprobe-installer binary resolves for this platform",
|
|
126
|
-
);
|
|
127
|
-
}
|
package/src/index.ts
CHANGED
|
@@ -15,7 +15,14 @@ export {
|
|
|
15
15
|
predictCursorTips,
|
|
16
16
|
} from "./audit-cursor";
|
|
17
17
|
export { type Beat, directCamera, type Framing } from "./camera";
|
|
18
|
-
export {
|
|
18
|
+
export {
|
|
19
|
+
FFMPEG_FLOOR,
|
|
20
|
+
FFMPEG_RELEASE,
|
|
21
|
+
resolveFfmpeg,
|
|
22
|
+
resolveFfprobe,
|
|
23
|
+
resolveManagedFfmpeg,
|
|
24
|
+
resolveManagedFfprobe,
|
|
25
|
+
} from "./ffmpeg";
|
|
19
26
|
export {
|
|
20
27
|
evaluateUiMorph,
|
|
21
28
|
launchAudioAtS,
|
package/src/launch-evaluate.ts
CHANGED
|
@@ -127,3 +127,21 @@ export function transitionOpacity(scene: LaunchScene, localS: number): number {
|
|
|
127
127
|
const d = Math.min(t.durationS ?? 0.45, duration / 2);
|
|
128
128
|
return Math.min(launchEase(localS / d), launchEase((duration - localS) / d));
|
|
129
129
|
}
|
|
130
|
+
|
|
131
|
+
/**
|
|
132
|
+
* Frame-grid clock helpers.
|
|
133
|
+
*
|
|
134
|
+
* Revideo advances scene time by accumulating 1/fps in floating point, so the
|
|
135
|
+
* clock at frame n sits a hair below n/fps; a `step` keyframe authored exactly on
|
|
136
|
+
* a frame is then reached one frame late. Prepared media carries millisecond
|
|
137
|
+
* timestamps (17, 33, 50 ms …), so seeking an HTMLVideoElement to n/fps lands
|
|
138
|
+
* just before the frame it names and the browser shows the previous one: every
|
|
139
|
+
* third source frame was skipped and the one before it held. Snapping the clock
|
|
140
|
+
* to the grid and seeking to the centre of the intended frame removes both.
|
|
141
|
+
*/
|
|
142
|
+
export function quantizeToFrame(seconds: number, fps: number): number {
|
|
143
|
+
return Math.round(seconds * fps) / fps;
|
|
144
|
+
}
|
|
145
|
+
export function frameCentreS(seconds: number, fps: number): number {
|
|
146
|
+
return (Math.round(seconds * fps) + 0.5) / fps;
|
|
147
|
+
}
|
package/src/launch-render.ts
CHANGED
|
@@ -16,7 +16,7 @@ import { tmpdir } from "node:os";
|
|
|
16
16
|
import { basename, dirname, extname, join, resolve, sep } from "node:path";
|
|
17
17
|
import { fileURLToPath } from "node:url";
|
|
18
18
|
import { renderVideo } from "@open-take/revideo-renderer";
|
|
19
|
-
import {
|
|
19
|
+
import { resolveFfmpeg, resolveFfprobe } from "./ffmpeg";
|
|
20
20
|
import { launchAudioAtS, launchDurationS } from "./launch-evaluate";
|
|
21
21
|
import type { LaunchAudioTrack, LaunchComposition, LaunchIssue } from "./launch-types";
|
|
22
22
|
import { formatLaunchIssues, validateLaunchComposition } from "./launch-validate";
|
|
@@ -876,7 +876,9 @@ async function renderExclusive(opts: RenderLaunchOpts): Promise<RenderLaunchResu
|
|
|
876
876
|
const out = resolve(opts.outPath);
|
|
877
877
|
await mkdir(dirname(out), { recursive: true });
|
|
878
878
|
assertLaunchOutputSafe(opts.composition, opts.compositionPath, out);
|
|
879
|
-
|
|
879
|
+
// Revideo's exporter spawns ffmpeg/ffprobe itself and would default to the
|
|
880
|
+
// binaries its own dependency bundles (an old 4.x); point it at ours.
|
|
881
|
+
const ffmpeg = { ffmpegPath: await resolveFfmpeg(), ffprobePath: await resolveFfprobe() };
|
|
880
882
|
const { dir, rendered } = await prepare(opts.composition, opts.compositionPath, !!opts.draft);
|
|
881
883
|
const deps = depsRoot();
|
|
882
884
|
const prev = process.cwd();
|
|
@@ -888,6 +890,7 @@ async function renderExclusive(opts: RenderLaunchOpts): Promise<RenderLaunchResu
|
|
|
888
890
|
outFile: "launch.mov",
|
|
889
891
|
outDir: "out-render",
|
|
890
892
|
workers: 1,
|
|
893
|
+
ffmpeg,
|
|
891
894
|
projectSettings: {
|
|
892
895
|
// Revideo exports both range endpoints; cap the last frame explicitly
|
|
893
896
|
// instead of including its extra scene-completion frames.
|