-
Notifications
You must be signed in to change notification settings - Fork 3
Expand file tree
/
Copy pathMCTD_.avsi
More file actions
1693 lines (1509 loc) · 133 KB
/
MCTD_.avsi
File metadata and controls
1693 lines (1509 loc) · 133 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
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
739
740
741
742
743
744
745
746
747
748
749
750
751
752
753
754
755
756
757
758
759
760
761
762
763
764
765
766
767
768
769
770
771
772
773
774
775
776
777
778
779
780
781
782
783
784
785
786
787
788
789
790
791
792
793
794
795
796
797
798
799
800
801
802
803
804
805
806
807
808
809
810
811
812
813
814
815
816
817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
840
841
842
843
844
845
846
847
848
849
850
851
852
853
854
855
856
857
858
859
860
861
862
863
864
865
866
867
868
869
870
871
872
873
874
875
876
877
878
879
880
881
882
883
884
885
886
887
888
889
890
891
892
893
894
895
896
897
898
899
900
901
902
903
904
905
906
907
908
909
910
911
912
913
914
915
916
917
918
919
920
921
922
923
924
925
926
927
928
929
930
931
932
933
934
935
936
937
938
939
940
941
942
943
944
945
946
947
948
949
950
951
952
953
954
955
956
957
958
959
960
961
962
963
964
965
966
967
968
969
970
971
972
973
974
975
976
977
978
979
980
981
982
983
984
985
986
987
988
989
990
991
992
993
994
995
996
997
998
999
1000
###########################################################################################################################
### ###
### Motion-Compensated Temporal Denoise: MCTD() ###
### ###
### v1.4.20 by "LaTo INV.", mod4.3 by 06_taro, mod4.4 ###
### ###
### ###
### 15 Oct 2022 ###
### ###
### ###
###########################################################################################################################
###
###
###
### /!\ Needed filters: MVTools2, MaskTools2,
### ------------------- LSFmod, FFT3Dgpu or FFT3Dfilter,
### vsTTempsmooth, RemoveGrain + Repair,
### Deblock, Deblock_QED, DctFilter,
### EEDI2, SangNom2,
### GradFun3DBmod, GradFun3, AddGrainC,
### Dither (https://gitlab.com/uvz/AviSynthPlus-Plugins-Scripts/-/blob/master/plugins64%2B/dither.dll).
###
###
###
### USAGE: MCTD(i, radius, sigma, twopass, useTTmpSm, limit, limitC, limit2, limitC2, post, chroma, interlaced, refine, pMode,
### sharp, adapt, strength, SHmode, SHmethod, Slimit, Sovershoot, Tlimit, Tovershoot, ssource, shF,
### protect, cutoff, threshold, maxdiff,
### AA, useEEDI2, reduc, maxd, AAthr, method, aaF,
### deblock, useQED, quant1, quant2,
### edgeclean, ECrad, ECthr, ECmode,
### stabilize, maxr, lthresh, cthresh, TTstr, stF,
### enhance, GFthr, AGstr, bias, temp, dbF,
### bwbh, owoh, blksize, overlap,
### GPU, fixband, bt, ncpu, precision,
### thSAD, thSAD2, thSCD1, thSCD2,
### truemotion, MVglobal, pel, pelsearch, search, searchparam, MVsharp, DCT,
### p, settings, useMMask,
### show, screenW, screenH,
### p1nr, p2nr, ppnr, pp)
###
###
###
### PARAMETERS:
### -----------
###
### +---------+
### | DENOISE |
### +---------+-------------------------------------------------------------------------------------------+
### | radius : Temporal radius [1...6] |
### | sigma : FFT3D sigma for the pre-filtering clip [0=no pre-filtering,1...] |
### | twopass : Do the denoising job in 2 stages (stronger but very slow) |
### | useTTmpSm : Use MDegrain (faster) or MCompensate+vsTTempsmooth (stronger) |
### | limit : Limit the effect of the first denoising [-2=luma-adaptive-auto,-1=auto,0=off,1...255] |
### | limitC : Limit the effect of the first denoising on chroma planes +--same--+ |
### | limit2 : Limit the effect of the second denoising (if twopass=true) | as | |
### | limit2 : Limit the effect of the second denoising on chroma planes (if twopass=true) +-limit--+ |
### | post : Sigma value for post-denoising with FFT3D (before all the PP stage) [0=off,...] |
### | /!\ Absolute value is taken, i.e., post=-2 is valid |
### | /!\ When post < 0, do not apply gradfun2db after post-denoising even if fixband==true |
### | chroma : Process or not the chroma plane |
### | interlaced : Input video interlaced or not |
### | refine : Refines and recalculate the analyzed motion vector for more robust result or not |
### | pMode : pre-filter mode (0 = off |
### | 1 = Luma-adaptive prefilter to bias to protect dark edges |
### | 2 = 1 plus expanding TV range to PC range for easier motion estimate) |
### | p1nr : Use your own denoising filter instead of internal MDegrain/vsTTempsmooth in the 1st pass |
### | p2nr : Use your own denoising filter instead of internal MDegrain/vsTTempsmooth in the 2nd pass |
### | ppnr : Use your own denoising filter instead of internal FFT3D in post-denoising |
### | (Set your filter in string, e.g., p1nr="FluxSmoothST(7, 7)") |
### +-----------------------------------------------------------------------------------------------------+
###
###
### +-------+
### | SHARP |
### +-------+-----------------------------------------------------------------------------------------------------------------------------+
### | sharp : Enable Post-Sharpening (Spatial-Sharpening + Motion-compensated temporal limiting) |
### | adapt : Adaptative sharpening --> sharp only static & detailed areas, prevents grain sharpening & save much bitrate (+-10/15%) |
### | strength : Sharpening strength ( see LSFmod: strength ) |
### | SHmode : Sharpening mode ( see LSFmod: Smode ) |
### | SHmethod : Sharpening method ( see LSFmod: Smethod ) |
### | Slimit : Spatial limiting ( see LSFmod: Lmode ) |
### | Sovershoot : Spatial overshoot ( see LSFmod: overshoot ) |
### | Tlimit : Temporal limiting (Motion compensated, clamp output to Tovershoot) |
### | Tovershoot : Temporal overshoot, = Maximum sharpening excess allowed (If Tovershoot=0, don't sharp more than the original clip.) |
### | /!\ If you set Tovershoot>0, be sure that Slimit!=0 (to not over-enhance edges... Slimit=2 is a good compromise) |
### | ssource : Can be either clip or bool |
### | If ssource is defined as a clip, MCTD doesn't sharp more a denoised clip than this ssource clip ( see LSFmod: source ) |
### | If ssource is bool and is True, MCTD doesn't sharp more a denoised clip than this the input clip |
### | shF : Use your own sharpening filter instead of internal LSFmod (Set your filter in string, e.g., shF="Sharpen(0.3)") |
### +-------------------------------------------------------------------------------------------------------------------------------------+
###
###
### +---------------------------------+
### | STAR & BRIGHT POINTS PROTECTION |
### +---------------------------------+---------------------------------------------------------------------------------------+
### | protect : Enable star & bright points protection |
### | cutoff : Luma cutoff (process only brighter areas than this value) [0=all,1...255] |
### | threshold : Luma threshold (minimal change needed to be filtered, the higher = the lesser areas are filtered) [0...127] |
### | maxdiff : Maximum change allowed between source and result (the lesser, the brighter) [0=source,1...255] |
### +-------------------------------------------------------------------------------------------------------------------------+
###
###
### +--------------+
### | ANTIALIASING |
### +--------------+----------------------------------------------------------------------------------------------------------------------+
### | AA : Enable antialiasing (only on edges) |
### | useEEDI2 : If true use EEDI2 filtering, else use SANGNOM filtering |
### | reduc : MC-soothe reduc parameter, reduc==-1 turn off "MC-antialiasing" [-1=off,0.0...1.0] |
### | maxd : If EEDI2 is used it's his maxd setting, if SANGNOM is used it's his AA setting (see docs of these filters) |
### | AAthr : Threshold for mask (the higher, the less "small edges" are processed) [0...255] |
### | method : Sharpness for downsize [0=bilinear,1=spline36,2=lanczos4] |
### | aaF : Use your own anti-aliasing filter instead of internal SANGNOM/EEDI2 (Set your filter in string, e.g., aaF="Sangnom(48)") |
### +-------------------------------------------------------------------------------------------------------------------------------------+
###
###
### +---------+
### | DEBLOCK |
### +---------+-----------------------------------------------------------------------------------+
### | deblock : Enable deblocking before the denoising |
### | useQED : If true, use Deblock_QED, else use Deblock (faster & stronger) |
### | quant1 : Deblock_QED "quant1" parameter (Deblock "quant" parameter is "(quant1+quant2)/2") |
### | quant2 : Deblock_QED "quant2" parameter (Deblock "quant" parameter is "(quant1+quant2)/2") |
### +---------------------------------------------------------------------------------------------+
###
###
### +------------------------------+
### | EDGECLEAN: DERING, DEHALO... |
### +------------------------------+-----------------------------------------------------------------------------------------------------+
### | edgeclean : Enable safe edgeclean process after the denoising (only on edges which are in non-detailed areas, so less detail loss) |
### | ECrad : Radius for mask (the higher, the greater distance from the edge is filtered) |
### | ECthr : Threshold for mask (the higher, the less "small edges" are process) [0...255] |
### | ECmode : Script/Filter used for cleaning edges (ex: "dfttest().dehalo_alpha()", don't forget quotes "") |
### +------------------------------------------------------------------------------------------------------------------------------------+
###
###
### +-----------+
### | STABILIZE |
### +-----------+------------------------------------------------------------------------------------------------+
### | stabilize : Enable TTempSmooth post processing to stabilize flat areas (background will be less "nervous") |
### | maxr : Temporal radius (the higher, the more stable image) |
### | lthresh : luma and motion thesholds (see TTempSmooth docs) |
### | cthresh : chroma and motion thesholds (see TTempSmooth docs) |
### | TTstr : Strength (see TTempSmooth docs) |
### | stF : Use your own stabilizing filter instead of internal TTempSmoothF (Set your filter in string) |
### +------------------------------------------------------------------------------------------------------------+
###
###
### +---------+
### | ENHANCE |
### +---------+-----------------------------------------------------------------------------------------------------------------------------------------------------------+
### | enhance : Enable GradFun3DBmod post processing to enhance flat areas (may avoid banding & blocking when encoding too) |
### | GFthr : Gradfun2db threshold [1.0=off,...] |
### | AGstr : AddGrain strength [0.0=off,...] |
### | bias : Brightness bias for adaptative grain mask (the higher, the less grain in dark areas & the more grain in bright areas) [-1=off,0=input,1...254,255=invert] |
### | temp : Temporal stabilization for grain (the higher, the more calm) [0=nervous,...,100=static] |
### | dbF : Use your own debanding filter instead of internal GradFun3dbmod (Set your filter in string, e.g., dbF="f3kdb(31, 32, 0, 0)") |
### | - filter with stacked 16-bit output is allowed, e.g., dbF="f3kdb(output_depth=16, output_mode=1)" |
### +---------------------------------------------------------------------------------------------------------------------------------------------------------------------+
###
###
### +---------------------+
### | BLOCKSIZE / OVERLAP |
### +---------------------+----------------+
### | bwbh : FFT3D blocksize |
### | owoh : FFT3D overlap |
### | - for speed: bwbh/4 |
### | - for quality: bwbh/2 |
### | blksize : MVTools blocksize |
### | overlap : MVTools overlap |
### | - for speed: blksize/4 |
### | - for quality: blksize/2 |
### +--------------------------------------+
###
###
### +-------+
### | FFT3D |
### +-------+---------------------------------------+
### | GPU : Use FFT3Dgpu instead of FFT3Dfilter |
### | fixband : Prevent banding issue with FFT3D |
### +---------------------------------------+-------+
### | bt : FFT3D block temporal size |
### | precision : FFT3Dgpu precision |
### +---------------------------------------+
###
###
### +---------+
### | MVTOOLS |
### +---------+----------------------------------------------------+
### | thSAD : MVTools thSAD for the first pass |
### | thSAD2 : MVTools thSAD for the second pass (if twopass=true) |
### | thSCD1 : MVTools thSCD1 |
### | thSCD2 : MVTools thSCD2 |
### +-----------------------------------+--------------------------+
### | truemotion : MVTools truemotion |
### | MVglobal : MVTools global |
### | pel : MVTools pel |
### | pelsearch : MVTools pelsearch |
### | search : MVTools search |
### | searchparam : MVTools searchparam |
### | MVsharp : MVTools sharp |
### | DCT : MVTools DCT |
### +-----------------------------------+
###
###
### +--------+
### | GLOBAL |
### +--------+--------------------------------------------------------------------------------------+
### | ncpu : Used threads [<0-threads for internal multithreading,>0-FFT3Dfilter ncpu] |
### | p : Set an external prefilter clip |
### | settings : Global MCTD settings [default="low"] |
### | - "very low" |
### | - "low" |
### | - "medium" |
### | - "high" |
### | - "very high" |
### | useMMask : Enable motion mask for sharp/stabilize/enhance along with edge mask [default=true] |
### | pp : Enable MCTDmod_PP for post-processing [default=true] |
### +-----------------------------------------------------------------------------------------------+
###
###
### +-------+
### | DEBUG |
### +-------+------------------------------------------------+
### | show : Show debug clip & informations |
### | screenW : Screen horizontal resolution (for show clip) |
### | screenH : Screen vertical resolution (for show clip) |
### +--------------------------------------------------------+
###
###
###
### DEFAULTS:
### ---------
###
### +-------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+
### | SETTINGS | VERY LOW | LOW | MEDIUM | HIGH | VERY HIGH |
### |-------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------|
### | radius | 1 | 2 | 3 | 2 | 3 |
### | sigma | 2 | 4 | 8 | 12 | 16 |
### | twopass | false | false | false | true | true |
### | useTTmpSm | false | false | false | false | false |
### | limit | -1 | -1 | -1 | -1 | 0 |
### | limitC | same as limit | same as limit | same as limit | same as limit | same as limit |
### | limit2 | -1 | -1 | -1 | 0 | 0 |
### | limitC2 | same as limit2 | same as limit2 | same as limit2 | same as limit2 | same as limit2 |
### | post | 0 | 0 | 0 | 0 | 0 |
### | chroma | false | false | true | true | true |
### | interlaced | false | false | false | false | false |
### | refine | false | false | false | false | false |
### | pMode | 0 | 0 | 0 | 0 | 0 |
### |-------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------|
### | sharp | true | true | true | true | true |
### | adapt | true | true | true | true | true |
### | strength | 100 | 100 | 150 | 200 | 200 |
### | SHmode | 3 | 3 | 3 | 3 | 3 |
### | SHmethod | 3 | 3 | 3 | 3 | 3 |
### | Slimit | 0 | 0 | 0 | 0 | 0 |
### | Sovershoot | 0 | 0 | 0 | 0 | 0 |
### | Tlimit | true | true | true | true | true |
### | Tovershoot | 2 | 2 | 1 | 0 | 0 |
### | ssource | false | false | false | false | false |
### | shF | "internal" | "internal" | "internal" | "internal" | "internal" |
### |-------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------|
### | protect | false | false | false | false | false |
### | cutoff | 64 | 64 | 64 | 64 | 64 |
### | threshold | 16 | 16 | 16 | 16 | 16 |
### | maxdiff | 4 | 4 | 4 | 4 | 4 |
### |-------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------|
### | AA | false | false | false | false | false |
### | useEEDI2 | true | true | false | false | false |
### | reduc | 0.5 | 0.5 | 0.5 | 0.5 | 0.5 |
### | maxd | 24 | 24 | 48 | 48 | 48 |
### | AAthr | 64 | 32 | 32 | 16 | 16 |
### | method | 2 | 1 | 1 | 0 | 0 |
### | aaF | "internal" | "internal" | "internal" | "internal" | "internal" |
### |-------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------|
### | deblock | false | false | false | false | false |
### | useQED | true | true | true | false | false |
### | quant1 | 10 | 20 | 30 | 30 | 40 |
### | quant2 | 20 | 40 | 60 | 60 | 80 |
### |-------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------|
### | edgeclean | false | false | false | false | false |
### | ECrad | 1 | 2 | 3 | 4 | 5 |
### | ECthr | 32 | 32 | 32 | 16 | 16 |
### | ECmode | "Removegrain(2,0)" | "Removegrain(2,0)" | "Removegrain(2,2)" | "Removegrain(4,4)" | "Removegrain(4,4)" |
### |-------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------|
### | stabilize | false | false | false | true | true |
### | maxr | 1 | 1 | 2 | 2 | 2 |
### | lthresh | 4 | 4 | 4 | 4 | 4 |
### | cthresh | 5 | 5 | 5 | 5 | 5 |
### | TTstr | 1 | 1 | 1 | 2 | 2 |
### | stF | "internal" | "internal" | "internal" | "internal" | "internal" |
### |-------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------|
### | enhance | true | true | false | false | false |
### | GFthr | 1.1 | 1.2 | 1.4 | 1.6 | 1.8 |
### | AGstr | 0.6 | 0.8 | 1.2 | 1.8 | 2.4 |
### | bias | 64 | 64 | 64 | 64 | 64 |
### | temp | 50 | 50 | 50 | 50 | 50 |
### | dbF | "internal" | "internal" | "internal" | "internal" | "internal" |
### |-------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------|
### | bwbh | HD?16:8 | HD?16:8 | HD?16:8 | HD?16:8 | HD?16:8 |
### | owoh | HD? 8:4 | HD? 8:4 | HD? 8:4 | HD? 8:4 | HD? 8:4 |
### | blksize | HD?16:8 | HD?16:8 | HD?16:8 | HD?16:8 | HD?16:8 |
### | overlap | HD? 8:4 | HD? 8:4 | HD? 8:4 | HD? 8:4 | HD? 8:4 |
### |-------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------|
### | GPU | false | false | false | false | false |
### | fixband | true | true | true | true | true |
### | bt | 1 | 3 | 3 | 3 | 4 |
### | ncpu | 1 | 1 | 1 | 1 | 1 |
### | precision | 2 | 2 | 2 | 2 | 2 |
### |-------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------|
### | thSAD | 200 | 300 | 400 | 500 | 600 |
### | thSAD2 | 200 | 300 | 400 | 500 | 600 |
### | thSCD1 | 200 | 300 | 400 | 500 | 600 |
### | thSCD2 | 90 | 100 | 100 | 130 | 130 |
### |-------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------|
### | truemotion | false | false | false | false | false |
### | MVglobal | true | true | true | true | true |
### | pel | 1 | 2 | 2 | 2 | 2 |
### | pelsearch | 1 | 2 | 2 | 2 | 2 |
### | search | 2 | 2 | 2 | 2 | 2 |
### | searchparam | 2 | 2 | 2 | 2 | 2 |
### | MVsharp | 2 | 2 | 2 | 1 | 0 |
### | DCT | 0 | 0 | 0 | 0 | 0 |
### |-------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------|
### | show | false | false | false | false | false |
### | screenW | 1280 | 1280 | 1280 | 1280 | 1280 |
### | screenH | 1024 | 1024 | 1024 | 1024 | 1024 |
### +-------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+-----------------------------+
###
###
###
### MCTD's Post Processor :
### ------------------------------------
###
### USAGE: MCTDmod_PP( denoised, source,
### sharp, adapt, strength, SHmode, SHmethod, Slimit, Sovershoot, Tlimit, Tovershoot, ssource, shF,
### protect, cutoff, threshold, maxdiff,
### AA, useEEDI2, reduc, maxd, AAthr, method, aaF,
### deblock, useQED, quant1, quant2,
### edgeclean, ECrad, ECthr, ECmode,
### stabilize, maxr, lthresh, cthresh, TTstr, stF,
### enhance, GFthr, AGstr, bias, temp, dbF,
### chroma, settings, useMMask )
###
### This is the post-processor used internally in MCTD.
### It can be called externally if you want some specific functionality without denoising.
###
### Parameters & defaults are the same as MCTD.
### By default, all filters are OFF!
###
### "Sharp" & "Protect" options need 2 inputs:
### EX: source=last
### denoised=source.FFT3Dfilter()
### MCTDmod_PP(denoised,source,...)
### The others only need "denoised".
###
###
###
### MCTD's Internal multithreading :
### ------------------------------------
###
### It requires significant amount of RAM.
### Always use SetMemoryMax(...) at the beginning of the script.
###
### Do not use prefetch() after MCTD.
###
### Always start from ncpu=-2 and decrease by 2 (-4,-6,-8...) until find the optimal value.
###
###
###
### CHANGELOG:
### ----------
###
### v1.4.20 mod4.4: Implemented internal multithreading.
###
### mt_lutxy syntax fixed when AA used.
###
### Fixed sharpening internal masks. (high bit depth)
###
### Fixed the high bit depth processing
### Replaced GradFun2DBmod with GradFun3DBmod
###
### Changed the names of the internal conflicted functions (realfinder)
###
### Added support for 10..16-bit clips.
###
### Replaced TTempSmooth(F) with vsTTempSmooth.
###
### replaced SangNom with SangNom2
###
### changed int "limit" to float "limit and int "limitC" to float "limitC"; changed GradFun2db to GradFun3 in prefiltering and in post-denoising (for the internal filter)
###
### v1.4.20 mod4.3: fix ""I don't know what "refine" means"" When the MCTemporalDenoise and MCTD in auto-load folder
###
### v1.4.20 mod4.2: fix documents and code comments of pMode
###
### v1.4.20 mod4.1: recalculate motion vectors for the second pass if refine=True
### recalculate motion masks and motion compensated frames of delta=1 for the second pass properly
### try to use native MDegrainN when radius > 3, but still keep backward capability with official mvtools2
###
### v1.4.20 mod4: rework on pMode's adaptive pre-filter, use [0:255 16:255 75:0 255:0] gradient mask map instead of [0:x bias:255 255:y](x=0 or y=0)
###
### v1.4.20 mod3.8: only use the finest hierarchical level for MSuper when capable
### added "refine" to recalculate super clip for more robust motion estimation
### added "pMode" to use adaptviely pre-filtered or even range-expanded clip for motion search
### added negative "sigma" value to use dfttest as a frequency-based adaptive pre-filter
### separate "limitC" and "limitC2" from "limit" and "limit2" to define different limit value for chroma planes
### added -2 for limit* to use luma-adaptive auto-limit mode
###
### v1.4.20 mod3.7: bug fixes
### added "ssource" as lsfmod's "source" clip
###
### v1.4.20 mod3.6: adjusted merge16_8 usage to latest version of dither package
###
### v1.4.20 mod3.5: now accept negative value of post as sigma ( was only used to define whether fixband is used on post-denoise, and must be used with custom "ppnr" )
### added "useMMask" in MCTD to turn motion mask on/off for sharpen/stabilize/enhance
###
### v1.4.20 mod3.4: fully supported Y/U/V in -65535~5 of MCPP_merge16_8, although MCTDmod_PP only needs value of 1/3
###
### v1.4.20 mod3.3: added "stF" to allow custom stabilizing filter
###
### v1.4.20 mod3.2: made lthresh/cthresh changeable
###
### v1.4.20 mod3.1: added "useMMask" in MCTDmod_PP to turn motion mask on/off for sharpen/stabilize/enhance
### changed the type of "sigma" from int to float
###
### v1.4.20 mod3: fixed scene change frames not being filtered correctly with sharp/stabilize/enhance
### added "pp" in MCTD to turn all post-processing in MCTDmod_PP off
### supported stacked 16-bit output for custom "dbF" ( mainly implemented by SAPikachu )
###
### v1.4.20 mod2: removed deblock mod16 warnings when deblock=true, pad and crop internally
### updated Deblock_QED with custom bug fix
###
### v1.4.20 mod : added "p1nr", "p2nr", "ppnr", "shF", "aaF", "dbF" to allow custom filters
###
### v1.4.20 : tweaked some settings
### updated QED_Deblock version
###
### v1.4.18 : fixed anti-aliasing PP (was broken since v1.4.07)
### updated MVTools-MaskTools-AddgrainC version
###
### v1.4.16 : added switch to avoid loading of unused filters
### fixed a bug in anti-aliasing part
###
### v1.4.08 : fixed MOD16 warning when deblock=true
###
### v1.4.07 : improved masking in PP-stage
### cleaned code (cosmetic)
###
### v1.4.00 : fixed bug with maxdiff=0
### fixed speed issue in MCTemporalDenoisePP (+20%)
### added "deblock" to MCTemporalDenoisePP
### changed "flat" to "enhance"
### cleaned and optimized all the code
### changed some settings
### updated documentation
###
### v1.3.09 : added MOD4 restriction
### updated MVTools version
###
### v1.3.00 : added a post-denoising stage (see "post")
### fixed a bug with fixFFT3D and defined p clip
### changed "very high" to be less insane
### renamed fixFFT3D to fixband
### cleaned some stuff
### adapted to LSFmod v1.8
###
### v1.2.02 : changed default gpu=true to gpu=false (set gpu=true if you want speed!!!)
### adapted to LSFmod v1.7
###
### v1.2.00 : adapted for LSFmod v1.6 & GradFun2DBmod v1.3
### changed sharp int->bool (deleted sharp=1)
###
### v1.1.27 : fixed a bug in MCTemporalDenoisePP with chroma=false
### adapted for LSFmod v1.5
###
### v1.1.26 : changed "flat" post-processing to use GradFun2DBmod
### changed int->float for AGstr
### fixed a small bug in AA
###
### v1.1.24 : fixed a chroma bug with PP
###
### v1.1.23 : adapted script for MvTools v2.3.0 (deleted MT & idx parameters)
### changed MCTemporalDenoisePP's defaults (now the same as MCTemporalDenoise)
### deleted safe parameter (slow & useless)
### changed some minor things
###
### v1.0.03 : fixed a bug in MCTemporalDenoisePP
###
### v1.0.02 : changed defaults according to new LSFmod v1.2
###
### v1.0.01 : fixed a speed issue in MCTemporalDenoisePP (introduced in beta5)
### changed documentation about MCTemporalDenoisePP
###
### v1.0.00 : first stable version
### changed sharp=2, need LSFmod v1.0 !
### fixed a bug introduced in beta5
###
### 1.0beta5: added new sharpening routine & deleted LSF (SHmode,Slimit,Sovershoot,Tlimit,Tovershoot)
### changed some code (cosmetic)
###
### 1.0beta4: changed some descriptions & blksize default (submitted by Didée)
### added auto blksize setting (16:HD & 8:SD, if you want speed use 16)
###
### 1.0beta3: all post-processing filters are now usable as a standalone function (MCTemporalDenoisePP)
### added MC-antialiasing (see reduc parameter)
###
### 1.0beta2: fixed MOD16 restriction (effective only if deblock=true)
### small speedup/fix with limit>0 and/or protect=true&maxdiff>0
### added warning about GPU & MT in the documentation
###
### 1.0beta1: changed name Udegrain --> MCTemporalDenoise (to be more specific and avoid confusion with chroma)
### added the choice to use MDegrain (since the chroma bug in MDegrain is fixed, +50% speed)
### added twopass option to do the denoising job in two stage (very effective but slow)
### added MT parameter for MVTools (be careful +- unstable)
### added fixFFT3D parameter to prevent banding/posterize with limit=-1
### added stabilize options (stabilize,maxr,TTstr)
### added deblock options (deblock,useQED,quant1,quant2)
### added new presets "light"(=low)/"heavy"(=medium) --> 5 presets (very high is 'a bit' extrem)
### added check/warning for some settings
### added thSAD2 & limit2 parameters for twopass=true
### added overrange parameter for controling sharpness (useful for sharpening more than the source)
### changed +- much code to implement twopass/MDegrain/MT, should be bug free (I hope)
### changed sharp->MVsharp & post->sharp
### changed "light Smode4" --> LimitedSharpenFaster for sharp=2 (strength,Smode,overshoot)
### reduced max radius to 6
### optimized chroma in PP stage (+20% with all PP on)
### fixed a bug with external p clip
### fixed a bug in Star&Bright Point Protection with maxdiff>0
### added YV12&MOD16 restriction
### changed some settings due to new presets
### restriction when using MT=true: bt=1 in FFT3Dgpu & plane=4 in MDegrainMulti (will be removed when fixed)
###
### v0.9.05a: changed version number: vX.XX branch -> v0.X.XX branch
### added AA options (AA,useEEDI2,maxd,AAthr,method)
### changed dering --> edgeclean: you can now use your own script
### fixed bug with show=true
### fixed bug with chroma in PP stage
### fixed omission with chroma=false in MAnalyse
### changed some settings
### added changelog in .avsi
###
### v0.9.01a: added adapt & SS for sharpening
### added dering option (dering, DRGrad, DRGthr, RGmode)
### added flat areas processing (flat, AGstr, GFthr, bias)
### added modX(=blocksize) checking
### changed some default settings
### updated documentation in .avsi
###
### v0.8.08c: fixed bug with chroma=false & interlaced=true
###
### v0.8.08b: added mocomp contra-sharpening (basic contra-sharpening always usable)
###
### v0.7.29a: added star & bright points protection
### changed some default options
### added more options for FFT3D
### added YV12 checking
###
### v0.7.25a: changed to chroma=false for light settings
### added temporal limiter for sharpening
###
### v0.7.24a: replaced blankclip by nop
###
### v0.7.23a: first public release
###
####################################################################################################################################
function MCTD( clip i, int "radius", float "sigma", bool "twopass", bool "useTTmpSm", float "limit", float "limitC", int "limit2", int "limitC2", float "post",
\ bool "chroma", bool "interlaced", bool "refine", int "pMode",
\ bool "sharp", bool "adapt", int "strength", int "SHmode", int "SHmethod", int "Slimit", int "Sovershoot", bool "Tlimit", int "Tovershoot", val "ssource", string "shF",
\ bool "protect", int "cutoff", int "threshold", int "maxdiff",
\ bool "AA", bool "useEEDI2", float "reduc", int "maxd", int "AAthr", int "method", string "aaF",
\ bool "deblock", bool "useQED", int "quant1", int "quant2",
\ bool "edgeclean", int "ECrad", int "ECthr", string "ECmode",
\ bool "stabilize", int "maxr", int "lthresh", int "cthresh", int "TTstr", string "stF",
\ bool "enhance", float "GFthr", float "AGstr", int "bias", int "temp", string "dbF",
\ int "bwbh", int "owoh", int "blksize", int "overlap",
\ bool "GPU", bool "fixband", int "bt", int "ncpu", int "precision",
\ int "thSAD", int "thSAD2", int "thSCD1", int "thSCD2",
\ bool "truemotion", bool "MVglobal", int "pel", int "pelsearch", int "search", int "searchparam", int "MVsharp", int "DCT",
\ clip "p", string "settings", bool "useMMask",
\ bool "show", int "screenW", int "screenH",
\ string "p1nr", string "p2nr", string "ppnr", bool "pp" )
{
### VERSION
version = "v1.4.20 mod4.4"
Assert(IsYUV(i) == True ? true : false, chr(10) + "This is not an YUV clip ! Please convert color space to YUV before using MCTD()" + chr(10))
Assert(ComponentSize(i) < 4 ? true : false, chr(10) + "Clip bit depth must be between 8..16-bit before using MCTD()" + chr(10))
### SETTINGS
settings = Default(settings, "low")
useMMask = Default(useMMask, true)
pp = Default(pp, true)
settings_num = -1
settings_num = (settings == "very low") ? 0 : settings_num
settings_num = (settings == "low") ? 1 : settings_num
settings_num = (settings == "medium") ? 2 : settings_num
settings_num = (settings == "high") ? 3 : settings_num
settings_num = (settings == "very high") ? 4 : settings_num
Assert(settings_num >=0 ? true : false, chr(10) + "These settings do not exist !" + chr(10))
function MCTDmod_Defaults(clip clp, int "settings_num", string "setting")
{
HD = (clp.width > 1024 || clp.height > 576) ? true : false
### DEFAULTS # VERY LOW # LOW # MEDIUM # HIGH # VERY HIGH #
radius = Select(settings_num, 1 , 2 , 3 , 2 , 3 )
sigma = Select(settings_num, 2 , 4 , 8 , 12 , 16 )
twopass = Select(settings_num, false , false , false , true , true )
useTTmpSm = Select(settings_num, false , false , false , false , false )
limit = Select(settings_num, -1 , -1 , -1 , -1 , 0 )
limit2 = Select(settings_num, -1 , -1 , -1 , 0 , 0 )
post = Select(settings_num, 0 , 0 , 0 , 0 , 0 )
chroma = Select(settings_num, false , false , true , true , true )
interlaced = Select(settings_num, false , false , false , false , false )
refine = Select(settings_num, false , false , false , false , false )
pMode = Select(settings_num, 0 , 0 , 0 , 0 , 0 )
sharp = Select(settings_num, true , true , true , true , true )
adapt = Select(settings_num, true , true , true , true , true )
strength = Select(settings_num, 100 , 100 , 150 , 200 , 200 )
SHmode = Select(settings_num, 3 , 3 , 3 , 3 , 3 )
SHmethod = Select(settings_num, 3 , 3 , 3 , 3 , 3 )
Slimit = Select(settings_num, 0 , 0 , 0 , 0 , 0 )
Sovershoot = Select(settings_num, 0 , 0 , 0 , 0 , 0 )
Tlimit = Select(settings_num, true , true , true , true , true )
Tovershoot = Select(settings_num, 2 , 2 , 1 , 0 , 0 )
ssource = Select(settings_num, false , false , false , false , false )
shF = Select(settings_num, "internal" , "internal" , "internal" , "internal" , "internal" )
protect = Select(settings_num, false , false , false , false , false )
cutoff = Select(settings_num, 64 , 64 , 64 , 64 , 64 )
threshold = Select(settings_num, 16 , 16 , 16 , 16 , 16 )
maxdiff = Select(settings_num, 4 , 4 , 4 , 4 , 4 )
AA = Select(settings_num, false , false , false , false , false )
useEEDI2 = Select(settings_num, true , true , false , false , false )
reduc = Select(settings_num, 0.5 , 0.5 , 0.5 , 0.5 , 0.5 )
maxd = Select(settings_num, 24 , 24 , 48 , 48 , 48 )
AAthr = Select(settings_num, 64 , 32 , 32 , 16 , 16 )
method = Select(settings_num, 2 , 1 , 1 , 0 , 0 )
aaF = Select(settings_num, "internal" , "internal" , "internal" , "internal" , "internal" )
deblock = Select(settings_num, false , false , false , false , false )
useQED = Select(settings_num, true , true , true , false , false )
quant1 = Select(settings_num, 10 , 20 , 30 , 30 , 40 )
quant2 = Select(settings_num, 20 , 40 , 60 , 60 , 80 )
edgeclean = Select(settings_num, false , false , false , false , false )
ECrad = Select(settings_num, 1 , 2 , 3 , 4 , 5 )
ECthr = Select(settings_num, 64 , 32 , 32 , 16 , 16 )
ECmode = Select(settings_num, "Removegrain(2,0)" , "Removegrain(2,0)" , "Removegrain(2,2)" , "Removegrain(4,4)" , "Removegrain(4,4)" )
stabilize = Select(settings_num, false , false , false , true , true )
maxr = Select(settings_num, 1 , 1 , 2 , 2 , 2 )
lthresh = Select(settings_num, 4 , 4 , 4 , 4 , 4 )
cthresh = Select(settings_num, 5 , 5 , 5 , 5 , 5 )
TTstr = Select(settings_num, 1 , 1 , 1 , 2 , 2 )
stF = Select(settings_num, "internal" , "internal" , "internal" , "internal" , "internal" )
enhance = Select(settings_num, true , true , false , false , false )
GFthr = Select(settings_num, 1.1 , 1.2 , 1.4 , 1.6 , 1.8 )
AGstr = Select(settings_num, 0.6 , 0.8 , 1.2 , 1.8 , 2.4 )
bias = Select(settings_num, 64 , 64 , 64 , 64 , 64 )
temp = Select(settings_num, 50 , 50 , 50 , 50 , 50 )
dbF = Select(settings_num, "internal" , "internal" , "internal" , "internal" , "internal" )
bwbh = Select(settings_num, HD?16:8 , HD?16:8 , HD?16:8 , HD?16:8 , HD?16:8 )
owoh = Select(settings_num, HD? 8:4 , HD? 8:4 , HD? 8:4 , HD? 8:4 , HD? 8:4 )
blksize = Select(settings_num, HD?16:8 , HD?16:8 , HD?16:8 , HD?16:8 , HD?16:8 )
overlap = Select(settings_num, HD? 8:4 , HD? 8:4 , HD? 8:4 , HD? 8:4 , HD? 8:4 )
GPU = Select(settings_num, false , false , false , false , false )
fixband = Select(settings_num, true , true , true , true , true )
bt = Select(settings_num, 1 , 3 , 3 , 3 , 4 )
ncpu = Select(settings_num, 1 , 1 , 1 , 1 , 1 )
precision = Select(settings_num, 2 , 2 , 2 , 2 , 2 )
thSAD = Select(settings_num, 200 , 300 , 400 , 500 , 600 )
thSAD2 = Select(settings_num, 200 , 300 , 400 , 500 , 600 )
thSCD1 = Select(settings_num, 200 , 300 , 400 , 500 , 600 )
thSCD2 = Select(settings_num, 90 , 100 , 100 , 130 , 130 )
truemotion = Select(settings_num, false , false , false , false , false )
MVglobal = Select(settings_num, true , true , true , true , true )
pel = Select(settings_num, 1 , 2 , 2 , 2 , 2 )
pelsearch = Select(settings_num, 1 , 2 , 2 , 2 , 2 )
search = Select(settings_num, 2 , 2 , 2 , 2 , 2 )
searchparam = Select(settings_num, 2 , 2 , 2 , 2 , 2 )
MVsharp = Select(settings_num, 2 , 2 , 2 , 1 , 0 )
DCT = Select(settings_num, 0 , 0 , 0 , 0 , 0 )
show = Select(settings_num, false , false , false , false , false )
screenW = Select(settings_num, 1280 , 1280 , 1280 , 1280 , 1280 )
screenH = Select(settings_num, 1024 , 1024 , 1024 , 1024 , 1024 )
return Eval(setting)
}
radius = default(radius, MCTDmod_Defaults( i, settings_num, "radius" ) )
sigma = default(sigma, MCTDmod_Defaults( i, settings_num, "sigma" ) )
twopass = default(twopass, MCTDmod_Defaults( i, settings_num, "twopass" ) )
useTTmpSm = default(useTTmpSm, MCTDmod_Defaults( i, settings_num, "useTTmpSm" ) )
limit = default(limit, MCTDmod_Defaults( i, settings_num, "limit" ) )
limitC = default(limitC, limit )
limit2 = default(limit2, MCTDmod_Defaults( i, settings_num, "limit2" ) )
limitC2 = default(limitC2, limit2 )
post = default(post, MCTDmod_Defaults( i, settings_num, "post" ) )
chroma = default(chroma, MCTDmod_Defaults( i, settings_num, "chroma" ) )
interlaced = default(interlaced, MCTDmod_Defaults( i, settings_num, "interlaced" ) )
refine = default(refine, MCTDmod_Defaults( i, settings_num, "refine" ) )
pMode = default(pMode, MCTDmod_Defaults( i, settings_num, "pMode" ) )
sharp = default(sharp, MCTDmod_Defaults( i, settings_num, "sharp" ) )
adapt = default(adapt, MCTDmod_Defaults( i, settings_num, "adapt" ) )
strength = default(strength, MCTDmod_Defaults( i, settings_num, "strength" ) )
SHmode = default(SHmode, MCTDmod_Defaults( i, settings_num, "SHmode" ) )
SHmethod = default(SHmethod, MCTDmod_Defaults( i, settings_num, "SHmethod" ) )
Slimit = default(Slimit, MCTDmod_Defaults( i, settings_num, "Slimit" ) )
Sovershoot = default(Sovershoot, MCTDmod_Defaults( i, settings_num, "Sovershoot" ) )
Tlimit = default(Tlimit, MCTDmod_Defaults( i, settings_num, "Tlimit" ) )
Tovershoot = default(Tovershoot, MCTDmod_Defaults( i, settings_num, "Tovershoot" ) )
ssource = default(ssource, MCTDmod_Defaults( i, settings_num, "ssource" ) )
shF = default(shF, MCTDmod_Defaults( i, settings_num, "shF" ) )
protect = default(protect, MCTDmod_Defaults( i, settings_num, "protect" ) )
cutoff = default(cutoff, MCTDmod_Defaults( i, settings_num, "cutoff" ) )
threshold = default(threshold, MCTDmod_Defaults( i, settings_num, "threshold" ) )
maxdiff = default(maxdiff, MCTDmod_Defaults( i, settings_num, "maxdiff" ) )
AA = default(AA, MCTDmod_Defaults( i, settings_num, "AA" ) )
useEEDI2 = default(useEEDI2, MCTDmod_Defaults( i, settings_num, "useEEDI2" ) )
reduc = default(reduc, MCTDmod_Defaults( i, settings_num, "reduc" ) )
maxd = default(maxd, MCTDmod_Defaults( i, settings_num, "maxd" ) )
AAthr = default(AAthr, MCTDmod_Defaults( i, settings_num, "AAthr" ) )
method = default(method, MCTDmod_Defaults( i, settings_num, "method" ) )
aaF = default(aaF, MCTDmod_Defaults( i, settings_num, "aaF" ) )
deblock = default(deblock, MCTDmod_Defaults( i, settings_num, "deblock" ) )
useQED = default(useQED, MCTDmod_Defaults( i, settings_num, "useQED" ) )
quant1 = default(quant1, MCTDmod_Defaults( i, settings_num, "quant1" ) )
quant2 = default(quant2, MCTDmod_Defaults( i, settings_num, "quant2" ) )
edgeclean = default(edgeclean, MCTDmod_Defaults( i, settings_num, "edgeclean" ) )
ECrad = default(ECrad, MCTDmod_Defaults( i, settings_num, "ECrad" ) )
ECthr = default(ECthr, MCTDmod_Defaults( i, settings_num, "ECthr" ) )
ECmode = default(ECmode, MCTDmod_Defaults( i, settings_num, "ECmode" ) )
stabilize = default(stabilize, MCTDmod_Defaults( i, settings_num, "stabilize" ) )
maxr = default(maxr, MCTDmod_Defaults( i, settings_num, "maxr" ) )
lthresh = default(lthresh, MCTDmod_Defaults( i, settings_num, "lthresh" ) )
cthresh = default(cthresh, MCTDmod_Defaults( i, settings_num, "cthresh" ) )
TTstr = default(TTstr, MCTDmod_Defaults( i, settings_num, "TTstr" ) )
stF = default(stF, MCTDmod_Defaults( i, settings_num, "stF" ) )
enhance = default(enhance, MCTDmod_Defaults( i, settings_num, "enhance" ) )
GFthr = default(GFthr, MCTDmod_Defaults( i, settings_num, "GFthr" ) )
AGstr = default(AGstr, MCTDmod_Defaults( i, settings_num, "AGstr" ) )
bias = default(bias, MCTDmod_Defaults( i, settings_num, "bias" ) )
temp = default(temp, MCTDmod_Defaults( i, settings_num, "temp" ) )
dbF = default(dbF, MCTDmod_Defaults( i, settings_num, "dbF" ) )
bwbh = default(bwbh, MCTDmod_Defaults( i, settings_num, "bwbh" ) )
owoh = default(owoh, MCTDmod_Defaults( i, settings_num, "owoh" ) )
blksize = default(blksize, MCTDmod_Defaults( i, settings_num, "blksize" ) )
overlap = default(overlap, MCTDmod_Defaults( i, settings_num, "overlap" ) )
GPU = default(GPU, MCTDmod_Defaults( i, settings_num, "GPU" ) )
fixband = default(fixband, MCTDmod_Defaults( i, settings_num, "fixband" ) )
bt = default(bt, MCTDmod_Defaults( i, settings_num, "bt" ) )
ncpu = default(ncpu, MCTDmod_Defaults( i, settings_num, "ncpu" ) )
precision = default(precision, MCTDmod_Defaults( i, settings_num, "precision" ) )
thSAD = default(thSAD, MCTDmod_Defaults( i, settings_num, "thSAD" ) )
thSAD2 = default(thSAD2, MCTDmod_Defaults( i, settings_num, "thSAD2" ) )
thSCD1 = default(thSCD1, MCTDmod_Defaults( i, settings_num, "thSCD1" ) )
thSCD2 = default(thSCD2, MCTDmod_Defaults( i, settings_num, "thSCD2" ) )
truemotion = default(truemotion, MCTDmod_Defaults( i, settings_num, "truemotion" ) )
MVglobal = default(MVglobal, MCTDmod_Defaults( i, settings_num, "MVglobal" ) )
pel = default(pel, MCTDmod_Defaults( i, settings_num, "pel" ) )
pelsearch = default(pelsearch, MCTDmod_Defaults( i, settings_num, "pelsearch" ) )
search = default(search, MCTDmod_Defaults( i, settings_num, "search" ) )
searchparam = default(searchparam, MCTDmod_Defaults( i, settings_num, "searchparam" ) )
MVsharp = default(MVsharp, MCTDmod_Defaults( i, settings_num, "MVsharp" ) )
DCT = default(DCT, MCTDmod_Defaults( i, settings_num, "DCT" ) )
show = default(show, MCTDmod_Defaults( i, settings_num, "show" ) )
screenW = default(screenW, MCTDmod_Defaults( i, settings_num, "screenW" ) )
screenH = default(screenH, MCTDmod_Defaults( i, settings_num, "screenH" ) )
show_p = defined(p) ? "external" : "internal"
rfn_blksize = blksize == 4 ? 4 : blksize / 2
rfn_overlap = overlap == 2 ? 2 : overlap / 4 * 2 + overlap % 4
rfn_thSAD = thSAD / 2
chr41 = chroma?4:1
chr31 = chroma?3:1
chr21 = chroma?2:1
### WARNING
Assert((radius>=1&&radius<=6) ? true : false, chr(10) + "'radius' have not a correct value! [0-6]" + chr(10))
Assert((limit>=-2&&limit<=255) ? true : false, chr(10) + "'limit' have not a correct value! [-2,-1,0,...255]" + chr(10))
Assert((limit2>=-2&&limit2<=255) ? true : false, chr(10) + "'limit2' have not a correct value! [-2,-1,0,...255]" + chr(10))
Assert((Tovershoot>=0) ? true : false, chr(10) + "'Tovershoot' have not a correct value! [>=0]" + chr(10))
Assert((cutoff>=0&&cutoff<=255) ? true : false, chr(10) + "'cutoff' have not a correct value! [0,...,255]" + chr(10))
Assert((threshold>=0&&threshold<=127) ? true : false, chr(10) + "'threshold' have not a correct value! [0,...,127]" + chr(10))
Assert((maxdiff>=0&&maxdiff<=255) ? true : false, chr(10) + "'maxdiff' have not a correct value! [0,...,255]" + chr(10))
Assert((reduc>=-1&&reduc<=1.0) ? true : false, chr(10) + "'reduc' have not a correct value! [-1,0.0,...,1.0]" + chr(10))
Assert((AAthr>=0&&AAthr<=255) ? true : false, chr(10) + "'AAthr' have not a correct value! [0,...,255]" + chr(10))
Assert((method>=0&&method<=2) ? true : false, chr(10) + "'method' have not a correct value! [0,1,2]" + chr(10))
Assert((ECrad>=1) ? true : false, chr(10) + "'ECrad' have not a correct value! [>=1]" + chr(10))
Assert((ECthr>=0&&ECthr<=255) ? true : false, chr(10) + "'ECthr' have not a correct value! [0,...,255]" + chr(10))
Assert((pMode>=0&&pMode<=2) ? true : false, chr(10) + "'pMode' have not a correct value! [0,1,2]" + chr(10))
Assert((ncpu!=0) ? true : false, chr(10) + "'ncpu' have not a correct value! [!=0]" + chr(10))
threads = (ncpu<0) ? Abs(ncpu) : 0
frames = (ncpu>0) ? 0 : threads
ncpu = (ncpu<0) ? 1 : ncpu
### INPUT
i = (interlaced==true) ? i.separatefields() : i
mod = (bwbh>=blksize) ? bwbh : blksize
xi = i.width()
xf = ceil(xi/float(mod))*mod - xi + mod
xn = int(xi+xf)
yi = i.height()
yf = ceil(yi/float(mod))*mod - yi + mod
yn = int(yi+yf)
idb = i
i = i.pointresize(xn,yn,-xf/2,-yf/2,xn,yn)
m4 = ((int(xi/4.0)*4==xi)&&(int(yi/4.0)*4==yi)) ? true : false
Assert( m4 ? true : false, chr(10) + "This is not a MOD4 clip! Please use crop() or addborders() before using MCTD()" + chr(10))
bits_8 = (ComponentSize(i) == 1)
Assert( (!bits_8 && GPU == true) ? false : true, chr(10) + "The clip must be 8-bit in order to use GPU." + chr(10))
### PREFILTERING
p = defined(p) ? p.pointresize(xn,yn,-xf/2,-yf/2,xn,yn)
\ : (sigma==0) ? i
\ : (sigma<0) ? i.dfttest(sstring="0.0:"+string(-sigma*4./3.)+" 0.2:"+string(-sigma*9./3.)+" 1.0:"+string(-sigma*15./3.),tbsize=(bt%2==0)?bt+1:bt,u=chroma,v=chroma,quiet=true,dither=fixband?round(-sigma/11.):0,threads=(threads)>0?1:0).prefetch(threads,frames)
\ : (GPU==false&&fixband==false) ? i.FFT3Dfilter(sigma=sigma*0.8,sigma2=sigma*0.6,sigma3=sigma*0.4,sigma4=sigma*0.2,bw=bwbh,bh=bwbh,ow=owoh,oh=owoh,plane=chroma?4:0,bt=bt,ncpu=ncpu).prefetch(threads,frames)
\ : (GPU==true &&fixband==false) ? i.FFT3Dgpu(sigma=sigma*0.8,sigma2=sigma*0.6,sigma3=sigma*0.4,sigma4=sigma*0.2,bw=bwbh,bh=bwbh,ow=owoh,oh=owoh,plane=chroma?4:0,bt=bt,precision=precision)
\ : (GPU==false&&fixband==true ) ? (bits_8) ? i.FFT3Dfilter(sigma=sigma*0.8,sigma2=sigma*0.6,sigma3=sigma*0.4,sigma4=sigma*0.2,bw=bwbh,bh=bwbh,ow=owoh,oh=owoh,plane=chroma?4:0,bt=bt,ncpu=ncpu).prefetch(threads,frames).GradFun3(thr=0.31 + sigma * 0.05).prefetch(threads,frames)
\ : i.FFT3Dfilter(sigma=sigma*0.8,sigma2=sigma*0.6,sigma3=sigma*0.4,sigma4=sigma*0.2,bw=bwbh,bh=bwbh,ow=owoh,oh=owoh,plane=chroma?4:0,bt=bt,ncpu=ncpu).prefetch(threads,frames).ConvertBits(16).ConvertToStacked().GradFun3(thr=0.31 + sigma * 0.05, lsb=true, lsb_in=true).prefetch(threads,frames).ConvertFromStacked().ConvertBits(BitsPerComponent(i))
\ : i.FFT3Dgpu(sigma=sigma*0.8,sigma2=sigma*0.6,sigma3=sigma*0.4,sigma4=sigma*0.2,bw=bwbh,bh=bwbh,ow=owoh,oh=owoh,plane=chroma?4:0,bt=bt,precision=precision).GradFun3(thr=0.31 + sigma * 0.05).prefetch(threads,frames)
### DEBLOCKING
padX = xi%8 == 0 ? 0 : (8 - xi%8)
padY = yi%8 == 0 ? 0 : (8 - yi%8)
d = (deblock==false) ? i
\ : (useQED==true) ? idb.deblock_QED(quant1=quant1,quant2=quant2,uv=chroma?3:2).prefetch(threads,frames).pointresize(xn,yn,-xf/2,-yf/2,xn,yn)
\ : ( padX==0 && padY==0 ) ? idb.deblock(quant=int(quant1*0.5+quant2*0.5)).prefetch(threads,frames).pointresize(xn,yn,-xf/2,-yf/2,xn,yn)
\ : idb.pointresize(xi+padX, yi+padY, 0, 0, xi+padX, xi+padY).deblock(quant=int(quant1*0.5+quant2*0.5)).prefetch(threads,frames).pointresize(xn,yn,-xf/2,-yf/2,xn-padX,yn-padX)
### PREPARING
nullclip = Blankclip()
range = BitLShift(1, BitsPerComponent(i))
half = BitShr(range, 1)
peak = Float(range - 1)
bias_ = (bits_8) ? bias : Round(bias * peak / 255)
lmsk = p.mt_lut("x " + string(bias_) + " - abs " + string( bias_ >= half ? peak / bias_ : peak / ( peak - bias_ ) ) + " *", U=1, V=1)
pAdp = mt_merge(i, p, lmsk, luma=chroma, U=chr31, V=chr31)
mAdp = mt_merge(p, i, i.mt_lut("x ymin < range_max x 75 scalef > 0 range_max x ymin - range_max 75 scalef ymin - / * - ? ?", U=1, V=1), luma=chroma, U=chr31, V=chr31)
pReb = pMode == 2 ? mAdp.MCTD_Luma_Rebuild(S0=2., c=0.0625, uv=chr31) /* 2: mReb for MC */
\ : pMode == 1 ? mAdp /* 1: mAdp for MC */
\ : p /* 0: p for MC */
pMVS = pReb.MSuper(hpad=0,vpad=0,pel=pel,sharp=MVsharp,rfilter=refine?4:2,chroma=chroma)
rMVS = refine ?
\ pReb.MSuper(hpad=0,vpad=0,pel=pel,sharp=MVsharp,rfilter=2,levels=1,chroma=chroma) : nullclip
f1v = (radius<1) ? nullclip
\ : pMVS.MAnalyse(isb=false, delta=1, truemotion=truemotion, blksize=blksize, overlap=overlap, pelsearch=pelsearch, search=search, searchparam=searchparam, DCT=DCT, global=MVglobal, chroma=chroma)
f2v = (radius<2) ? nullclip
\ : pMVS.MAnalyse(isb=false, delta=2, truemotion=truemotion, blksize=blksize, overlap=overlap, pelsearch=pelsearch, search=search, searchparam=searchparam, DCT=DCT, global=MVglobal, chroma=chroma)
f3v = (radius<3) ? nullclip
\ : pMVS.MAnalyse(isb=false, delta=3, truemotion=truemotion, blksize=blksize, overlap=overlap, pelsearch=pelsearch, search=search, searchparam=searchparam, DCT=DCT, global=MVglobal, chroma=chroma)
f4v = (radius<4) ? nullclip
\ : pMVS.MAnalyse(isb=false, delta=4, truemotion=truemotion, blksize=blksize, overlap=overlap, pelsearch=pelsearch, search=search, searchparam=searchparam, DCT=DCT, global=MVglobal, chroma=chroma)
f5v = (radius<5) ? nullclip
\ : pMVS.MAnalyse(isb=false, delta=5, truemotion=truemotion, blksize=blksize, overlap=overlap, pelsearch=pelsearch, search=search, searchparam=searchparam, DCT=DCT, global=MVglobal, chroma=chroma)
f6v = (radius<6) ? nullclip
\ : pMVS.MAnalyse(isb=false, delta=6, truemotion=truemotion, blksize=blksize, overlap=overlap, pelsearch=pelsearch, search=search, searchparam=searchparam, DCT=DCT, global=MVglobal, chroma=chroma)
b1v = (radius<1) ? nullclip
\ : pMVS.MAnalyse(isb=true, delta=1, truemotion=truemotion, blksize=blksize, overlap=overlap, pelsearch=pelsearch, search=search, searchparam=searchparam, DCT=DCT, global=MVglobal, chroma=chroma)
b2v = (radius<2) ? nullclip
\ : pMVS.MAnalyse(isb=true, delta=2, truemotion=truemotion, blksize=blksize, overlap=overlap, pelsearch=pelsearch, search=search, searchparam=searchparam, DCT=DCT, global=MVglobal, chroma=chroma)
b3v = (radius<3) ? nullclip
\ : pMVS.MAnalyse(isb=true, delta=3, truemotion=truemotion, blksize=blksize, overlap=overlap, pelsearch=pelsearch, search=search, searchparam=searchparam, DCT=DCT, global=MVglobal, chroma=chroma)
b4v = (radius<4) ? nullclip
\ : pMVS.MAnalyse(isb=true, delta=4, truemotion=truemotion, blksize=blksize, overlap=overlap, pelsearch=pelsearch, search=search, searchparam=searchparam, DCT=DCT, global=MVglobal, chroma=chroma)
b5v = (radius<5) ? nullclip
\ : pMVS.MAnalyse(isb=true, delta=5, truemotion=truemotion, blksize=blksize, overlap=overlap, pelsearch=pelsearch, search=search, searchparam=searchparam, DCT=DCT, global=MVglobal, chroma=chroma)
b6v = (radius<6) ? nullclip
\ : pMVS.MAnalyse(isb=true, delta=6, truemotion=truemotion, blksize=blksize, overlap=overlap, pelsearch=pelsearch, search=search, searchparam=searchparam, DCT=DCT, global=MVglobal, chroma=chroma)
f1v = !refine || (radius<1) ? f1v
\ : rMVS.MRecalculate(f1v, truemotion=truemotion, blksize=rfn_blksize, overlap=rfn_overlap, search=search, searchparam=searchparam, DCT=DCT, thSAD=rfn_thSAD, chroma=chroma).prefetch(threads,frames)
f2v = !refine || (radius<2) ? f2v
\ : rMVS.MRecalculate(f2v, truemotion=truemotion, blksize=rfn_blksize, overlap=rfn_overlap, search=search, searchparam=searchparam, DCT=DCT, thSAD=rfn_thSAD, chroma=chroma).prefetch(threads,frames)
f3v = !refine || (radius<3) ? f3v
\ : rMVS.MRecalculate(f3v, truemotion=truemotion, blksize=rfn_blksize, overlap=rfn_overlap, search=search, searchparam=searchparam, DCT=DCT, thSAD=rfn_thSAD, chroma=chroma).prefetch(threads,frames)
f4v = !refine || (radius<4) ? f4v
\ : rMVS.MRecalculate(f4v, truemotion=truemotion, blksize=rfn_blksize, overlap=rfn_overlap, search=search, searchparam=searchparam, DCT=DCT, thSAD=rfn_thSAD, chroma=chroma).prefetch(threads,frames)
f5v = !refine || (radius<5) ? f5v
\ : rMVS.MRecalculate(f5v, truemotion=truemotion, blksize=rfn_blksize, overlap=rfn_overlap, search=search, searchparam=searchparam, DCT=DCT, thSAD=rfn_thSAD, chroma=chroma).prefetch(threads,frames)
f6v = !refine || (radius<6) ? f6v
\ : rMVS.MRecalculate(f6v, truemotion=truemotion, blksize=rfn_blksize, overlap=rfn_overlap, search=search, searchparam=searchparam, DCT=DCT, thSAD=rfn_thSAD, chroma=chroma).prefetch(threads,frames)
b1v = !refine || (radius<1) ? b1v
\ : rMVS.MRecalculate(b1v, truemotion=truemotion, blksize=rfn_blksize, overlap=rfn_overlap, search=search, searchparam=searchparam, DCT=DCT, thSAD=rfn_thSAD, chroma=chroma).prefetch(threads,frames)
b2v = !refine || (radius<2) ? b2v
\ : rMVS.MRecalculate(b2v, truemotion=truemotion, blksize=rfn_blksize, overlap=rfn_overlap, search=search, searchparam=searchparam, DCT=DCT, thSAD=rfn_thSAD, chroma=chroma).prefetch(threads,frames)
b3v = !refine || (radius<3) ? b3v
\ : rMVS.MRecalculate(b3v, truemotion=truemotion, blksize=rfn_blksize, overlap=rfn_overlap, search=search, searchparam=searchparam, DCT=DCT, thSAD=rfn_thSAD, chroma=chroma).prefetch(threads,frames)
b4v = !refine || (radius<4) ? b4v
\ : rMVS.MRecalculate(b4v, truemotion=truemotion, blksize=rfn_blksize, overlap=rfn_overlap, search=search, searchparam=searchparam, DCT=DCT, thSAD=rfn_thSAD, chroma=chroma).prefetch(threads,frames)
b5v = !refine || (radius<5) ? b5v
\ : rMVS.MRecalculate(b5v, truemotion=truemotion, blksize=rfn_blksize, overlap=rfn_overlap, search=search, searchparam=searchparam, DCT=DCT, thSAD=rfn_thSAD, chroma=chroma).prefetch(threads,frames)
b6v = !refine || (radius<6) ? b6v
\ : rMVS.MRecalculate(b6v, truemotion=truemotion, blksize=rfn_blksize, overlap=rfn_overlap, search=search, searchparam=searchparam, DCT=DCT, thSAD=rfn_thSAD, chroma=chroma).prefetch(threads,frames)
function MCTDmod_CTM(clip "i", clip "iMVS", clip "SAD_f1m", clip "SAD_b1m", clip "f1c", clip "b1c",
\ clip "f1v", clip "f2v", clip "f3v", clip "f4v", clip "f5v", clip "f6v", clip "b1v", clip "b2v", clip "b3v", clip "b4v", clip "b5v", clip "b6v",
\ int "radius", bool "chroma", int "thSAD", int "thSCD1", int "thSCD2", string "cnr", int "threads", int "frames")
{
nullclip = BlankClip()
SAD_f2m = (radius>=2) ? i.MMask(f2v, kind=1, ml=thSAD, gamma=0.999, Ysc=255) : nullclip
SAD_f3m = (radius>=3) ? i.MMask(f3v, kind=1, ml=thSAD, gamma=0.999, Ysc=255) : nullclip
SAD_f4m = (radius>=4) ? i.MMask(f4v, kind=1, ml=thSAD, gamma=0.999, Ysc=255) : nullclip
SAD_f5m = (radius>=5) ? i.MMask(f5v, kind=1, ml=thSAD, gamma=0.999, Ysc=255) : nullclip
SAD_f6m = (radius>=6) ? i.MMask(f6v, kind=1, ml=thSAD, gamma=0.999, Ysc=255) : nullclip
SAD_b2m = (radius>=2) ? i.MMask(b2v, kind=1, ml=thSAD, gamma=0.999, Ysc=255) : nullclip
SAD_b3m = (radius>=3) ? i.MMask(b3v, kind=1, ml=thSAD, gamma=0.999, Ysc=255) : nullclip
SAD_b4m = (radius>=4) ? i.MMask(b4v, kind=1, ml=thSAD, gamma=0.999, Ysc=255) : nullclip
SAD_b5m = (radius>=5) ? i.MMask(b5v, kind=1, ml=thSAD, gamma=0.999, Ysc=255) : nullclip
SAD_b6m = (radius>=6) ? i.MMask(b6v, kind=1, ml=thSAD, gamma=0.999, Ysc=255) : nullclip
b = BlankClip(i,color_yuv=$008080)
SAD_m = (radius==6) ? interleave(SAD_f6m, SAD_f5m, SAD_f4m, SAD_f3m, SAD_f2m, SAD_f1m, b, SAD_b1m, SAD_b2m, SAD_b3m, SAD_b4m, SAD_b5m, SAD_b6m).prefetch(threads,frames)
\ : (radius==5) ? interleave( SAD_f5m, SAD_f4m, SAD_f3m, SAD_f2m, SAD_f1m, b, SAD_b1m, SAD_b2m, SAD_b3m, SAD_b4m, SAD_b5m ).prefetch(threads,frames)
\ : (radius==4) ? interleave( SAD_f4m, SAD_f3m, SAD_f2m, SAD_f1m, b, SAD_b1m, SAD_b2m, SAD_b3m, SAD_b4m ).prefetch(threads,frames)
\ : (radius==3) ? interleave( SAD_f3m, SAD_f2m, SAD_f1m, b, SAD_b1m, SAD_b2m, SAD_b3m ).prefetch(threads,frames)
\ : (radius==2) ? interleave( SAD_f2m, SAD_f1m, b, SAD_b1m, SAD_b2m ).prefetch(threads,frames)
\ : (radius==1) ? interleave( SAD_f1m, b, SAD_b1m ).prefetch(threads,frames)
\ : nullclip
b2c = (radius>=2) ? i.MCompensate(iMVS, b2v, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2).prefetch(threads,frames) : nullclip
b3c = (radius>=3) ? i.MCompensate(iMVS, b3v, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2).prefetch(threads,frames) : nullclip
b4c = (radius>=4) ? i.MCompensate(iMVS, b4v, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2).prefetch(threads,frames) : nullclip
b5c = (radius>=5) ? i.MCompensate(iMVS, b5v, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2).prefetch(threads,frames) : nullclip
b6c = (radius>=6) ? i.MCompensate(iMVS, b6v, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2).prefetch(threads,frames) : nullclip
f2c = (radius>=2) ? i.MCompensate(iMVS, f2v, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2).prefetch(threads,frames) : nullclip
f3c = (radius>=3) ? i.MCompensate(iMVS, f3v, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2).prefetch(threads,frames) : nullclip
f4c = (radius>=4) ? i.MCompensate(iMVS, f4v, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2).prefetch(threads,frames) : nullclip
f5c = (radius>=5) ? i.MCompensate(iMVS, f5v, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2).prefetch(threads,frames) : nullclip
f6c = (radius>=6) ? i.MCompensate(iMVS, f6v, thSAD=thSAD, thSCD1=thSCD1, thSCD2=thSCD2).prefetch(threads,frames) : nullclip
c = (radius==6) ? interleave(f6c, f5c, f4c, f3c, f2c, f1c, i, b1c, b2c, b3c, b4c, b5c, b6c).prefetch(threads,frames)
\ : (radius==5) ? interleave( f5c, f4c, f3c, f2c, f1c, i, b1c, b2c, b3c, b4c, b5c ).prefetch(threads,frames)
\ : (radius==4) ? interleave( f4c, f3c, f2c, f1c, i, b1c, b2c, b3c, b4c ).prefetch(threads,frames)
\ : (radius==3) ? interleave( f3c, f2c, f1c, i, b1c, b2c, b3c ).prefetch(threads,frames)
\ : (radius==2) ? interleave( f2c, f1c, i, b1c, b2c ).prefetch(threads,frames)
\ : (radius==1) ? interleave( f1c, i, b1c ).prefetch(threads,frames)
\ : nullclip
sm = Defined(cnr) ? Eval("c."+cnr)
\ : c.vsTTempSmooth(radius,255,255,255,1,1,1,strength=radius+1,pfclip=SAD_m,fp=false,scthresh=99.9)
sm = sm.SelectEvery(1+radius*2,radius)
return sm
}
function MCTDmod_MVD(clip "i", clip "iMVS",
\ clip "f1v", clip "f2v", clip "f3v", clip "f4v", clip "f5v", clip "f6v", clip "b1v", clip "b2v", clip "b3v", clip "b4v", clip "b5v", clip "b6v",
\ int "radius", bool "chroma", int "thSAD", int "thSCD1", int "thSCD2")
{
nullclip = BlankClip()
Try {
vMulti = (radius==4) ? Interleave(b1v, f1v, b2v, f2v, b3v, f3v, b4v, f4v)
\ : (radius==5) ? Interleave(b1v, f1v, b2v, f2v, b3v, f3v, b4v, f4v, b5v, f5v)
\ : (radius==6) ? Interleave(b1v, f1v, b2v, f2v, b3v, f3v, b4v, f4v, b5v, f5v, b6v, f6v)
\ : nullclip