@anime-studio/cli 0.2.1 → 0.3.0
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/bin.js +54 -2
- package/dist/bin.js.map +1 -1
- package/dist/doctor.d.ts +8 -1
- package/dist/doctor.d.ts.map +1 -1
- package/dist/doctor.js +30 -5
- package/dist/doctor.js.map +1 -1
- package/dist/index.d.ts +3 -0
- package/dist/index.d.ts.map +1 -1
- package/dist/index.js +3 -0
- package/dist/index.js.map +1 -1
- package/dist/mix.d.ts +21 -0
- package/dist/mix.d.ts.map +1 -0
- package/dist/mix.js +95 -0
- package/dist/mix.js.map +1 -0
- package/dist/raster.d.ts +63 -0
- package/dist/raster.d.ts.map +1 -0
- package/dist/raster.js +145 -0
- package/dist/raster.js.map +1 -0
- package/dist/render-worker.d.ts +27 -0
- package/dist/render-worker.d.ts.map +1 -0
- package/dist/render-worker.js +33 -0
- package/dist/render-worker.js.map +1 -0
- package/dist/video.d.ts +64 -0
- package/dist/video.d.ts.map +1 -0
- package/dist/video.js +221 -0
- package/dist/video.js.map +1 -0
- package/package.json +6 -5
- package/skills/animestudio/SKILL.md +12 -9
- package/skills/animestudio/references/rendering.md +25 -4
- package/skills/animestudio/references/scene-format.md +1 -1
- package/skills/animestudio/references/validation-and-debugging.md +6 -7
- package/skills/animestudio-animation/SKILL.md +3 -2
- package/skills/animestudio-script/references/actions.md +2 -2
- package/skills/animestudio-sets/references/fx.md +6 -5
package/dist/raster.js
ADDED
|
@@ -0,0 +1,145 @@
|
|
|
1
|
+
import { execFileSync } from "node:child_process";
|
|
2
|
+
import { existsSync, readdirSync, statSync } from "node:fs";
|
|
3
|
+
import { join } from "node:path";
|
|
4
|
+
import { Resvg } from "@resvg/resvg-js";
|
|
5
|
+
const GENERIC = ["sans-serif", "serif", "monospace", "cursive", "fantasy"];
|
|
6
|
+
/** Every font family named in an SVG's `font-family` attributes and styles. */
|
|
7
|
+
export function svgFontFamilies(svg) {
|
|
8
|
+
const found = new Set();
|
|
9
|
+
for (const m of svg.matchAll(/font-family\s*(?:=\s*"([^"]*)"|=\s*'([^']*)'|:\s*([^;"}>]*))/g)) {
|
|
10
|
+
for (const raw of (m[1] ?? m[2] ?? m[3] ?? "").split(",")) {
|
|
11
|
+
const name = raw.trim().replace(/^['"]|['"]$/g, "").replace(/"|'|'/g, "").trim();
|
|
12
|
+
if (name)
|
|
13
|
+
found.add(name);
|
|
14
|
+
}
|
|
15
|
+
}
|
|
16
|
+
return [...found];
|
|
17
|
+
}
|
|
18
|
+
const fontFileRe = /\.(ttf|otf|ttc|otc)$/i;
|
|
19
|
+
function filesIn(path) {
|
|
20
|
+
if (!existsSync(path))
|
|
21
|
+
return [];
|
|
22
|
+
if (!statSync(path).isDirectory())
|
|
23
|
+
return fontFileRe.test(path) ? [path] : [];
|
|
24
|
+
return readdirSync(path, { recursive: true, encoding: "utf8" })
|
|
25
|
+
.filter((f) => fontFileRe.test(f))
|
|
26
|
+
.map((f) => join(path, f));
|
|
27
|
+
}
|
|
28
|
+
/** Resolves font families to files, caching each answer for the life of the process. */
|
|
29
|
+
export class FontResolver {
|
|
30
|
+
files = new Map();
|
|
31
|
+
generic = new Map();
|
|
32
|
+
extra;
|
|
33
|
+
fontconfig;
|
|
34
|
+
constructor(extra = []) {
|
|
35
|
+
this.extra = extra.flatMap(filesIn);
|
|
36
|
+
let ok = false;
|
|
37
|
+
try {
|
|
38
|
+
execFileSync("fc-match", ["--version"], { stdio: "ignore" });
|
|
39
|
+
ok = true;
|
|
40
|
+
}
|
|
41
|
+
catch {
|
|
42
|
+
ok = false;
|
|
43
|
+
}
|
|
44
|
+
this.fontconfig = ok;
|
|
45
|
+
}
|
|
46
|
+
fc(args) {
|
|
47
|
+
try {
|
|
48
|
+
return execFileSync(args[0], args.slice(1), { encoding: "utf8", stdio: ["ignore", "pipe", "ignore"] });
|
|
49
|
+
}
|
|
50
|
+
catch {
|
|
51
|
+
return "";
|
|
52
|
+
}
|
|
53
|
+
}
|
|
54
|
+
/** Every file of a family (all its weights and styles), or [] when the system does not have it. */
|
|
55
|
+
familyFiles(family) {
|
|
56
|
+
let hit = this.files.get(family);
|
|
57
|
+
if (!hit) {
|
|
58
|
+
hit = this.fontconfig
|
|
59
|
+
? this.fc(["fc-list", family, "file"])
|
|
60
|
+
.split("\n")
|
|
61
|
+
.map((l) => l.trim().replace(/:$/, ""))
|
|
62
|
+
.filter((l) => fontFileRe.test(l))
|
|
63
|
+
: [];
|
|
64
|
+
this.files.set(family, hit);
|
|
65
|
+
}
|
|
66
|
+
return hit;
|
|
67
|
+
}
|
|
68
|
+
/** The family fontconfig picks for a generic name (sans-serif → Verdana on a Mac) and its file. */
|
|
69
|
+
genericFamily(name) {
|
|
70
|
+
if (!this.fontconfig)
|
|
71
|
+
return undefined;
|
|
72
|
+
if (!this.generic.has(name))
|
|
73
|
+
this.generic.set(name, this.fc(["fc-match", "-f", "%{family[0]}", name]).trim());
|
|
74
|
+
return this.generic.get(name) || undefined;
|
|
75
|
+
}
|
|
76
|
+
/** resvg's font options for one SVG. */
|
|
77
|
+
fontOptions(svg) {
|
|
78
|
+
const families = svgFontFamilies(svg);
|
|
79
|
+
if (!families.length)
|
|
80
|
+
return { loadSystemFonts: false, fontFiles: this.extra };
|
|
81
|
+
if (!this.fontconfig)
|
|
82
|
+
return { loadSystemFonts: true, fontFiles: this.extra };
|
|
83
|
+
const files = new Set(this.extra);
|
|
84
|
+
const g = {};
|
|
85
|
+
for (const name of GENERIC) {
|
|
86
|
+
const fam = this.genericFamily(name);
|
|
87
|
+
if (!fam)
|
|
88
|
+
continue;
|
|
89
|
+
g[name] = fam;
|
|
90
|
+
if (families.includes(name) || name === "sans-serif")
|
|
91
|
+
for (const f of this.familyFiles(fam))
|
|
92
|
+
files.add(f);
|
|
93
|
+
}
|
|
94
|
+
for (const fam of families)
|
|
95
|
+
if (!GENERIC.includes(fam))
|
|
96
|
+
for (const f of this.familyFiles(fam))
|
|
97
|
+
files.add(f);
|
|
98
|
+
return {
|
|
99
|
+
loadSystemFonts: false,
|
|
100
|
+
fontFiles: [...files],
|
|
101
|
+
defaultFontFamily: g["sans-serif"],
|
|
102
|
+
sansSerifFamily: g["sans-serif"],
|
|
103
|
+
serifFamily: g.serif,
|
|
104
|
+
monospaceFamily: g.monospace,
|
|
105
|
+
cursiveFamily: g.cursive,
|
|
106
|
+
fantasyFamily: g.fantasy,
|
|
107
|
+
};
|
|
108
|
+
}
|
|
109
|
+
}
|
|
110
|
+
/** Renders SVG frames to RGBA pixels or PNG files at one size. */
|
|
111
|
+
export class Rasterizer {
|
|
112
|
+
opts;
|
|
113
|
+
fonts;
|
|
114
|
+
warned = false;
|
|
115
|
+
constructor(opts) {
|
|
116
|
+
this.opts = opts;
|
|
117
|
+
this.fonts = new FontResolver(opts.fonts);
|
|
118
|
+
}
|
|
119
|
+
render(svg) {
|
|
120
|
+
const font = this.fonts.fontOptions(svg);
|
|
121
|
+
if (font.loadSystemFonts && !this.warned) {
|
|
122
|
+
this.warned = true;
|
|
123
|
+
this.opts.onWarning?.("fontconfig (fc-match) was not found: loading every system font for frames with text, which is slow. Install fontconfig or pass --fonts <dir>.");
|
|
124
|
+
}
|
|
125
|
+
return new Resvg(svg, { fitTo: { mode: "width", value: this.opts.width }, font, shapeRendering: 2, textRendering: 1, imageRendering: 0 }).render();
|
|
126
|
+
}
|
|
127
|
+
/** Straight (not premultiplied) RGBA, `width × height × 4` bytes. */
|
|
128
|
+
rgba(svg) {
|
|
129
|
+
const img = this.render(svg);
|
|
130
|
+
const { width, height } = this.opts;
|
|
131
|
+
if (img.width === width && img.height === height)
|
|
132
|
+
return img.pixels;
|
|
133
|
+
// The SVG's aspect differs from the output's: pad or crop to the exact frame size.
|
|
134
|
+
const out = Buffer.alloc(width * height * 4);
|
|
135
|
+
const rows = Math.min(height, img.height);
|
|
136
|
+
const cols = Math.min(width, img.width) * 4;
|
|
137
|
+
for (let y = 0; y < rows; y++)
|
|
138
|
+
img.pixels.copy(out, y * width * 4, y * img.width * 4, y * img.width * 4 + cols);
|
|
139
|
+
return out;
|
|
140
|
+
}
|
|
141
|
+
png(svg) {
|
|
142
|
+
return this.render(svg).asPng();
|
|
143
|
+
}
|
|
144
|
+
}
|
|
145
|
+
//# sourceMappingURL=raster.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"raster.js","sourceRoot":"","sources":["../src/raster.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,YAAY,EAAE,MAAM,oBAAoB,CAAC;AAClD,OAAO,EAAE,UAAU,EAAE,WAAW,EAAE,QAAQ,EAAE,MAAM,SAAS,CAAC;AAC5D,OAAO,EAAE,IAAI,EAAE,MAAM,WAAW,CAAC;AACjC,OAAO,EAAE,KAAK,EAAE,MAAM,iBAAiB,CAAC;AAkBxC,MAAM,OAAO,GAAG,CAAC,YAAY,EAAE,OAAO,EAAE,WAAW,EAAE,SAAS,EAAE,SAAS,CAAU,CAAC;AAEpF,+EAA+E;AAC/E,MAAM,UAAU,eAAe,CAAC,GAAW;IACzC,MAAM,KAAK,GAAG,IAAI,GAAG,EAAU,CAAC;IAChC,KAAK,MAAM,CAAC,IAAI,GAAG,CAAC,QAAQ,CAAC,+DAA+D,CAAC,EAAE,CAAC;QAC9F,KAAK,MAAM,GAAG,IAAI,CAAC,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,CAAC,CAAC,CAAC,CAAC,IAAI,EAAE,CAAC,CAAC,KAAK,CAAC,GAAG,CAAC,EAAE,CAAC;YAC1D,MAAM,IAAI,GAAG,GAAG,CAAC,IAAI,EAAE,CAAC,OAAO,CAAC,cAAc,EAAE,EAAE,CAAC,CAAC,OAAO,CAAC,sBAAsB,EAAE,EAAE,CAAC,CAAC,IAAI,EAAE,CAAC;YAC/F,IAAI,IAAI;gBAAE,KAAK,CAAC,GAAG,CAAC,IAAI,CAAC,CAAC;QAC5B,CAAC;IACH,CAAC;IACD,OAAO,CAA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B,MAAM,EAAE,KAAK,EAAE,MAAM,EAAE,GAAG,IAAI,CAAC,IAAI,CAAC;QACpC,IAAI,GAAG,CAAC,KAAK,KAAK,KAAK,IAAI,GAAG,CAAC,MAAM,KAAK,MAAM;YAAE,OAAO,GAAG,CAAC,MAAM,CAAC;QACpE,mFAAmF;QACnF,MAAM,GAAG,GAAG,MAAM,CAAC,KAAK,CAAC,KAAK,GAAG,MAAM,GAAG,CAAC,CAAC,CAAC;QAC7C,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,MAAM,EAAE,GAAG,CAAC,MAAM,CAAC,CAAC;QAC1C,MAAM,IAAI,GAAG,IAAI,CAAC,GAAG,CAAC,KAAK,EAAE,GAAG,CAAC,KAAK,CAAC,GAAG,CAAC,CAAC;QAC5C,KAAK,IAAI,CAAC,GAAG,CAAC,EAAE,CAAC,GAAG,IAAI,EAAE,CAAC,EAAE;YAAE,GAAG,CAAC,MAAM,CAAC,IAAI,CAAC,GAAG,EAAE,CAAC,GAAG,KAAK,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,KAAK,GAAG,CAAC,EAAE,CAAC,GAAG,GAAG,CAAC,KAAK,GAAG,CAAC,GAAG,IAAI,CAAC,CAAC;QAChH,OAAO,GAAG,CAAC;IACb,CAAC;IAED,GAAG,CAAC,GAAW;QACb,OAAO,IAAI,CAAC,MAAM,CAAC,GAAG,CAAC,CAAC,KAAK,EAAE,CAAC;IAClC,CAAC;CACF"}
|
|
@@ -0,0 +1,27 @@
|
|
|
1
|
+
export interface WorkerData {
|
|
2
|
+
file: string;
|
|
3
|
+
width: number;
|
|
4
|
+
height: number;
|
|
5
|
+
transparent: boolean;
|
|
6
|
+
png: boolean;
|
|
7
|
+
fonts: string[];
|
|
8
|
+
}
|
|
9
|
+
export type WorkerRequest = {
|
|
10
|
+
index: number;
|
|
11
|
+
time: number;
|
|
12
|
+
};
|
|
13
|
+
export type WorkerMessage = {
|
|
14
|
+
type: "ready";
|
|
15
|
+
} | {
|
|
16
|
+
type: "warn";
|
|
17
|
+
message: string;
|
|
18
|
+
} | {
|
|
19
|
+
type: "frame";
|
|
20
|
+
index: number;
|
|
21
|
+
data: ArrayBuffer;
|
|
22
|
+
} | {
|
|
23
|
+
type: "error";
|
|
24
|
+
index?: number;
|
|
25
|
+
message: string;
|
|
26
|
+
};
|
|
27
|
+
//# sourceMappingURL=render-worker.d.ts.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-worker.d.ts","sourceRoot":"","sources":["../src/render-worker.ts"],"names":[],"mappings":"AASA,MAAM,WAAW,UAAU;IACzB,IAAI,EAAE,MAAM,CAAC;IACb,KAAK,EAAE,MAAM,CAAC;IACd,MAAM,EAAE,MAAM,CAAC;IACf,WAAW,EAAE,OAAO,CAAC;IACrB,GAAG,EAAE,OAAO,CAAC;IACb,KAAK,EAAE,MAAM,EAAE,CAAC;CACjB;AAED,MAAM,MAAM,aAAa,GAAG;IAAE,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,MAAM,CAAA;CAAE,CAAC;AAC5D,MAAM,MAAM,aAAa,GACrB;IAAE,IAAI,EAAE,OAAO,CAAA;CAAE,GACjB;IAAE,IAAI,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,GACjC;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,IAAI,EAAE,WAAW,CAAA;CAAE,GACnD;IAAE,IAAI,EAAE,OAAO,CAAC;IAAC,KAAK,CAAC,EAAE,MAAM,CAAC;IAAC,OAAO,EAAE,MAAM,CAAA;CAAE,CAAC"}
|
|
@@ -0,0 +1,33 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* A video-export worker: loads the scene or sequence once, then turns frame times into pixels.
|
|
3
|
+
* Frames are pure functions of time, so workers render any frames in any order.
|
|
4
|
+
*/
|
|
5
|
+
import { parentPort, workerData } from "node:worker_threads";
|
|
6
|
+
import { frameToSVG } from "@anime-studio/core";
|
|
7
|
+
import { loadEvaluable } from "./doctor.js";
|
|
8
|
+
import { Rasterizer } from "./raster.js";
|
|
9
|
+
const port = parentPort;
|
|
10
|
+
const data = workerData;
|
|
11
|
+
try {
|
|
12
|
+
const ev = await loadEvaluable(data.file);
|
|
13
|
+
const raster = new Rasterizer({ width: data.width, height: data.height, fonts: data.fonts, onWarning: (message) => port.postMessage({ type: "warn", message }) });
|
|
14
|
+
port.on("message", ({ index, time }) => {
|
|
15
|
+
try {
|
|
16
|
+
const frame = ev.frameAtTime(time);
|
|
17
|
+
const svg = frameToSVG(data.transparent ? { ...frame, background: undefined } : frame);
|
|
18
|
+
const buf = data.png ? raster.png(svg) : raster.rgba(svg);
|
|
19
|
+
// A fresh ArrayBuffer of exactly the frame, moved (not copied) to the main thread.
|
|
20
|
+
const out = new Uint8Array(buf.length);
|
|
21
|
+
out.set(buf);
|
|
22
|
+
port.postMessage({ type: "frame", index, data: out.buffer }, [out.buffer]);
|
|
23
|
+
}
|
|
24
|
+
catch (e) {
|
|
25
|
+
port.postMessage({ type: "error", index, message: e.message });
|
|
26
|
+
}
|
|
27
|
+
});
|
|
28
|
+
port.postMessage({ type: "ready" });
|
|
29
|
+
}
|
|
30
|
+
catch (e) {
|
|
31
|
+
port.postMessage({ type: "error", message: e.message });
|
|
32
|
+
}
|
|
33
|
+
//# sourceMappingURL=render-worker.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"render-worker.js","sourceRoot":"","sources":["../src/render-worker.ts"],"names":[],"mappings":"AAAA;;;GAGG;AACH,OAAO,EAAE,UAAU,EAAE,UAAU,EAAE,MAAM,qBAAqB,CAAC;AAC7D,OAAO,EAAE,UAAU,EAAE,MAAM,oBAAoB,CAAC;AAChD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,UAAU,EAAE,MAAM,UAAU,CAAC;AAkBtC,MAAM,IAAI,GAAG,UAAW,CAAC;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AE,CAAC;YACX,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,KAAK,EAAE,OAAO,EAAG,CAAW,CAAC,OAAO,EAA0B,CAAC,CAAC;QACpG,CAAC;IACH,CAAC,CAAC,CAAC;IACH,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,OAAO,EAA0B,CAAC,CAAC;AAC9D,CAAC;AAAC,OAAO,CAAC,EAAE,CAAC;IACX,IAAI,CAAC,WAAW,CAAC,EAAE,IAAI,EAAE,OAAO,EAAE,OAAO,EAAG,CAAW,CAAC,OAAO,EAA0B,CAAC,CAAC;AAC7F,CAAC"}
|
package/dist/video.d.ts
ADDED
|
@@ -0,0 +1,64 @@
|
|
|
1
|
+
/**
|
|
2
|
+
* Video export without a browser: worker threads evaluate frames and rasterise them with resvg,
|
|
3
|
+
* the main thread puts them back in order and streams raw pixels into ffmpeg, together with the
|
|
4
|
+
* audio mixed by `mixAudio`. Frames are pure functions of time, so there are no torn or stale
|
|
5
|
+
* captures and the same document always gives the same pixels.
|
|
6
|
+
*/
|
|
7
|
+
/** mp4 (H.264), webm (VP9, alpha with `transparent`), mov (ProRes; 4444 with alpha), gif, png (a folder of frames). */
|
|
8
|
+
export declare const VIDEO_FORMATS: readonly ["mp4", "webm", "mov", "gif", "png"];
|
|
9
|
+
export type VideoFormat = (typeof VIDEO_FORMATS)[number];
|
|
10
|
+
export interface RenderVideoOptions {
|
|
11
|
+
/** Output file, or a folder for `png`. */
|
|
12
|
+
out: string;
|
|
13
|
+
/** Default: from the extension of `out` (a path with no extension → png frames). */
|
|
14
|
+
format?: VideoFormat;
|
|
15
|
+
/** Timeline range in seconds. Default: the whole document. */
|
|
16
|
+
from?: number;
|
|
17
|
+
to?: number;
|
|
18
|
+
/** Frames per second. Default: the document's. Any rate works: frames are sampled in time. */
|
|
19
|
+
fps?: number;
|
|
20
|
+
/** Output size. Default: the document's; one side alone keeps the aspect ratio. */
|
|
21
|
+
width?: number;
|
|
22
|
+
height?: number;
|
|
23
|
+
/** Worker threads. Default: CPU cores − 1 (at most 8). */
|
|
24
|
+
workers?: number;
|
|
25
|
+
/** Quality for mp4 (default 16) and webm (default 28): lower is better and bigger. */
|
|
26
|
+
crf?: number;
|
|
27
|
+
/** Leave out the scene's background colour (webm, mov, gif and png keep the alpha). */
|
|
28
|
+
transparent?: boolean;
|
|
29
|
+
/** No audio track. */
|
|
30
|
+
mute?: boolean;
|
|
31
|
+
/** Extra font files or folders (searched before the system fonts). */
|
|
32
|
+
fonts?: string[];
|
|
33
|
+
onProgress?: (done: number, total: number) => void;
|
|
34
|
+
onWarning?: (message: string) => void;
|
|
35
|
+
}
|
|
36
|
+
export interface RenderVideoResult {
|
|
37
|
+
out: string;
|
|
38
|
+
format: VideoFormat;
|
|
39
|
+
frames: number;
|
|
40
|
+
fps: number;
|
|
41
|
+
width: number;
|
|
42
|
+
height: number;
|
|
43
|
+
/** Length of the output (s). */
|
|
44
|
+
duration: number;
|
|
45
|
+
/** Whether an audio track (or audio.wav next to png frames) was written. */
|
|
46
|
+
audio: boolean;
|
|
47
|
+
/** Wall-clock time of the export (s). */
|
|
48
|
+
elapsed: number;
|
|
49
|
+
}
|
|
50
|
+
export declare function videoFormat(out: string, format?: string): VideoFormat;
|
|
51
|
+
/** The ffmpeg arguments that encode raw RGBA frames (and an optional WAV) into `format`. */
|
|
52
|
+
export declare function ffmpegArgs(o: {
|
|
53
|
+
format: Exclude<VideoFormat, "png">;
|
|
54
|
+
width: number;
|
|
55
|
+
height: number;
|
|
56
|
+
fps: number;
|
|
57
|
+
out: string;
|
|
58
|
+
wav?: string;
|
|
59
|
+
crf?: number;
|
|
60
|
+
transparent?: boolean;
|
|
61
|
+
}): string[];
|
|
62
|
+
/** Renders a scene or sequence file to a video, a GIF or PNG frames. */
|
|
63
|
+
export declare function renderVideo(file: string, opts: RenderVideoOptions): Promise<RenderVideoResult>;
|
|
64
|
+
//# sourceMappingURL=video.d.ts.map
|
|
@@ -0,0 +1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MAAM,EAAE,MAAM,CAAC;IACf,gCAAgC;IAChC,QAAQ,EAAE,MAAM,CAAC;IACjB,4EAA4E;IAC5E,KAAK,EAAE,OAAO,CAAC;IACf,yCAAyC;IACzC,OAAO,EAAE,MAAM,CAAC;CACjB;AAED,wBAAgB,WAAW,CAAC,GAAG,EAAE,MAAM,EAAE,MAAM,CAAC,EAAE,MAAM,GAAG,WAAW,CAIrE;AAID,4FAA4F;AAC5F,wBAAgB,UAAU,CAAC,CAAC,EAAE;IAAE,MAAM,EAAE,OAAO,CAAC,WAAW,EAAE,KAAK,CAAC,CAAC;IAAC,KAAK,EAAE,MAAM,CAAC;IAAC,MAAM,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,GAAG,CAAC,EAAE,MAAM,CAAC;IAAC,WAAW,CAAC,EAAE,OAAO,CAAA;CAAE,GAAG,MAAM,EAAE,CAe3L;AAYD,wEAAwE;AACxE,wBAAsB,WAAW,CAAC,IAAI,EAAE,MAAM,EAAE,IAAI,EAAE,kBAAkB,GAAG,OAAO,CAAC,iBAAiB,CAAC,CAkHpG"}
|
package/dist/video.js
ADDED
|
@@ -0,0 +1,221 @@
|
|
|
1
|
+
import { spawn } from "node:child_process";
|
|
2
|
+
import { mkdirSync, mkdtempSync, rmSync, writeFileSync } from "node:fs";
|
|
3
|
+
import { availableParallelism, tmpdir } from "node:os";
|
|
4
|
+
import { createRequire } from "node:module";
|
|
5
|
+
import { extname, join, resolve } from "node:path";
|
|
6
|
+
import { pathToFileURL } from "node:url";
|
|
7
|
+
import { Worker } from "node:worker_threads";
|
|
8
|
+
import { loadEvaluable } from "./doctor.js";
|
|
9
|
+
import { mixAudio, writeWav } from "./mix.js";
|
|
10
|
+
/**
|
|
11
|
+
* Video export without a browser: worker threads evaluate frames and rasterise them with resvg,
|
|
12
|
+
* the main thread puts them back in order and streams raw pixels into ffmpeg, together with the
|
|
13
|
+
* audio mixed by `mixAudio`. Frames are pure functions of time, so there are no torn or stale
|
|
14
|
+
* captures and the same document always gives the same pixels.
|
|
15
|
+
*/
|
|
16
|
+
/** mp4 (H.264), webm (VP9, alpha with `transparent`), mov (ProRes; 4444 with alpha), gif, png (a folder of frames). */
|
|
17
|
+
export const VIDEO_FORMATS = ["mp4", "webm", "mov", "gif", "png"];
|
|
18
|
+
export function videoFormat(out, format) {
|
|
19
|
+
const f = (format ?? (extname(out).slice(1).toLowerCase() || "png"));
|
|
20
|
+
if (!VIDEO_FORMATS.includes(f))
|
|
21
|
+
throw new Error(`unknown video format "${f}" (one of ${VIDEO_FORMATS.join(", ")})`);
|
|
22
|
+
return f;
|
|
23
|
+
}
|
|
24
|
+
const even = (n) => Math.max(2, Math.round(n / 2) * 2);
|
|
25
|
+
/** The ffmpeg arguments that encode raw RGBA frames (and an optional WAV) into `format`. */
|
|
26
|
+
export function ffmpegArgs(o) {
|
|
27
|
+
const input = ["-f", "rawvideo", "-pix_fmt", "rgba", "-s", `${o.width}x${o.height}`, "-framerate", String(o.fps), "-i", "-"];
|
|
28
|
+
const audioIn = o.wav && o.format !== "gif" ? ["-i", o.wav] : [];
|
|
29
|
+
const map = audioIn.length ? ["-map", "0:v", "-map", "1:a"] : [];
|
|
30
|
+
const tail = ["-y", o.out];
|
|
31
|
+
switch (o.format) {
|
|
32
|
+
case "mp4":
|
|
33
|
+
return ["-v", "error", ...input, ...audioIn, ...map, "-c:v", "libx264", "-preset", "medium", "-crf", String(o.crf ?? 16), "-pix_fmt", "yuv420p", "-movflags", "+faststart", ...(audioIn.length ? ["-c:a", "aac", "-b:a", "192k"] : []), ...tail];
|
|
34
|
+
case "webm":
|
|
35
|
+
return ["-v", "error", ...input, ...audioIn, ...map, "-c:v", "libvpx-vp9", "-crf", String(o.crf ?? 28), "-b:v", "0", "-row-mt", "1", "-pix_fmt", o.transparent ? "yuva420p" : "yuv420p", ...(o.transparent ? ["-auto-alt-ref", "0"] : []), ...(audioIn.length ? ["-c:a", "libopus", "-b:a", "160k"] : []), ...tail];
|
|
36
|
+
case "mov":
|
|
37
|
+
return ["-v", "error", ...input, ...audioIn, ...map, "-c:v", "prores_ks", "-profile:v", o.transparent ? "4" : "3", "-pix_fmt", o.transparent ? "yuva444p10le" : "yuv422p10le", "-vendor", "apl0", ...(audioIn.length ? ["-c:a", "pcm_s16le"] : []), ...tail];
|
|
38
|
+
case "gif":
|
|
39
|
+
return ["-v", "error", ...input, "-filter_complex", "split[a][b];[a]palettegen=reserve_transparent=1:stats_mode=diff[p];[b][p]paletteuse=dither=sierra2_4a:alpha_threshold=128", "-loop", "0", ...tail];
|
|
40
|
+
}
|
|
41
|
+
}
|
|
42
|
+
/** The worker script, and the Node flags it needs: from source (.ts) it runs through tsx. */
|
|
43
|
+
function workerSpec() {
|
|
44
|
+
const fromSource = import.meta.url.endsWith(".ts");
|
|
45
|
+
const url = new URL(`./render-worker${fromSource ? ".ts" : ".js"}`, import.meta.url);
|
|
46
|
+
if (!fromSource || process.execArgv.some((a) => /[\\/]tsx[\\/]dist[\\/]/.test(a)))
|
|
47
|
+
return { url };
|
|
48
|
+
// Started some other way (a test runner): register tsx in the worker.
|
|
49
|
+
const tsx = pathToFileURL(createRequire(import.meta.url).resolve("tsx/esm")).href;
|
|
50
|
+
return { url, execArgv: [...process.execArgv, "--import", tsx] };
|
|
51
|
+
}
|
|
52
|
+
/** Renders a scene or sequence file to a video, a GIF or PNG frames. */
|
|
53
|
+
export async function renderVideo(file, opts) {
|
|
54
|
+
const started = Date.now();
|
|
55
|
+
const format = videoFormat(opts.out, opts.format);
|
|
56
|
+
const doc = await loadEvaluable(file);
|
|
57
|
+
const fps = opts.fps ?? doc.fps;
|
|
58
|
+
const from = Math.max(0, opts.from ?? 0);
|
|
59
|
+
const to = Math.min(doc.duration, opts.to ?? doc.duration);
|
|
60
|
+
if (!(to > from))
|
|
61
|
+
throw new Error(`nothing to render: from ${from} s to ${to} s`);
|
|
62
|
+
const count = Math.max(1, Math.ceil((to - from) * fps - 1e-6));
|
|
63
|
+
const aspect = doc.height / doc.width;
|
|
64
|
+
let width = opts.width ?? (opts.height ? opts.height / aspect : doc.width);
|
|
65
|
+
let height = opts.height ?? (opts.width ? opts.width * aspect : doc.height);
|
|
66
|
+
// yuv420p needs even sizes.
|
|
67
|
+
if (format === "mp4" || format === "webm")
|
|
68
|
+
[width, height] = [even(width), even(height)];
|
|
69
|
+
else
|
|
70
|
+
[width, height] = [Math.round(width), Math.round(height)];
|
|
71
|
+
const tmp = mkdtempSync(join(tmpdir(), "toon-render-"));
|
|
72
|
+
const out = resolve(opts.out);
|
|
73
|
+
let wav;
|
|
74
|
+
try {
|
|
75
|
+
// Audio first: it is quick, and a missing file should fail before minutes of rendering.
|
|
76
|
+
const clips = opts.mute || format === "gif" ? [] : doc.audio;
|
|
77
|
+
if (clips.length) {
|
|
78
|
+
const samples = await mixAudio(clips, count / fps, from);
|
|
79
|
+
wav = format === "png" ? join(out, "audio.wav") : join(tmp, "mix.wav");
|
|
80
|
+
if (format === "png")
|
|
81
|
+
mkdirSync(out, { recursive: true });
|
|
82
|
+
writeWav(wav, samples);
|
|
83
|
+
}
|
|
84
|
+
const png = format === "png";
|
|
85
|
+
if (png)
|
|
86
|
+
mkdirSync(out, { recursive: true });
|
|
87
|
+
const ff = png ? undefined : startFfmpeg(ffmpegArgs({ format, width, height, fps, out, wav, crf: opts.crf, transparent: opts.transparent }));
|
|
88
|
+
const n = Math.max(1, Math.min(opts.workers ?? Math.min(8, availableParallelism() - 1), count));
|
|
89
|
+
const workerData = { file: resolve(file), width, height, transparent: !!opts.transparent, png, fonts: opts.fonts ?? [] };
|
|
90
|
+
const spec = workerSpec();
|
|
91
|
+
const workers = Array.from({ length: n }, () => new Worker(spec.url, { workerData, execArgv: spec.execArgv }));
|
|
92
|
+
const warned = new Set();
|
|
93
|
+
try {
|
|
94
|
+
await new Promise((done, fail) => {
|
|
95
|
+
let next = 0; // next frame to hand out
|
|
96
|
+
let written = 0; // next frame to write (in order, for ffmpeg)
|
|
97
|
+
let finished = 0;
|
|
98
|
+
let failed = false;
|
|
99
|
+
const ready = new Map();
|
|
100
|
+
const idle = [];
|
|
101
|
+
// Frames held for ordering are bounded, so memory stays flat on long renders.
|
|
102
|
+
const window = n * 4;
|
|
103
|
+
const fail1 = (e) => {
|
|
104
|
+
if (failed)
|
|
105
|
+
return;
|
|
106
|
+
failed = true;
|
|
107
|
+
fail(e);
|
|
108
|
+
};
|
|
109
|
+
const dispatch = () => {
|
|
110
|
+
while (idle.length && next < count && next < written + window) {
|
|
111
|
+
const w = idle.pop();
|
|
112
|
+
w.postMessage({ index: next, time: from + next / fps });
|
|
113
|
+
next++;
|
|
114
|
+
}
|
|
115
|
+
};
|
|
116
|
+
let flushing = false;
|
|
117
|
+
const flush = async () => {
|
|
118
|
+
if (flushing || failed)
|
|
119
|
+
return;
|
|
120
|
+
flushing = true;
|
|
121
|
+
try {
|
|
122
|
+
while (ready.has(written)) {
|
|
123
|
+
const buf = ready.get(written);
|
|
124
|
+
ready.delete(written);
|
|
125
|
+
if (ff && !ff.stdin.write(buf))
|
|
126
|
+
await Promise.race([new Promise((r) => ff.stdin.once("drain", r)), ff.dead]);
|
|
127
|
+
written++;
|
|
128
|
+
dispatch();
|
|
129
|
+
}
|
|
130
|
+
}
|
|
131
|
+
catch (e) {
|
|
132
|
+
fail1(e);
|
|
133
|
+
}
|
|
134
|
+
finally {
|
|
135
|
+
flushing = false;
|
|
136
|
+
}
|
|
137
|
+
if (ready.has(written))
|
|
138
|
+
void flush();
|
|
139
|
+
if (written === count)
|
|
140
|
+
done();
|
|
141
|
+
};
|
|
142
|
+
ff?.dead.catch((e) => fail1(e));
|
|
143
|
+
for (const w of workers) {
|
|
144
|
+
w.on("error", (e) => fail1(e));
|
|
145
|
+
w.on("message", (m) => {
|
|
146
|
+
if (m.type === "warn") {
|
|
147
|
+
if (!warned.has(m.message))
|
|
148
|
+
opts.onWarning?.(m.message);
|
|
149
|
+
warned.add(m.message);
|
|
150
|
+
return;
|
|
151
|
+
}
|
|
152
|
+
if (m.type === "error")
|
|
153
|
+
return fail1(new Error(m.index !== undefined ? `frame ${m.index}: ${m.message}` : m.message));
|
|
154
|
+
if (m.type === "frame") {
|
|
155
|
+
const buf = Buffer.from(m.data);
|
|
156
|
+
finished++;
|
|
157
|
+
opts.onProgress?.(finished, count);
|
|
158
|
+
if (png) {
|
|
159
|
+
writeFileSync(join(out, `${String(m.index).padStart(5, "0")}.png`), buf);
|
|
160
|
+
ready.set(m.index, Buffer.alloc(0));
|
|
161
|
+
}
|
|
162
|
+
else
|
|
163
|
+
ready.set(m.index, buf);
|
|
164
|
+
void flush();
|
|
165
|
+
}
|
|
166
|
+
idle.push(w);
|
|
167
|
+
dispatch();
|
|
168
|
+
});
|
|
169
|
+
}
|
|
170
|
+
});
|
|
171
|
+
}
|
|
172
|
+
finally {
|
|
173
|
+
await Promise.all(workers.map((w) => w.terminate()));
|
|
174
|
+
}
|
|
175
|
+
if (ff)
|
|
176
|
+
await ff.close();
|
|
177
|
+
return { out, format, frames: count, fps, width, height, duration: count / fps, audio: !!wav, elapsed: (Date.now() - started) / 1000 };
|
|
178
|
+
}
|
|
179
|
+
finally {
|
|
180
|
+
rmSync(tmp, { recursive: true, force: true });
|
|
181
|
+
}
|
|
182
|
+
}
|
|
183
|
+
/** ffmpeg reading frames on stdin; `close()` ends the input and waits for the file, quoting ffmpeg's errors. */
|
|
184
|
+
function startFfmpeg(args) {
|
|
185
|
+
const ff = spawn("ffmpeg", args, { stdio: ["pipe", "ignore", "pipe"] });
|
|
186
|
+
let errors = "";
|
|
187
|
+
let spawnError;
|
|
188
|
+
ff.stderr.on("data", (c) => (errors += c));
|
|
189
|
+
const exited = new Promise((r) => {
|
|
190
|
+
ff.on("error", (e) => {
|
|
191
|
+
spawnError = e;
|
|
192
|
+
r(null);
|
|
193
|
+
});
|
|
194
|
+
ff.on("close", r);
|
|
195
|
+
});
|
|
196
|
+
// A broken pipe surfaces as the exit error below.
|
|
197
|
+
ff.stdin.on("error", () => { });
|
|
198
|
+
let closing = false;
|
|
199
|
+
const failure = (code) => spawnError
|
|
200
|
+
? new Error(`cannot run ffmpeg (${spawnError.message}): install it (macOS: brew install ffmpeg; Debian/Ubuntu: apt install ffmpeg), or export PNG frames to a folder`)
|
|
201
|
+
: new Error(`ffmpeg failed: ${errors.trim() || `exit ${code}`}`);
|
|
202
|
+
/** Rejects as soon as ffmpeg stops before `close()`: a missing binary or a bad argument fails the render at once. */
|
|
203
|
+
const dead = exited.then((code) => {
|
|
204
|
+
if (!closing || code !== 0)
|
|
205
|
+
throw failure(code);
|
|
206
|
+
return undefined;
|
|
207
|
+
});
|
|
208
|
+
dead.catch(() => { });
|
|
209
|
+
return {
|
|
210
|
+
stdin: ff.stdin,
|
|
211
|
+
dead,
|
|
212
|
+
async close() {
|
|
213
|
+
closing = true;
|
|
214
|
+
ff.stdin.end();
|
|
215
|
+
const code = await exited;
|
|
216
|
+
if (spawnError || code !== 0)
|
|
217
|
+
throw failure(code);
|
|
218
|
+
},
|
|
219
|
+
};
|
|
220
|
+
}
|
|
221
|
+
//# sourceMappingURL=video.js.map
|
|
@@ -0,0 +1 @@
|
|
|
1
|
+
{"version":3,"file":"video.js","sourceRoot":"","sources":["../src/video.ts"],"names":[],"mappings":"AAAA,OAAO,EAAE,KAAK,EAAE,MAAM,oBAAoB,CAAC;AAC3C,OAAO,EAAE,SAAS,EAAE,WAAW,EAAE,MAAM,EAAE,aAAa,EAAE,MAAM,SAAS,CAAC;AACxE,OAAO,EAAE,oBAAoB,EAAE,MAAM,EAAE,MAAM,SAAS,CAAC;AACvD,OAAO,EAAE,aAAa,EAAE,MAAM,aAAa,CAAC;AAC5C,OAAO,EAAE,OAAO,EAAE,IAAI,EAAE,OAAO,EAAE,MAAM,WAAW,CAAC;AACnD,OAAO,EAAE,aAAa,EAAE,MAAM,UAAU,CAAC;AACzC,OAAO,EAAE,MAAM,EAAE,MA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
3
|
+
"version": "0.3.0",
|
|
4
4
|
"description": "The toon CLI for animeStudio: validate, describe, render, debug and lip sync character and scene documents.",
|
|
5
5
|
"keywords": [
|
|
6
6
|
"animation",
|
|
@@ -47,10 +47,11 @@
|
|
|
47
47
|
"access": "public"
|
|
48
48
|
},
|
|
49
49
|
"dependencies": {
|
|
50
|
-
"@
|
|
51
|
-
"@anime-studio/
|
|
52
|
-
"@anime-studio/
|
|
53
|
-
"@anime-studio/
|
|
50
|
+
"@resvg/resvg-js": "^2.6.2",
|
|
51
|
+
"@anime-studio/core": "0.3.0",
|
|
52
|
+
"@anime-studio/import-svg": "0.3.0",
|
|
53
|
+
"@anime-studio/lipsync": "0.3.0",
|
|
54
|
+
"@anime-studio/rigid": "0.3.0"
|
|
54
55
|
},
|
|
55
56
|
"devDependencies": {
|
|
56
57
|
"tsx": "^4.23.15"
|
|
@@ -108,7 +108,7 @@ const svg = frameToSVG(evaluateScene(scene, 1.2)); // standalone SVG
|
|
|
108
108
|
```bash
|
|
109
109
|
toon validate my.scene.json # schema → assets → full compile; every error has a JSON path
|
|
110
110
|
toon describe hero.toon.json # the character's real controls, clips, anchors, channels
|
|
111
|
-
toon render my.scene.json --time 2.5 -o f.
|
|
111
|
+
toon render my.scene.json --time 2.5 -o f.png # one frame (rigid bodies simulated), SVG or PNG by extension
|
|
112
112
|
toon debug my.scene.json [--from s --to s] # frame-by-frame library checks: NaN, broken refs, pops, jumps
|
|
113
113
|
toon doctor video.mp4 my.scene.json # after a render: flickers / unpainted nodes (Remotion debug strip)
|
|
114
114
|
```
|
|
@@ -119,12 +119,14 @@ meet, and what validation does **not** catch:
|
|
|
119
119
|
|
|
120
120
|
## Render
|
|
121
121
|
|
|
122
|
-
- **Still:** `
|
|
123
|
-
|
|
124
|
-
|
|
125
|
-
|
|
126
|
-
|
|
127
|
-
|
|
122
|
+
- **Still:** `toon render my.scene.json --time 2.5 -o f.png`, or in code
|
|
123
|
+
`frameToSVG(evaluateScene(scene, t))` → `rsvg-convert -w <width> in.svg -o out.png`. Then actually
|
|
124
|
+
look at the PNG.
|
|
125
|
+
- **Video without a browser:** `toon video my.scene.json -o out.mp4` (scenes and sequences; also
|
|
126
|
+
`.webm`/`.mov` with `--transparent`, `.gif`, or a folder of PNG frames). Parallel workers, resvg,
|
|
127
|
+
ffmpeg, the audio mixed with fades, loops and music ducked under speech. Needs ffmpeg. Details
|
|
128
|
+
and the by-hand pipeline ([examples/render-video.ts](examples/render-video.ts)):
|
|
129
|
+
[references/rendering.md](references/rendering.md).
|
|
128
130
|
- **Remotion:** `<Composition component={ToonComposition} {...toonMetadata(scene)}
|
|
129
131
|
defaultProps={{ scene, assets }} />`; sequences use `ToonSequenceComposition`.
|
|
130
132
|
|
|
@@ -135,8 +137,9 @@ Pipelines, quality settings, sequences, Remotion setup and their pitfalls:
|
|
|
135
137
|
|
|
136
138
|
1. **Never invent names.** Clips, emotions, views, fx types, actions and fields come from
|
|
137
139
|
`toon describe`, `toon validate` messages or the docs. The format rejects unknown fields
|
|
138
|
-
(`Unrecognized key`),
|
|
139
|
-
|
|
140
|
+
(`Unrecognized key`), and with the characters loaded an unknown **pose value**
|
|
141
|
+
(`emotion: "glad"`), view or clip is an error listing the valid ones — `toon validate` reports
|
|
142
|
+
every bad action at once.
|
|
140
143
|
2. **Validate with assets.** `validateScene(doc)` without assets only checks the schema; pass
|
|
141
144
|
`{ characters, lipsync }` (or use `toon validate`, which loads them) to compile the script.
|
|
142
145
|
3. **Render with `prepareScene`** (`@anime-studio/rigid`), not bare `compileScene`, whenever props
|