This repository has been archived by the owner on Jul 1, 2020. It is now read-only.
-
Notifications
You must be signed in to change notification settings - Fork 3
/
index.html
137 lines (116 loc) · 5.06 KB
/
index.html
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
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
<!DOCTYPE html>
<html>
<head lang="en">
<meta charset="UTF-8">
<title>Mirror</title>
</head>
<style>
#content{
position: absolute;
height: 98%;
width: 98%
}
#stats{
position: absolute;
left: 2px;
z-index: 1;
}
video{
position: absolute;
height: 100%;
transform: scale(-1, 1); /*For Firefox (& IE) */
-webkit-transform: scale(-1, 1); /*for Chrome & Opera (& Safari) */
}
table, th, td {
border: 1px solid grey;
border-collapse: collapse;
text-align: right;
}
td:first-child{
text-align: left;
}
</style>
<body>
<div id="content">
<div id="stats"></div>
<video id="vidme" autoplay></video>
</div>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.4.0/jquery.min.js"></script>
<script>
$(document).ready( function(){
var video = $('#vidme')[0]; //use var so we only call jQuery selectors once
var w = 1920, //video width
h = 1080; //video width
//Get the local video with getUserMedia
navigator.getUserMedia = navigator.getUserMedia || navigator.webkitGetUserMedia || navigator.mozGetUserMedia || navigator.msGetUserMedia;
//Make sure getUserMedia is available
if(!navigator.getUserMedia){
$("#content").html(":( Your browser does not support getUserMedia")
}
else{
//ToDo: use adapter.js and use the new constraint format
var constraints = {
audio: false, //no need for audio
video: {
mandatory: {
maxWidth: w,
maxHeight: h
}
}
};
function onSuccess(stream) {
window.stream = stream; // stream available to console
video.src = window.URL.createObjectURL(stream);
video.play();
console.log("showing video");
//start collecting stats when the video starts
video.addEventListener("playing", calculateStats());
}
function onFail(err){
//To DO: on fail due to camera constraints try again with a lower res
$('#content').html("Sorry - you have an error: " + err);
console.log(err);
}
console.log("requested video size is: " + w + " x " + h );
navigator.getUserMedia(constraints, onSuccess, onFail);
}
//modified from: http://git.chromium.org/gitweb/?p=chromium.git;a=blob;f=chrome/test/data/media/html/media_stat_perf.html
function calculateStats() {
var decodedFrames = 0,
droppedFrames = 0,
startTime = new Date().getTime(),
initialTime = new Date().getTime();
window.setInterval(function(){
//see if webkit stats are available; exit if they aren't
if (!video.webkitDecodedFrameCount){
console.log("Video FPS calcs not supported");
}
//get the stats
else{
var currentTime = new Date().getTime();
var deltaTime = (currentTime - startTime) / 1000;
var totalTime = (currentTime - initialTime) / 1000;
startTime = currentTime;
// Calculate decoded frames per sec.
var currentDecodedFPS = (video.webkitDecodedFrameCount - decodedFrames) / deltaTime;
var decodedFPSavg = video.webkitDecodedFrameCount / totalTime;
decodedFrames = video.webkitDecodedFrameCount;
// Calculate dropped frames per sec.
var currentDroppedFPS = (video.webkitDroppedFrameCount - droppedFrames) / deltaTime;
var droppedFPSavg = video.webkitDroppedFrameCount / totalTime;
droppedFrames = video.webkitDroppedFrameCount;
//write the results to a table
var stats =
"<table><tr><th>Type</th><th>Total</th><th>Avg</th><th>Current</th></tr>" +
"<tr><td>Decoded</td><td>" + decodedFrames + "</td><td>" + decodedFPSavg.toFixed() + "</td><td>" + currentDecodedFPS.toFixed()+ "</td></tr>" +
"<tr><td>Dropped</td><td>" + droppedFrames + "</td><td>" + droppedFPSavg.toFixed() + "</td><td>" + currentDroppedFPS.toFixed() + "</td></tr>" +
"<tr><td>All</td><td>" + (decodedFrames + droppedFrames) + "</td><td>" + (decodedFPSavg + droppedFPSavg).toFixed() + "</td><td>" + (currentDecodedFPS + currentDroppedFPS).toFixed() + "</td></tr></table>" +
"Camera resolution: " + video.videoWidth + " x " + video.videoHeight;
$("#stats").html(stats);
}
}, 1000);
}
});
</script>
</body>
</html>