-
Notifications
You must be signed in to change notification settings - Fork 0
/
aioner.html
354 lines (339 loc) · 15.8 KB
/
aioner.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
239
240
241
242
243
244
245
246
247
248
249
250
251
252
253
254
255
256
257
258
259
260
261
262
263
264
265
266
267
268
269
270
271
272
273
274
275
276
277
278
279
280
281
282
283
284
285
286
287
288
289
290
291
292
293
294
295
296
297
298
299
300
301
302
303
304
305
306
307
308
309
310
311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
343
344
345
346
347
348
349
350
351
352
353
354
<html>
<head>
<title>All in One Recorder</title>
<meta name="author" content="HanishKVC">
<meta name="license" content="GPL">
</head>
<body>
<h1>All in One Recorder</h1>
<version>v20230704IST1212</version>
<div style="margin-block: 1vh;">
<button id="RecScr" title="Record screen and or audio playback"> Record Screen </button>
<button id="RecDev" title="Record camera and or mic"> Record Devices </button>
<button id="RecAud" title="Record mic"> Record Audio </button>
<button id="RecScrMic" title="Record screan and or audio playback and or mic"> Record Screen + Mic </button>
<button id="RecStop" title="Stop the recording"> Stop </button>
</div>
<div style="margin-block: 1vh;">
<label for="RecQuality">Quality</label>
<select id="RecQuality" title="Control the quality of capture/recording">
<option value='{"q":"high", "v":2560000, "a":128000}'>high</option>
<option value='{"q":"mid", "v":1280000, "a":96000}'>mid</option>
<option value='{"q":"low", "v":512000, "a":64000}'>low</option>
<option value='{"q":"default"}' selected>default</option>
</select>
</div>
<div style="margin-block: 1vh;">
<hr>
[[Status]]
<p id="Status"></p>
[[Tracks]]
<p id="InfoTracks"></p>
<hr>
</div>
<div>
<video id="RecPreview" autoplay muted playsinline width="256"></video>
</div>
<script>
let theStream = null
let theStreams = []
let mediaRec = null;
let mediaChunks = []
let dataChunkCnt = 0
let fileData = null
const DATACHUNK_MS = 20000
let mediaFileCnt = 0
let dl = null
let elStatus = null
let startDateTime = 194708150000
let recType = "???"
/** @type {HTMLInputElement} */
let inRecQual = null
let vidPreview = null
let elInfoTracks = null
let infoTracksSpecial = ""
/**
* Generate a number containing the parts of date time specified in the string template.
*/
function get_datetime(tmpl) {
let val = 0
let dt = new Date()
for (i in tmpl) {
let t = tmpl[i]
switch (t) {
case 'Y':
val = (val*10000) + dt.getFullYear()
break;
case 'M':
val = (val*100) + (dt.getMonth()+1)
break;
case 'D':
val = (val*100) + dt.getDate()
break;
case 'h':
val = (val*100) + dt.getHours()
break;
case 'm':
val = (val*100) + dt.getMinutes()
break;
case 's':
val = (val*100) + dt.getSeconds()
break;
default:
break;
}
}
return val
}
/**
* Handle the captured data chunks, as and when provided by the system/browser.
*/
function got_data(be) {
mediaChunks.push(be.data)
dataChunkCnt += 1
console.log("INFO:GotData:", dataChunkCnt)
elStatus.innerHTML = `Recording ${recType}... ${dataChunkCnt}`
}
function stopped_capture() {
save_chunks()
}
/**
* Prepare and start the media recorder
* @param {MediaStream} stream
*/
function prep_mr(stream, options={}) {
mediaChunks = []
dataChunkCnt = 0
theStream = stream
mediaFileCnt += 1
console.debug("DEBUG:PrepMR:", stream, options)
mediaRec = new MediaRecorder(stream, options)
mediaRec.ondataavailable = got_data
mediaRec.onstop = stopped_capture
mediaRec.start(DATACHUNK_MS)
startDateTime = get_datetime("YMDhms")
vidPreview.srcObject = stream
elInfoTracks.innerHTML = ""
stream.getTracks().forEach((track)=>{
let sInfo = `<p>* ${track.kind}:${track.enabled}:${track.label}:${track.contentHint}</p>`
elInfoTracks.innerHTML += sInfo
console.debug("INFO:PrepMR:",sInfo)
})
if (infoTracksSpecial.trim() !== "") {
elInfoTracks.innerHTML += `<p>* ${infoTracksSpecial}</p>`
}
}
function options_recqual(options={}) {
let userQual = {}
console.debug("DEBUG:OptsRQ:", inRecQual.value)
if (inRecQual.value.trim() !== "") {
userQual = JSON.parse(inRecQual.value)
}
if (userQual['v'] !== undefined) {
options['videoBitsPerSecond'] = userQual['v']
}
if (userQual['a'] !== undefined) {
options['audioBitsPerSecond'] = userQual['a']
}
return options
}
function start_rs(params) {
infoTracksSpecial = ""
navigator.mediaDevices.getDisplayMedia({audio: true, video: true}).then((stream)=>{
theStreams.push(stream)
recType = "screen"
prep_mr(stream, options_recqual())
elStatus.innerHTML = "Started screen recording..."
console.log("INFO:RecScr:Started...")
}).catch((reason)=>{
recType = "???"
elStatus.innerHTML = `ERRR:StartRS:${reason}`
console.error(elStatus.innerHTML)
})
}
function start_rd(params) {
infoTracksSpecial = ""
navigator.mediaDevices.getUserMedia({audio: true, video: true}).then((stream)=>{
theStreams.push(stream)
recType = "devices"
prep_mr(stream, options_recqual())
elStatus.innerHTML = "Started device recording..."
console.log("INFO:RecDev:Started...")
}).catch((reason)=>{
recType = "???"
elStatus.innerHTML = `ERRR:StartRD:${reason}`
console.error(elStatus.innerHTML)
})
}
function start_ra(params) {
infoTracksSpecial = ""
navigator.mediaDevices.getUserMedia({audio: true}).then((stream)=>{
theStreams.push(stream)
recType = "audio"
prep_mr(stream, options_recqual())
elStatus.innerHTML = "Started audio recording..."
console.log("INFO:RecAud:Started...")
}).catch((reason)=>{
recType = "???"
elStatus.innerHTML = `ERRR:StartRA:${reason}`
console.error(elStatus.innerHTML)
})
}
function start_rsm_merged(params) {
infoTracksSpecial = ""
navigator.mediaDevices.getDisplayMedia({audio: true, video: true}).then((stream1)=>{
theStreams.push(stream1)
navigator.mediaDevices.getUserMedia({audio:true}).then((stream2)=>{
theStreams.push(stream2)
recType = "screen+mic"
let mstream = new MediaStream()
if (stream1.getVideoTracks().length > 0) {
mstream.addTrack(stream1.getVideoTracks()[0])
}
let ax = new AudioContext()
let amix = ax.createMediaStreamDestination()
let alabel = "MixAudio("
if (stream1.getAudioTracks().length > 0) {
let a1ms = new MediaStream()
a1ms.addTrack(stream1.getAudioTracks()[0])
let a1src = ax.createMediaStreamSource(a1ms)
a1src.connect(amix)
alabel += `+${stream1.getAudioTracks()[0].label}`
}
if (stream2.getAudioTracks().length > 0) {
let a2ms = new MediaStream()
a2ms.addTrack(stream2.getAudioTracks()[0])
let a2src = ax.createMediaStreamSource(a2ms)
a2src.connect(amix)
alabel += `+${stream2.getAudioTracks()[0].label}`
}
alabel +=")"
//amix.stream.getAudioTracks()[0].label = alabel
mstream.addTrack(amix.stream.getAudioTracks()[0])
//mstream.getAudioTracks()[0].label = alabel
//mstream.getAudioTracks()[0].contentHint = alabel
infoTracksSpecial = alabel
prep_mr(mstream, options_recqual())
elStatus.innerHTML = "Started screen+mic recording..."
console.log("INFO:RecScrMicMrgd:Started...")
}).catch((reason)=>{
recType = "screen(no mic)"
prep_mr(stream1, options_recqual())
elStatus.innerHTML = "Started screen recording...(no mic)"
console.log("INFO:RecScrMicMrgd:Started...(no mic)")
})
}).catch((reason)=>{
recType = "???"
elStatus.innerHTML = `ERRR:StartRSMMrgd:${reason}`
console.error(elStatus.innerHTML)
})
}
function start_rsm_lr(params) {
infoTracksSpecial = ""
navigator.mediaDevices.getDisplayMedia({audio: true, video: true}).then((stream1)=>{
theStreams.push(stream1)
navigator.mediaDevices.getUserMedia({audio:true}).then((stream2)=>{
theStreams.push(stream2)
recType = "screen+mic"
let mstream = new MediaStream()
if (stream1.getVideoTracks().length > 0) {
mstream.addTrack(stream1.getVideoTracks()[0])
}
let ax = new AudioContext()
let adest = ax.createMediaStreamDestination()
let alr = ax.createChannelMerger()
alr.connect(adest)
let alabel = "MixAudio("
if (stream1.getAudioTracks().length > 0) {
let a1ms = new MediaStream()
a1ms.addTrack(stream1.getAudioTracks()[0])
let a1src = ax.createMediaStreamSource(a1ms)
a1src.connect(alr, 0, 0)
alabel += `+${stream1.getAudioTracks()[0].label}`
}
if (stream2.getAudioTracks().length > 0) {
let a2ms = new MediaStream()
a2ms.addTrack(stream2.getAudioTracks()[0])
let a2src = ax.createMediaStreamSource(a2ms)
a2src.connect(alr, 0, 1)
alabel += `+${stream2.getAudioTracks()[0].label}`
}
alabel +=")"
//adest.stream.getAudioTracks()[0].label = alabel
mstream.addTrack(adest.stream.getAudioTracks()[0])
//mstream.getAudioTracks()[0].label = alabel
//mstream.getAudioTracks()[0].contentHint = alabel
infoTracksSpecial = alabel
prep_mr(mstream, options_recqual())
elStatus.innerHTML = "Started screen+mic recording..."
console.log("INFO:RecScrMicLR:Started...")
}).catch((reason)=>{
recType = "screen(no mic)"
prep_mr(stream1, options_recqual())
elStatus.innerHTML = "Started screen recording...(no mic)"
console.log("INFO:RecScrMicLR:Started...(no mic)")
})
}).catch((reason)=>{
recType = "???"
elStatus.innerHTML = `ERRR:StartRSMLR:${reason}`
console.error(elStatus.innerHTML)
})
}
function save_chunks() {
console.log(`INFO:SaveChunks:${recType}:NumOfMediaChunks:`, mediaChunks.length)
if (fileData !== null) {
window.URL.revokeObjectURL(fileData)
}
let dataBlob = new Blob(mediaChunks)
fileData = window.URL.createObjectURL(dataBlob)
if (dl !== null) {
window.document.body.removeChild(dl)
}
dl = document.createElement('a')
dl.id = "SaveLink"
dl.setAttribute('download', `captured_${startDateTime}_${mediaFileCnt}`)
dl.href = fileData
dl.innerHTML = "Save last capture"
window.document.body.appendChild(dl)
elStatus.innerHTML = `Captured ${recType} data prepared for saving...`
console.log("INFO:SaveChunks:", elStatus.innerHTML)
}
function stop_rec(params) {
if (mediaRec !== null) {
mediaRec.stop()
mediaRec = null
elStatus.innerHTML = `Stopped recording ${recType}...`
console.log("INFO:RecStop:Stopped recording...")
vidPreview.srcObject = null
theStreams.forEach((stream)=>{
let tracks = /** @type {MediaStream} */(stream).getTracks()
tracks.forEach((track)=>{
track.stop()
})
})
} else {
elStatus.innerHTML = "Nothing to stop..."
console.log("INFO:RecStop:Nothing to stop...")
}
}
function init (params) {
let brs = document.getElementById("RecScr")
brs.onclick = start_rs
let brd = document.getElementById("RecDev")
brd.onclick = start_rd
let bra = document.getElementById("RecAud")
bra.onclick = start_ra
document.getElementById("RecScrMic").onclick = start_rsm_lr
let brstop = document.getElementById("RecStop")
brstop.onclick = stop_rec
elStatus = document.getElementById("Status")
inRecQual = document.getElementById("RecQuality")
vidPreview = document.getElementById("RecPreview")
elInfoTracks = document.getElementById("InfoTracks")
console.log("INFO:Init:Setup UI...")
elStatus.innerHTML = "Setup UI..."
}
window.onload = init
</script>
</body>
</html>