Introducing a new way to review your PRs.

Read the announcement

walterlow / freecut

FreeCut is a professional-grade video editor that runs entirely in your browser. Professional video editing, zero installation. Create stunning videos with multi-track editing, keyframe animations, real-time preview, and high-quality exports.

View on GitHub

19 documents · Updated Oct 30, 2026

docs / headless-server-and-rendering

Headless server and rendering

Headless use runs the FreeCut render engine in Chrome without mounting the editor UI. A local service serves the browser harness and project media, then accepts render and inspection requests that produce media files or measured canvas state.

System role

The headless system turns a project and its media references into browser-rendered video, audio, images, or layout data. It keeps automated output aligned with the editor's composition rules while exposing a small HTTP boundary for scripts and other services.

The main entry points are:

The parent page, Headless automation, covers the wider automation lifecycle. Programmatic editing covers the edit operations that use the same warm browser service.

Server lifecycle

Harness startup

The harness is a browser page that exposes rendering actions without the editor screens. The service can use a built local page or a reachable development page. In both cases, media IDs become URLs that the browser can fetch.

The service starts the harness before it opens its HTTP listener. It then starts one Chrome process and one ready page. This gives each request a stable browser context and avoids a cold browser start for every operation.

References: headless/…/render-core.mjs• L124-171 headless/serve.mjs• L236-256

Warm service

The warm service keeps Chrome and the harness page alive across requests. It serializes page work through one queue because rendering and browser media work can compete for CPU and GPU resources. After a failed page operation, it can recreate the page before accepting later work.

The service holds the workspace writer lock for its lifetime. This prevents another writer from changing project data while the service reads, edits, or renders it.

References: headless/serve.mjs• L203-285 headless/serve.mjs• L1056-1081

Service state

The status model gives clients a view of service readiness, active work, queue state, and the last completed operation. Render progress is attached to the active render operation and is bounded before it is exposed.

The service moves through these states:

  • starting while the harness and browser are opening.
  • ready when requests can run.
  • draining while shutdown waits for work to finish.
  • stopped after resources close.

References: headless/…/service-status.mjs• L20-101 headless/serve.mjs• L249-285 headless/serve.mjs• L847-855

Shutdown flow

Shutdown stops new work, closes the HTTP listener, drains the operation queue, and then closes the page, browser, media servers, and workspace lock. A shutdown deadline prevents a stuck operation from keeping the process alive without limit.

This sequence protects in-flight output while still giving operators a bounded way to stop the service.

References: headless/serve.mjs• L1056-1084

HTTP and media serving

Browser transport

The harness and media servers provide the browser with the page assets and the source bytes for project media. The render layer passes media IDs with URLs and stored metadata, so the browser can fetch bytes while still knowing source dimensions, duration, and audio properties.

Media access supports range reads. This lets the browser read part of a large source instead of loading the complete file into memory before rendering.

References: headless/…/render-core.mjs• L141-171 headless/…/render-core.mjs• L174-188 headless/serve.mjs• L683-718

HTTP contract

The service supports health and capability checks, project and media resources, editing, rendering, frame capture, layout inspection, and asynchronous checkpoint work. Versioned routes provide the main contract. Short routes remain for compatibility with existing callers.

The principal rendering and inspection routes are:

RoutePurposeResult
GET /healthReport browser, GPU, harness, and workspace stateJSON
GET /v1/statusReport service state, queue state, and operation historyJSON
GET /v1/capabilitiesDescribe supported actions and request shapesJSON
POST /v1/render or POST /renderRender video or audioMedia attachment
POST /frameRender one composited frameImage attachment
POST /layoutMeasure visible item geometryJSON
POST /v1/media/:id/probeRead browser media metadataJSON

References: headless/serve.mjs• L847-1009 headless/serve.mjs• L1010-1044

Request protection

The HTTP boundary validates request data before it reaches the browser. It limits request size and connection time, restricts resource identifiers, and returns structured errors for invalid input, missing media, queue limits, timeouts, and internal failures.

The service binds to 127.0.0.1 by default because it has no built-in authentication. A different host is an explicit deployment choice that needs protection outside this service.

References: headless/serve.mjs• L127-139 headless/serve.mjs• L457-497 headless/serve.mjs• L1010-1044

Browser probing

Runtime readiness

The browser page is ready only after its headless API is available. The service also probes the WebGPU adapter and reports whether it is a real hardware adapter or a software adapter. This makes a host capability visible before a render depends on it.

GPU effects require usable hardware acceleration. A software adapter causes such jobs to fail rather than silently changing their pixels. Other render paths can use their supported fallback behavior when the missing capability does not change the contract.

References: headless/serve.mjs• L249-285 headless/…/render-core.mjs• L244-268

Media probing

Media probing asks the browser to inspect a source through the same URL path used by rendering. The result can be returned to the caller or stored as media metadata. This keeps source facts used by later renders close to the browser's actual decode behavior.

References: headless/serve.mjs• L683-718 headless/serve.mjs• L721-757

Pixel oracle

The frame oracle is a local determinism check for the full frame path. It creates a temporary workspace with synthetic clips, runs the warm service, captures selected PNG frames, and prints one SHA-256 value per frame.

The oracle is not a cross-machine golden test because GPU drivers can change rendered bytes. Its value is in comparing two runs on the same environment. Ablation removes one fixture feature at a time so a change in the related hash shows that the frame path still exercises that feature.

References: headless/frame-oracle.mjs• L1-26 headless/frame-oracle.mjs• L317-429

Rendering orchestration

Project preparation

Before browser work starts, the render core validates the request, loads the project, resolves output settings, computes any time range, and collects the media used by that range. It passes resolved media URLs and metadata to the browser and keeps missing sources visible in the job summary.

This preparation stage also determines the output path and whether strict validation applies. The browser then owns composition and encoding while the Node side owns workspace access and file transfer.

References: headless/…/render-core.mjs• L174-232 headless/…/render-core.mjs• L284-353

Video and audio output

The browser renders the prepared project and reports the settings that it actually used. The driver saves the browser download with the effective container, then returns the file and warnings to the CLI or HTTP caller.

The result separates requested settings from effective settings. This matters when browser capability checks select a different codec or container than the request asked for.

References: headless/…/render-core.mjs• L284-353 headless/serve.mjs• L457-497

Frame inspection

Frame capture renders one selected project frame directly to an image. It uses the composition render path without creating a temporary video, so callers can inspect a visual result quickly on a warm page.

The response identifies the selected frame and returns the image format, dimensions, and any missing-media signal. A successful image is therefore not proof that every source was present.

References: headless/serve.mjs• L759-814 headless/frame-oracle.mjs• L392-407

Layout inspection

Layout inspection measures visible items at one frame without drawing pixels or fetching media bytes. It gives automation the canvas-space placement needed to check composition or plan related graphics before a full render.

The measurements still use media metadata and the render path's text and transform rules. Missing source metadata can therefore make a size less reliable even though layout does not fetch source bytes.

References: headless/serve.mjs• L816-837

Render sequence

The render flow moves from a project request to prepared media, browser composition, downloaded output, and a caller-visible summary.

flowchart LR
  A[Project request] --> B[Validate and prepare]
  B --> C[Resolve media URLs and metadata]
  C --> D[Browser composition and encoding]
  D --> E[Save effective output]
  E --> F[Return file, settings, and warnings]

References: headless/…/render-core.mjs• L199-232 headless/…/render-core.mjs• L284-353

Rendering contracts

Browser boundary

The browser harness owns browser-only work such as media decode, composition, frame drawing, and encoding. The Node service owns lifecycle, workspace access, request validation, queueing, and movement of binary output across the HTTP boundary.

This split keeps the HTTP API stable without making the server duplicate the browser's composition rules.

References: headless/…/render-core.mjs• L284-353 headless/serve.mjs• L457-516 headless/serve.mjs• L763-837

Input rules

Render, frame, and layout requests select a project by ID or provide an inline project object. Render requests can choose output mode, codec, container, quality, size, frame rate, and time range. Inspection requests select one frame by time or frame number.

The contract rejects ambiguous combinations and settings that cannot produce a clear output. Missing media and warnings remain explicit so callers can distinguish a valid result from a degraded one.

References: headless/…/render-core.mjs• L39-121 headless/…/render-core.mjs• L199-232 headless/serve.mjs• L457-497

Output and warning rules

The saved file follows the browser's effective settings rather than only the requested extension. Warnings travel with the result and can also appear in HTTP headers. Strict jobs turn relevant validation findings into failures before they produce output.

This contract lets machine clients make a safe choice: inspect effective settings and warning codes instead of trusting a requested codec, file name, or HTTP success alone.

References: headless/…/render-core.mjs• L235-253 headless/…/render-core.mjs• L294-352 headless/serve.mjs• L484-496

Change checklist

When these files or sections are changed, remember to consider these:

  • Keep service status transitions and operation tracking aligned with queue acceptance and shutdown behavior.
  • Keep browser progress fields aligned with the public /v1/status shape.
  • Keep effective output settings aligned with the saved extension, MIME type, and warning headers.
  • Keep media URL, range-read, and metadata behavior aligned between workspace resolution and browser probing.
  • Keep frame and layout selection aligned with full rendering so inspection results remain predictive.
  • Keep hardware-GPU checks aligned with the effects that require them.
  • Keep the frame oracle fixture aligned with the frame features it is meant to exercise.

Important failure modes

TriggerConsequenceGuard
Built harness is absent and build-on-start is disabledThe service cannot open the browser pageBuild the application or enable the build option
The browser reports only a software GPU for a GPU-effect projectThe render is rejected before compositionUse a supported hardware GPU or remove the GPU effect
A source file is missingA full render fails by default or reports a degraded frameRestore the source or explicitly allow missing media and inspect warnings
Browser codec support differs from the requestThe output uses another effective codec or containerRead the effective settings and warning codes
The service is exposed beyond loopback without access controlUntrusted clients can call the render and edit APIKeep the default bind address or add an external access layer
A render operation blocks the queue past its deadlineThe request fails and the page may be recreatedSet a suitable timeout and use the status endpoint to observe progress
Font readiness or source metadata differs between inspection and renderText or item geometry can differ from the final imageTreat readiness and metadata warnings as part of the render result

Key files

FileWhy to read it
headless/serve.mjsShows service startup, routes, queue use, status reporting, output responses, and shutdown.
headless/…/render-core.mjsShows the shared boundary between request preparation, media resolution, browser rendering, and saved output.
headless/…/service-status.mjsDefines the public view of service state, active work, progress, and operation results.
headless/frame-oracle.mjsShows the local pixel-level check for frame determinism and feature coverage.
headless/server.mjsShows the built harness and browser media transport.
headless/media-server.mjsShows the development-mode media transport.
headless/…/contract.mjsDefines request validation and the public headless capability contract.
headless/…/page-session.mjsShows browser readiness, page errors, and page recovery boundaries.