forked from EasyScreenCast/EasyScreenCast
-
Notifications
You must be signed in to change notification settings - Fork 0
/
utilgsp.js
738 lines (651 loc) · 25 KB
/
utilgsp.js
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
355
356
357
358
359
360
361
362
363
364
365
366
367
368
369
370
371
372
373
374
375
376
377
378
379
380
381
382
383
384
385
386
387
388
389
390
391
392
393
394
395
396
397
398
399
400
401
402
403
404
405
406
407
408
409
410
411
412
413
414
415
416
417
418
419
420
421
422
423
424
425
426
427
428
429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
449
450
451
452
453
454
455
456
457
458
459
460
461
462
463
464
465
466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
481
482
483
484
485
486
487
488
489
490
491
492
493
494
495
496
497
498
499
500
501
502
503
504
505
506
507
508
509
510
511
512
513
514
515
516
517
518
519
520
521
522
523
524
525
526
527
528
529
530
531
532
533
534
535
536
537
538
539
540
541
542
543
544
545
546
547
548
549
550
551
552
553
554
555
556
557
558
559
560
561
562
563
564
565
566
567
568
569
570
571
572
573
574
575
576
577
578
579
580
581
582
583
584
585
586
587
588
589
590
591
592
593
594
595
596
597
598
599
600
601
602
603
604
605
606
607
608
609
610
611
612
613
614
615
616
617
618
619
620
621
622
623
624
625
626
627
628
629
630
631
632
633
634
635
636
637
638
639
640
641
642
643
644
645
646
647
648
649
650
651
652
653
654
655
656
657
658
659
660
661
662
663
664
665
666
667
668
669
670
671
672
673
674
675
676
677
678
679
680
681
682
683
684
685
686
687
688
689
690
691
692
693
694
695
696
697
698
699
700
701
702
703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
721
722
723
724
725
726
727
728
729
730
731
732
733
734
735
736
737
738
/*
Copyright (C) 2016 Borsato Ivano
The JavaScript code in this page is free software: you can
redistribute it and/or modify it under the terms of the GNU
General Public License (GNU GPL) as published by the Free Software
Foundation, either version 3 of the License, or (at your option)
any later version. The code is distributed WITHOUT ANY WARRANTY;
without even the implied warranty of MERCHANTABILITY or FITNESS
FOR A PARTICULAR PURPOSE. See the GNU GPL for more details.
*/
'use strict';
import * as Lib from './convenience.js';
import * as Settings from './settings.js';
// CONST GSP - base
const SCREEN =
'_SCREENCAST_RES_ _ENCODER_VIDEO_ ! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 ! _CONTAINER_';
// CONST GSP - base plus sound
const SCREEN_SOUND =
'queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 ! _SCREENCAST_RES_ _ENCODER_VIDEO_ ! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 ! mux. pulsesrc ! audioconvert ! _ENCODER_AUDIO_ ! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 ! mux. _CONTAINER_ name=mux ';
// CONST GSP - base plus webcam
const SCREEN_WEBCAM =
'queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 ! videomixer name=mix _WEBCAM_OPT_ ! videoconvert ! _SCREENCAST_RES_ _ENCODER_VIDEO_ ! mux. v4l2src _WEBCAM_DEV_ ! _WEBCAM_CAP_ ! videoscale ! video/x-raw, width=_WEBCAM_W_, height=_WEBCAM_H_, add-borders=false ! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 ! mix. _CONTAINER_ name=mux';
// CONST GSP - base plus sound and webcam stream
const SCREEN_WEBCAM_SOUND =
'queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 ! videomixer name=mix _WEBCAM_OPT_ ! videoconvert ! _SCREENCAST_RES_ _ENCODER_VIDEO_ ! mux. v4l2src _WEBCAM_DEV_ ! _WEBCAM_CAP_ ! videoscale ! video/x-raw, width=_WEBCAM_W_, height=_WEBCAM_H_, add-borders=false ! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 ! mix. pulsesrc ! audioconvert ! _ENCODER_AUDIO_ ! queue max-size-buffers=0 max-size-time=0 max-size-bytes=0 ! mux. _CONTAINER_ name=mux';
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// CONST CONTAINER - WebM
const webmVP8 = {
fileExt: '.webm',
nameGSP: 'webmmux',
quality: [
{
// quality level 0
fps: 15,
vq:
'vp8enc min_quantizer=13 max_quantizer=20 cpu-used=5 deadline=1000000 sharpness=2 target-bitrate=10000 threads=%T',
aq: 'vorbisenc',
descr:
'FPS: 15 \nVideo -> VP8 Encoder:\n-min_quantizer=13\n-max_quantizer=20\n-cpu-used=5\n-deadline=1000000\n-sharpness=2\n-target-bitrate=10000\nAudio -> Vorbis Encoder',
},
{
// quality level 1
fps: 30,
vq:
'vp8enc min_quantizer=4 max_quantizer=13 cpu-used=2 deadline=500000 sharpness=0 target-bitrate=15000 threads=%T',
aq: 'vorbisenc',
descr:
'FPS: 30 \nVideo -> VP8 Encoder:\n-min_quantizer=4\n-max_quantizer=13\n-cpu-used=2\n-deadline=500000\n-sharpness=0\n-target-bitrate=15000\nAudio -> Vorbis Encoder',
},
{
// quality level 2
fps: 30,
vq:
'vp8enc min_quantizer=0 max_quantizer=7 cpu-used=1 deadline=500000 sharpness=0 target-bitrate=25000 threads=%T',
aq: 'vorbisenc',
descr:
'FPS: 30 \nVideo -> VP8 Encoder:\n-min_quantizer=0\n-max_quantizer=7\n-cpu-used=1\n-deadline=500000\n-sharpness=0\n-target-bitrate=25000\nAudio -> Vorbis Encoder',
},
{
// quality level 3
fps: 60,
vq:
'vp8enc min_quantizer=0 max_quantizer=0 cpu-used=0 deadline=100000 sharpness=0 target-bitrate=40000 threads=%T',
aq: 'vorbisenc',
descr:
'FPS: 60 \nVideo -> VP8 Encoder:\n-min_quantizer=0\n-max_quantizer=0\n-cpu-used=0\n-deadline=100000\n-sharpness=0\n-target-bitrate=40000\nAudio -> Vorbis Encoder',
},
],
};
const webmVP9 = {
fileExt: '.webm',
nameGSP: 'webmmux',
quality: [
{
// quality level 0
fps: 15,
vq:
'vp9enc min_quantizer=13 max_quantizer=20 cpu-used=5 deadline=1000000 sharpness=2 target-bitrate=10000 threads=%T',
aq: 'vorbisenc',
descr:
'FPS: 15 \nVideo -> VP9 Encoder:\n-min_quantizer=13\n-max_quantizer=20\n-cpu-used=5\n-deadline=1000000\n-sharpness=2\n-target-bitrate=10000\nAudio -> Vorbis Encoder',
},
{
// quality level 1
fps: 30,
vq:
'vp9enc min_quantizer=4 max_quantizer=13 cpu-used=2 deadline=500000 sharpness=0 target-bitrate=15000 threads=%T',
aq: 'vorbisenc',
descr:
'FPS: 30 \nVideo -> VP9 Encoder:\n-min_quantizer=4\n-max_quantizer=13\n-cpu-used=2\n-deadline=500000\n-sharpness=0\n-target-bitrate=15000\nAudio -> Vorbis Encoder',
},
{
// quality level 2
fps: 30,
vq:
'vp9enc min_quantizer=0 max_quantizer=7 cpu-used=1 deadline=500000 sharpness=0 target-bitrate=25000 threads=%T',
aq: 'vorbisenc',
descr:
'FPS: 30 \nVideo -> VP9 Encoder:\n-min_quantizer=0\n-max_quantizer=7\n-cpu-used=1\n-deadline=500000\n-sharpness=0\n-target-bitrate=25000\nAudio -> Vorbis Encoder',
},
{
// quality level 3
fps: 60,
vq:
'vp9enc min_quantizer=0 max_quantizer=0 cpu-used=0 deadline=100000 sharpness=0 target-bitrate=40000 threads=%T',
aq: 'vorbisenc',
descr:
'FPS: 60 \nVideo -> VP9 Encoder:\n-min_quantizer=0\n-max_quantizer=0\n-cpu-used=0\n-deadline=100000\n-sharpness=0\n-target-bitrate=40000\nAudio -> Vorbis Encoder',
},
],
};
// CONST CONTAINER - Mp4
const mp4 = {
fileExt: '.mp4',
nameGSP: 'mp4mux',
quality: [
{
// quality level 0
fps: 15,
vq:
'x264enc psy-tune="none" speed-preset="superfast" subme=1 qp-min=28 qp-max=40 threads=%T',
aq: 'lamemp3enc',
descr:
'FPS: 15 \nVideo -> x264enc Encoder:\n-psy-tune="none"\n-speed-preset="superfast"\n-subme=1\n-qp-min=28\n-qp-max=40\nAudio -> Mp3 Encoder',
},
{
// quality level 1
fps: 30,
vq:
'x264enc psy-tune="animation" speed-preset="fast" subme=5 qp-min=18 qp-max=28 threads=%T',
aq: 'lamemp3enc',
descr:
'FPS: 30 \nVideo -> x264enc Encoder:\n-psy-tune="animation"\n-speed-preset="fast"\n-subme=5\n-qp-min=18\n-qp-max=28\nAudio -> Mp3 Encoder',
},
{
// quality level 2
fps: 30,
vq:
'x264enc psy-tune="animation" speed-preset="medium" subme=8 qp-min=10 qp-max=18 threads=%T',
aq: 'lamemp3enc',
descr:
'FPS: 30 \nVideo -> x264enc Encoder:\n-psy-tune="animation"\n-speed-preset="medium"\n-subme=8\n-qp-min=10\n-qp-max=18\nAudio -> Mp3 Encoder',
},
{
// quality level 3
fps: 60,
vq:
'x264enc psy-tune="film" speed-preset="slower" subme=10 qp-min=0 qp-max=10 threads=%T',
aq: 'lamemp3enc',
descr:
'FPS: 60 \nVideo -> x264enc Encoder:\n-psy-tune="film"\n-speed-preset="slower"\n-subme=10\n-qp-min=0\n-qp-max=10\nAudio -> Mp3 Encoder',
},
],
};
const mp4Aac = {
fileExt: '.mp4',
nameGSP: 'mp4mux',
quality: [
{
// quality level 0
fps: 15,
vq:
'x264enc psy-tune="none" speed-preset="superfast" subme=1 qp-min=28 qp-max=40 threads=%T',
aq: 'avenc_aac',
descr:
'FPS: 15 \nVideo -> x264enc Encoder:\n-psy-tune="none"\n-speed-preset="superfast"\n-subme=1\n-qp-min=28\n-qp-max=40\nAudio -> AAC Encoder',
},
{
// quality level 1
fps: 30,
vq:
'x264enc psy-tune="animation" speed-preset="fast" subme=5 qp-min=18 qp-max=28 threads=%T',
aq: 'avenc_aac',
descr:
'FPS: 30 \nVideo -> x264enc Encoder:\n-psy-tune="animation"\n-speed-preset="fast"\n-subme=5\n-qp-min=18\n-qp-max=28\nAudio -> AAC Encoder',
},
{
// quality level 2
fps: 30,
vq:
'x264enc psy-tune="animation" speed-preset="medium" subme=8 qp-min=10 qp-max=18 threads=%T',
aq: 'avenc_aac',
descr:
'FPS: 30 \nVideo -> x264enc Encoder:\n-psy-tune="animation"\n-speed-preset="medium"\n-subme=8\n-qp-min=10\n-qp-max=18\nAudio -> AAC Encoder',
},
{
// quality level 3
fps: 60,
vq:
'x264enc psy-tune="film" speed-preset="slower" subme=10 qp-min=0 qp-max=10 threads=%T',
aq: 'avenc_aac',
descr:
'FPS: 60 \nVideo -> x264enc Encoder:\n-psy-tune="film"\n-speed-preset="slower"\n-subme=10\n-qp-min=0\n-qp-max=10\nAudio -> AAC Encoder',
},
],
};
// CONST CONTAINER - Mkv
const mkv = {
fileExt: '.mkv',
nameGSP: 'matroskamux',
quality: [
{
// quality level 0
fps: 15,
vq:
'x264enc psy-tune="none" speed-preset="superfast" subme=1 qp-min=28 qp-max=40 threads=%T',
aq: 'flacenc',
descr:
'FPS: 15 \nVideo -> x264enc Encoder:\n-psy-tune="none"\n-speed-preset="superfast"\n-subme=1\n-qp-min=28\n-qp-max=40\nAudio -> Flac Encoder',
},
{
// quality level 1
fps: 30,
vq:
'x264enc psy-tune="animation" speed-preset="fast" subme=5 qp-min=18 qp-max=28 threads=%T',
aq: 'flacenc',
descr:
'FPS: 30 \nVideo -> x264enc Encoder:\n-psy-tune="animation"\n-speed-preset="fast"\n-subme=5\n-qp-min=18\n-qp-max=28\nAudio -> Flac Encoder',
},
{
// quality level 2
fps: 30,
vq:
'x264enc psy-tune="animation" speed-preset="medium" subme=8 qp-min=10 qp-max=18 threads=%T',
aq: 'flacenc',
descr:
'FPS: 30 \nVideo -> x264enc Encoder:\n-psy-tune="animation"\n-speed-preset="medium"\n-subme=8\n-qp-min=10\n-qp-max=18\nAudio -> Flac Encoder',
},
{
// quality level 3
fps: 60,
vq:
'x264enc psy-tune="film" speed-preset="slower" subme=10 qp-min=0 qp-max=10 threads=%T',
aq: 'flacenc',
descr:
'FPS: 60 \nVideo -> x264enc Encoder:\n-psy-tune="film"\n-speed-preset="slower"\n-subme=10\n-qp-min=0\n-qp-max=10\nAudio -> Flac Encoder',
},
],
};
// CONST CONTAINER - Ogg
const ogg = {
fileExt: '.ogg',
nameGSP: 'oggmux',
quality: [
{
// quality level 0
fps: 15,
vq:
'theoraenc speed-level=3 vp3-compatible=true quality=10 bitrate=10000',
aq: 'opusenc',
descr:
'FPS: 15 \nVideo -> Theora Encoder:\n-speed-level=3\n-vp3-compatible=true\n-quality=10\n-bitrate=10000\nAudio -> Opus Encoder',
},
{
// quality level 1
fps: 30,
vq:
'theoraenc speed-level=1 vp3-compatible=false quality=30 bitrate=25000',
aq: 'opusenc',
descr:
'FPS: 30 \nVideo -> Theora Encoder:\n-speed-level=1\n-vp3-compatible=false\n-quality=30\n-bitrate=25000\nAudio -> Opus Encoder',
},
{
// quality level 2
fps: 30,
vq:
'theoraenc speed-level=0 vp3-compatible=false quality=50 bitrate=50000',
aq: 'opusenc',
descr:
'FPS: 30 \nVideo -> Theora Encoder:\n-speed-level=0\n-vp3-compatible=false\n-quality=50\n-bitrate=50000\nAudio -> Opus Encoder',
},
{
// quality level 3
fps: 60,
vq:
'theoraenc speed-level=0 vp3-compatible=false quality=60 bitrate=100000',
aq: 'opusenc',
descr:
'FPS: 60 \nVideo -> Theora Encoder\n-speed-level=0\n-vp3-compatible=false\n-quality=60\n-bitrate=100000\nAudio -> Opus Encoder',
},
],
};
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// CONST RESOLUTION
const RESOLUTION = [
// NATIVE SCREENCAST RESOLUTION
'',
// PRESET/CUSTOM SCREENCAST RESOLUTION
'videoscale ! video/x-raw, width=_RES_WIDTH_, height=_RES_HEIGHT_, add-borders=_RES_KAR_ ! ',
];
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
// VAR ARRAY CONTAINER
// see cbt_FileContainer in *.glade files for the combo box
const CONTAINER = [webmVP8, webmVP9, mp4, mkv, ogg, mp4Aac];
// @@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@@
/**
* Compose GSP
*
* @param {EasyScreenCastSettings} settings the extension's settings
* @param {MixerAudio} mixer the mixer
*
* @returns {string}
*/
function composeGSP(settings, mixer) {
Lib.TalkativeLog('-§-COMPOSE GSP');
let tmpGSP = '';
// retrieve options
let deviceWebcam = settings.getOption('s', Settings.DEVICE_WEBCAM_SETTING_KEY);
let deviceAudio = settings.getOption('i', Settings.INPUT_AUDIO_SOURCE_SETTING_KEY);
let qualityGSP = settings.getOption('i', Settings.QUALITY_SETTING_KEY);
let qualityWebcam = settings.getOption('s', Settings.QUALITY_WEBCAM_SETTING_KEY);
let resolutionType = settings.getOption('i', Settings.FILE_RESOLUTION_TYPE_SETTING_KEY);
let resolutionKAR = settings.getOption('b', Settings.FILE_RESOLUTION_KAR_SETTING_KEY);
let resolutionHeight = settings.getOption('i', Settings.FILE_RESOLUTION_HEIGHT_SETTING_KEY);
let resolutionWidth = settings.getOption('i', Settings.FILE_RESOLUTION_WIDTH_SETTING_KEY);
let container = settings.getOption('i', Settings.FILE_CONTAINER_SETTING_KEY);
Lib.TalkativeLog(
`-§-get option||devW: ${deviceWebcam}||devA: ${deviceAudio}||Qgsp: ${qualityGSP}||Qwc: ${qualityWebcam}||Res: ${resolutionType}||Cont: ${container}`
);
if (deviceWebcam !== '') {
switch (deviceAudio) {
case 0:
Lib.TalkativeLog('-§- SCREEN-WEBCAM');
tmpGSP = SCREEN_WEBCAM;
// replace WEBCAM_DEVICE/WEBCAM_CAPS
tmpGSP = _replaceWebcam(
tmpGSP,
deviceWebcam,
qualityWebcam,
settings
);
break;
case 1:
Lib.TalkativeLog('-§-SCREEN-WEBCAM-AUDIO(d)');
tmpGSP = SCREEN_WEBCAM_SOUND;
// replace WEBCAM_DEVICE/WEBCAM_CAPS/ENCODER-AUDIO
tmpGSP = _replaceAudio(
_replaceWebcam(tmpGSP, deviceWebcam, qualityWebcam, settings),
true,
container,
qualityGSP,
mixer
);
break;
default:
Lib.TalkativeLog('-§-SCREEN-WEBCAM-AUDIO');
tmpGSP = SCREEN_WEBCAM_SOUND;
// replace WEBCAM_DEVICE/WEBCAM_CAPS/ENCODER-AUDIO/AUDIO_DEVICE
tmpGSP = _replaceAudio(
_replaceWebcam(tmpGSP, deviceWebcam, qualityWebcam, settings),
false,
container,
qualityGSP,
mixer
);
}
} else {
switch (deviceAudio) {
case 0:
Lib.TalkativeLog('-§-SCREEN');
tmpGSP = SCREEN;
break;
case 1:
Lib.TalkativeLog('-§-SCREEN-AUDIO(d)');
tmpGSP = SCREEN_SOUND;
// replace ENCODER-AUDIO
tmpGSP = _replaceAudio(
tmpGSP,
true,
container,
qualityGSP,
mixer
);
break;
default:
Lib.TalkativeLog('-§-SCREEN-AUDIO');
tmpGSP = SCREEN_SOUND;
// replace ENCODER-AUDIO/AUDIO_DEVICE
tmpGSP = _replaceAudio(
tmpGSP,
false,
container,
qualityGSP,
mixer
);
}
}
// compose resolution string
var resolution = _composeResolution(
resolutionType,
resolutionHeight,
resolutionWidth,
resolutionKAR
);
// replace RESOLUTION/ENCODER-VIDEO/CONTAINER
var mapObj = {
_SCREENCAST_RES_: resolution,
_ENCODER_VIDEO_: CONTAINER[container].quality[qualityGSP].vq,
_CONTAINER_: CONTAINER[container].nameGSP,
};
tmpGSP = tmpGSP.replace(
/_SCREENCAST_RES_|_ENCODER_VIDEO_|_CONTAINER_/gi,
match => {
return mapObj[match];
}
);
Lib.TalkativeLog(`-§-final GSP :${tmpGSP}`);
return tmpGSP;
}
/**
* replace audio
*
* @param {string} gspRA input pipeline to be modified
* @param {boolean} defaultAudio whether to use the default audio device
* @param {int} ConTMP selected output container. Used to determine correct audio encoder
* @param {int} QGSPtmp quality setting
* @param {MixerAudio} mixer audio mixer
* @returns {string} pipeline with audio
*/
function _replaceAudio(gspRA, defaultAudio, ConTMP, QGSPtmp, mixer) {
Lib.TalkativeLog(`-§-replace audio default->${defaultAudio}`);
// replace device/encoder
var aq = CONTAINER[ConTMP].quality[QGSPtmp].aq;
Lib.TalkativeLog(`-§-pipeline pre-audio:${gspRA} aq:${aq}`);
var audioPipeline;
if (defaultAudio) {
Lib.TalkativeLog('-§-default audio source');
audioPipeline = gspRA.replace(/_ENCODER_AUDIO_/gi, aq);
} else {
var audiosource = mixer.getAudioSource();
if (audiosource === undefined) {
Lib.TalkativeLog('-§-failure combination of array audio sources');
audioPipeline = gspRA.replace(/_ENCODER_AUDIO_/gi, aq);
} else {
Lib.TalkativeLog('-§-correct audio source assignment');
if (audiosource.indexOf('output') !== -1) {
audiosource += '.monitor';
}
var reDev = `pulsesrc device="${audiosource}"`;
var mapObj = {
pulsesrc: reDev,
_ENCODER_AUDIO_: aq,
};
audioPipeline = gspRA.replace(
/pulsesrc|_ENCODER_AUDIO_/gi,
match => {
return mapObj[match];
}
);
}
}
Lib.TalkativeLog(`-§-pipeline post-audio:${audioPipeline}`);
return audioPipeline;
}
/**
* replace webcam
*
* @param {string} gspRW input pipeline to be modified
* @param {string} device webcam device file (e.g. /dev/video0)
* @param {string} caps quality options
* @param {EasyScreenCastSettings} settings the extension's settings
* @returns {string} pipeline with webcam settings
*/
function _replaceWebcam(gspRW, device, caps, settings) {
Lib.TalkativeLog(`-§-replace webcam -> ${device} caps: ${caps}`);
// replace device/caps
var reDev = `device=${device}`;
var reWCopt = _composeWebCamOption(settings);
var [reWCwidth, reWCheight] = _getWebCamDimension(settings);
Lib.TalkativeLog(`-§-pipeline pre-webcam:${gspRW}`);
var mapObj = {
_WEBCAM_DEV_: reDev,
_WEBCAM_CAP_: caps,
_WEBCAM_OPT_: reWCopt,
_WEBCAM_W_: reWCwidth,
_WEBCAM_H_: reWCheight,
};
var webcamPipeline = gspRW.replace(
/_WEBCAM_DEV_|_WEBCAM_CAP_|_WEBCAM_OPT_|_WEBCAM_W_|_WEBCAM_H_/gi,
match => {
return mapObj[match];
}
);
Lib.TalkativeLog(`-§-pipeline post-webcam:${webcamPipeline}`);
return webcamPipeline;
}
/**
* replace resolution
*
* @param {int} tmpRes resolution type: native/custom
* @param {int} h custom height
* @param {int} w custom width
* @param {boolean} kar whether to keep aspect ratio
* @returns {string} pipeline part for scaling resolution
*/
function _composeResolution(tmpRes, h, w, kar) {
Lib.TalkativeLog(`-§-resolution option: ${tmpRes}`);
var strRes = RESOLUTION[0];
var mapObj = {};
switch (tmpRes) {
case -1:
break;
case 999:
mapObj = {
_RES_KAR_: kar ? 'true' : 'false',
_RES_HEIGHT_: h,
_RES_WIDTH_: w,
};
strRes = RESOLUTION[1].replace(
/_RES_KAR_|_RES_HEIGHT_|_RES_WIDTH_/gi,
match => {
return mapObj[match];
}
);
break;
default:
mapObj = {
_RES_KAR_: 'true',
_RES_HEIGHT_: h,
_RES_WIDTH_: w,
};
strRes = RESOLUTION[1].replace(
/_RES_KAR_|_RES_WIDTH_|_RES_HEIGHT_/gi,
match => {
return mapObj[match];
}
);
}
Lib.TalkativeLog(`-§-compose resolution: ${strRes}`);
return strRes;
}
/**
* compose option webcam position
*
* @param {EasyScreenCastSettings} settings the extension's settings
*
* @returns {string}
*/
function _composeWebCamOption(settings) {
Lib.TalkativeLog('-§-compose webcam option');
// retrieve option webcam
var webcamAlpha = settings.getOption('d', Settings.ALPHA_CHANNEL_WEBCAM_SETTING_KEY);
var webcamMarginX = settings.getOption('i', Settings.MARGIN_X_WEBCAM_SETTING_KEY);
var webcamMarginY = settings.getOption('i', Settings.MARGIN_Y_WEBCAM_SETTING_KEY);
var webcamCornerPosition = settings.getOption('i', Settings.CORNER_POSITION_WEBCAM_SETTING_KEY);
var [webcamWidth, webcamHeight, screenWidth, screenHeight] = _getWebCamDimension(settings);
var posX = 0;
var posY = 0;
Lib.TalkativeLog(
`-§-alpha=${webcamAlpha} |marX=${webcamMarginX} |marY=${webcamMarginY} |corner=${webcamCornerPosition}`
);
// corner top-left
posX = webcamMarginX;
posY = webcamMarginY;
switch (webcamCornerPosition) {
case 0:
// corner bottom-right
posX = Math.floor(screenWidth - (webcamWidth + webcamMarginX));
posY = Math.floor(screenHeight - (webcamHeight + webcamMarginY));
break;
case 1:
// corner bottom-left
posX = webcamMarginX;
posY = Math.floor(screenHeight - (webcamHeight + webcamMarginY));
break;
case 2:
// corner top-right
posX = Math.floor(screenWidth - (webcamWidth + webcamMarginX));
posY = webcamMarginY;
break;
default:
}
// check valid position
if ((posX < 0 || posX > screenWidth) && (posY < 0 || posY > screenHeight)) {
Lib.TalkativeLog('-§-NOT valid position');
posX = 0;
posY = 0;
}
var tmpWCopt =
`sink_0::alpha=1 sink_1::alpha=${
webcamAlpha
} sink_1::xpos=${
posX
} sink_1::ypos=${
posY
} `;
Lib.TalkativeLog(`-§-posX=${posX} |posY=${posY}`);
Lib.TalkativeLog(`-§-webcam option=${tmpWCopt}`);
return tmpWCopt;
}
/**
* retrieve dimension webcam
*
* @param {EasyScreenCastSettings} settings the extension's settings
*
* @returns {*[]} array with webcam width,height,screen-width,screen-height
*/
function _getWebCamDimension(settings) {
Lib.TalkativeLog('-§-get webcam dimension');
var webcamWidth = settings.getOption('i', Settings.WIDTH_WEBCAM_SETTING_KEY);
var webcamHeight = settings.getOption('i', Settings.HEIGHT_WEBCAM_SETTING_KEY);
var webcamUnit = settings.getOption('i', Settings.TYPE_UNIT_WEBCAM_SETTING_KEY);
var screenWidth = settings.getOption('i', Settings.WIDTH_SETTING_KEY);
var screenHeight = settings.getOption('i', Settings.HEIGHT_SETTING_KEY);
if (settings.getOption('i', Settings.AREA_SCREEN_SETTING_KEY) === 0) {
screenWidth = global.screen_width;
screenHeight = global.screen_height;
}
Lib.TalkativeLog(
`-§-WC w=${webcamWidth} WC h=${webcamHeight} WCtype=${webcamUnit} screen W=${screenWidth} screen H=${screenHeight}`
);
if (webcamUnit === 0) {
webcamWidth = Math.floor((screenWidth * webcamWidth) / 100);
webcamHeight = Math.floor((screenHeight * webcamHeight) / 100);
}
Lib.TalkativeLog(`-§-after percentage WCw=${webcamWidth} WCh=${webcamHeight}`);
return [webcamWidth, webcamHeight, screenWidth, screenHeight];
}
/**
* get description
*
* @param {int} quality selected quality
* @param {int} container selected container format
* @returns {string}
*/
function getDescr(quality, container) {
Lib.TalkativeLog(`-§-get description Q-> ${quality} C-> ${container}`);
return CONTAINER[container].quality[quality].descr;
}
/**
* get fps
*
* @param {int} quality selected quality
* @param {int} container selected container format
* @returns {number}
*/
function getFps(quality, container) {
Lib.TalkativeLog(`-§-get fps Q-> ${quality} C-> ${container}`);
return CONTAINER[container].quality[quality].fps;
}
/**
* get file extension
*
* @param {int} container selected container format
* @returns {string}
*/
function getFileExtension(container) {
Lib.TalkativeLog(`-§-get file extension C-> ${container}`);
return CONTAINER[container].fileExt;
}
export {composeGSP, getDescr, getFps, getFileExtension};