The VS Code of video editing, built for agents.
TypeScript
Update README and improve timestamp handling in media processing
konstantin-paulus2ec71b57af25
diff --git a/README.md b/README.mdindex d2a1b5d6..4e13bb95 100644--- a/README.md+++ b/README.md@@ -76,7 +76,7 @@ dapi node screenshot # see the canvas itself| `dapi open` | Launch the app, open a file, or turn a folder of footage into a project || `dapi context` | Summary of the open project: scenes, playhead, fonts || `dapi mount` | Compile and mount a JSX composition |-| `dapi node …` | The scene graph: `ls`, `tree`, `grep`, `patch`, `insert`, `cp`, `rm`, `screenshot`, `export` |+| `dapi node …` | The scene graph: `ls`, `tree`, `grep`, `patch`, `insert`, `cp`, `rm`, `screenshot`, `render` || `dapi asset …` | The media library: `add`, `ls`, `tree`, `mv`, `rm`, `export` || `dapi media …` | Inspect a file by id or path: `probe`, `grab`, `filmstrip`, `waveform`, `transcribe`, `listen` || `dapi project …` / `dapi folder …` / `dapi selection …` | Projects, library folders, canvas selection |diff --git a/apps/web/src/components/engine/api/assets.ts b/apps/web/src/components/engine/api/assets.tsindex 1e041458..828c6e92 100644--- a/apps/web/src/components/engine/api/assets.ts+++ b/apps/web/src/components/engine/api/assets.ts@@ -920,9 +920,15 @@ export async function fetchMimeType(handle: string): Promise<string | null> {/*** Playable content length of a media track, in seconds: the end timestamp- * minus the track's first timestamp. A track may carry a global time offset- * (a non-zero first timestamp); using the raw end timestamp as the duration- * would over-report the length by that offset. Clamped to >= 0.+ * minus the track's first *presented* timestamp. A track may carry a global+ * time offset (a non-zero first timestamp); using the raw end timestamp as the+ * duration would over-report the length by that offset.+ *+ * A negative first timestamp means the head has been trimmed by an edit list+ * (e.g. a QuickTime `elst` with a non-zero media_time); those pre-roll samples+ * "should not be presented", so the presented content is [0, end]. Clamp the+ * start to 0 — otherwise `end - start` counts the trimmed region and+ * over-reports the duration by the trim amount. Clamped to >= 0.*/async function trackContentDuration(track?: InputTrack | null): Promise<number> {if (!track) return 0;@@ -931,5 +937,5 @@ async function trackContentDuration(track?: InputTrack | null): Promise<number>track.getFirstTimestamp(),track.computeDuration(),]);- return Math.max(0, end - start);+ return Math.max(0, end - Math.max(0, start));}diff --git a/apps/web/src/components/engine/decoders/video.ts b/apps/web/src/components/engine/decoders/video.tsindex 84759d6e..d81519b6 100644--- a/apps/web/src/components/engine/decoders/video.ts+++ b/apps/web/src/components/engine/decoders/video.ts@@ -72,7 +72,7 @@ export class VideoBuffer {this.cache.rotation = videoTrack.rotation;this.packetSink = new EncodedPacketSink(videoTrack);- this.firstPacketTimestamp = await videoTrack.getFirstTimestamp() ?? 0;+ this.firstPacketTimestamp = Math.max(0, await videoTrack.getFirstTimestamp() ?? 0);this.lastFrameIndex = Math.max(0, Math.round(this.asset.duration * this.asset.frameRate) - 1);this.isDirty = true;} catch (e) {@@ -432,7 +432,9 @@ export class VideoExporter {this.input = new Input({ formats: ALL_FORMATS, source: new BlobSource(blob) });const track = await this.input.getPrimaryVideoTrack();assert(track, 'Video track not found');- this.firstTimestamp = await track.getFirstTimestamp() ?? 0;+ // See VideoBuffer.initialize: clamp so an edit-list head trim (negative first+ // timestamp) doesn't offset every exported frame relative to the audio.+ this.firstTimestamp = Math.max(0, await track.getFirstTimestamp() ?? 0);this.canvasSink = new CanvasSink(track, { poolSize: 2 });} catch (e) {console.error('Error initializing video exporter', e);