MediaTrackConstraints

The MediaTrackConstraints dictionary is used to describe a set of capabilities and the value or values each can take on. A constraints dictionary is passed into applyConstraints() to allow a script to establish a set of exact (required) values or ranges and/or preferred values or ranges of values for the track, and the most recently-requested set of custom constraints can be retrieved by calling getConstraints().

Constraints

The following types are used to specify a constraint for a property. They allow you to specify one or more exact values from which one must be the parameter's value, or a set of ideal values which should be used if possible. You can also specify a single value (or an array of values) which the user agent will do its best to match once all more stringent constraints have been applied.

To learn more about how constraints work, see Capabilities, constraints, and settings.

ConstrainBoolean

The ConstrainBoolean constraint type is used to specify a constraint for a property whose value is a Boolean value. Its value may either be set to a Boolean (true or false) or an object containing the following properties:

exact

A Boolean which must be the value of the property. If the property can't be set to this value, matching will fail.

ideal

A Boolean specifying an ideal value for the property. If possible, this value will be used, but if it's not possible, the user agent will use the closest possible match.

ConstrainDouble

The ConstrainDouble constraint type is used to specify a constraint for a property whose value is a double-precision floating-point number. Its value may either be set to a number or an object containing the following properties:

max

A decimal number specifying the largest permissible value of the property it describes. If the value cannot remain equal to or less than this value, matching will fail.

min

A decimal number specifying the smallest permissible value of the property it describes. If the value cannot remain equal to or greater than this value, matching will fail.

exact

A decimal number specifying a specific, required, value the property must have to be considered acceptable.

ideal

A decimal number specifying an ideal value for the property. If possible, this value will be used, but if it's not possible, the user agent will use the closest possible match.

ConstrainDOMString

The ConstrainDOMString constraint type is used to specify a constraint for a property whose value is a string. Its value may either be set to a string, an array of strings, or an object containing the following properties:

exact

A DOMString, or an array of DOMStrings, one of which must be the value of the property. If the property can't be set to one of the listed values, matching will fail.

ideal

A DOMString, or an array of DOMStrings, specifying ideal values for the property. If possible, one of the listed values will be used, but if it's not possible, the user agent will use the closest possible match.

ConstrainULong

The ConstrainULong constraint type is used to specify a constraint for a property whose value is an integer. Its value may either be set to a number or an object containing the following properties:

max

An integer specifying the largest permissible value of the property it describes. If the value cannot remain equal to or less than this value, matching will fail.

min

An integer specifying the smallest permissible value of the property it describes. If the value cannot remain equal to or greater than this value, matching will fail.

exact

An integer specifying a specific, required, value the property must have to be considered acceptable.

ideal

An integer specifying an ideal value for the property. If possible, this value will be used, but if it's not possible, the user agent will use the closest possible match.

Properties

Some combination—but not necessarily all—of the following properties will exist on the object. This may be because a given browser doesn't support the property, or because it doesn't apply. For example, because RTP doesn't provide some of these values during negotiation of a WebRTC connection, a track associated with a RTCPeerConnection will not include certain values, such as facingMode or groupId.

Properties of all media tracks

deviceId

A ConstrainDOMString object specifying a device ID or an array of device IDs which are acceptable and/or required.

groupId

A ConstrainDOMString object specifying a group ID or an array of group IDs which are acceptable and/or required.

Properties of audio tracks

autoGainControl

A ConstrainBoolean object which specifies whether automatic gain control is preferred and/or required.

channelCount

A ConstrainULong specifying the channel count or range of channel counts which are acceptable and/or required.

echoCancellation

A ConstrainBoolean object specifying whether or not echo cancellation is preferred and/or required.

latency

A ConstrainDouble specifying the latency or range of latencies which are acceptable and/or required.

noiseSuppression

A ConstrainBoolean which specifies whether noise suppression is preferred and/or required.

sampleRate

A ConstrainULong specifying the sample rate or range of sample rates which are acceptable and/or required.

sampleSize

A ConstrainULong specifying the sample size or range of sample sizes which are acceptable and/or required.

volume

A ConstrainDouble specifying the volume or range of volumes which are acceptable and/or required.

Properties of image tracks

whiteBalanceMode

A String specifying one of "none", "manual", "single-shot", or "continuous".

exposureMode

A String specifying one of "none", "manual", "single-shot", or "continuous".

focusMode

A String specifying one of "none", "manual", "single-shot", or "continuous".

pointsOfInterest

The pixel coordinates on the sensor of one or more points of interest. This is either an object in the form { x:value, y:value } or an array of such objects, where value is a double-precision integer.

exposureCompensation

A ConstrainDouble (a double-precision integer) specifying f-stop adjustment by up to ±3.

colorTemperature

A ConstrainDouble (a double-precision integer) specifying a desired color temperature in degrees kelvin.

iso

A ConstrainDouble (a double-precision integer) specifying a desired iso setting.

brightness

A ConstrainDouble (a double-precision integer) specifying a desired brightness setting.

contrast

A ConstrainDouble (a double-precision integer) specifying the degree of difference between light and dark.

saturation

A ConstrainDouble (a double-precision integer) specifying the degree of color intensity.

sharpness

A ConstrainDouble (a double-precision integer) specifying the intensity of edges.

focusDistance

A ConstrainDouble (a double-precision integer) specifying distance to a focused object.

zoom

A ConstrainDouble (a double-precision integer) specifying the desired focal length.

torch

A boolean value defining whether the fill light is continuously connected, meaning it stays on as long as the track is active.

Properties of video tracks

aspectRatio

A ConstrainDouble specifying the video aspect ratio or range of aspect ratios which are acceptable and/or required.

facingMode

A ConstrainDOMString object specifying a facing or an array of facings which are acceptable and/or required.

frameRate

A ConstrainDouble specifying the frame rate or range of frame rates which are acceptable and/or required.

height

A ConstrainULong specifying the video height or range of heights which are acceptable and/or required.

width

A ConstrainULong specifying the video width or range of widths which are acceptable and/or required.

resizeMode

A ConstrainDOMString object specifying a mode or an array of modes the UA can use to derive the resolution of a video track. Allowed values are none and crop-and-scale. none means that the user agent uses the resolution provided by the camera, its driver or the OS. crop-and-scale means that the user agent can use cropping and downscaling on the camera output in order to satisfy other constraints that affect the resolution.

Properties of shared screen tracks

These constraints apply to MediaTrackConstraints objects specified as part of the DisplayMediaStreamConstraints object's video property when using getDisplayMedia() to obtain a stream for screen sharing.

cursor

A ConstrainDOMString which specifies whether or not to include the mouse cursor in the generated track, and if so, whether or not to hide it while not moving. The value may be a single one of the following strings, or an array of them to allow the browser flexibility in deciding what to do about the cursor.

always

The mouse is always visible in the video content of the {domxref("MediaStream"), unless the mouse has moved outside the area of the content.

motion

The mouse cursor is always included in the video if it's moving, and for a short time after it stops moving.

never

The mouse cursor is never included in the shared video.

displaySurface

A ConstrainDOMString which specifies the types of display surface that may be selected by the user. This may be a single one of the following strings, or a list of them to allow multiple source surfaces:

application

The stream contains all of the windows of the application chosen by the user rendered into the one video track.

browser

The stream contains the contents of a single browser tab selected by the user.

monitor

The stream's video track contains the entire contents of one or more of the user's screens.

window

The stream contains a single window selected by the user for sharing.

logicalSurface

A ConstrainBoolean value which may contain a single Boolean value or a set of them, indicating whether or not to allow the user to choose source surfaces which do not directly correspond to display areas. These may include backing buffers for windows to allow capture of window contents that are hidden by other windows in front of them, or buffers containing larger documents that need to be scrolled through to see the entire contents in their windows.

Specifications

Browser compatibility

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari WebView Android Chrome Android Firefox for Android Opera Android Safari on IOS Samsung Internet
MediaTrackConstraints
59
≤18
Yes
No
46
11
59
Yes
Yes
43
11
Yes
aspectRatio
59
≤79
No
No
Yes
11
59
59
29
?
11
7.0
autoGainControl
Yes
≤79
55
46
No
Yes
No
Yes
Yes
55
46
?
No
Yes
channelCount
59
≤79
No
No
Yes
11
59
59
No
?
11
7.0
cursor
No
No
No
No
Yes
No
No
No
No
?
No
No
deviceId
59
≤79
36
Before Firefox 69, Firefox only supported deviceId in constraints passed into getUserMedia().
No
Yes
11
59
59
36
Firefox for Android only supports deviceId when used in constraints passed into getUserMedia().
?
11
7.0
displaySurface
No
No
No
No
Yes
11.1
No
No
No
?
11.3
No
echoCancellation
59
≤79
50
No
Yes
11
59
59
50
?
11
7.0
facingMode
59
≤79
50
No
Yes
11
59
59
50
?
11
7.0
frameRate
59
≤79
50
No
Yes
11
59
59
50
?
11
7.0
groupId
59
≤79
70
No
Yes
11
59
59
No
?
11
7.0
height
59
≤79
50
No
Yes
11
59
59
50
?
11
7.0
latency
59
≤79
50
No
Yes
11
59
59
50
?
11
7.0
logicalSurface
No
No
No
No
Yes
11.1
No
No
No
?
11.3
No
noiseSuppression
Yes
≤79
55
46
No
Yes
No
Yes
Yes
55
46
?
No
Yes
sampleRate
59
≤79
No
No
Yes
11
59
59
No
?
11
7.0
sampleSize
59
≤79
No
No
Yes
11
59
59
No
?
11
7.0
volume
59
≤79
No
No
Yes
11
59
59
No
?
11
7.0
width
59
≤79
50
No
Yes
11
59
59
50
?
11
7.0

See also

© 2005–2021 MDN contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/MediaTrackConstraints