This document provides a detailed reference of all core classes, helper services, and individual method functions inside the media-render server-side export engine. Use this guide to understand the execution roles and properties of each function when modifying the codebase.
The rendering pipeline is split into three main modules to keep concerns separated:
┌────────────────────────────────────────┐
│ exporter() loop │
└──────────────────┬─────────────────────┘
│
┌────────────────────────┼────────────────────────┐
▼ ▼ ▼
┌───────────────────────┐ ┌───────────────────────┐ ┌───────────────────┐
│ AssetRegistry │ │ CanvasRenderer │ │ AudioPipeline │
│ │ │ │ │ │
│ Pre-fetches and caches│ │ Drains frame loops & │ │ Processes Filter- │
│ video demuxers, raw │ │ compiles Scene Graph │ │ Complex (amix) & │
│ image frames, fonts. │ │ nodes (RootNode tree).│ │ outputs PCM data. │
└───────────────────────┘ └──────────┬────────────┘ └───────────────────┘
│
▼
┌────────────────────────┐
│ SkiaCompositor │
│ │
│ Synchronizes textures &│
│ composites onto canvas.│
└────────────────────────┘
Manages timeline boundaries, size configurations, and scene graph compilation.
- Purpose: Calculates the total duration (in seconds) of the video project based on the main track elements.
- Logic:
- Finds the first track where
type === "video"andisMain === true. - Sums the
durationparameter of all timeline elements in this track.
- Finds the first track where
- Returns: Total seconds of timeline playback (
0if no main track is found).
- Purpose: Generates a single composite image frame at timestamp
time. - Flow:
- Calls
assetRegistry.ensureAssetsLoaded(manifest)to pre-load missing images or video sinks. - Calls
buildSceneGraph(manifest)to rebuild the Node tree. - Calls
rootNode.buildFrame(time, this, "root")to retrieve active frame item descriptors and texture definitions. - Triggers
skiaCompositor.syncTextures(textures)to upload/clear offscreen canvases. - Invokes
skiaCompositor.render(frameDescriptor, ctx)to draw layers in Z-Index order onto the virtual renderer canvas.
- Calls
- Purpose: Rebuilds the memory Node tree hierarchy (Scene Graph) based on the latest manifest track states.
- Logic (2-Pass):
- Pass 1: Finds the main track, sorts elements chronologically by
startTime(with alphabeticalidfallbacks), and appendsBlurBackgroundNodeinstances to the tree first. - Pass 2: Gathers main and overlay tracks (reversed to render index
0topmost), sorts elements, and registers visual nodes (VideoNode,TextNode, etc.) dynamically via the registry.
- Pass 1: Finds the main track, sorts elements chronologically by
Handles asynchronous prefetching, asset downloading, and texture caches.
- Purpose: Pre-loads images, registers remote fonts, and opens video stream demuxers before drawing loops start.
- Key Fields:
imagesMap: Caches downloaded raw image and sticker objects.videoSinksMap: Holds decoded frame sinks (VideoSampleSink) for all active video clips.inputsMap: Caches raw mediaInputreaders.
- Purpose: Clean up native bindings. Disposes and releases all
Inputdecoder instances cached inside the registry.
Orchestrates multi-channel audio mixing using the FFmpeg FilterComplex API.
- Purpose: Scans the manifest and filters out all elements containing audio channels (from
"audio"tracks or video elements inside"video"tracks).
- Purpose: Instantiates demuxers and registers delay filters for audio mixing.
- Logic:
- Open demuxer and decoder streams for each audio resource.
- Calculate delay offset parameters (
adelay=${startTime}) and trim intervals (atrim=start=${trimStart}). - Build an
amixFilterGraph string (e.g.[0:a]adelay=1000|1000[a0]; [1:a]adelay=0|0[a1]; [a0][a1]amix=inputs=2[a_final]). - Instantiate the native decoder frames generator
FilterComplexAPI.
- Purpose: Iterates over mixed PCM buffers from the filter graph and pushes them to the media writer.
- Logic: Calls
.next()on the generator loop until exhausted, wrapping frames insideAudioSampleobjects.
- Purpose: Restricts audio generator playback to prevent reading packets past the element's configured timeline
durationboundary.
Performs high-performance 2D canvas drawing and transformation matrix operations.
- Purpose: Maintains a cached map of offscreen canvas textures. Re-creates canvas surfaces only when size, content, or hash identifiers change.
- Purpose: Composes texture layers onto the main export canvas.
- Matrix Logic: Applies rotation, flipping, scale and offset operations centered at
(centerX, centerY)for each descriptor before callingtargetCtx.drawImage.