The VS Code of video editing, built for agents.
TypeScript
Refactor node capture logic for improved clarity and default handling
konstantin-paulus54cd22f0387f
diff --git a/apps/cli/src/index.ts b/apps/cli/src/index.tsindex f6466c27..66d6aadd 100644--- a/apps/cli/src/index.ts+++ b/apps/cli/src/index.ts@@ -435,19 +435,15 @@ type CaptureOptions = { time?: string[]; timestamp?: boolean };async function nodeCapture(id: string, opts: CaptureOptions): Promise<void> {const eid = parseNodeIds([id])[0];- let times: number[] | undefined;- let frames: number[] | undefined;- if (opts.time !== undefined) {- times = opts.time.map((t) => parseTimeArg(t, "--time"));- frames = times.map((t) => Math.round(t * TIME_FPS));- }+ const times = (opts.time ?? ["0"]).map((t) => parseTimeArg(t, "--time"));+ const frames = times.map((t) => Math.round(t * TIME_FPS));try {const shots = await editor.node.capture.query({ id: eid, frames, timestamp: opts.timestamp });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 }));+ console.log(JSON.stringify({ time: times[i], path }));}} catch (e) {handleSocketError(e);@@ -1344,7 +1340,7 @@ node`Render a node in isolation to PNGs, one per position, each stamped in the top-left with its HH:MM:SS:FF timestamp. The node is drawn offscreen at 720p height, tightly framed to its own bounds on a transparent background — siblings and overlapping scene content are not included, so capture a scene id to check composition ("what plays at time T": layout, overlaps, text, timing). For a video asset's own full-resolution pixels use \`media grab\`.`,).argument("<id>", "node id to capture")- .option("-t, --time <time...>", `one or more positions to capture, relative to the node's start (0 = its first visible frame) — seconds ("1.5"), frames ("45f"), or "MM:SS" (default: the node's frame under the current playhead)`)+ .option("-t, --time <time...>", `one or more positions to capture, relative to the node's start (0 = its first visible frame) — seconds ("1.5"), frames ("45f"), or "MM:SS" (default: 0, the node's first visible frame)`).option("--no-timestamp", "don't stamp each capture with its HH:MM:SS:FF timestamp label").action((id: string, opts: CaptureOptions) => nodeCapture(id, opts));diff --git a/apps/web/src/context/editor-api/node.ts b/apps/web/src/context/editor-api/node.tsindex 6b33936b..c8907884 100644--- a/apps/web/src/context/editor-api/node.ts+++ b/apps/web/src/context/editor-api/node.ts@@ -10,7 +10,6 @@ import { ElectronWritableFileHandle } from "@/lib/electron-file-writable";import {deleteEntity,- getParentEntity,isText,isScene,getEntityTree,@@ -37,7 +36,6 @@ import type {NodeRenderRequest,NodeRenderResult,} from "@diffusionstudio/cli/channels";-import { clamp } from "@/utils";import type { EncoderConfig } from "@/components/engine/encode/interfaces";import type { Accessor } from "solid-js";@@ -273,33 +271,17 @@ export function handleNodeGrep(engine: Accessor<Engine>) {};}-// Walk up from a node to the scene that owns it (a scene resolves to itself).-function sceneOfNode(world: EngineWorld, eid: number): number | null {- let cur: number | null = eid;- while (cur !== null) {- if (isScene(world, cur)) return cur;- cur = getParentEntity(world, cur);- }- return null;-}-export function handleNodeCapture(engine: Accessor<Engine>) {return async ({ id, frames, timestamp }: { id: number; frames?: number[]; timestamp?: boolean }): Promise<{ base64: string }[]> => {const e = engine();const w = e.world;- const c = w.components;const eid = resolveNodeEid(w, id);- // `undefined` means the current playhead, mapped into the node's local- // timeline (the encoder's frame 0 is the node's first visible frame).+ // `undefined` means the node's first visible frame (the encoder's frame 0).let shots = frames;if (shots === undefined || shots.length === 0) {- const sceneEid = sceneOfNode(w, eid);- const sceneFrame = sceneEid !== null ? c.Computed.localTime[sceneEid] ?? 0 : 0;- const start = c.Computed.start[eid] ?? 0;- const duration = c.Computed.duration[eid] ?? 0;- shots = [clamp(sceneFrame - start, 0, Math.max(0, duration - 1))];+ shots = [0];}const encoder = await createImageEncoder(w, {