VideoCodecOptions.qml
18.8 KB
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
/* Webcamoid, webcam capture application.
* Copyright (C) 2020 Gonzalo Exequiel Pedone
*
* Webcamoid is free software: you can redistribute it and/or modify
* it under the terms of the GNU General Public License as published by
* the Free Software Foundation, either version 3 of the License, or
* (at your option) any later version.
*
* Webcamoid is distributed in the hope that it will be useful,
* but WITHOUT ANY WARRANTY; without even the implied warranty of
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
* GNU General Public License for more details.
*
* You should have received a copy of the GNU General Public License
* along with Webcamoid. If not, see <http://www.gnu.org/licenses/>.
*
* Web-Site: http://webcamoid.github.io/
*/
import QtQuick
import QtQuick.Controls
import QtQuick.Layouts
import Ak
Dialog {
id: videoCodecOptions
title: qsTr("Video Codec Options")
standardButtons: Dialog.Ok | Dialog.Cancel | Dialog.Reset
width: AkUnit.create(420 * AkTheme.controlScale, "dp").pixels
height: AkUnit.create(320 * AkTheme.controlScale, "dp").pixels
modal: true
property variant controlValues: ({})
property int startChildren: 4
onVisibleChanged: bitrate.forceActiveFocus()
function updateOptions() {
for (let i = mainLayout.children.length - 1; i >= startChildren; i--)
mainLayout.children[i].destroy()
let codecOptions = recording.codecOptions(AkCaps.CapsVideo);
for (let i in codecOptions) {
let option = AkPropertyOption.create(codecOptions[i])
if (option.type != AkPropertyOption.OptionType_Flags) {
let cLabel = controlLabel.createObject(mainLayout);
cLabel.text = option.description
}
let value =
recording.codecOptionValue(AkCaps.CapsVideo, option.name)
switch (option.type) {
case AkPropertyOption.OptionType_String:
if (option.menu.length < 1) {
let cString = controlString.createObject(mainLayout)
cString.key = option.name
cString.defaultValue = option.defaultValue
cString.text = value
cString.onControlChanged.connect(updateValues)
} else {
let cMenu = controlMenu.createObject(mainLayout)
cMenu.key = option.name
cMenu.defaultValue = option.defaultValue
cMenu.update(option)
cMenu.onControlChanged.connect(updateValues)
}
break
case AkPropertyOption.OptionType_Number:
if (option.menu.length < 1) {
let minimumValue = option.min
let maximumValue = option.max
let stepSize = option.step
let maxSteps = 4096
if ((maximumValue - minimumValue) <= maxSteps * stepSize) {
let cRangeDiscrete = controlRangeDiscrete.createObject(mainLayout)
cRangeDiscrete.key = option.name
cRangeDiscrete.defaultValue = option.defaultValue
cRangeDiscrete.from = minimumValue
cRangeDiscrete.to = maximumValue
cRangeDiscrete.stepSize = stepSize
cRangeDiscrete.value = value
cRangeDiscrete.onControlChanged.connect(updateValues)
} else {
let cRange = controlRange.createObject(mainLayout)
cRange.key = option.name
cRange.defaultValue = option.defaultValue
cRange.text = value
cRange.onControlChanged.connect(updateValues)
}
} else {
let cMenu = controlMenu.createObject(mainLayout)
cMenu.key = option.name
cMenu.defaultValue = option.defaultValue
cMenu.update(option)
cMenu.onControlChanged.connect(updateValues)
}
break
case AkPropertyOption.OptionType_Boolean:
let cBoolean = controlBoolean.createObject(mainLayout)
cBoolean.key = option.name
cBoolean.defaultValue = option.defaultValue
cBoolean.checked = value
cBoolean.onControlChanged.connect(updateValues)
break
case AkPropertyOption.OptionType_Flags:
let cFlags = controlFlags.createObject(mainLayout)
cFlags.key = option.name
cFlags.defaultValue = option.defaultValue
cFlags.title = option.description
cFlags.update(option)
cFlags.onControlChanged.connect(updateValues)
break
case AkPropertyOption.OptionType_Frac:
let cFrac = controlFrac.createObject(mainLayout)
cFrac.key = option.name
cFrac.defaultValue = option.defaultValue
cFrac.text = value
cFrac.onControlChanged.connect(updateValues)
break
case AkPropertyOption.OptionType_ImageSize:
let cImageSize = controlImageSize.createObject(mainLayout)
cImageSize.key = option.name
cImageSize.defaultValue = option.defaultValue
cImageSize.text = value
cImageSize.onControlChanged.connect(updateValues)
break
default:
break
}
}
}
function updateValues(key, value) {
controlValues[key] = value
}
Connections {
target: recording
function onBitrateChanged(type, bitrate)
{
if (type == AkCaps.CapsVideo)
bitrate.text = bitrate
}
function onVideoGOPChanged(gop)
{
videoGOP.text = gop
}
function onCodecOptionsChanged(type, options)
{
videoCodecOptions.updateOptions()
}
}
ScrollView {
id: scrollView
anchors.fill: parent
contentHeight: mainLayout.height
clip: true
GridLayout {
id: mainLayout
columns: 2
width: scrollView.width
Label {
id: txtBitrate
text: qsTr("Bitrate")
}
TextField {
id: bitrate
placeholderText: qsTr("Bitrate (bits/secs)")
Accessible.name: txtBitrate.text
selectByMouse: true
validator: RegularExpressionValidator {
regularExpression: /\d+/
}
Layout.fillWidth: true
Component.onCompleted:
text = recording.bitrate(AkCaps.CapsVideo)
}
Label {
id: txtGOP
text: qsTr("Keyframes stride (ms)")
}
TextField {
id: videoGOP
placeholderText: qsTr("1000")
Accessible.name: txtGOP.text
selectByMouse: true
validator: RegularExpressionValidator {
regularExpression: /\d+/
}
Layout.fillWidth: true
Component.onCompleted:
text = recording.videoGOP
}
Component.onCompleted: videoCodecOptions.updateOptions()
}
}
onAccepted: {
recording.setBitrate(AkCaps.CapsVideo,
Number.fromLocaleString(locale, bitrate.text))
recording.videoGOP = Number.fromLocaleString(locale, videoGOP.text)
for (let key in controlValues)
recording.setCodecOptionValue(AkCaps.CapsVideo,
key,
controlValues[key]);
}
onRejected: {
bitrate.text = recording.bitrate(AkCaps.CapsVideo)
videoGOP.text = recording.videoGOP
for (let i in mainLayout.children)
if (mainLayout.children[i].restore)
mainLayout.children[i].restore()
}
onReset: {
bitrate.text = recording.defaultBitrate(AkCaps.CapsAudio)
videoGOP.text = recording.defaultVideoGOP
for (let i in mainLayout.children)
if (mainLayout.children[i].reset)
mainLayout.children[i].reset()
}
Component {
id: controlLabel
Label {
}
}
Component {
id: controlString
TextField {
selectByMouse: true
Layout.fillWidth: true
Accessible.name: key
property string key: ""
property variant defaultValue: null
signal controlChanged(string key, variant value)
function restore() {
text = recording.codecOptionValue(AkCaps.CapsVideo, key)
}
function reset() {
text = defaultValue
}
onTextChanged: controlChanged(key, text)
}
}
Component {
id: controlFrac
TextField {
selectByMouse: true
validator: RegularExpressionValidator {
regularExpression: /-?\d+\/\d+/
}
Layout.fillWidth: true
Accessible.name: key
property string key: ""
property variant defaultValue: null
signal controlChanged(string key, variant value)
function restore() {
text = recording.codecOptionValue(AkCaps.CapsVideo, key)
}
function reset() {
text = defaultValue
}
onTextChanged: controlChanged(key, text)
}
}
Component {
id: controlRangeDiscrete
GridLayout {
id: rangeLayout
columns: 2
property string key: ""
property variant defaultValue: null
property real value: 0
property real from: 0
property real to: 1
property real stepSize: 1
signal controlChanged(string key, variant value)
function restore() {
sldRange.value =
recording.codecOptionValue(AkCaps.CapsVideo, key)
}
function reset() {
sldRange.value = defaultValue
}
Slider {
id: sldRange
value: parent.value
from: parent.from
to: parent.to
stepSize: parent.stepSize
Layout.fillWidth: true
Accessible.name: rangeLayout.key
onValueChanged: {
spbRange.value = spbRange.multiplier * value
rangeLayout.controlChanged(rangeLayout.key, value)
}
}
SpinBox {
id: spbRange
value: multiplier * sldRange.value
from: multiplier * parent.from
to: multiplier * parent.to
stepSize: multiplier * parent.stepSize
editable: true
validator: DoubleValidator {
bottom: Math.min(spbRange.from, spbRange.to)
top: Math.max(spbRange.from, spbRange.to)
}
Accessible.name: rangeLayout.key
readonly property int decimals: parent.stepSize < 1? 2: 0
readonly property int multiplier: Math.pow(10, decimals)
textFromValue: function(value, locale) {
return Number(value / multiplier).toLocaleString(locale, 'f', decimals)
}
valueFromText: function(text, locale) {
return Number.fromLocaleString(locale, text) * multiplier
}
onValueModified: sldRange.value = value / multiplier
}
}
}
Component {
id: controlRange
TextField {
selectByMouse: true
validator: RegularExpressionValidator {
regularExpression: /[-+]?(\d+(\.\d*)?|\.\d+)([eE][-+]?\d+)?/
}
Layout.fillWidth: true
Accessible.name: key
property string key: ""
property variant defaultValue: null
signal controlChanged(string key, variant value)
function restore() {
text = recording.codecOptionValue(AkCaps.CapsVideo, key)
}
function reset() {
text = defaultValue
}
onTextChanged: controlChanged(key, Number(text))
}
}
Component {
id: controlBoolean
Switch {
Layout.alignment: Qt.AlignRight | Qt.AlignVCenter
Accessible.name: key
property string key: ""
property variant defaultValue: null
signal controlChanged(string key, variant value)
function restore() {
checked = recording.codecOptionValue(AkCaps.CapsVideo, key)
}
function reset() {
checked = defaultValue
}
onCheckedChanged: controlChanged(key, checked)
}
}
Component {
id: controlMenu
ComboBox {
model: ListModel {
}
textRole: "description"
Layout.fillWidth: true
Accessible.description: key
property string key: ""
property variant defaultValue: null
signal controlChanged(string key, variant value)
function restore() {
let value = recording.codecOptionValue(AkCaps.CapsVideo, key)
for (let i = 0; i < model.count; i++)
if (model.get(i).value == value) {
currentIndex = i
return
}
currentIndex = model.count > 0? 0: -1
}
function reset() {
for (let i = 0; i < model.count; i++)
if (model.get(i).value == defaultValue) {
currentIndex = i
return
}
currentIndex = model.count > 0? 0: -1
}
function update(option)
{
model.clear()
let menu = option.menu
for (let i in menu) {
let menuOption = AkMenuOption.create(menu[i])
model.append({
value: menuOption.value,
description: menuOption.description
})
}
currentIndex = currentMenuIndex(option)
}
function currentMenuIndex(option)
{
let value = recording.codecOptionValue(AkCaps.CapsVideo,
option.name)
let menu = option.menu
for (let i in menu) {
let menuOption = AkMenuOption.create(menu[i])
if (menuOption.value == value)
return i
}
return menu.length > 0? 0: -1
}
onCurrentIndexChanged: {
if (currentIndex >= 0)
controlChanged(key, model.get(currentIndex).value);
}
}
}
Component {
id: controlFlags
GroupBox {
Layout.columnSpan: 2
Layout.fillWidth: true
Accessible.name: key
property string key: ""
property variant defaultValue: null
signal controlChanged(string key, variant value)
ColumnLayout {
id: flagsLayout
anchors.fill: parent
}
Component {
id: classFlag
CheckBox {
Layout.fillWidth: true
property int flagValue: 0
}
}
function restore() {
let value = recording.codecOptionValue(AkCaps.CapsVideo, key)
for (let i in flagsLayout.children) {
flagsLayout.children[i].checked =
value & flagsLayout.children[i].flagValue
}
}
function reset() {
for (let i in flagsLayout.children) {
flagsLayout.children[i].checked =
defaultValue & flagsLayout.children[i].flagValue
}
}
function update(option)
{
// Remove old controls.
for (let i = flagsLayout.children.length - 1; i >= 0; i--)
flagsLayout.children[i].destroy()
let value = recording.codecOptionValue(AkCaps.CapsVideo,
option.name)
let menu = option.menu
// Create new ones.
for (let i in menu) {
let menuOption = AkMenuOption.create(menu[i])
let flag = classFlag.createObject(flagsLayout)
flag.text = menuOption.description
flag.flagValue = menuOption.value
flag.checked = value & menuOption.value
flag.onCheckedChanged.connect(function (checked)
{
let flags = 0
for (var i in flagsLayout.children) {
if (flagsLayout.children[i].checked)
flags |= flagsLayout.children[i].flagValue
}
controlChanged(key, flags)
})
}
}
}
}
Component {
id: controlImageSize
TextField {
selectByMouse: true
validator: RegularExpressionValidator {
regularExpression: /\d+x\d+/
}
Layout.fillWidth: true
Accessible.name: key
property string key: ""
property variant defaultValue: null
signal controlChanged(string key, variant value)
function restore() {
let value = recording.codecOptionValue(AkCaps.CapsVideo, key)
text = value.width + "x" + value.height
}
function reset() {
text = defaultValue
}
onTextChanged: {
let sizeParts = text.split("x")
let width = Number.fromLocaleString(locale, sizeParts[0])
let height = Number.fromLocaleString(locale, sizeParts[1])
controlChanged(key, Qt.size(width, height))
}
}
}
}