-
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathrender.ts
More file actions
76 lines (67 loc) · 2.18 KB
/
render.ts
File metadata and controls
76 lines (67 loc) · 2.18 KB
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
import path from "path";
import { bundle } from "@remotion/bundler";
import { renderMedia, selectComposition } from "@remotion/renderer";
const parseArgs = (argv: string[]) => {
const args: Record<string, string> = {};
for (let i = 2; i < argv.length; i++) {
if (argv[i].startsWith("--") && i + 1 < argv.length) {
args[argv[i].slice(2)] = argv[i + 1];
i++;
}
}
return args;
};
const main = async () => {
const args = parseArgs(process.argv);
const compositionId = args["id"];
if (!compositionId) {
console.error("Usage: tsx render.ts --id <compositionId> [options]");
console.error("Options:");
console.error(" --output <path> Output file path");
console.error(" --codec gif|h264 Output codec (default: gif)");
console.error(" --scale <number> Scale factor (default: 1)");
console.error(
" --every-nth-frame <n> Frame skip for GIF (default: 2)",
);
process.exit(1);
}
const codec = (args["codec"] as "gif" | "h264") ?? "gif";
const ext = codec === "gif" ? "gif" : "mp4";
const outputPath =
args["output"] ?? path.join(__dirname, "out", `${compositionId}.${ext}`);
const scale = args["scale"] ? parseFloat(args["scale"]) : 1;
const everyNthFrame = args["every-nth-frame"]
? parseInt(args["every-nth-frame"], 10)
: codec === "gif"
? 2
: 1;
console.log(`Bundling...`);
const bundled = await bundle({
entryPoint: path.join(__dirname, "src", "index.ts"),
webpackOverride: (config) => config,
});
console.log(`Selecting composition "${compositionId}"...`);
const composition = await selectComposition({
serveUrl: bundled,
id: compositionId,
});
console.log(
`Rendering ${composition.durationInFrames} frames (${codec}, scale: ${scale}, everyNthFrame: ${everyNthFrame})...`,
);
await renderMedia({
composition,
serveUrl: bundled,
codec,
outputLocation: outputPath,
everyNthFrame,
scale,
onProgress: ({ progress }) => {
process.stdout.write(`\rProgress: ${(progress * 100).toFixed(1)}%`);
},
});
console.log(`\nDone! Output: ${outputPath}`);
};
main().catch((err) => {
console.error(err);
process.exit(1);
});