-
Notifications
You must be signed in to change notification settings - Fork 11
/
Copy pathbitrate.html
238 lines (231 loc) · 7.08 KB
/
bitrate.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
138
139
140
141
142
143
144
145
146
147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
174
175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
210
211
212
213
214
215
216
217
218
219
220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
<!DOCTYPE html>
<html>
<head>
<title>Visionular bitrate viewer</title>
<style>
.highcharts-figure, .highcharts-data-table table {
min-width: 360px;
max-width: 100%;
margin: 1em auto;
}
.highcharts-data-table table {
font-family: Verdana, sans-serif;
border-collapse: collapse;
border: 1px solid #EBEBEB;
margin: 10px auto;
text-align: center;
width: 100%;
max-width: 500px;
}
.highcharts-data-table caption {
padding: 1em 0;
font-size: 1.2em;
color: #555;
}
.highcharts-data-table th {
font-weight: 600;
padding: 0.5em;
}
.highcharts-data-table td, .highcharts-data-table th, .highcharts-data-table caption {
padding: 0.5em;
}
.highcharts-data-table thead tr, .highcharts-data-table tr:nth-child(even) {
background: #f8f8f8;
}
.highcharts-data-table tr:hover {
background: #f1f7ff;
}
</style>
</head>
<script src="https://code.highcharts.com/highcharts.js"></script>
<script src="https://code.highcharts.com/modules/data.js"></script>
<script src="https://code.highcharts.com/modules/exporting.js"></script>
<script src="https://code.highcharts.com/modules/export-data.js"></script>
<script src="https://code.highcharts.com/modules/accessibility.js"></script>
<body>
<div>
<video id="videoA" width="480" controls style="vertical-align:left;">
Your browser does not support the video tag.
</video>
<video id="videoB" width="480" controls style="vertical-align:left;">
Your browser does not support the video tag.
</video>
<video id="videoC" width="480" controls style="vertical-align:left;">
Your browser does not support the video tag.
</video>
<video id="videoD" width="480" controls style="vertical-align:left;">
Your browser does not support the video tag.
</video>
</div>
<div>
VideoA: <input id="v_file_A" type="file" onchange="playFile('v_file_A', 'videoA')" />
VideoB: <input id="v_file_B" type="file" onchange="playFile('v_file_B', 'videoB')" />
VideoC: <input id="v_file_C" type="file" onchange="playFile('v_file_C', 'videoC')" />
VideoD: <input id="v_file_D" type="file" onchange="playFile('v_file_D', 'videoD')" />
AvgWin: <input id="avgwin" value='1' /> <input id="avgwinBtn" type="button" value="Update" onclick="updateAvgWin()" />
<input id="playall" type="button" value="Play All" onclick="playall()" />
Video/Audio: <input id="stream" type="checkbox" checked onclick="SelectStream()"/>
</div>
<figure class="highcharts-figure">
<div id="container"></div>
</figure>
<script>
var series = [];
var pktsize_datas = [];
var t = document.getElementById('avgwin');
var avgWin = parseInt(t.value);
var query = window.location.search.substring(1);
var vars = query.split("&");
// console.log('vars: ', vars, 'len', vars.length);
var stream = 'v';
function loadUrl(idx) {
var pair = vars[idx].split("=");
if (pair.length <2) {
return;
}
var video = document.getElementById(pair[0])
var names = pair[1].split('/');
var name = names[ names.length -1 ];
fetch(pair[1])
.then(r => r.blob())
.then(myBlob => {
video.src = URL.createObjectURL(myBlob);
const vfile = new window.File([myBlob], name, { type: myBlob.type })
console.log('name: ', name, 'blob', vfile);
getPkts(vfile, pair[0]);
if (idx < vars.length - 1) {
loadUrl(idx+1)
}
});
}
if (vars.length >= 1) {
loadUrl(0);
}
var videoTags = ['videoA', 'videoB', 'videoC', 'videoD'];
var videos = [];
for (var tag of videoTags) {
var v = document.getElementById(tag)
videos.push(v);
}
function playall() {
for (var v of videos) {
v.play();
}
//setInterval(updateChart, 1000);
}
function playFile(id, tag) {
var file = document.getElementById(id).files[0];
if (!file) {
return;
}
var v = document.getElementById(tag)
v.src = URL.createObjectURL(file);
getPkts(file, id);
}
function parseCSV(str) {
var data = [];
var lines = str.split('\n');
for (var line of lines) {
var items = line.split(',');
if (items[0] === "packet") {
var time = parseFloat(items[1]);
var size = parseInt(items[2]);
var flags = items[3];
if (flags && flags.startsWith('K')) {
data.push( {x:time, y:size, color: "red", marker: { enabled: true}} );
} else {
data.push( [time, size] );
}
}
}
return data;
}
function calcAvgBitrate(data, range){
if (range <= 1) return data;
if (data.length / range < 10) {
range = Math.ceil(data.length / 10);
}
var avg_data = [];
for (let a = 0; a < data.length-range; a+= range) {
var time = ('x'in data[a]) ? data[a].x :data[a][0];
var sum = 0;
for (let i = 0; i < range; i++) {
sum += ('y' in data[a+i] ?data[a+i].y : data[a+i][1]);
}
var size = sum *8.0;
avg_data.push( [time, size] );
}
return avg_data;
}
function updateAvgWin() {
var t = document.getElementById('avgwin')
avgWin = parseInt(t.value);
series = [];
for ( var seq of pktsize_datas ) {
var data = (avgWin > 1) ? calcAvgBitrate(seq.data, avgWin) : seq.data;
var newSeries = {
name: seq.name,
data: data
};
series.push(newSeries);
}
updateChart();
}
function SelectStream() {
stream = stream =='a' ? 'v' : 'a';
//console.log('msg: ', stream);
}
function getPkts(file, vid) {
var worker = new Worker('dist/probe_worker.js');
worker.addEventListener('message', function (e) {
var csvData = parseCSV(e.data.results);
var newData = {
name: e.data.name,
data: csvData
};
pktsize_datas.push(newData);
console.log("getPkts", newData.data[0]);
var lineData = calcAvgBitrate(csvData, avgWin);
var newSeries = {
name: e.data.name,
data:lineData,
id: vid,
};
series.push(newSeries);
updateChart();
}, false);
//console.log('msg: ', file);
worker.postMessage({file:file, stream:stream });
}
function updateChart () {
Highcharts.chart('container', {
chart: {
zoomType: 'x',
type: 'line'
},
title: {
text: 'video bitrate over time'
},
subtitle: {
text: document.ontouchstart === undefined ?
'Click and drag in the plot area to zoom in' : 'Pinch the chart to zoom in'
},
tooltip: {
crosshairs: true,
shared: true
},
xAxis: {
type: 'float'
},
yAxis: {
title: {
text: avgWin > 1 ? 'bitrate (bps)' : "pkg size(Bytes)"
}
},
series: series
});
}
updateChart();
</script>
</body>
</html>