HTMLCanvasElement.captureStream() - Web APIs 编辑
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
- 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 | Status | Comment |
---|---|---|
Media Capture from DOM Elements The definition of 'HTMLCanvasElement.captureStream()' in that specification. | Working Draft | Initial definition |
Browser compatibility
BCD tables only load in the browser
See also
HTMLMediaElement.captureStream()
, which allows capturing a stream from a media element.MediaStream
Media Capture and Streams API
如果你对这篇内容有疑问,欢迎到本站社区发帖提问 参与讨论,获取更多帮助,或者扫码二维码加入 Web 技术交流群。
绑定邮箱获取回复消息
由于您还没有绑定你的真实邮箱,如果其他用户或者作者回复了您的评论,将不能在第一时间通知您!
发布评论