Recording · class

ClipEncoder

Explained in Recording and clips.

class ClipEncoder
import { ClipEncoder } from '@driftengine/media';

Accessors

NameTypeDescription
errorgetstring | nullThe error that ended the encode, or null while it is going well.
audioCodecgetClipAudioCodec | nullThe audio codec the file carries, or null before open has configured one.
More

Survives finish, deliberately: the caller asks after it has a blob.

Methods

openstatic

static open(options: ClipEncoderOptions): Promise<ClipEncoder>

Configure the encoders and the container.

ParameterTypeDescription
optionsClipEncoderOptions
More

The muxer is imported here rather than at the top of the module, so a player who never exports never downloads it. Rejects when the browser cannot encode, which the caller answers by recording instead.

addFrame

addFrame(source: CanvasImageSource, index: number): Promise<void>

One frame, at its own index.

ParameterTypeDescription
sourceCanvasImageSource
indexnumber
More

Awaits while the encoder is behind, which is the only backpressure in the pipeline: a render loop with nothing to wait for will queue a thousand 1080x1920 frames and run the tab out of memory long before the encoder catches up.

addAudio

addAudio(buffer: AudioBuffer): Promise<void>

The whole score, in order.

ParameterTypeDescription
bufferAudioBuffer
More

Interleaved into the encoder's f32 planar layout by hand rather than handed the AudioBuffer, because AudioData takes a flat buffer and the two channels of an AudioBuffer are separate arrays.

finish

finish(): Promise<Blob | null>

Flush both encoders, close the container, and hand back the file.

abort

abort(): void

Give everything back without producing a file. Safe at any point.