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
== 'started') {
63 console
.log('recording!');
64 } else if (msg
.data
.name
== 'data') {
65 appendData(msg
.data
.data
);
66 } else if (msg
.data
.name
== 'stopped') {
67 console
.log('done recording! bytes: ' + dataArray
.byteLength
);
68 } else if (msg
.data
.name
== 'supportedProfiles') {
69 console
.log('profiles: ', msg
.data
);
70 var profileList
= $('profileList');
71 for (var i
= 0; i
< msg
.data
.profiles
.length
; i
++) {
72 var item
= document
.createElement('option');
73 item
.label
= item
.value
= msg
.data
.profiles
[i
];
74 profileList
.appendChild(item
);
79 function resetData() {
80 window
.dataArray
= new ArrayBuffer(0);
83 function appendData(data
) {
84 var tmp
= new Uint8Array(dataArray
.byteLength
+ data
.byteLength
);
85 tmp
.set(new Uint8Array(dataArray
), 0 );
86 tmp
.set(new Uint8Array(data
), dataArray
.byteLength
);
87 dataArray
= tmp
.buffer
;
88 $('length').innerHTML
= ' Size: ' + dataArray
.byteLength
+ ' bytes';
91 function initialize() {
93 plugin
.addEventListener('message', handleMessage
, false);
97 $('start').addEventListener('click', function (e
) {
101 $('stop').addEventListener('click', function (e
) {
104 $('download').addEventListener('click', function (e
) {
105 saveBlob(new Blob([dataArray
], { type
: "application/octet-stream" }));
109 document
.addEventListener('DOMContentLoaded', initialize
, false);
114 <h1>Video Encoder API Example
</h1><br>
115 This example demonstrates receiving frames from a video MediaStreamTrack and
116 encoding them in a plugin.
118 <select id=
"profileList"></select>
119 <input type=
"button" id=
"start" value=
"Start Recording"/>
120 <input type=
"button" id=
"stop" value=
"Stop Recording"/>
121 <input type=
"button" id=
"download" value=
"Download Recording"/>
122 <div id=
"length"></div>
125 <embed id=
"plugin" type=
"application/x-ppapi-example-video-encode"/>
126 <video id=
"video" width=
"640" height=
"480"/>