Implementation:0xsline OpenChatCut PlanExport
Appearance
| Knowledge Sources | |
|---|---|
| Domains | Video_Export, Validation, Media_Processing |
| Last Updated | 2026-10-22 14:00 GMT |
Overview
Concrete function that validates an export request and normalizes it into a fully-resolved `ExportPlan` with codec, resolution, frame range, scale, and filename.
Description
The planExport function is the entry point for export plan validation. It takes a raw `ExportRequest` (which may contain a timeline state, a full project doc, codec, resolution, FPS, and frame range) and produces a frozen `ExportPlan` ready for media materialization and rendering.
Key behaviors:
- Timeline validation: Validates `state` as a `TimelineState` with an items array.
- Nested project support: If `project` is provided, runs migrations, validates the sequence graph, and resolves the nested timeline's render plan.
- Codec/format defaults: Defaults to `h264` for video, `mp3` for audio; validates format/codec compatibility.
- Resolution scaling: Computes the scale factor for the requested resolution; rejects unrepresentable fractional scales.
- Frame range normalization: Converts start/end (in frames or seconds) into a normalized inclusive range.
- ProRes constraints: ProRes mezzanine exports do not accept `videoBitrate`.
- Retime FPS: If a different FPS is requested, sets `retimeFps` for post-render retiming.
Usage
- Server-side export: Called by `acceptExportSubmission` to validate before materialization.
- Direct API: The export-plan plugin exposes `planExport` over HTTP for pre-flight checks.
- Export recovery: Re-planning from a stored request to resume an interrupted export.
Code Reference
Source Location
- Repository: OpenChatCut
- File:*** server/plugins/export-plan.ts
Signature
export type ExportRequest = {
state?: unknown;
project?: unknown;
timelineId?: unknown;
operationId?: unknown;
format?: 'video' | 'audio';
codec?: 'h264' | 'vp8' | 'prores' | 'mp3' | 'wav';
name?: string;
startFrame?: number;
endFrameExclusive?: number;
startSeconds?: number;
endSeconds?: number;
resolution?: ExportResolution;
fps?: number;
videoBitrate?: number;
};
export interface ExportPlan {
state: TimelineState;
project?: ProjectDoc;
timelineId?: string;
format: 'video' | 'audio';
media: (typeof EXPORT_MEDIA)[keyof typeof EXPORT_MEDIA];
frameRange: [number, number] | undefined;
totalFrames: number;
filename: string;
durationSeconds: number;
scale: number;
retimeFps: number | undefined;
videoBitrate: number | undefined;
}
export function planExport(body: ExportRequest | null): ExportPlan;
export function validateVideoParams(
body: { resolution?: unknown; fps?: unknown; videoBitrate?: unknown } | null,
format: 'video' | 'audio',
): void;
export function exportFilename(name: string | undefined, ext: string): string;
Import
import { planExport, type ExportPlan, type ExportRequest } from '../server/plugins/export-plan.ts';
I/O Contract
Inputs
| Name | Type | Required | Description |
|---|---|---|---|
| body.state | TimelineState | Yes | Timeline state to export |
| body.project | ProjectDoc | No | Full project for nested timeline export |
| body.timelineId | string | No | Timeline to export (requires project) |
| body.format | 'audio' | No | Defaults to 'video' |
| body.codec | string | No | h264, vp8, prores, mp3, or wav |
| body.resolution | ExportResolution | No | 480p, 720p, 1080p, or 4k |
| body.fps | number | No | 24, 25, 30, 50, or 60 |
| body.videoBitrate | number | No | Integer 1M–80M bps |
| body.name | string | No | Output filename (sanitized) |
Outputs
| Name | Type | Description |
|---|---|---|
| planExport() returns | ExportPlan | Frozen export plan with all fields resolved |
| validateVideoParams() returns | void | Throws ExportRequestError on invalid params |
Usage Examples
Basic Video Export Plan
import { planExport } from '../server/plugins/export-plan.ts';
const plan = planExport({
state: timelineState,
format: 'video',
codec: 'h264',
resolution: '1080p',
fps: 30,
name: 'my-export',
});
console.log(`Output: ${plan.filename}`);
console.log(`Frames: ${plan.totalFrames}`);
console.log(`Duration: ${plan.durationSeconds}s`);
console.log(`Scale: ${plan.scale}`);
Nested Project Export
const plan = planExport({
project: projectDoc,
timelineId: 'main-timeline',
codec: 'prores',
name: 'mezzanine-master',
});
// ProRes: no videoBitrate, no retimeFps
console.assert(plan.videoBitrate === undefined);
console.assert(plan.retimeFps === undefined);
Related Pages
Implements Principle
Requires Environment
Page Connections
Double-click a node to navigate. Hold to expand connections.
Principle
Implementation
Heuristic
Environment