VideoEncoder.configure()

Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.

The configure() method of the VideoEncoder interface enqueues a control message to configure the audio decoder for decoding chunks.

Syntax

AudioDecoder.configure(config)

Parameters

config

A dictionary object containing the following members:

codec

A string containing a valid codec string.

widthOptional

An integer representing the width of each output EncodedVideoChunk in pixels, before any ratio adjustments.

heightOptional

An integer representing the height of each output EncodedVideoChunk in pixels, before any ratio adjustments.

displayWidthOptional

An integer representing the intended display width of each output EncodedVideoChunk in pixels when displayed.

displayHeightOptional

An integer representing the vertical dimension of each output EncodedVideoChunk in pixels when displayed.

hardwareAcceleration

A hint that configures the hardware acceleration method of this codec. One of:

  • "no-preference"
  • "prefer-hardware"
  • "prefer-software"
bitrate

An integer containing the average bitrate of the encoded video in units of bits per second.

framerate

An integer containing the expected frame rate in frames per second.

alpha

A string indicating whether the alpha component of the VideoFrame inputs should be kept or discarded prior to encoding. One of:

  • "discard" (default)
  • "keep"
scalabilityMode

A string containing an encoding scalability mode identifier as defined in WebRTC.

bitrateMode

A string containing a bitrate mode. One of:

  • "constant"
  • "variable" (default)
latencyMode

A string containing a value that configures the latency behavior of this codec. One of:

  • "quality" (default)
  • "realtime"

Return Value

None.

Exceptions

TypeError DOMException

Thrown if the provided config is invalid.

InvalidStateError DOMException

Thrown if the state is "closed".

NotSupportedError DOMException

Thrown if the provided config is valid but the user agent cannot provide a codec that can decode this profile.

Examples

The following example creates a new VideoEncoder and configures it with some of the available options.

const init = {
  output: handleChunk,
  error: (e) => {
    console.log(e.message);
  }
};

let config = {
  codec: 'vp8',
  width: 640,
  height: 480,
  bitrate: 2_000_000, // 2 Mbps
  framerate: 30,
};

let encoder = new VideoEncoder(init);
encoder.configure(config);

Specifications

Specification
WebCodecs
# dom-videoencoder-configure

Browser compatibility

BCD tables only load in the browser