VideoEncoder: VideoEncoder() constructor
Limited availability
This feature is not Baseline because it does not work in some of the most widely-used browsers.
Secure context: This feature is available only in secure contexts (HTTPS), in some or all supporting browsers.
Note: This feature is available in Dedicated Web Workers.
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 VideoEncoder.state to "unconfigured".
Syntax
new VideoEncoder(options)
Parameters
options-
An object containing two required callbacks.
output-
A callback which takes an
EncodedVideoChunkobject as the first argument, and an optional metadata object as the second. The metadata object has three members:decoderConfigOptional-
An object containing:
codec-
A string containing a valid codec string.
descriptionOptional-
An
ArrayBuffer, aTypedArray, or aDataViewcontaining a sequence of codec-specific bytes, commonly known as "extradata". codedWidthOptional-
An integer representing the width of the
VideoFramein pixels, potentially including non-visible padding, and prior to considering potential ratio adjustments. codedHeightOptional-
An integer representing the height of the
VideoFramein pixels, potentially including non-visible padding, and prior to considering potential ratio adjustments. displayAspectWidthOptional-
An integer representing the horizontal dimension of the
VideoFrame's aspect ratio when displayed. displayAspectHeightOptional-
An integer representing the vertical dimension of the
VideoFrame's aspect ratio when displayed. colorSpaceOptional-
An object you pass to the
VideoColorSpaceconstructor as theinitargument, configuring theVideoFrame.colorSpaceforVideoFramesassociated with thisdecoderConfigobject. IfcolorSpaceexists, the provided values will override any in-band values from the bitstream. hardwareAccelerationOptional-
A string that configures hardware acceleration for this codec. Defaults to
"no-preference". Options are:"no-preference""prefer-hardware""prefer-software"
optimizeForLatencyOptional-
A boolean representing whether the selected decoder should be configured to minimize the number of
EncodedVideoChunksthat have to be decoded before aVideoFrameis output.
svcOptional-
An optional object with only one member:
temporalLayerId, which is a number that identifies the temporal layer for the associatedEncodedVideoChunk. alphaSideDataOptional-
An
ArrayBuffer, aTypedArray, or aDataViewthat contains theEncodedVideoChunk's extra alpha channel data.
error-
A callback which takes an
Errorobject as its only argument.
Examples
In the following example a VideoEncoder is created with the two required callback functions, one to deal with the encoded frame and the other to handle errors.
const videoEncoder = new VideoEncoder({
output(chunk, metadata) {
console.log(chunk.timestamp);
console.log(chunk.byteLength);
console.log(JSON.stringify(metadata));
},
error(error) {
console.log(error);
},
});
Specifications
| Specification |
|---|
| WebCodecs> # dom-videoencoder-videoencoder> |
Browser compatibility
Loading…