-
Notifications
You must be signed in to change notification settings - Fork 0
/
test.html
160 lines (142 loc) · 3.75 KB
/
test.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
<!DOCTYPE html>
<html>
<head>
<meta charset="utf-8"/>
<style>
canvas {
max-width: 144px;
max-height: 82px;
}
</style>
</head>
<body>
<script src="bitview.js"></script>
<script src=//cdnjs.cloudflare.com/ajax/libs/seedrandom/2.3.10/seedrandom.min.js></script>
<script>
var ids = [1,
1954,
4625,
4795,
14295,
14298,
14299,
14319,
15500,
14326,
15058];
function sha256(imageData) {
return crypto.subtle.digest("SHA-256", imageData.data).then(function (hash) {
return hex(hash);
});
}
function hex(buffer) {
var hexCodes = [];
var view = new DataView(buffer);
for (var i = 0; i < view.byteLength; i += 4) {
var value = view.getUint32(i)
var stringValue = value.toString(16)
var padding = '00000000'
var paddedValue = (padding + stringValue).slice(-padding.length)
hexCodes.push(paddedValue);
}
return hexCodes.join("");
}
function getHash(cb, count) {
if(video.error) {
results.push({digest: null, error: {code: video.error.code, message: video.error.message}});
cb();
return;
}
if(video.videoWidth == 0) {
setTimeout(function() { getHash(cb, count +1) }, 100);
return;
}
var canvas = document.createElement('canvas');
canvas.id = ids[i-1];
canvas.height = video.videoHeight;
canvas.width = video.videoWidth;
var ctx = canvas.getContext('2d');
ctx.drawImage(video, 0, 0, canvas.width, canvas.height);
var data = ctx.getImageData(0, 0, canvas.width, canvas.height);
sha256(data).then(function(digest) {
if(digest == "5a1c685ca6829cbbe95b235f4763b312a6e5013ecede57dfe82dad963d88d635" && count < 10) {
setTimeout(function() { getHash(cb, count +1) }, 100);
return;
}
results.push({digest: digest, error: video.error});
if(!hashes.has(digest)) {
hashes.add(digest);
document.body.appendChild(canvas);
}
cb();
}, function(error) {
console.log(error);
results.push({digest: null, error: error});
cb();
});
}
Math.seedrandom('hello.');
var buffer = null;;
var sourceBuffer;
var video = document.createElement('video');
var mediaSource;
var i = 0;
var results = [];
var hashes = new Set();
var assetURL = 'output_frag.mp4';
var mimeCodec = 'video/mp4; codecs="avc1.640015"';
var size = 0;
function fuzz(buffer) {
var buf = buffer.slice(0);
var bv = new BitView(buf);
bv.setBit(ids[i], !bv.getBit(ids[i]));
return buf;
}
function fetchAB (url, cb) {
var xhr = new XMLHttpRequest;
xhr.open('get', url);
xhr.responseType = 'arraybuffer';
xhr.onload = function () {
cb(xhr.response);
};
xhr.send();
};
function setup() {
if ('MediaSource' in window && MediaSource.isTypeSupported(mimeCodec)) {
mediaSource = new MediaSource;
video.src = URL.createObjectURL(mediaSource);
mediaSource.addEventListener('sourceopen', sourceOpen);
} else {
console.error('Unsupported MIME type or codec: ', mimeCodec);
}
}
function sourceOpen (_) {
var mediaSource = this;
mediaSource.removeEventListener('sourceopen', sourceOpen);
sourceBuffer = mediaSource.addSourceBuffer(mimeCodec);
sourceBuffer.addEventListener('updateend', updateEnd);
if(buffer === null) {
fetchAB(assetURL, function (buf) {
buffer = buf;
sourceBuffer.appendBuffer(buffer);
});
} else {
var fuzzed = fuzz(buffer);
sourceBuffer.appendBuffer(fuzzed);
}
}
function updateEnd (_) {
if(i < ids.length) {
getHash(setup, 0);
i++;
console.log(i + "/" + ids.length);
} else {
var pre = document.createElement("pre");
pre.innerHTML = JSON.stringify(results, undefined, 2);
document.body.appendChild(pre);
}
}
setup();
</script>
</body>
</html>