Screen helpers · class

FrameRecorder

Explained in Recording and clips.

class FrameRecorder
import { FrameRecorder } from '@driftengine/core';

Constructor

new

constructor(options: FrameRecorderOptions)
ParameterTypeDescription
optionsFrameRecorderOptions

Accessors

NameTypeDescription
mimeTypegetstring
pacinggetFramePacingReport | nullWhat the pacing actually was, or null when recording the canvas directly.
More

The measurement is the point rather than a diagnostic afterthought: an export that ran below its target rate produced a juddering file, and the only honest options are to say so or to have not measured.

duplicateFramegetbooleanWhether the frame frameRendered just composited repeats the one before it.
More

False without a target, and false when presentedFrames was never supplied — the same two "no evidence yet" cases pacing already has to account for. See ExportTarget.duplicateFrame, which this only forwards.

Methods

prepare

prepare(): { width: number; height: number; reduced: boolean; } | null

Take over the render surface before recording starts.

More

Separate from start because the aspect has to be in force before the first frame anybody records: the camera composes for renderer.aspect, so locking and recording in the same breath would put a screen-shaped shot in the first frames of a vertical clip. Returns the frame size that will be recorded, which is not always the one requested — see measuredFps.

captureDue

captureDue(nowMs: number): boolean

Whether the frame about to be drawn will be kept. True when there is no fixed target, so a caller can gate its render pass unconditionally.

ParameterTypeDescription
nowMsnumber
More

Call once per animation frame, drawing or not: the instant is kept and reused when the frame is handed over, so one clock decides and commits.

frameRendered

frameRendered(): boolean

One rendered frame, offered to the recording.

More

Call at the very end of the render pass. Cheap and false when there is no fixed target, so a caller can hand every frame over unconditionally. Takes no instant — it uses the one captureDue was given for this frame.

resetPacing

resetPacing(): void

Start the measurement over, keeping the schedule.

More

For a caller that records a warm-up in front of the clip proper: what a device costs while an encoder gets going is not what the clip is like, and the report is what the export decides whether to warn the player on.

start

start(): void

stop

stop(): Promise<Blob | null>

Resolves with the finished clip, or null if nothing was recorded.

More

The surface goes back before the promise resolves either way. A cancelled export that left the drawing buffer pinned to 1080x1920 would leave the game rendering into the wrong shape for the rest of the session.

release

release(): void

Give the render surface back. Safe at any point, and idempotent.