import { VideoCodec } from 'mediabunny'; /** * Chunk planner — timeline sharding for deterministic renders. * * Because vos evaluation is a pure function of time (seek(t) — the whole * point of the sampler tween backend), any frame range can render in * isolation. The planner splits [0, totalFrames) into balanced, contiguous * ranges; each chunk encodes independently (so it starts on a keyframe by * construction) with chunk-LOCAL timestamps starting at 0, and the finalize * step (concat.ts) offsets packets back onto the global timeline. * * Pure math — no I/O — so the policy stays unit-testable and reusable by * every harness (CLI, local server, render service). */ interface ChunkPlanPolicy { /** Upper bound on simultaneous chunk renders (browser pages/sessions). */ maxParallel: number; /** * Below this many frames per chunk, extra parallelism costs more in * per-chunk fixed overhead (page load, module import, first seek) than it * saves — stop splitting. (Remotion's floor is 5; ours is higher because * chunk startup includes CDN module imports.) */ minFramesPerChunk?: number; } declare const DEFAULT_MIN_FRAMES_PER_CHUNK = 24; interface RenderChunk { /** 0-based chunk index; also the concat order. */ index: number; /** First frame of the chunk (inclusive, global frame numbering). */ startFrame: number; /** End frame (exclusive). */ endFrame: number; frameCount: number; /** Global start time in seconds (startFrame / fps). */ startTime: number; /** Exact chunk duration in seconds (frameCount / fps). */ duration: number; } /** * Split `totalFrames` into at most `maxParallel` balanced contiguous chunks. * Sizes differ by at most one frame; chunk boundaries are exact frame * indices so no frame is rendered twice or skipped. */ declare function planChunks(totalFrames: number, fps: number, policy: ChunkPlanPolicy): RenderChunk[]; /** * Finalize concat — stream-copy chunk videos into one file, no re-encode. * * Each chunk is an independently encoded file whose timestamps start at 0 * (chunk-local). Concat demuxes every chunk's video packets and re-muxes * them into one output, offsetting timestamps by the chunk's global start * time. Because chunks were encoded with identical codec/params (the caller's * responsibility — one encoder config per render) and every independently * encoded file begins with a keyframe, packet-level concatenation is valid * with zero quality loss and near-zero CPU: pure container work, runs in * plain Node (mediabunny demux/mux is pure JS; no WebCodecs needed). * * Audio is deliberately absent here: per the rendering plan, audio renders * ONCE centrally and gets muxed against the concatenated video, so encoder * priming seams never exist. */ interface ConcatChunk { /** Encoded chunk file bytes (WebM or MP4, matching `format`). */ data: Uint8Array; /** * The chunk's exact intended duration in seconds (frameCount / fps, from * the chunk plan). Used as the timestamp offset for the NEXT chunk — * derived from the plan, not from packet rounding, so drift can't * accumulate across chunks. */ duration: number; } interface ConcatOptions { format: 'webm' | 'mp4'; /** Stamped into the output track metadata (players use it as a hint). */ frameRate?: number; } interface ConcatResult { bytes: Uint8Array; /** Total video packets written. */ packetCount: number; /** Codec copied through (from the first chunk). */ codec: VideoCodec; } interface MuxExportOptions extends ConcatOptions { /** * Video parts in plan order. An async iterable lets the caller feed parts * ONE at a time from storage instead of materializing all of them first * (the worker finalize's memory shape). */ video: AsyncIterable | Iterable; /** * Optional encoded audio file (any container mediabunny reads — the audio * mix page produces Opus in WebM). Its packets are STREAM-COPIED into the * output's audio track: no decode, no WebCodecs, pure container work, so * this runs in a Worker isolate exactly like the video concat. */ audio?: Uint8Array; } /** * Mux a chunked export's final artifact: stream-copy the video parts with * plan-derived timestamp offsets, and stream-copy the pre-encoded audio * track when one is provided. `packetCount` counts VIDEO packets only — * that is the frame-parity contract callers assert against the plan. */ declare function muxEncodedExport(options: MuxExportOptions): Promise; /** * Concatenate independently encoded chunk videos into one stream-copied file. * Chunks must share codec and encoder params; the first packet of every * chunk must be a keyframe (violations throw — better a loud failure at * finalize than a corrupt artifact). Thin wrapper over muxEncodedExport, * kept as the CLI's finalize entry point. */ declare function concatEncodedVideo(chunks: ConcatChunk[], options: ConcatOptions): Promise; /** * Count video packets in an encoded file — cheap integrity check used by * parity verification (chunked and single-flight renders of the same * composition must contain the same number of frames). */ declare function countVideoPackets(data: Uint8Array): Promise; /** * The take audio producer — page JavaScript implementing the export audio mix * for the take data schema, as a source string for injection into render * pages (the engine's `capture.audioProducerCode` seam for single-flight * captures, the audio mix page, and the finalize page for chunked exports). * * MIRRORS the client exporter's audio path (the platform's * decodeAudio → spliceAudio → mixExportAudio) — the same * algorithm, so a cloud export sounds identical to a client export of the * same composition. KEEP THEM IN SYNC when the client mixer changes. * * The producer is `window.__vosAudioProducer__({ data, plan, duration, * sampleRate })`. Inputs read from `data` (all optional): * videoSrc recording URL (requires hasAudio; the VOICE on legacy takes, * the SYSTEM track on split takes) * micSrc mic sidecar URL (the mic/system split) — the voice; when present the * recording's own track mixes as system audio under sysGain * hasAudio whether the recording carries audio * segments [{ in, out, rate? }] SOURCE spans — mic is spliced/resampled * so trims and speed changes stay lip-synced (pitch shifts with * rate, matching preservesPitch=false preview playback) * micGain voice master fader (default 1) * sysGain system-audio master fader (default 1; split takes only) * * The music/SFX clips no longer ride `data`: they live on the * studio stack entry (`vosso.studio`), and the host builds an ENGINE audio * plan from them ahead of the page (studio-core's `studioAudioPlan`), the * shape `@vosjs/core/audio`'s `mixAudio` renders. The page imports that * mixer from the CDN and renders the plan to ONE buffer beside the * recording's tracks. `plan` reaches the producer either as a call argument * (a page's CONFIG) or baked into the code as `window.__vosAudioPlan__` * (the engine's capture template calls the producer with `{ data, duration, * sampleRate }` only, so single-flight captures bake it); no plan, no clips. */ /** * The `@vosjs/core/audio` build a render page imports for `mixAudio`. * Pinned to the version the api installs (`coreAudioCdn.test.ts` there * holds it to the installed package): render-core has no engine dependency. */ declare const CORE_AUDIO_VERSION = "0.31.5"; declare const CORE_AUDIO_CDN_URL = "https://esm.sh/@vosjs/core@0.31.5/audio?target=es2022"; /** * The mixer's URL on a host's module mirror, laid out as the engine's * `engineMirrorLayout` says (`/@/`): the host * bundles `@vosjs/core/audio` with its one dependency (`@vosjs/tween`) * into one ESM file at `audio.js`, since the package's own entry imports * by bare specifier. No mirror, esm.sh. */ declare function coreAudioUrl(mirror?: string | null): string; /** * A sampled audio plan, structurally `@vosjs/core/audio`'s `AudioPlan` (and * studio-core's `StudioAudioPlan`), typed here so render-core depends on * neither. */ interface AudioPlanJson { duration: number; step: number; tracks: { id: string; src: string; loop: boolean; points: { t: number; on: boolean; pos: number; gain: number; }[]; }[]; } interface AudioProducerCodeOptions { /** * Bake the plan into the code (`window.__vosAudioPlan__`) for callers * that cannot pass one at call time (the engine's capture template). */ plan?: AudioPlanJson | null; /** Override the mixer import (tests, a self-hosted engine). */ coreAudioUrl?: string; } /** * The studio entry's own data out of a stack in either shape: the STORED * config's `stack` array (`[{ id, data, … }]`) or the lowered record keyed * by entry id (`{ 'vosso.studio': data }`). Null when there is none. */ declare function studioEntryData(stack: unknown): Record | null; declare function audioProducerCode(options?: AudioProducerCodeOptions): string; /** * Does this composition carry anything the audio producer could mix? The * voice reads off `data`; the clips off the studio stack entry (`stack` in * either shape `studioEntryData` reads) or an already-built plan. */ declare function dataHasAudio(data: unknown, stack?: unknown, plan?: AudioPlanJson | null): boolean; export { type AudioPlanJson, type AudioProducerCodeOptions, CORE_AUDIO_CDN_URL, CORE_AUDIO_VERSION, type ChunkPlanPolicy, type ConcatChunk, type ConcatOptions, type ConcatResult, DEFAULT_MIN_FRAMES_PER_CHUNK, type MuxExportOptions, type RenderChunk, audioProducerCode, concatEncodedVideo, coreAudioUrl, countVideoPackets, dataHasAudio, muxEncodedExport, planChunks, studioEntryData };