--- title: HTMLCanvasElement.captureStream() slug: Web/API/HTMLCanvasElement/captureStream translation_of: Web/API/HTMLCanvasElement/captureStream original_slug: Web/API/HTMLCanvasElement/捕获流 ---
该 HTMLCanvasElement
.captureStream()
方法返回的 {{domxref("CanvasCaptureMediaStream")}} 是一个实时视频捕获的画布。
MediaStream = canvas.captureStream(frameRate);
frameRate
可选0
,则会捕获单个帧。对一个 {{domxref("MediaStream")}} 对象的引用.
//
获取所需要截取媒体流的canvas element var canvasElt = document.querySelector('canvas'); //截取到媒体流
var stream = canvasElt.captureStream(25); // 25 FPS //使用媒体流 // E.g.使用RTCPeerConnection来传输给其它的电脑 // 下面的pc是其他地方创建的一个RTCPeerConnection pc.addStream(stream);
Specification | Status | Comment |
---|---|---|
{{SpecName('Media Capture DOM Elements', '#widl-HTMLCanvasElement-captureStream-CanvasCaptureMediaStream-double-frameRate', 'HTMLCanvasElement.captureStream()')}} | {{Spec2('Media Capture DOM Elements')}} | Initial definition |
{{CompatibilityTable}}
Feature | Chrome | Firefox (Gecko) | Internet Explorer | Opera | Safari |
---|---|---|---|---|---|
Basic support | {{CompatChrome(51.0)}} | {{CompatGeckoDesktop(43)}}[1] | {{CompatNo}} | {{CompatOpera(36.0)}} | {{CompatUnknown}} |
Feature | Android | Android Webview | Chrome for Android | Firefox Mobile (Gecko) | IE Mobile | Opera Mobile | Safari Mobile |
---|---|---|---|---|---|---|---|
Basic support | {{CompatNo}} | {{CompatChrome(51.0)}} | {{CompatChrome(51.0)}} | {{CompatGeckoMobile(43)}} | {{CompatNo}} | {{CompatOpera(38)}} | {{CompatUnknown}} |
[1] 在Firefox 41和42中,此功能默认是禁用的; 将首选项 canvas.capturestream.enabled
设置 true
。