OLD | NEW |
(Empty) | |
| 1 <!DOCTYPE html> |
| 2 <html> |
| 3 <!-- |
| 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. |
| 7 --> |
| 8 <head> |
| 9 <title>Video Encoder Example</title> |
| 10 <style type="text/css"> |
| 11 #video { |
| 12 position: fixed; |
| 13 } |
| 14 #video-playback { |
| 15 position: fixed; |
| 16 left: 640px; |
| 17 } |
| 18 #plugin { |
| 19 position: fixed; |
| 20 } |
| 21 </style> |
| 22 <script type="text/javascript"> |
| 23 var plugin; |
| 24 var track; |
| 25 var video; |
| 26 |
| 27 function $(id) { |
| 28 return document.getElementById(id); |
| 29 } |
| 30 |
| 31 function success(stream) { |
| 32 track = stream.getVideoTracks()[0]; |
| 33 video.src = URL.createObjectURL(stream); |
| 34 video.play(); |
| 35 |
| 36 plugin.postMessage({ |
| 37 command: 'start', |
| 38 track: track, |
| 39 width: 640, |
| 40 height: 480 |
| 41 }); |
| 42 } |
| 43 |
| 44 function failure(e) { |
| 45 console.log("Error: ", e); |
| 46 } |
| 47 |
| 48 function startRecord() { |
| 49 console.log("starting record"); |
| 50 navigator.webkitGetUserMedia({audio: false, video: true}, |
| 51 success, failure); |
| 52 } |
| 53 |
| 54 function stopRecord() { |
| 55 plugin.postMessage({ |
| 56 command: "stop" |
| 57 }); |
| 58 var video = $('video'); |
| 59 video.pause(); |
| 60 track.stop(); |
| 61 } |
| 62 |
| 63 function saveBlob(blob) { |
| 64 var blobUrl = URL.createObjectURL(blob); |
| 65 window.location = blobUrl; |
| 66 } |
| 67 |
| 68 function handleMessage(msg) { |
| 69 if (msg.data.name == 'started') { |
| 70 console.log('recording!'); |
| 71 } else if (msg.data.name == 'data') { |
| 72 appendData(msg.data.data); |
| 73 } else if (msg.data.name == 'stopped') { |
| 74 console.log('done recording! bytes: ' + dataArray.byteLength); |
| 75 } |
| 76 } |
| 77 |
| 78 function resetData() { |
| 79 window.dataArray = new ArrayBuffer(0); |
| 80 } |
| 81 |
| 82 function appendData(data) { |
| 83 var tmp = new Uint8Array(dataArray.byteLength + data.byteLength); |
| 84 tmp.set(new Uint8Array(dataArray), 0 ); |
| 85 tmp.set(new Uint8Array(data), dataArray.byteLength); |
| 86 dataArray = tmp.buffer; |
| 87 $('length').innerHTML = ' Size: ' + dataArray.byteLength + ' bytes'; |
| 88 } |
| 89 |
| 90 function initialize() { |
| 91 plugin = $('plugin'); |
| 92 plugin.addEventListener('message', handleMessage, false); |
| 93 |
| 94 video = $('video'); |
| 95 |
| 96 $('start').addEventListener('click', function (e) { |
| 97 resetData(); |
| 98 startRecord(); |
| 99 }); |
| 100 $('stop').addEventListener('click', function (e) { |
| 101 stopRecord(); |
| 102 }); |
| 103 $('download').addEventListener('click', function (e) { |
| 104 saveBlob(new Blob([dataArray], { type: "application/octet-stream" })); |
| 105 }); |
| 106 } |
| 107 |
| 108 document.addEventListener('DOMContentLoaded', initialize, false); |
| 109 </script> |
| 110 </head> |
| 111 |
| 112 <body> |
| 113 <h1>Video Encoder API Example</h1><br> |
| 114 This example demonstrates receiving frames from a video MediaStreamTrack and |
| 115 encoding them in a plugin. |
| 116 <br> |
| 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> |
| 121 <br> |
| 122 <div> |
| 123 <embed id="plugin" type="application/x-ppapi-example-video-encode"/> |
| 124 <video id="video" width="640" height="480"/> |
| 125 </div> |
| 126 </body> |
| 127 </html> |
OLD | NEW |