files/en-us/web/api/videoencoder/configure/index.md
{{APIRef("WebCodecs API")}}{{SecureContext_Header}}{{AvailableInWorkers("window_and_dedicated")}}
The configure() method of the {{domxref("VideoEncoder")}} interface changes the {{domxref("VideoEncoder.state", "state")}} of the encoder to "configured" and asynchronously prepares the encoder to accept {{domxref("VideoEncoder")}}s 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 {{domxref("VideoEncoder")}} constructor.
If the {{domxref("VideoEncoder")}} has been previously configured, the new configuration will not be applied until all previous tasks have completed.
configure(config)
config
codec
width {{optional_inline}}
height {{optional_inline}}
displayWidth {{optional_inline}}
displayHeight {{optional_inline}}
hardwareAcceleration
"no-preference""prefer-hardware""prefer-software"bitrate
framerate
alpha
VideoFrame inputs should be kept or discarded prior to encoding. One of:
"discard" (default)"keep"scalabilityMode
bitrateMode {{optional_inline}}
"constant"
"variable" (default)
"quantizer"
bitrate option and instead it will use codec-specific quantizer values specified for each frame in the options parameter to {{domxref("VideoEncoder.encode()")}}.latencyMode {{optional_inline}}
"quality" (default)
"realtime"
framerate.None ({{jsxref("undefined")}}).
config is invalid.InvalidStateError {{domxref("DOMException")}}
"closed".NotSupportedError {{domxref("DOMException")}}
config is valid but the user agent cannot provide a codec that can decode this profile.The following example creates a new {{domxref("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}}
{{Compat}}