4 Copyright 2015 The Chromium Authors. All rights reserved.
5 Use of this source code is governed by a BSD-style license that can be
6 found in the LICENSE file.
9 <title>Video Encoder Example
</title>
10 <script type=
"text/javascript">
16 return document
.getElementById(id
);
19 function success(stream
) {
20 track
= stream
.getVideoTracks()[0];
21 video
.src
= URL
.createObjectURL(stream
);
24 var list
= $('profileList');
25 var profile
= (list
.length
< 1) ? 'vp8'
26 : list
.options
[list
.selectedIndex
].value
;
38 console
.log("Error: ", e
);
41 function startRecord() {
42 $('length').innerHTML
= ' Size: ' + dataArray
.byteLength
+ ' bytes';
43 navigator
.webkitGetUserMedia({audio
: false, video
: true},
47 function stopRecord() {
51 var video
= $('video');
56 function saveBlob(blob
) {
57 var blobUrl
= URL
.createObjectURL(blob
);
58 window
.location
= blobUrl
;
61 function handleMessage(msg
) {
62 if (msg
.data
.name
== 'data') {
63 appendData(msg
.data
.data
);
64 } else if (msg
.data
.name
== 'supportedProfiles') {
65 console
.log('profiles: ', msg
.data
);
66 var profileList
= $('profileList');
67 for (var i
= 0; i
< msg
.data
.profiles
.length
; i
++) {
68 var item
= document
.createElement('option');
69 item
.label
= item
.value
= msg
.data
.profiles
[i
];
70 profileList
.appendChild(item
);
72 } else if (msg
.data
.name
== 'log') {
73 console
.log(msg
.data
.message
);
77 function resetData() {
78 window
.dataArray
= new ArrayBuffer(0);
81 function appendData(data
) {
82 var tmp
= new Uint8Array(dataArray
.byteLength
+ data
.byteLength
);
83 tmp
.set(new Uint8Array(dataArray
), 0 );
84 tmp
.set(new Uint8Array(data
), dataArray
.byteLength
);
85 dataArray
= tmp
.buffer
;
86 $('length').textContent
= ' Size: ' + dataArray
.byteLength
+ ' bytes';
89 function initialize() {
91 plugin
.addEventListener('message', handleMessage
, false);
95 $('start').addEventListener('click', function (e
) {
99 $('stop').addEventListener('click', function (e
) {
102 $('download').addEventListener('click', function (e
) {
103 saveBlob(new Blob([dataArray
], { type
: "application/octet-stream" }));
107 document
.addEventListener('DOMContentLoaded', initialize
, false);
112 <h1>Video Encoder API Example
</h1><br>
113 This example demonstrates receiving frames from a video MediaStreamTrack and
114 encoding them in a plugin.
116 <select id=
"profileList"></select>
117 <input type=
"button" id=
"start" value=
"Start Recording"/>
118 <input type=
"button" id=
"stop" value=
"Stop Recording"/>
119 <input type=
"button" id=
"download" value=
"Download Recording"/>
120 <div id=
"length"></div>
123 <embed id=
"plugin" type=
"application/x-ppapi-example-video-encode"/>
124 <video id=
"video" width=
"640" height=
"480"/>