Skip to content

The VS Code of video editing, built for agents.

TypeScript

Enhance node capture functionality to support multiple timeline positions

konstantin-paulus6878007846e2
diff --git a/apps/cli/reference/node/capture.md b/apps/cli/reference/node/capture.md
index fa9c1326..2ce8749b 100644
--- a/apps/cli/reference/node/capture.md
+++ b/apps/cli/reference/node/capture.md
@@ -1,16 +1,16 @@
-# `dapi node capture [id] [-t, --time <time>]`
+# `dapi node capture [id] [-t, --time <time...>]`
-Focuses the node on the canvas and captures it, written to a PNG file in the system temp directory. If `[id]` is omitted, captures the canvas (the active scene). To grab a video asset's own pixels at full resolution instead of the composited canvas, use [`media grab`](../media/grab.md).
+Focuses the node on the canvas and captures it, writing one PNG to the system temp directory per timeline position. If `[id]` is omitted, captures the canvas (the active scene). To grab a video asset's own pixels at full resolution instead of the composited canvas, use [`media grab`](../media/grab.md).
## Input
- `[id]`: node id (optional; defaults to the canvas)
-- `-t, --time <time>`: timeline position at which to record the node, a `Time` value (optional; defaults to the current playhead position)
+- `-t, --time <time...>`: one or more timeline positions at which to record the node, each a `Time` value (optional; defaults to the current playhead position)
## Output
-One JSON object: the absolute path to a freshly written PNG in the system temp directory with a uuid filename.
+One JSON object per line (JSON Lines), in the order the times were given: each has the requested time in seconds (`null` for the current playhead) and the absolute path to a freshly written PNG in the system temp directory with a uuid filename.
```ts
-{ path: string } // e.g. "/tmp/3f2c1a8e-....png"
+{ time: number | null, path: string } // e.g. { "time": 1.5, "path": "/tmp/3f2c1a8e-....png" }
```
diff --git a/apps/cli/src/index.ts b/apps/cli/src/index.ts
index e5722b51..92b8975e 100644
--- a/apps/cli/src/index.ts
+++ b/apps/cli/src/index.ts
@@ -430,21 +430,25 @@ async function grepNodes(pattern: string, id: string | undefined, opts: NodeGrep
}
}
-type CaptureOptions = { time?: string };
+type CaptureOptions = { time?: string[] };
async function nodeCapture(id: string | undefined, opts: CaptureOptions): Promise<void> {
const eid = id !== undefined ? parseNodeIds([id])[0] : undefined;
- let frame: number | undefined;
+ let times: number[] | undefined;
+ let frames: number[] | undefined;
if (opts.time !== undefined) {
- frame = Math.round(parseTimeArg(opts.time, "--time") * TIME_FPS);
+ times = opts.time.map((t) => parseTimeArg(t, "--time"));
+ frames = times.map((t) => Math.round(t * TIME_FPS));
}
try {
- const { base64 } = await editor.node.capture.query({ id: eid, frame });
- const path = join(tmpdir(), `${randomUUID()}.png`);
- writeFileSync(path, Buffer.from(base64, "base64"));
- console.log(JSON.stringify({ path }));
+ const shots = await editor.node.capture.query({ id: eid, frames });
+ for (const [i, { base64 }] of shots.entries()) {
+ const path = join(tmpdir(), `${randomUUID()}.png`);
+ writeFileSync(path, Buffer.from(base64, "base64"));
+ console.log(JSON.stringify({ time: times ? times[i] : null, path }));
+ }
} catch (e) {
handleSocketError(e);
}
@@ -1295,9 +1299,9 @@ node
node
.command("capture")
- .description(`Focus a node on the canvas and capture it as a PNG. Commonly useful to confirm what the viewer actually sees at a moment (layout, overlaps, text, timing), since the composited canvas is the truest "what plays at time T" check${docs("node/capture")}`)
+ .description(`Focus a node on the canvas and capture it as a PNG, one per timeline position. Commonly useful to confirm what the viewer actually sees at a moment (layout, overlaps, text, timing), since the composited canvas is the truest "what plays at time T" check${docs("node/capture")}`)
.argument("[id]", "node id to capture (optional; defaults to the canvas)")
- .option("-t, --time <time>", `timeline position to record at — seconds ("1.5"), frames ("45f"), or "MM:SS" (default: the current playhead)`)
+ .option("-t, --time <time...>", `one or more timeline positions to record at — seconds ("1.5"), frames ("45f"), or "MM:SS" (default: the current playhead)`)
.action((id: string | undefined, opts: CaptureOptions) => nodeCapture(id, opts));
node
diff --git a/apps/web/src/context/editor-api/node.ts b/apps/web/src/context/editor-api/node.ts
index 3d65953e..abaa9446 100644
--- a/apps/web/src/context/editor-api/node.ts
+++ b/apps/web/src/context/editor-api/node.ts
@@ -285,7 +285,7 @@ function sceneOfNode(world: EngineWorld, eid: number): number | null {
}
export function handleNodeCapture(engine: Accessor<Engine>) {
- return async ({ id, frame }: { id?: number; frame?: number }): Promise<{ base64: string }> => {
+ return async ({ id, frames }: { id?: number; frames?: number[] }): Promise<{ base64: string }[]> => {
const e = engine();
const w = e.world;
const c = w.components;
@@ -298,12 +298,6 @@ export function handleNodeCapture(engine: Accessor<Engine>) {
switchActiveScene(w, sceneEid);
}
- if (frame !== undefined && sceneEid !== null) {
- c.Playback.playing[sceneEid] = 0;
- c.Computed.localTime[sceneEid] = frame;
- c.Computed.localTimeInSeconds[sceneEid] = frame / w.frameRate;
- }
-
// Select the captured node so the capture shows its bounds.
if (eid !== undefined) {
for (const sel of query(w, [c.Selected, Or(c.Geometry, c.Group, c.AdjustmentLayer)])) {
@@ -317,16 +311,27 @@ export function handleNodeCapture(engine: Accessor<Engine>) {
else e.camera.focusEntities([eid]);
}
- // Realtime decoder seeks are fire-and-forget — give video paints time to
- // decode the new frame before capturing.
- await new Promise((resolve) => setTimeout(resolve, 2000));
+ // `undefined` means the current playhead; each explicit frame is captured in order.
+ const shots = frames !== undefined && frames.length > 0 ? frames : [undefined];
+ const results: { base64: string }[] = [];
+ for (const frame of shots) {
+ if (frame !== undefined && sceneEid !== null) {
+ c.Playback.playing[sceneEid] = 0;
+ c.Computed.localTime[sceneEid] = frame;
+ c.Computed.localTimeInSeconds[sceneEid] = frame / w.frameRate;
+ }
+
+ // Realtime decoder seeks are fire-and-forget — give video paints time to
+ // decode the new frame before capturing.
+ await new Promise((resolve) => setTimeout(resolve, 2000));
- const canvas = w.canvas;
- if (!(canvas instanceof HTMLCanvasElement)) {
- throw new Error("Canvas is not ready");
+ const canvas = w.canvas;
+ if (!(canvas instanceof HTMLCanvasElement)) {
+ throw new Error("Canvas is not ready");
+ }
+ results.push({ base64: canvas.toDataURL("image/png").split(",")[1] ?? "" });
}
- const base64 = canvas.toDataURL("image/png").split(",")[1] ?? "";
- return { base64 };
+ return results;
};
}
diff --git a/docs/cli.md b/docs/cli.md
index 05248a46..f16641b7 100644
--- a/docs/cli.md
+++ b/docs/cli.md
@@ -106,10 +106,10 @@ Searches entity records by regex and prints matching entities with the component
### `node capture`
```sh
-dapi node capture [id] [-t, --time <time>]
+dapi node capture [id] [-t, --time <time...>]
```
-Focuses the node (or the active scene, if omitted) and captures it to a PNG at the given timeline position. Prints `{ path }`.
+Focuses the node (or the active scene, if omitted) and captures it to a PNG at each given timeline position. Prints one `{ time, path }` JSON line per capture.
### `selection`
diff --git a/docs/getting-started.md b/docs/getting-started.md
index edd3e9a5..b9fd4d89 100644
--- a/docs/getting-started.md
+++ b/docs/getting-started.md
@@ -60,7 +60,7 @@ The `key` is the scene's stable identity: re-running the mount rebuilds that sce
Check the result visually:
```sh
-dapi node capture # prints { "path": "/tmp/….png" }
+dapi node capture # prints { "time": null, "path": "/tmp/….png" }
```
## Render