Recording · class
ClipEncoder
Explained in Recording and clips.
class ClipEncoderimport { ClipEncoder } from '@driftengine/media';Accessors
| Name | Type | Description |
|---|---|---|
errorget | string | null | The error that ended the encode, or null while it is going well. |
audioCodecget | ClipAudioCodec | null | The audio codec the file carries, or null before open has configured one.MoreSurvives |
Methods
openstatic
static open(options: ClipEncoderOptions): Promise<ClipEncoder>Configure the encoders and the container.
| Parameter | Type | Description |
|---|---|---|
options | ClipEncoderOptions |
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.
| Parameter | Type | Description |
|---|---|---|
source | CanvasImageSource | |
index | number |
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.
| Parameter | Type | Description |
|---|---|---|
buffer | AudioBuffer |
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(): voidGive everything back without producing a file. Safe at any point.