aboutsummaryrefslogtreecommitdiff
path: root/files/zh-cn/web/api/htmlcanvaselement/捕获流/index.html
blob: 999485b6f63545c09335381bd2b41e28dc6b5b69 (plain)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
106
107
108
109
110
111
112
113
114
115
116
117
118
119
120
121
122
---
title: HTMLCanvasElement.captureStream()
slug: Web/API/HTMLCanvasElement/捕获流
translation_of: Web/API/HTMLCanvasElement/captureStream
---
<div>{{APIRef("Media Capture and Streams")}}{{SeeCompatTable}}</div>

<p><code><strong>HTMLCanvasElement</strong></code><strong><code>.captureStream()</code></strong> 方法返回的 {{domxref("CanvasCaptureMediaStream")}} 是一个实时视频捕获的画布。</p>

<h2 id="语法">语法</h2>

<pre class="syntaxbox"><var>MediaStream</var> = <var>canvas</var>.captureStream(<var>frameRate</var>);
</pre>

<h3 id="参数">参数</h3>

<dl>
 <dt><code>frameRate</code> 可选</dt>
 <dd><font><font>设置双精准度浮点值为每个帧的捕获速率。</font><font>如果未设置,则每次画布更改时都会捕获一个新帧。</font><font>如果设置为</font></font><code>0</code><font><font>,则会捕获单个帧。</font></font></dd>
</dl>

<h3 id="返回值">返回值</h3>

<p>对一个 {{domxref("MediaStream")}} <font>对象</font><font>的引用</font>.</p>

<h2 id="例子">例子</h2>

<pre class="brush: js"><code>//</code>获取所需要截取媒体流的canvas element
var canvasElt = document.querySelector('canvas');

//<code>截取到媒体流</code>
var stream = canvasElt.captureStream(25); // 25 FPS

//使用媒体流
// E.g.使用RTCPeerConnection来传输给其它的电脑
// 下面的pc是其他地方创建的一个RTCPeerConnection
pc.addStream(stream);
</pre>

<h2 id="产品规格">产品规格</h2>

<table class="standard-table">
 <thead>
  <tr>
   <th scope="col">Specification</th>
   <th scope="col">Status</th>
   <th scope="col">Comment</th>
  </tr>
 </thead>
 <tbody>
  <tr>
   <td>{{SpecName('Media Capture DOM Elements', '#widl-HTMLCanvasElement-captureStream-CanvasCaptureMediaStream-double-frameRate', 'HTMLCanvasElement.captureStream()')}}</td>
   <td>{{Spec2('Media Capture DOM Elements')}}</td>
   <td>Initial definition</td>
  </tr>
 </tbody>
</table>

<h2 id="浏览器兼容性"><font><font>浏览器兼容性</font></font></h2>

<p>{{CompatibilityTable}}</p>

<div id="compat-desktop">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Chrome</th>
   <th>Firefox (Gecko)</th>
   <th>Internet Explorer</th>
   <th>Opera</th>
   <th>Safari</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatChrome(51.0)}}</td>
   <td>{{CompatGeckoDesktop(43)}}<sup>[1]</sup></td>
   <td>{{CompatNo}}</td>
   <td>{{CompatOpera(36.0)}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<div id="compat-mobile">
<table class="compat-table">
 <tbody>
  <tr>
   <th>Feature</th>
   <th>Android</th>
   <th>Android Webview</th>
   <th>Chrome for Android</th>
   <th>Firefox Mobile (Gecko)</th>
   <th>IE Mobile</th>
   <th>Opera Mobile</th>
   <th>Safari Mobile</th>
  </tr>
  <tr>
   <td>Basic support</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatChrome(51.0)}}</td>
   <td>{{CompatChrome(51.0)}}</td>
   <td>{{CompatGeckoMobile(43)}}</td>
   <td>{{CompatNo}}</td>
   <td>{{CompatOpera(38)}}</td>
   <td>{{CompatUnknown}}</td>
  </tr>
 </tbody>
</table>
</div>

<p>[1] <font>在Firefox 41和42中,此功能默认是禁用的; </font><font>将首选项</font> <code>canvas.capturestream.enabled</code> 设置 <code>true</code> 。</p>

<h2 id="看看其他">看看其他</h2>

<ul>
 <li>{{domxref("CanvasCaptureMediaStream")}},所属接口.</li>
 <li>{{domxref("HTMLMediaElement.captureStream()")}}, 允许从一个媒体中获取流</li>
 <li>{{domxref("MediaStream")}}</li>
 <li>{{domxref("Media Capture and Streams API")}}</li>
</ul>