VideoEncoder Class

Encodes video (https://w3c.github.io/webcodecs/#videoencoder-interface): the VideoFrame objects given to VideoEncoder.Encode are encoded by the codecs of BrowsingContextOptions.MediaCodecs, and the EncodedVideoChunk objects are given to the output callback with the configuration of their decoder.

public sealed class VideoEncoder : EventTarget
Inheritance
EventTarget VideoEncoder

Constructors

NameDescription
VideoEncoder(VideoEncoderInit)Creates an encoder (https://w3c.github.io/webcodecs/#dom-videoencoder-videoencoder).

VideoEncoder(VideoEncoderInit)

Codecs.cs

Creates an encoder (https://w3c.github.io/webcodecs/#dom-videoencoder-videoencoder).

public VideoEncoder(VideoEncoderInit init)

Parameters

init VideoEncoderInit
The output and error callbacks.

See also

Properties

NameDescription
EncodeQueueSizeGets the number of pending encode requests.
OnDequeueGets or sets the event handler of the dequeue event (the queue size decreased).
StateGets the state of the encoder.

EncodeQueueSize

Codecs.cs

Gets the number of pending encode requests.

public uint EncodeQueueSize { get; }

OnDequeue

Codecs.cs

Gets or sets the event handler of the dequeue event (the queue size decreased).

public Action<Event>? OnDequeue { get; set; }

Gets the state of the encoder.

public CodecState State { get; }

Methods

NameDescription
Close()Closes the encoder (https://w3c.github.io/webcodecs/#dom-videoencoder-close).
Configure(VideoEncoderConfig)Configures the encoder (https://w3c.github.io/webcodecs/#dom-videoencoder-configure): a configuration that the codecs do not support closes it with a NotSupportedError.
Encode(VideoFrame, VideoEncoderEncodeOptions?)Encodes a frame (https://w3c.github.io/webcodecs/#dom-videoencoder-encode): a clone of the frame is encoded.
Flush()Encodes the pending frames (https://w3c.github.io/webcodecs/#dom-videoencoder-flush): the promise resolves once the chunks are delivered.
IsConfigSupported(VideoEncoderConfig)Returns whether the codecs support a configuration (https://w3c.github.io/webcodecs/#dom-videoencoder-isconfigsupported).
Reset()Discards the pending frames and the configuration (https://w3c.github.io/webcodecs/#dom-videoencoder-reset).

Close()

Codecs.cs

Closes the encoder (https://w3c.github.io/webcodecs/#dom-videoencoder-close).

public void Close()

Exceptions

DomException
An InvalidStateError when the encoder is closed.

See also

Configure(VideoEncoderConfig)

Codecs.cs

Configures the encoder (https://w3c.github.io/webcodecs/#dom-videoencoder-configure): a configuration that the codecs do not support closes it with a NotSupportedError.

public void Configure(VideoEncoderConfig config)

Parameters

config VideoEncoderConfig
The configuration.

Exceptions

TypeErrorException
The configuration is invalid.
DomException
An InvalidStateError when the encoder is closed.

See also

Encode(VideoFrame, VideoEncoderEncodeOptions?)

Codecs.cs

Encodes a frame (https://w3c.github.io/webcodecs/#dom-videoencoder-encode): a clone of the frame is encoded.

public void Encode(VideoFrame frame, VideoEncoderEncodeOptions? options = null)

Parameters

frame VideoFrame
The frame.
options VideoEncoderEncodeOptions?
The options of the encoding of the frame.

Exceptions

TypeErrorException
The frame is closed.
DomException
An InvalidStateError when the encoder is not configured, a DataError when the orientation of the frame is not the one of the first frame.

See also

Flush()

Codecs.cs

Encodes the pending frames (https://w3c.github.io/webcodecs/#dom-videoencoder-flush): the promise resolves once the chunks are delivered.

public Task Flush()

IsConfigSupported(VideoEncoderConfig)

Codecs.cs

Returns whether the codecs support a configuration (https://w3c.github.io/webcodecs/#dom-videoencoder-isconfigsupported).

public static Task<VideoEncoderSupport> IsConfigSupported(VideoEncoderConfig config)

Parameters

config VideoEncoderConfig
The configuration.

Returns

Task<VideoEncoderSupport> A task that completes with the support and the configuration with the recognized members, or fails with a TypeErrorException for an invalid configuration.

See also

Reset()

Codecs.cs

Discards the pending frames and the configuration (https://w3c.github.io/webcodecs/#dom-videoencoder-reset).

public void Reset()

Exceptions

DomException
An InvalidStateError when the encoder is closed.

See also