The HTMLCanvasElement
captureStream()
method returns a MediaStream
which includes a CanvasCaptureMediaStreamTrack
containing a real-time video capture of the canvas's contents.
MediaStream = canvas.captureStream(frameRate);
frameRate
Optional
0
, frames will not be captured automatically; instead, they will only be captured when the returned track's requestFrame()
method is called.A reference to a MediaStream
object, which has a single CanvasCaptureMediaStreamTrack
in it.
NotSupportedError
frameRate
is negative.// Find the canvas element to capture var canvasElt = document.querySelector('canvas'); // Get the stream var stream = canvasElt.captureStream(25); // 25 FPS // Do things to the stream // E.g. Send it to another computer using an RTCPeerConnection // pc is an RTCPeerConnection created elsewhere pc.addStream(stream);
Specification | Status | Comment |
---|---|---|
Media Capture from DOM Elements The definition of 'HTMLCanvasElement.captureStream()' in that specification. | Working Draft | Initial definition |
Desktop | ||||||
---|---|---|---|---|---|---|
Chrome | Edge | Firefox | Internet Explorer | Opera | Safari | |
Basic support | 51 | ? | 43 | No | 36 | ? |
Mobile | |||||||
---|---|---|---|---|---|---|---|
Android webview | Chrome for Android | Edge Mobile | Firefox for Android | Opera for Android | iOS Safari | Samsung Internet | |
Basic support | 51 | 51 | ? | 43 | 38 | ? | 5.0 |
HTMLMediaElement.captureStream()
, which allows capturing a stream from a media element.MediaStream
Media Capture and Streams API
© 2005–2018 Mozilla Developer Network and individual contributors.
Licensed under the Creative Commons Attribution-ShareAlike License v2.5 or later.
https://developer.mozilla.org/en-US/docs/Web/API/HTMLCanvasElement/captureStream