Table of Contents

Class VideoEncoder

Namespace
CSharpToJavaScript.APIs.JS
Assembly
CSharpToJavaScript.dll

The VideoEncoder interface of the 'WebCodecs API' encodes VideoFrame objects into EncodedVideoChunks.

[Value("VideoEncoder")]
public class VideoEncoder : EventTarget
Inheritance
VideoEncoder
Inherited Members

Remarks

Constructors

VideoEncoder()

public VideoEncoder()

VideoEncoder(VideoEncoderInit)

The VideoEncoder() constructor creates a new VideoEncoder object with the provided options.output callback assigned as the output callback, the provided options.error callback as the error callback, and sets the State to "unconfigured".

public VideoEncoder(VideoEncoderInit init)

Parameters

init VideoEncoderInit

Remarks

Properties

EncodeQueueSize

The encodeQueueSize read-only property of the VideoEncoder interface returns the number of pending encode requests in the queue.

[Value("encodeQueueSize")]
public ulong EncodeQueueSize { get; }

Property Value

ulong

An integer containing the number of requests.

Remarks

Ondequeue

[Value("ondequeue")]
public EventHandlerNonNull Ondequeue { get; set; }

Property Value

EventHandlerNonNull

State

The state read-only property of the VideoEncoder interface returns the current state of the underlying codec.

[Value("state")]
public CodecState State { get; }

Property Value

CodecState

A string containing one of the following values:

Remarks

Methods

Close()

The close() method of the VideoEncoder interface ends all pending work and releases system resources.

[Value("close")]
public GlobalObject.Undefined Close()

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

Configure(VideoEncoderConfig)

The configure() method of the VideoEncoder interface changes the State of the encoder to "configured" and asynchronously prepares the encoder to accept VideoEncoders for encoding with the specified parameters. If the encoder doesn't support the specified parameters or can't be initialized for other reasons an error will be reported via the error callback provided to the VideoEncoder constructor.

[Value("configure")]
public GlobalObject.Undefined Configure(VideoEncoderConfig config)

Parameters

config VideoEncoderConfig

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

If the VideoEncoder has been previously configured, the new configuration will not be applied until all previous tasks have completed.

See also on MDN

Encode(VideoFrame, VideoEncoderEncodeOptions)

The encode() method of the VideoEncoder interface asynchronously encodes a VideoFrame.
Encoded data (EncodedVideoChunk) or an error will eventually be returned via the callbacks provided to the VideoEncoder constructor.

[Value("encode")]
public GlobalObject.Undefined Encode(VideoFrame frame, VideoEncoderEncodeOptions options = null)

Parameters

frame VideoFrame
options VideoEncoderEncodeOptions

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

Flush()

The flush() method of the VideoEncoder interface forces all pending encodes to complete.

[Value("flush")]
public Task<GlobalObject.Undefined> Flush()

Returns

Task<GlobalObject.Undefined>

A {{jsxref("Promise")}} that resolves once the encoder's initialization is completed and all pending EncodedVideoChunks are returned.

Remarks

IsConfigSupported(VideoEncoderConfig)

The isConfigSupported() static method of the VideoEncoder interface checks if VideoEncoder can be successfully configured with the given config.

[Value("isConfigSupported")]
public static Task<VideoEncoderSupport> IsConfigSupported(VideoEncoderConfig config)

Parameters

config VideoEncoderConfig

Returns

Task<VideoEncoderSupport>

A Promise that resolves with an object containing the following members:

Remarks

Reset()

The reset() method of the VideoEncoder interface synchronously cancels all pending encodes and callbacks, frees all underlying resources and sets the State to "unconfigured".
After calling reset(), Configure(VideoEncoderConfig) must be called before resuming Encode(VideoFrame, VideoEncoderEncodeOptions) calls.

[Value("reset")]
public GlobalObject.Undefined Reset()

Returns

GlobalObject.Undefined

None (GlobalObject.Undefined).

Remarks

NOTE

To avoid discarding frames queued via Encode(VideoFrame, VideoEncoderEncodeOptions), Flush() should be called and completed before calling reset().

See also on MDN