Enhance asset frame grabbing and timestamp formatting

Update the CLI description for the `grab` command to clarify that it outputs high-resolution PNGs with timestamp labels, improving usability for frame inspection. Additionally, export the `formatTimestamp` function for broader use and integrate it into the asset frame handling process, allowing for better timestamp visualization on frames.
This commit is contained in:
konstantin-paulus 2026-07-10 07:34:12 +02:00
parent f159d2c073
commit 526d1d934f
3 changed files with 25 additions and 3 deletions

View File

@ -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)")

View File

@ -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;

View File

@ -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;