Chromium Code Reviews| Index: ppapi/examples/video_encode/video_encode.html |
| diff --git a/ppapi/examples/video_encode/video_encode.html b/ppapi/examples/video_encode/video_encode.html |
| new file mode 100644 |
| index 0000000000000000000000000000000000000000..3cf18cb031d4f3c7b6ca665c552fec47a6e7804c |
| --- /dev/null |
| +++ b/ppapi/examples/video_encode/video_encode.html |
| @@ -0,0 +1,115 @@ |
| +<!DOCTYPE html> |
| +<html> |
| + <!-- |
| + Copyright 2014 The Chromium Authors. All rights reserved. |
|
bbudge
2015/02/19 21:54:38
nit: 2015
llandwerlin-old
2015/02/27 14:19:44
Done.
|
| + Use of this source code is governed by a BSD-style license that can be |
| + found in the LICENSE file. |
| + --> |
| +<head> |
| + <title>Video Encoder Example</title> |
| + <style type="text/css"> |
| + #video { |
| + position: fixed; |
| + } |
| + #plugin { |
| + position: fixed; |
| + } |
| + </style> |
| + <script type="text/javascript"> |
| + var plugin; |
| + var track; |
| + var video; |
| + |
| + function success(stream) { |
| + track = stream.getVideoTracks()[0]; |
| + video.src = URL.createObjectURL(stream); |
| + video.play(); |
| + |
| + plugin.postMessage({ |
| + command: 'start', |
| + track: track |
| + }); |
| + } |
| + |
| + function failure(e) { |
| + console.log("Error: ", e); |
| + } |
| + |
| + function startRecord() { |
| + console.log("starting record"); |
| + navigator.webkitGetUserMedia({audio: false, video: true}, success, failure); |
|
bbudge
2015/02/19 21:54:38
nit: line length > 80
llandwerlin-old
2015/02/27 14:19:44
Done.
|
| + } |
| + |
| + function stopRecord() { |
| + plugin.postMessage({ |
| + command: "stop" |
| + }); |
| + var video = document.getElementById('video'); |
| + video.pause(); |
| + track.stop(); |
| + } |
| + |
| + function saveBlob(blob) { |
| + var blobUrl = URL.createObjectURL(blob); |
| + window.location = blobUrl; |
| + } |
| + |
| + function handleMessage(msg) { |
| + if (msg.data.name == 'started') { |
| + console.log('recording!'); |
| + } else if (msg.data.name == 'data') { |
| + appendData(msg.data.data); |
| + } else if (msg.data.name == 'stopped') { |
| + console.log('done recording! bytes: ' + dataArray.byteLength); |
| + saveBlob(new Blob([dataArray], { type: "application/octet-stream" })); |
|
bbudge
2015/02/19 21:54:38
On my Mac, the encoder failed (no hardware) and I
|
| + resetData(); |
| + } |
| + } |
| + |
| + function resetData() { |
| + window.dataArray = new ArrayBuffer(0); |
| + } |
| + |
| + function appendData(data) { |
| + var tmp = new Uint8Array(dataArray.byteLength + data.byteLength); |
| + tmp.set(new Uint8Array(dataArray), 0 ); |
| + tmp.set(new Uint8Array(data), dataArray.byteLength); |
| + dataArray = tmp.buffer; |
| + } |
| + |
| + function initialize() { |
| + plugin = document.getElementById('plugin'); |
| + plugin.addEventListener('message', handleMessage, false); |
| + |
| + video = document.getElementById('video'); |
| + |
| + var selectEl = document.getElementById('start'); |
| + selectEl.addEventListener('click', function (e) { |
| + resetData(); |
| + startRecord(); |
| + }); |
| + selectEl = document.getElementById('stop'); |
| + selectEl.addEventListener('click', function (e) { |
| + stopRecord(); |
| + }); |
| + } |
| + |
| + document.addEventListener('DOMContentLoaded', initialize, false); |
| + </script> |
| +</head> |
| + |
| +<body> |
| + <h1>Video Encoder API Example</h1><br> |
| + This example demonstrates receiving frames from a video MediaStreamTrack and |
| + encoding them in a plugin. |
| + <br> |
| + <input type="button" id="start" value="Start Recording"/> |
| + <input type="button" id="stop" value="Stop Recording"/> |
| + <br> |
| + <div> |
| + <embed id="plugin" type="application/x-ppapi-example-video-encode" |
| + width="640" height="480"/> |
| + <video id="video" width="640" height="480"/> |
| + </div> |
| +</body> |
| +</html> |