Web/API/MediaStream Image Capture API

From Get docs

This is an experimental technologyCheck the Browser compatibility table carefully before using this in production.


The MediaStream Image Capture API is an API for capturing images or videos from a photographic device. In addition to capturing data, it also allows you to retrieve information about device capabilities such as image size, red-eye reduction and whether or not there is a flash and what they are currently set to. Conversely, the API allows the capabilities to be configured within the constraints what the device allows.

MediaStream image capture concepts and usage

The process of retrieving an image or video stream happens as described below. The example code is adapted from Chrome's Image Capture examples.

First, get a reference to a device by calling MediaDevices.getUserMedia(). The example below simply says give me whatever video device is available, though the getUserMedia() method allows more specific capabilities to be requested. This method returns a Promise that resolves with a MediaStream object.

navigator.mediaDevices.getUserMedia({ video: true })
  .then(mediaStream => {
    // Do something with the stream.
  })

Next, isolate the visual part of the media stream. Do this by calling MediaStream.getVideoTracks(). This returns an array of MediaStreamTrack objects. The code below assumes that the first item in the MediaStreamTrack array is the one to use. You can use the properties of the MediaStreamTrack objects to select the one you need.

const track = mediaStream.getVideoTracks()[0];

At this point, you might want to configure the device capabilities before capturing an image. You can do this by calling applyConstraints() on the track object before doing anything else.

let zoom = document.querySelector('#zoom');
const capabilities = track.getCapabilities();
// Check whether zoom is supported or not.
if(!capabilities.zoom) {
  return;
}
track.applyConstraints({ advanced : [{ zoom: zoom.value }] });

Finally, pass the MediaStreamTrack object to the ImageCapture() constructor. Though a MediaStream holds several types of tracks and provides multiple methods for retrieving them, the ImageCapture constructor will throw a DOMException of type NotSupportedError if MediaStreamTrack.kind is not "video".

let imageCapture = new ImageCapture(track);

Interfaces

ImageCapture
An interface for capturing images from a photographic device referenced through a valid MediaStreamTrack.
PhotoCapabilities
Provides available configuration options for an attached photographic device. Retrieve a PhotoCapabilities object by calling ImageCapture.getPhotoCapabilities().

Specifications

Specification Status Comment
MediaStream Image Capture Working Draft Initial definition.

Browser compatibility

ImageCapture

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet

ImageCapture

Experimental'

Chrome

Full support 59

Edge

Full support ≤79

Firefox

?

IE

No support No

Opera

Full support 46

Safari

No support No

WebView Android

Full support 59

Chrome Android

Full support 59

Firefox Android

?

Opera Android

Full support 43

Safari iOS

No support No

Samsung Internet Android

Full support 7.0

ImageCapture() constructor

Experimental'

Chrome

Full support 59

Edge

Full support ≤79

Firefox

?

IE

No support No

Opera

Full support 46

Safari

No support No

WebView Android

Full support 59

Chrome Android

Full support 59

Firefox Android

?

Opera Android

Full support 43

Safari iOS

No support No

Samsung Internet Android

Full support 7.0

getPhotoCapabilities

Experimental'

Chrome

Full support 59

Edge

Full support ≤79

Firefox

?

IE

No support No

Opera

Full support 46

Safari

No support No

WebView Android

Full support 59

Chrome Android

Full support 59

Firefox Android

?

Opera Android

Full support 43

Safari iOS

No support No

Samsung Internet Android

Full support 7.0

getPhotoSettings

Experimental'

Chrome

Full support 61

Edge

Full support ≤79

Firefox

?

IE

No support No

Opera

Full support 46

Safari

No support No

WebView Android

Full support 61

Chrome Android

Full support 61

Firefox Android

?

Opera Android

Full support 43

Safari iOS

No support No

Samsung Internet Android

Full support 8.0

grabFrame

Experimental'

Chrome

Full support 59

Edge

Full support ≤79

Firefox

?

IE

No support No

Opera

Full support 46

Safari

No support No

WebView Android

Full support 59

Chrome Android

Full support 59

Firefox Android

?

Opera Android

Full support 43

Safari iOS

No support No

Samsung Internet Android

Full support 7.0

takePhoto

Experimental'

Chrome Full support 60


Full support 60


No support 59 — 60

Notes'

Notes' photoSettings argument not supported.

Edge

Full support ≤79

Firefox

?

IE

No support No

Opera Full support 47


Full support 47


No support 46 — 47

Notes'

Notes' photoSettings argument not supported.

Safari

No support No

WebView Android Full support 60


Full support 60


No support 59 — 60

Notes'

Notes' photoSettings argument not supported.

Chrome Android Full support 60


Full support 60


No support 59 — 60

Notes'

Notes' photoSettings argument not supported.

Firefox Android

?

Opera Android Full support 44


Full support 44


No support 43 — 44

Notes'

Notes' photoSettings argument not supported.

Safari iOS

No support No

Samsung Internet Android Full support 8.0


Full support 8.0


No support 7.0 — 8.0

Notes'

Notes' photoSettings argument not supported.

track

Experimental'

Chrome

Full support 59

Edge

Full support ≤79

Firefox

?

IE

No support No

Opera

Full support 46

Safari

No support No

WebView Android

Full support 59

Chrome Android

Full support 59

Firefox Android

?

Opera Android

Full support 43

Safari iOS

No support No

Samsung Internet Android

Full support 7.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.'
Experimental. Expect behavior to change in the future.
See implementation notes.'
See implementation notes.


PhotoCapabilities

Update compatibility data on GitHub

Desktop Mobile
Chrome Edge Firefox Internet Explorer Opera Safari Android webview Chrome for Android Firefox for Android Opera for Android Safari on iOS Samsung Internet

PhotoCapabilities

Experimental'

Chrome

Full support 59

Edge

Full support ≤79

Firefox

?

IE

No support No

Opera

Full support 46

Safari

No support No

WebView Android

Full support 59

Chrome Android

Full support 59

Firefox Android

?

Opera Android

Full support 43

Safari iOS

No support No

Samsung Internet Android

Full support 7.0

fillLightMode

Experimental'

Chrome

Full support 59

Edge

Full support ≤79

Firefox

?

IE

No support No

Opera

Full support 46

Safari

No support No

WebView Android

Full support 59

Chrome Android

Full support 59

Firefox Android

?

Opera Android

Full support 43

Safari iOS

No support No

Samsung Internet Android

Full support 7.0

imageHeight

Experimental'

Chrome

Full support 59

Edge

Full support ≤79

Firefox

?

IE

No support No

Opera

Full support 46

Safari

No support No

WebView Android

Full support 59

Chrome Android

Full support 59

Firefox Android

?

Opera Android

Full support 43

Safari iOS

No support No

Samsung Internet Android

Full support 7.0

imageWidth

Experimental'

Chrome

Full support 59

Edge

Full support ≤79

Firefox

?

IE

No support No

Opera

Full support 46

Safari

No support No

WebView Android

Full support 59

Chrome Android

Full support 59

Firefox Android

?

Opera Android

Full support 43

Safari iOS

No support No

Samsung Internet Android

Full support 7.0

redEyeReduction

Experimental'

Chrome

Full support 59

Edge

Full support ≤79

Firefox

?

IE

No support No

Opera

Full support 46

Safari

No support No

WebView Android

Full support 59

Chrome Android

Full support 59

Firefox Android

?

Opera Android

Full support 43

Safari iOS

No support No

Samsung Internet Android

Full support 7.0

Legend

Full support  
Full support
No support  
No support
Compatibility unknown  
Compatibility unknown
Experimental. Expect behavior to change in the future.'
Experimental. Expect behavior to change in the future.


See also