Miraiclip SDK
API reference

@miraiclip/server-export

Server-side export for Miraiclip: run exportProject in headless Chrome from Node — same pipeline as the browser, preview/export parity by construction.

npm install @miraiclip/server-export
Version0.4.3
Runs inNode ≥ 18, with Chrome or Chromium
Exports19
GuidesServer (Node)

Functions

createExportSession

A persistent exporter: ONE headless Chrome + harness page kept warm across calls, so an export costs an export — not a browser launch (~1-2s each that exportProjectFile pays per call). Exports run through the exact same in-page exportProject pipeline; one page runs one export at a time, so calls queue. Built for batch rendering (@miraiclip/templates) and export-on-demand services.

function createExportSession(options?: CreateExportSessionOptions): Promise<ExportSession>

Guides: Server (Node), Roadmap, Batch rendering

createRenderSession

A persistent still-frame renderer: ONE headless Chrome + harness page kept warm across calls, so rendering a frame costs a frame — not a browser launch. Frames render through the exact export pipeline (same compositor, decode path, and fonts), so a still is what that composition time will look like in the exported file. Built for agent loops (@miraiclip/mcp's preview_frame) and thumbnail generation.

function createRenderSession(options?: CreateRenderSessionOptions): Promise<RenderSession>

Guides: Server (Node), Stills, Roadmap

exportProjectFile

Export a Miraiclip project document from Node: launches headless Chrome, serves a harness page + the project's media on a loopback server, runs the exact same exportProject the browser uses, and returns the encoded file.

MP4 needs a real Chrome (free Chromium has no H.264 encoder — it fails the up-front codec probe with a clear error); WebM works on any Chromium.

function exportProjectFile(doc: ProjectDocument, options: ExportProjectFileOptions): Promise<ExportProjectFileResult>

Guides: Server (Node), Roadmap

launchBrowser

Launch order: explicit executablePath → MIRAICLIP_BROWSER env → the machine's installed Chrome (Playwright's "chrome" channel). We depend on playwright-core (no forced browser download at install); real Chrome is the recommended runtime because it ships the proprietary H.264/AAC encoders — free Chromium builds export WebM only.

function launchBrowser(options?: BrowserOptions): Promise<Browser>

parseCliArgs

Pure and unit-testable: argv (after node + script) → validated options.

function parseCliArgs(argv: string[]): ParsedCliArgs

resolveAssetSources

Decide where each asset's bytes come from. Pure given exists, so the mapping rules are unit-testable: an explicit assets entry wins, remote URLs pass through untouched, and anything else is treated as a local path resolved against assetsDir. Local assets are rewritten to /assets/<id> so the in-page pipeline fetches them from the harness's own origin (media fetches are range requests — the static server must answer them).

function resolveAssetSources(doc: ProjectDocument, options: {
    assets?: Record<string, string> | undefined;
    assetsDir?: string | undefined;
    exists: (filePath: string) => boolean;
}): ResolvedAssets

Classes

ServerExportAbortedError

Thrown when the export is cancelled via the AbortSignal.

Extends Error.

new ServerExportAbortedError()

Guides: Server (Node)

Interfaces

BrowserOptions

MemberTypeDescription
executablePath?stringPath to a Chrome/Chromium executable. Highest priority. Any distribution works — system Chrome, Chrome for Testing, Playwright's Chromium — but only real Chrome builds carry the proprietary H.264/AAC encoders MP4 export needs; free Chromium is WebM-only.
args?string[]Extra Chrome flags, appended after the defaults.
swiftshader?booleanRender WebGL on SwiftShader (software GL). Defaults to true on Linux — servers rarely have a GPU, and Chrome's default ANGLE stalls on GPU-less readback — and false elsewhere.

CreateExportSessionOptions

MemberTypeDescription
assets?Record<string, string>Asset id → local file path (same contract as exportProjectFile).
assetsDir?stringBase directory for resolving relative asset src paths (default: cwd).
browser?BrowserOptions

CreateRenderSessionOptions

MemberTypeDescription
assets?Record<string, string>Asset id → local file path (same contract as exportProjectFile).
assetsDir?stringBase directory for resolving relative asset src paths (default: cwd).
browser?BrowserOptions

ExportProjectFileOptions

MemberTypeDescription
format"mp4" | "webm"
quality?"draft" | "standard" | "high" | { videoBitrate: number; }
fps?numberOutput frame rate (default: the project's fps).
width?numberOutput size (default: the project's composition size).
height?number
range?{ startUs: number; endUs: number; }Composition range in µs (default: the whole composition).
assets?Record<string, string>Where each asset's media lives on THIS machine: asset id → local file path. Assets whose src is already an http(s) or data URL are fetched as-is and need no entry; every other asset must either have an entry here or a src that resolves to a file under assetsDir.
assetsDir?stringBase directory for resolving relative asset src paths (default: cwd).
out?stringWrite the encoded file here (created/overwritten). With out set the encoded chunks STREAM from the browser to the file as they are produced — peak memory stays flat however long the output is, and bytes is not returned. Omit to get the whole file back in memory instead (fine for short outputs; the in-page → Node hop transiently costs ~2× the size).
audioChunkSeconds?numberAudio mix chunk length in seconds (default 60): audio mixes in bounded sequential chunks, so timeline length does not grow mix memory.
signal?AbortSignal
onProgress?(progress: ServerExportProgress) => void
browser?BrowserOptions

ExportProjectFileResult

MemberTypeDescription
bytes?Uint8ArrayThe encoded file — absent when out was given (it streamed to disk).
filePath?stringSet when out was given: the absolute path written.
bytesWritten?numberSet when out was given: total bytes streamed into the file.

ExportSession

MemberTypeDescription
exportFile(doc: ProjectDocument, options: ExportFileOptions) => Promise<ExportProjectFileResult>Export one document — same options and result as exportProjectFile, without the browser launch. The document is passed per call, so a session outlives edits and serves any number of documents.
close() => Promise<void>

ParsedCliArgs

MemberTypeDescription
projectPathstring
optionsExportProjectFileOptions
quietboolean

ProjectDocument

The document: everything that is part of the composition, serialized and covered by undo history.

MemberTypeDescription
schemaVersion1
settingsProjectSettings
assetsRecord<string, Asset>
tracksRecord<string, Track>
trackOrderstring[]Render order: index 0 is the bottom layer.
clipsRecord<string, Clip>
transitionsRecord<string, Transition>Transitions between adjacent clips, keyed by id.

Guides: Collaboration, Stills, Defining templates

RenderSession

MemberTypeDescription
renderStill(doc: ProjectDocument, options: RenderStillOptions) => Promise<Uint8Array>Render one frame of doc as a PNG. The document is passed per call, so a session outlives edits — hand it the latest state every time.
close() => Promise<void>

Guides: Stills

RenderStillOptions

MemberTypeDescription
timeUsnumberComposition time to render, in microseconds.
width?numberOutput size (default: the document's composition size).
height?number

ServerExportProgress

Mirrors the renderer's ExportProgress — re-declared so the Node side has no runtime dependency on the renderer.

MemberTypeDescription
phase"audio" | "video" | "finalizing"
framesDonenumber
totalFramesnumber
audioMixedUs?number
audioTotalUs?number
bytesWritten?numberStreamed exports (out set) only: bytes written to the file so far. framesDone / totalFrames is the true completion fraction — total output size is the encoder's decision and unknowable up front — but this gives live file size, MB/s, and a remaining-bytes estimate: bytesWritten × (totalFrames − framesDone) / framesDone. Output flushes in ~16MiB chunks, so short exports may read 0 until finalize.

Types

ExportFileOptions

Per-export options: everything exportProjectFile takes minus the session-level fields.

type ExportFileOptions = Omit<ExportProjectFileOptions, "assets" | "assetsDir" | "browser">;

On this page