HTMLCanvasElement.captureStream()
The HTMLCanvasElement
captureStream()
method returns a MediaStream
which includes a CanvasCaptureMediaStreamTrack
containing a real-time video capture of the canvas's contents.
Syntax
MediaStream = canvas.captureStream(frameRate);
Parameters
frameRate
Optional-
A double-precision floating-point value that indicates the rate of capture of each frame. If not set, a new frame will be captured each time the canvas changes; if set to
0
, frames will not be captured automatically; instead, they will only be captured when the returned track'srequestFrame()
method is called.
Return value
A reference to a MediaStream
object, which has a single
CanvasCaptureMediaStreamTrack
in it.
Exceptions
NotSupportedError
DOMException
-
Thrown if the value of
frameRate
is negative.
Example
// 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);
Specifications
Specification |
---|
Media Capture from DOM Elements # dom-htmlcanvaselement-capturestream |
Browser compatibility
Report problems with this compatibility data on GitHubdesktop | mobile | |||||||||||
---|---|---|---|---|---|---|---|---|---|---|---|---|
captureStream | ChromeFull support51 | EdgeFull support79 | FirefoxFull support43 | Internet ExplorerNo supportNo | OperaFull support36 | SafariFull support11 | WebView AndroidFull support51 | Chrome AndroidFull support51 | Firefox for AndroidFull support43 | Opera AndroidFull support36 | Safari on iOSFull support11 | Samsung InternetFull support5.0 |
Legend
- Full support
- Full support
- No support
- No support
- Experimental. Expect behavior to change in the future.
The compatibility table on this page is generated from structured data. If you'd like to contribute to the data, please check out https://github.com/mdn/browser-compat-data and send us a pull request.
See also
-
HTMLMediaElement.captureStream()
, which allows capturing a stream from a media element. MediaStream
Media Capture and Streams API