Skip to content

The VS Code of video editing, built for agents.

TypeScript

Enhance asset frame grabbing and timestamp formatting

konstantin-paulus526d1d934f15
diff --git a/apps/cli/src/index.ts b/apps/cli/src/index.ts
index c2bb8f7c..32016f99 100644
--- a/apps/cli/src/index.ts
+++ b/apps/cli/src/index.ts
@@ -1081,7 +1081,7 @@ asset
asset
.command("grab")
- .description(`Decode one or more frames of a video asset and write them as PNGs. Commonly useful for pinning down scene transitions and exact cut timestamps or to sample visuals at the given timestamps${docs("asset/grab")}`)
+ .description(`Decode one or more frames of a video asset and write them as high-res PNGs, each stamped in the top-left with its HH:MM:SS:FF timestamp. Best for inspecting individual frames in detail where a filmstrip is too coarse: seeks to the exact requested time with frame-level precision${docs("asset/grab")}`)
.argument("<id|path>", "video asset id, or a local video file to grab frames from")
.option("-t, --time <time...>", `one or more timestamps to grab — seconds ("1.5"), frames ("45f"), or "MM:SS" (default: 0)`)
.option("-r, --resolution <pixels>", "cap each frame to this many total pixels, preserving aspect ratio; 0 for native (default: 147456, i.e. 384x384)")
diff --git a/apps/web/src/components/engine/utils/transcode.ts b/apps/web/src/components/engine/utils/transcode.ts
index ef1e1fae..de4282cc 100644
--- a/apps/web/src/components/engine/utils/transcode.ts
+++ b/apps/web/src/components/engine/utils/transcode.ts
@@ -93,7 +93,7 @@ const SILENCE_THRESHOLD = 12; // peak value (0-255) at/below which audio counts
const SILENCE_MIN_SECONDS = 0.4;
const AUDIO_RULER_FRAME_RATE = 30;
-function formatTimestamp(seconds: number, frameRate: number): string {
+export function formatTimestamp(seconds: number, frameRate: number): string {
const fps = Math.max(1, Math.round(frameRate));
const totalFrames = Math.round(seconds * fps);
const frames = totalFrames % fps;
diff --git a/apps/web/src/context/editor-api/assets.ts b/apps/web/src/context/editor-api/assets.ts
index 8c484955..c1723c87 100644
--- a/apps/web/src/context/editor-api/assets.ts
+++ b/apps/web/src/context/editor-api/assets.ts
@@ -6,7 +6,7 @@ import { ALL_FORMATS, BlobSource, CanvasSink, Input } from 'mediabunny';
import { ElectronFileHandle } from '@/lib/electron-file-handle';
import { ElectronWritableFileHandle } from '@/lib/electron-file-writable';
import { trpc } from '@/lib/trpc';
-import { uploadBlob, visualizeAsset, loadAsset, removeAsset, describeFileAsset, getAssetFile } from '@/components/engine';
+import { uploadBlob, visualizeAsset, loadAsset, removeAsset, describeFileAsset, getAssetFile, formatTimestamp } from '@/components/engine';
import { assert, mimeTypeToExtension } from '@/utils';
import {
transcodeForTranscription,
@@ -360,6 +360,28 @@ export function handleAssetFrame(engine: Accessor<Engine>) {
for await (const wrapped of sink.canvasesAtTimestamps(timestamps)) {
const { time, index } = ordered[i++];
assert(wrapped, `No frame found at ${time}s.`);
+
+ const ctx = wrapped.canvas.getContext("2d");
+
+ if (ctx) {
+ const label = formatTimestamp(time, asset.frameRate)
+ const bandHeight = Math.max(20, Math.round(wrapped.canvas.height * 0.06));
+ const fontSize = Math.round(bandHeight * 0.72);
+ const paddingLeft = Math.round(bandHeight * 0.4);
+ const y = paddingLeft + bandHeight / 2;
+
+ ctx.font = `normal ${fontSize}px sans-serif`;
+ ctx.textBaseline = "middle";
+ ctx.textAlign = "left";
+
+ ctx.lineJoin = "round";
+ ctx.lineWidth = Math.max(2, Math.round(fontSize / 3));
+ ctx.strokeStyle = "#000";
+ ctx.strokeText(label, paddingLeft, y);
+ ctx.fillStyle = "#FFF";
+ ctx.fillText(label, paddingLeft, y);
+ }
+
result[index] = { time, base64: await canvasToPngBase64(wrapped.canvas) };
}
return result;