MediaCapabilities.encodingInfo()
The MediaCapabilities.encodingInfo()
method, part of
the MediaCapabilities
interface of the Media Capabilities API, returns a
promise with the tested media configuration's capabilities information; this
contains the three Boolean properties supported
, smooth
, and
powerefficient
, which describe how compatible the device is with the type
of media.
Syntax
mediaCapabilities.encodingInfo(mediaEncodingConfiguration)
Parameters
mediaEncodingConfiguration
-
A valid
MediaEncodingConfiguration
dictionary containing a valid media encoding type ofrecord
ortransmission
and a valid media configuration: either anAudioConfiguration
orVideoConfiguration
dictionary.
Return value
A Promise
fulfilling with an object containing three Boolean attributes:
supported
: Given the properties defined in theMediaConfiguration
, can the specified piece of media content be encoded (ifMediaEncodingConfiguration
is set) or decode (ifMediaDecodingConfiguration
is set) at all? If yes,supported
is true. Otherwise, it is false.smooth
: Given the properties defined in theMediaConfiguration
, will the playback of the specified piece of media be high quality? Will it be smooth? Ifsupported
istrue
, and playback will be smooth,smooth
is true, Otherwise, is it false.powerEfficient
: Given the properties defined in theMediaConfiguration
, will the playback of the specified piece of media be power efficient? Ifsupported
istrue
, and playback will be power efficient,powerEfficient
is true, Otherwise, is it false.
Browsers will report a supported media configuration as smooth
and powerEfficient
until stats on this device have been recorded. All supported audio codecs are reported to be power efficient.
Exceptions
A TypeError
is raised if the MediaConfiguration
passed to the
encodingInfo()
method is invalid, either because the type is not video or
audio, the contentType
is not a valid codec MIME type, or any other error
in the media configuration passed to the method, including omitting any of the media encoding configuration
elements.
Example
//Create media configuration to be tested
const mediaConfig = {
type : 'record', // or 'transmission'
video : {
contentType : "video/webm;codecs=vp8.0", // valid content type
width : 1920, // width of the video
height : 1080, // height of the video
bitrate : 120000, // number of bits used to encode 1s of video
framerate : 48 // number of frames making up that 1s.
}
};
// check support and performance
navigator.mediaCapabilities.encodingInfo(mediaConfig).then(result => {
console.log('This configuration is ' +
(result.supported ? '' : 'not ') + 'supported, ' +
(result.smooth ? '' : 'not ') + 'smooth, and ' +
(result.powerEfficient ? '' : 'not ') + 'power efficient.')
});
Specifications
Specification |
---|
Media Capabilities # ref-for-dom-mediacapabilities-encodinginfo |
Browser compatibility
BCD tables only load in the browser