The VS Code of video editing, built for agents.
TypeScript
Refactor asset warmup integration in encoder
konstantin-paulusf1b86549b946
diff --git a/packages/encoder/src/encoder.ts b/packages/encoder/src/encoder.tsindex 2f9950ec..5f3415f5 100644--- a/packages/encoder/src/encoder.ts+++ b/packages/encoder/src/encoder.ts@@ -63,6 +63,8 @@ export async function createEncoder(world: World, config: EncoderConfig) {const computed = store(world, Computed);const playback = store(world, Playback);+ await warmupAssets(world);+const frameRate = world.get(FrameRate)?.value ?? 30;const sceneWidth = computed.width[sceneId]!;const sceneHeight = computed.height[sceneId]!;@@ -232,12 +234,6 @@ export async function createEncoder(world: World, config: EncoderConfig) {const render = async (): Promise<ExportResult> => {try {- // A rendered project starts with every `src` unresolved, and the- // decoders the playback system opens are keyed off the asset an- // element is bound to. Settle them before the first frame, or- // frame zero is drawn against media that is not there yet.- await warmupAssets(world);-await output.start();const start = performance.now();const startTime = start;@@ -447,7 +443,7 @@ function normalizeSceneTransform(world: World, sceneId: number): void {* a transcript that waits for the scene's own sources to land). Bounded, so* a source that keeps re-requesting cannot hold an export open forever.*/-async function warmupAssets(world: World): Promise<void> {+export async function warmupAssets(world: World): Promise<void> {for (let pass = 0; pass < 16; pass++) {assetSystem(world);if (!world.get(FramePromises)?.list?.length) return;diff --git a/packages/encoder/src/image-encoder.ts b/packages/encoder/src/image-encoder.tsindex 0db7f872..f76247d3 100644--- a/packages/encoder/src/image-encoder.ts+++ b/packages/encoder/src/image-encoder.ts@@ -14,7 +14,7 @@ import {Time, FrameRate,} from '@diffusionstudio/runtime';-import { resolverSystem, recomputeAllTimeRanges } from './encoder';+import { resolverSystem, recomputeAllTimeRanges, warmupAssets } from './encoder';import type { Entity, World } from 'koota';import type { AABB } from '@diffusionstudio/runtime';@@ -53,6 +53,8 @@ export async function createImageEncoder(world: World, config: ImageEncoderConfi// for the lazy audio-bus wiring to have something to bind to.world.set(AudioEngine, { context: new OfflineAudioContext(2, 1, 48000) });+ await warmupAssets(world);+const frameRate = world.get(FrameRate)?.value ?? 30;const computed = store(world, Computed);const playback = store(world, Playback);@@ -146,6 +148,8 @@ export async function createImageEncoder(world: World, config: ImageEncoderConfi}assert(Number.isFinite(bounds.minX), 'Entity is not visible at any of the requested frames');+ await resolverSystem(world);+const boundsWidth = Math.max(1, bounds.maxX - bounds.minX);const boundsHeight = Math.max(1, bounds.maxY - bounds.minY);