大网数据广告活动
Web 标准与前端开发

VideoEncoder: configure() method

· 52CE 我爱测

The **`configure()`** method of the VideoEncoder interface changes the VideoEncoder.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 parame

WebCodecs APIwindow_and_dedicated

The configure() method of the VideoEncoder interface changes the VideoEncoder.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.

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

Syntax

configure(config)

Parameters

  • config
    • : A dictionary object containing the following members:
      • codec
      • width
        • : An integer representing the width of each output EncodedVideoChunk in pixels, before any ratio adjustments.
      • height
        • : An integer representing the height of each output EncodedVideoChunk in pixels, before any ratio adjustments.
      • displayWidth
        • : An integer representing the intended display width of each output EncodedVideoChunk in pixels when displayed.
      • displayHeight
        • : 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"
            • : The encoder will target constant bitrate.
          • "variable" (default)
            • : The encoder will target a variable bitrate, allowing more space to be used for complex signals and less space for less complex signals.
          • "quantizer"
            • : The encoder will disregard the bitrate option and instead it will use codec-specific quantizer values specified for each frame in the options parameter to VideoEncoder.encode().
      • latencyMode
        • : A string containing a value that configures the latency behavior of this codec. One of:
          • "quality" (default)
            • : The encoder should optimize for encoding quality.
          • "realtime"
            • : The encoder should optimize for low latency and may even drop frames to honor framerate.

Return value

None (undefined).

Exceptions

  • TypeError
    • : Thrown if the provided config is invalid.
  • InvalidStateError DOMException
    • : Thrown if the VideoEncoder.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

Browser compatibility

See also

来源:MDN Web Docs / Mozilla 贡献者 · 作者与贡献记录 · CC BY-SA 2.5。离线整理了版式、链接和媒体显示。

资料来源与适用范围

资料来源
MDN Web Docs / Mozilla 贡献者
适用范围
请按文中版本与环境说明核对
内容语言
中文;命令、路径和错误标识保留技术原文
本地收录日期
2026-11-15
授权说明
CC BY-SA 2.5

正文与所需资源由本站本地存储。查看来源及更新记录 ↗

请按适用版本和实际日志确认原因;本站没有对每一种系统或设备逐项执行文中的操作。