-
-
Notifications
You must be signed in to change notification settings - Fork 13
/
Copy pathResizersPack.avsi
1678 lines (1416 loc) · 82.9 KB
/
ResizersPack.avsi
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
######################################################
### ##
### ##
### Resizers Functions Pack 12.2 (05-01-2025) ##
### ##
### by Dogway (Jose Linares) ##
### ##
### https://forum.doom9.org/showthread.php?t=182881 ##
### ##
### ##
### ##
### Functions: ##
### deep_resize ##
### nnedi3resize ##
### eedi3resize ##
### RAVUresize ##
### FSRresize ##
### waifu2xresize ##
### SmoothMotion ##
### RIFEwrap ##
### nnedi3wrap ##
### EEDI3wrap ##
### RatioResize ##
### PadResize ##
### PadBorders ##
### nmod ##
### mmod ##
### ColortoHex ##
### bicubic_coeffs ##
### MatteCrop ##
### ##
### ##
######################################################
##############################
###
### deep_resize() - by Dogway (26-05-2023)
###
### Convenient and high performance function to resize natural images (not cartoons) in high quality (different kernels for edge/flat areas).
### Defaults work pretty nice out-of-the-box so you don't need to spend time tweaking settings.
### At 8-bits performs 6% faster than nnedi3_resize16(), but much higher quality and frame properties support.
### If you want more control (ColorSpaces, UVRecon, nomoiree, etc) use directly ConvertFormat().
### Supports all YUV formats at any given bitdepth (not RGB).
###
### deconv: An option to undo the oversharpening or blur of the original downscaling kernel.
### Following suggested values for 'deconv':
###
### -10 "SoftCubic100"
### -7 "Robidoux Soft"
### -6 "SoftCubic75"
### -6 "Bilinear"
### -6 "BilcubicD"
### -6 "BilcubicU"
### -6 "Hermite"
### -5 "Robidoux"
### -5 "Centroid"
### -5 "Mitchell-Netravali"
### -4 "Robidoux Sharp"
### -5 "SoftCubic50"
### -0 "Cub-grange"
### -0 "Catmull-Rom"
### +1 "Didee"
### +4 "Zopti"
### +4 "ZoptiN"
### +2 "Precise Bicubic"
### +2 "Sharp"
### +0 "Spline16"
### +0 "Spline36"
### +2 "DPID"
### +0 "SSIM2"
### +0 "SincLin"
### +15 "SinPow"
###
###
### Dependencies:
### ExTools
### MasksPack
### TransformsPack
### FilmGrain+ (for grain > 0)
### GradePack (for show=true)
### Resizer of choice
### NNEDI3CL (for default "nnedi3" upscale) (requires at least AVS+ v3.7.3)
### LSFplus (for default "nnedi3" upscale) (and its dependencies)
### SharpenersPack (for default "nnedi3" upscale)
### SimilarityMetrics (for 'SSIM2' downscaling)
### vsTCanny
### fmtconv
###
###
### Benchmark (1080p to 2160p) (Prefetch(8)) :
### 100.0% 100.0% deep_resize() (8-bit 20.6fps, 16-bit 18.0fps)
### 94.7% 16.7% nnedi3_resize16() (8-bit 19.5fps, 16-bit 3.0fps)
###
###
### Info on scaling kernels:
### General: https://github.com/Dogway/Avisynth-Scripts/blob/master/TransformsPack - Main.avsi#L340
### Bicubics: https://github.com/Dogway/Avisynth-Scripts/blob/master/TransformsPack - Main.avsi#L1939
###
###
### General resampling guidelines:
### -Avoid bicubics for highly compressed images as it will amplify DCT blocks
### -For downscaling use a 2-lobes sinc function (aka not bicubics)
### -For downscaling while preventing moiree use a 4-lobes sinc filter (ie. Lanczos4)
### -For sharp images (upscaling) use 3-lobes, for blurry ones 4 or more
### -More tappered (rolled-off) kernel bell shapes require higher taps (4 or above; Hann, Bohman, Blackman, Parzen, etc)
### -Use even number of taps (taps=lobes in AviSynth) to avoid a final positive lobe ("ringing") before cutoff of the window support. Negative lobes "ringing" are rarely created in gamma light resizing.
###
### More info: https://avisynth.nl/index.php/Resampling
###
### Function Definition:
### (
### clip,
### float width=1920.00 (0.00 to 3840.00),
### float height=1080.00 (0.00 to 2160.00),
### string "edge"="nnedi3" ("nnedi3"/ "EEDI3"/ "FCBI"/ "SuperResXBR"/ "Waifu2x"/ "RAVU"/ "FSR1"/ "Krig"/ "FSRCNN"/ "DPID"/ "SSIM"/ "SSIM2"/ "--"/ "Point"/ "Nearest"/ "Box"/ "Bilinear"/ "Bicubic"/ "Quadratic"/ "Gauss"/ "--"/ "Wiener"/ "Spline"/ "Spline16"/ "Spline36"/ "Spline64"/ "Spline100"/ "Spline144"/ "Spline196"/ "Spline256"/ "--"/ "Jinc"/ "Jinc16"/ "Jinc36"/ "Jinc64"/ "Jinc100"/ "Jinc144"/ "Jinc196"/ "Jinc256"/ "EWASharp"/ "EWASharp2"/ "EWASharp4"/ "EWASharper"/ "EWASharper2"/ "EWASharper4"/ "EWASharpest"/ "EWASoft"/ "HaasnSoft"/ "Tukey"/ "--"/ "Sinc"/ "SincLin"/ "SinPow"/ "--"/ "Welch"/ "Cosine"/ "Bessel"/ "Wiener"/ "Hamming"/ "Hann"/ "EWA_Hann"/ "Kaiser"/ "Blackman"/ "Black-Harris"/ "Black-Nuttall"/ "Nuttall"/ "Bohman"/ "Parzen"/ "Lanczos"/ "EWA_Lanczos"/ "Ginseng"/ "EWA_Ginseng"/ "Flat-Top"/ "MinSide"/ "--"/ "Notch"/ "SoftCubic100"/ "Robidoux Soft"/ "SoftCubic75"/ "BilcubicD"/ "BilcubicU"/ "Hermite"/ "Robidoux"/ "EWA_Robidoux"/ "Centroid"/ "Mitchell-Netravali"/ "Robidoux Sharp"/ "EWA_RobidouxSharp"/ "SoftCubic50"/ "CatMule-Dog"/ "Cub-grange"/ "Catmull-Rom"/ "Didee"/ "Zopti"/ "ZoptiN"/ "ZoptiH"/ "Zopti720"/ "Zopti720U"/ "Zopti1080"/ "Precise"/ "Sharp"/ "Hatch"),
### string "flat"="Lanczos" ("nnedi3"/ "EEDI3"/ "FCBI"/ "SuperResXBR"/ "Waifu2x"/ "RAVU"/ "FSR1"/ "Krig"/ "FSRCNN"/ "DPID"/ "SSIM"/ "SSIM2"/ "--"/ "Point"/ "Nearest"/ "Box"/ "Bilinear"/ "Bicubic"/ "Quadratic"/ "Gauss"/ "--"/ "Wiener"/ "Spline"/ "Spline16"/ "Spline36"/ "Spline64"/ "Spline100"/ "Spline144"/ "Spline196"/ "Spline256"/ "--"/ "Jinc"/ "Jinc16"/ "Jinc36"/ "Jinc64"/ "Jinc100"/ "Jinc144"/ "Jinc196"/ "Jinc256"/ "EWASharp"/ "EWASharp2"/ "EWASharp4"/ "EWASharper"/ "EWASharper2"/ "EWASharper4"/ "EWASharpest"/ "EWASoft"/ "HaasnSoft"/ "Tukey"/ "--"/ "Sinc"/ "SincLin"/ "SinPow"/ "--"/ "Welch"/ "Cosine"/ "Bessel"/ "Wiener"/ "Hamming"/ "Hann"/ "EWA_Hann"/ "Kaiser"/ "Blackman"/ "Black-Harris"/ "Black-Nuttall"/ "Nuttall"/ "Bohman"/ "Parzen"/ "Lanczos"/ "EWA_Lanczos"/ "Ginseng"/ "EWA_Ginseng"/ "Flat-Top"/ "MinSide"/ "--"/ "Notch"/ "SoftCubic100"/ "Robidoux Soft"/ "SoftCubic75"/ "BilcubicD"/ "BilcubicU"/ "Hermite"/ "Robidoux"/ "EWA_Robidoux"/ "Centroid"/ "Mitchell-Netravali"/ "Robidoux Sharp"/ "EWA_RobidouxSharp"/ "SoftCubic50"/ "CatMule-Dog"/ "Cub-grange"/ "Catmull-Rom"/ "Didee"/ "Zopti"/ "ZoptiN"/ "ZoptiH"/ "Zopti720"/ "Zopti720U"/ "Zopti1080"/ "Precise"/ "Sharp"/ "Hatch"),
### string "chroma"="Blackman" ("nnedi3"/ "EEDI3"/ "FCBI"/ "SuperResXBR"/ "Waifu2x"/ "RAVU"/ "FSR1"/ "Krig"/ "FSRCNN"/ "DPID"/ "SSIM"/ "SSIM2"/ "--"/ "Point"/ "Nearest"/ "Box"/ "Bilinear"/ "Bicubic"/ "Quadratic"/ "Gauss"/ "--"/ "Wiener"/ "Spline"/ "Spline16"/ "Spline36"/ "Spline64"/ "Spline100"/ "Spline144"/ "Spline196"/ "Spline256"/ "--"/ "Jinc"/ "Jinc16"/ "Jinc36"/ "Jinc64"/ "Jinc100"/ "Jinc144"/ "Jinc196"/ "Jinc256"/ "EWASharp"/ "EWASharp2"/ "EWASharp4"/ "EWASharper"/ "EWASharper2"/ "EWASharper4"/ "EWASharpest"/ "EWASoft"/ "HaasnSoft"/ "Tukey"/ "--"/ "Sinc"/ "SincLin"/ "SinPow"/ "--"/ "Welch"/ "Cosine"/ "Bessel"/ "Wiener"/ "Hamming"/ "Hann"/ "EWA_Hann"/ "Kaiser"/ "Blackman"/ "Black-Harris"/ "Black-Nuttall"/ "Nuttall"/ "Bohman"/ "Parzen"/ "Lanczos"/ "EWA_Lanczos"/ "Ginseng"/ "EWA_Ginseng"/ "Flat-Top"/ "MinSide"/ "--"/ "Notch"/ "SoftCubic100"/ "Robidoux Soft"/ "SoftCubic75"/ "BilcubicD"/ "BilcubicU"/ "Hermite"/ "Robidoux"/ "EWA_Robidoux"/ "Centroid"/ "Mitchell-Netravali"/ "Robidoux Sharp"/ "EWA_RobidouxSharp"/ "SoftCubic50"/ "CatMule-Dog"/ "Cub-grange"/ "Catmull-Rom"/ "Didee"/ "Zopti"/ "ZoptiN"/ "ZoptiH"/ "Zopti720"/ "Zopti720U"/ "Zopti1080"/ "Precise"/ "Sharp"/ "Hatch"),
### int "e_taps"=6 (2 to 20),
### int "f_taps"=8 (2 to 20),
### int "c_taps"=6 (2 to 20),
### int "deconv"=0 (-10 to 15),
### float "sharpness"=1 (0 to 20),
### [float "grain"=0.0 (0.0 to 3.0)],
### float "th_rat"=1.25 (1.00 to 2.00 by 0.05),
### float "th"=1.0 (0.0 to 5.0),
### float "elast"=4.0 (1.0 to 10.0),
### int "qual"=1 (1 to 2),
### [bool "show"=false]
### )
###
###
### Examples:
### # 720p to 1080p (for anime)
### deep_resize(1920,flat="nnedi3",grain=0,qual=2)
###
### # 720p to 1080p
### deep_resize(1920) or deep_resize(1920,grain=0) for no grain
###
### # 1080p to 2160p
### deep_resize(3840) or deep_resize(3840,grain=0) for no grain
###
### # 2160p to 1080p
### deep_resize(1920,edge="Zopti1080") # for UHD sources "Zopti1080" is the default so can be omitted
###
### # 1080p to 720p
### deep_resize(1280,edge="SSIM2") # SSIM2 is the default so can be omitted
###
### # 2160p to 720p
### deep_resize(1920) or deep_resize(1920,edge="Zopti1080",flat="Zopti1080") # for dw flat=edge so flat="Zopti1080" can be omitted, dw to 1080p defaults to "Zopti1080" so can also be skipped
### deep_resize(1280)
###
###
function deep_resize(clip a, val "width", val "height", string "edge", string "flat", string "chroma", int "e_taps", int "f_taps", int "c_taps", string "sspace", bool "noring", int "deconv", float "sharpness", float "grain", bool "HBD", float "th_rat", float "th", float "elast", int "qual", int "threads", int "cores", val "gpuid", bool "show") {
wu = !Defined(width)
hu = !Defined(height)
w = width (a)
h = height(a)
rgb = isRGB (a)
isy = isy (a)
mod = is444 (a) || rgb || isy ? 1 : 2
FC = FrameCount(a)>1
bi = BitsPerComponent(a)
fs = propNumElements (a,"_ColorRange") > 0 ? \
propGetInt (a,"_ColorRange") == 0 : rgb
cpl = propNumElements (a,"_ChromaLocation") > 0 ? \
propGetInt (a,"_ChromaLocation") : 0
w2 = Default(width, w)
h2 = Default(height, h)
Assert(IsVersionOrGreater(3,7,3), "deep_resize: Update AviSynth+ version")
Assert(isFloat(w2) || isFloat(h2), "deep_resize: Width/Height type not supported")
w2 = isInt(w2) && w2<=10 ? float(w2) : isFloat(w2) && w2>10. ? int(w2) : w2
h2 = isInt(h2) && h2<=10 ? float(h2) : isFloat(h2) && h2>10. ? int(h2) : h2
w2 = w2<=10. ? w*w2 : w2 w2 = nmod(w2,mod)
h2 = h2<=10. ? h*h2 : h2 h2 = nmod(h2,mod)
w2 = w2 == 0 || wu ? nmod((w*(h2/float(h))),mod) : w2
h2 = h2 == 0 || hu ? nmod((h*(w2/float(w))),mod) : h2
isHD = (w > 1099 || h > 599)
isHD2 = (w2 > 1099 || h2 > 599)
isUHD = (w > 2599 || h > 1499)
isUHD2 = (w2 > 2599 || h2 > 1499)
rw = w2/float(w)
rh = h2/float(h)
mrat = max(rw,rh)
factor = mrat < 2.5 ? 2 : mrat < 6.0 ? 4 : 8
rat = abs(mrat-1)+1
rth = Default(th_rat, 1.25) # threshold for mix mode. Lower than this (target_size/source_size) will use only 'kernel1' kernel
krn1 = Default(edge, rw<1 && rh<1 ? rat<=rth*0.95 ? "Didee" : /* # Resize kernel for the edge area. AI upscalers recommended here: nnedi3, FSRCNN, FCBI, SuperResXBR...or for downscaling: DPID, SSIM2, Zopti */
\ isUHD ? "Zopti1080": "SSIM2" /* # By default, for small upscales -> "blackman" (define *small* with 'th_rat' value) */
\ : rat<=rth ? "Blackman" : "nnedi3" ) /* # By default, for big upscales -> "nnedi3"
# By default, for small downscales -> "Didée"
# By default, for big downscales -> "Zopti1080"
# By default, for mid downscales -> "SSIM2" (DPID also fine for down to 720p) (Beware!! for UHD to HD against all logic I recommend going with Zopti1080 (b=-0.99,c=0.06) ) */
krn1c = Default(chroma,rat<=rth && krn1!="nnedi3" ? krn1 : rw<1&&rh<1 ? "Zopti" : "Lanczos")# Chroma resizing kernel (no edge/flat discretion) *Remember you can directly call "kernel + taps". ie. Blackman6, Lanczos4
krn2 = Default(flat, rat<=rth && krn1!="nnedi3" ? krn1 : rw<1&&rh<1 ? krn1 : isHD&&isUHD2 ? "Sinc" : "Lanczos" ) # Resize kernel for the flat area (noop when downscaling). Ringing kernels are ok here (specially when up ratio is <1.7) like SincLin, Blackman, Lanczos, Sinc... ('Sinc' low taps -ie. 4- is worth testing, creates some faints halos specially for SD to HD so see whether it's faint enough for you)
etp = Default(e_taps, krn1=="Blackman" ? 6 : krn1 =="Lanczos" ? 4 : 0) # taps for edge kernel (0 for undefined)
ftp = Default(f_taps,rat<=rth ? etp : krn2=="Blackman" ? 16 : krn2 =="Lanczos" ? 8 : 0) # taps for flat kernel (0 for undefined)
ctp = Default(c_taps, krn1c=="Blackman" ? 5 : krn1c=="Lanczos" ? 3 : 0) # taps for chroma kernel (0 for undefined)
mul = Default(sharpness,krn1 =="nnedi3" ? 1 : 0) # Add sharpness (only to nnedi3 based upscaling)
thr = Default(th, 1.0) # 0-255 (normally up to 10)
ela = Default(elast, 4.0) # 1-255 (normally up to 10)
qual = Default(qual, 1) # nnedi3 'qual' argument
ssp = Default(sspace, "Gamma") # Scale space: "gamma", "linear" (best for down), "sigmoid" (best for up) or "log" for quasilog
nr = Default(noring, false)
sh = Default(show, false)
HBD = Default(HBD, ssp!="Gamma" && krn1!="nnedi3")
threads= Default(threads, 8) # Only for gpuid=-1 ("cpu" nnedi3)
cores = Default(cores,nmod(threads/2,2,4)) # Only for gpuid=-1 ("cpu" nnedi3)
ddec = Defined(deconv)
dec = Default(deconv, 0) # 0~10 (0 is disabled, raise to apply deconvolution when upscaling a very sharpened downscale -anything sharper than Catmull-Rom-)
gr = Default(grain, rw>1 && rh>1 && rat>rth ? 0.3 : 0 ) # Grain strength. >0 Add grain to big upscales as a mean of cheap detail hallucination
decs = FindStr(LCase(krn2),"sinc")>0 && StrLen(krn2) < 7 ? dec+2 : dec
dec = ddec && dec == 0 ? 0 : abs(0.00135*decs*(w*0.5*rat)-0.095) # higher deconvolution the higher the upscale
dec = dec == 0.095 ? 0 : dec
und = Undefined()
# gpuid=[0,-2,-1] means gpu for 'edge', auto for 'flat' and cpu for 'chroma'. If using int as gpuid=0, only 'edge' will run on gpu or the indicated value, the rest as auto (-2)
gpu = Defined(gpuid) ? isArray(gpuid) ? ArraySize(gpuid)==2 ? ArrayAdd(gpuid,-2) : ArraySize(gpuid)==1 ? [gpuid[0],-2,-2] : gpuid : [gpuid,-2,-2] : [-2,-2,-2]
egpu = gpu[0]
fgpu = gpu[1]
cgpu = gpu[2]
ecgpu = egpu!=-2 && cgpu!=-2 ? [egpu,cgpu] : egpu!=-2 && cgpu==-2 ? [egpu] : und # cannot specify chroma without specifying luma, so fallback to auto
fcgpu = fgpu!=-2 && cgpu!=-2 ? [fgpu,cgpu] : fgpu!=-2 && cgpu==-2 ? [fgpu] : und
egpu = egpu!=-2 ? egpu : und
if (rw==1 && rh==1) {
a
} else if (krn1 == krn2 && etp == ftp) {
# Downscale/upscale with same edge/flat kernel
krn1=="nnedi3" && krn1c=="nnedi3" ? \
nnedi3resize (a, w2,h2,qual=qual,HBD=HBD,threads=threads,cores=cores,gpuid=egpu) : \
ConvertFormat(a, w2,h2,cs_out="",EOTFi="",kernel=krn1,kernel_c=krn1c,taps=[etp,ctp],tv_in=!fs,tv_out=!fs,scale_space=ssp,noring=nr,threads=threads,cores=cores,gpuid=ecgpu)
mul>0 ? LSFplus(preset="LSF",strength=2*mul*(FC?rat:1),Smode=4,Lmode=2,edgemode=0,soothe=FC,overshoot=0,soft=-2,keep=0,tv_range=!fs) : last
} else {
# Y for edges + 8-bit for nnedi3
oned = krn1 == "nnedi3" && (h == h2 || w == w2)
an = !isy ? a.ExtractY() : a
an = !HBD ? an.ConvertBits(8,dither=-1,fulls=fs,fulld=fs) : an
edge1 = ConvertFormat(an,w2,h2,cs_out="",EOTFi="",kernel=krn1, taps=etp, tv_in=!fs,tv_out=!fs,threads=threads,cores=cores,gpuid=egpu,scale_space=ssp,noring=nr) # noring and scale_space is only applied to edges
# don't sharpen nnedi3 when one dimensional resize case
edge1b = "!HBD ? ConvertBits(edge1, bi, fulls=fs, fulld=fs) : edge1"
edge = krn1=="nnedi3" ? oned ? Eval(edge1b) : \
mul>0 ? LSFplus (edge1,preset="LSF",strength=2*mul*(FC?rat:1),Smode=4,Lmode=2,edgemode=0,soothe=FC,overshoot=0,soft=-2,keep=0,tv_range=!fs).\
ConvertBits(bi, fulls=fs, fulld=fs) : Eval(edge1b) : Eval(edge1b)
# resizing chroma+flat area
flat = ConvertFormat(a, w2,h2,cs_out="",EOTFi="",kernel=krn2,kernel_c=krn1c,taps=[ftp,ctp],tv_in=!fs,tv_out=!fs,threads=threads,cores=cores,gpuid=fcgpu)
# edge/flat limiting
!isy ? CombinePlanes(edge, flat, planes="YUV", pixel_type=PixelType(a)) : edge
ex_limitdif(flat, last, thr=thr, elast=ela, UV=1)
# deconvolution from source downscaling
dec == 0 ? last : ex_unsharp(w!=w2?-dec/100.:0,h!=h2?-dec/100.:0, Fc=max(w2,h2)/(rat*2)) }
size = 1.5 * ( 0.000173*w2 + 0.667 )
grain = gr * ( 0.000260*w2 + 0.500 )
sharp = min (-0.000156*w2 + 1.3,1 )
gr > 0 ? FilmGrainPlus(size=size,str=grain,strc=isUHD2?0:Und,sharpness=sharp,lo=0.7,hi=0.9,preblur=0,temp=0.2,tv_range=!fs) : last
if (sh) {
taps = """ krn1 == "Blackman" || krn1 == "Lanczos" || krn1 == "Sinc" || krn1 == "SincLin" || krn1 == "Jinc" """
etp = etp == 0 ? "" : Eval(taps) ? Format("[{etp}]") : ""
ftp = ftp == 0 ? "" : Eval(ReplaceStr(taps,"krn1","krn2" )) ? Format("[{ftp}]") : ""
ctp = ctp == 0 ? "" : Eval(ReplaceStr(taps,"krn1","krn1c")) ? Format("[{ctp}]") : ""
ecb = bicubic_coeffs(krn1)
fcb = bicubic_coeffs(krn2)
ccb = bicubic_coeffs(krn1c) nul = "-2.000000, -2.000000"
ecb = ArrayPrint(ecb,true) != nul ? "["+string(ecb[0],"%1.2f")+","+string(ecb[1],"%1.2f")+"]" : ""
fcb = ArrayPrint(fcb,true) != nul ? "["+string(fcb[0],"%1.2f")+","+string(fcb[1],"%1.2f")+"]" : ""
ccb = ArrayPrint(ccb,true) != nul ? "["+string(ccb[0],"%1.2f")+","+string(ccb[1],"%1.2f")+"]" : ""
msize = min(w2,h2)
bg = BoxMask(0,round(msize/1.55),0,round(msize/1.65), invert=true, tv_out=!fs)
ex_blend(bg,"multiply",opacity=0.5,tv_range=!fs)
Subtitle(" deep_resize()", size=msize/16,lsp=4,text_color=$ff5050,font="Segoe UI")
Subtitle("\n\n SETTINGS:", size=msize/25,lsp=4,text_color=$ffcc99)
Subtitle("\n\n\n\n " \
+"size IN:\n " \
+"size OUT:\n " \
+"edge:\n " \
+"flat:\n " \
+"chroma:\n " \
+"deconv:\n " \
+"grain:\n " \
+"th_rat:\n " \
+"th:\n " \
+"elast:", size=msize/25,lsp=4,text_color=$ffcc99)
Subtitle(Format("\n\n\n\n " \
+"{w}x{h} \n " \
+"{w2}x{h2} \n " \
+"{krn1} " + etp + ecb + " \n " \
+"{krn2} " + ftp + fcb + " \n " \
+"{krn1c} " + ctp + ccb + " \n " \
+string(dec,"%1.3f")+" \n " \
+string(gr, "%1.3f")+" \n " \
+string(rth,"%1.3f")+" \n " \
+string(thr,"%1.3f")+" \n " \
+string(ela,"%1.3f")), x=msize/4, size=msize/25,lsp=4,text_color=$ffcc99)
} }
#
# nnedi3resize()
#
# Wrapper for nnedi3wrap() for simplified ____resize() style arguments.
# Performant neural network based upscaler recommended for graphics or textureless images.
# It accepts arbitrary dimension values, not only limited to powers of 2
#
# Dependencies:
# see nnedi3wrap() below
#
function nnedi3resize(clip a, val "width", val "height", float "src_left", float "src_top", bool "HBD", float "sharpness", int "qual", int "nns", int "nsize", int "etype", int "pscrn", string "cshift", int_array "planes", int "threads", int "cores", int "gpuid") {
wu = !Defined(width)
hu = !Defined(height)
w = width (a)
h = height(a)
mod = isRGB (a) || is444(a) || isy(a) ? 1 : 2
w2 = Default(width, w)
h2 = Default(height, h)
Assert(IsVersionOrGreater(3,7,3), "nnedi3resize: Update AviSynth+ version")
Assert(isFloat(w2) || isFloat(h2), "nnedi3resize: Width/Height type not supported")
w2 = isInt(w2) && w2<=10 ? float(w2) : isFloat(w2) && w2>10. ? int(w2) : w2
h2 = isInt(h2) && h2<=10 ? float(h2) : isFloat(h2) && h2>10. ? int(h2) : h2
w2 = w2<=10. ? w*w2 : w2 w2 = nmod(w2,mod)
h2 = h2<=10. ? h*h2 : h2 h2 = nmod(h2,mod)
w2 = w2 == 0 || wu ? nmod((w*(h2/float(h))),mod) : w2
h2 = h2 == 0 || hu ? nmod((h*(w2/float(w))),mod) : h2
hs = h == h2
ws = w == w2
oned = hs || ws
nns = Default(nns, oned ? 1 : 3)
nsize = Default(nsize, oned ? 6 : 0)
rw = w2/float(w)
rh = h2/float(h)
factor = max(rw,rh) < 2.5 ? 2 : max(rw,rh) < 6 ? 4 : 8
rfactor = rw<factor && rh<factor
krnn = Default(cshift, rfactor ? "Bicubic" : "Blackman")
nnedi3wrap(a,ws?1:factor,hs?1:factor,nns=nns,nsize=nsize,qual=qual,etype=etype,pscrn=pscrn,fwidth=w2,fheight=h2,src_left=src_left,src_top=src_top,sharpness=sharpness,cshift=krnn,HBD=HBD,planes=planes,threads=threads,cores=cores,gpuid=gpuid)
}
function eedi3resize(clip a, val "width", val "height", float "src_left", float "src_top", bool "HBD", float "sharpness", float "alpha", float "beta", float "gamma", int "nrad", int "mdis", int "vcheck", bool "hp", bool "ucubic", bool "cost3", string "cshift", int_array "planes", int "gpuid") {
wu = !Defined(width)
hu = !Defined(height)
w = width (a)
h = height(a)
mod = isRGB (a) || is444(a) || isy(a) ? 1 : 2
w2 = Default(width, w)
h2 = Default(height, h)
Assert(IsVersionOrGreater(3,7,3), "eedi3resize: Update AviSynth+ version")
Assert(isFloat(w2) || isFloat(h2), "eedi3resize: Width/Height type not supported")
w2 = isInt(w2) && w2<=10 ? float(w2) : isFloat(w2) && w2>10. ? int(w2) : w2
h2 = isInt(h2) && h2<=10 ? float(h2) : isFloat(h2) && h2>10. ? int(h2) : h2
w2 = w2<=10. ? w*w2 : w2 w2 = nmod(w2,mod)
h2 = h2<=10. ? h*h2 : h2 h2 = nmod(h2,mod)
w2 = w2 == 0 || wu ? nmod((w*(h2/float(h))),mod) : w2
h2 = h2 == 0 || hu ? nmod((h*(w2/float(w))),mod) : h2
hs = h == h2
ws = w == w2
oned = hs || ws
rw = w2/float(w)
rh = h2/float(h)
factor = max(rw,rh) < 2.5 ? 2 : max(rw,rh) < 6 ? 4 : 8 # maybe make the threshold higher? (so rpow is triggered before, like factor=4 for 2.5x)
rfactor = rw<factor && rh<factor
krnn = Default(cshift, rfactor ? "Bicubic" : "Blackman")
eedi3wrap(a,ws?1:factor,hs?1:factor,src_left=src_left,src_top=src_top,alpha=alpha,beta=beta,gamma=gamma,nrad=nrad,mdis=mdis,hp=hp,ucubic=ucubic,cost3=cost3,fwidth=w2,fheight=h2,cshift=krnn,sharpness=sharpness,HBD=HBD,planes=planes,gpuid=gpuid)
}
#
# RAVUresize()
#
# Wrapper for libplacebo_Shader() with RAVU4 upscaler from avs_libplacebo by Asd-g.
# RAVU (Rapid and Accurate Video Upscaling) is a set of prescalers inspired by RAISR (Rapid and Accurate Image Super Resolution).
# Similar in quality to XBR and nnedi3. Accepts arbitrary dimension values, not only limited to powers of 2
#
# Dependencies:
# avs_libplacebo
# ExTools
# TransformsPack
# FilmGrain+ (for grain>0)
#
function RAVUresize(clip a, val "width", val "height", float "grain", string "path", int "gpuid") {
wu = !Defined(width)
hu = !Defined(height)
w = width (a)
h = height(a)
isy = isy (a)
is4 = is444 (a)
rgb = isRGB (a)
mod = rgb || is4 || isy ? 1 : 2
bi = BitsPerComponent(a)
fs = propNumElements (a,"_ColorRange" ) > 0 ? \
propGetInt (a,"_ColorRange" ) == 0 : rgb
w2 = Default(width, w)
h2 = Default(height, h)
pt = Default(path, "C:\Program Files (x86)\AviSynth+\plugins64+\Shaders\avslibplacebo\ravu-r4.hook")
Assert(IsVersionOrGreater(3,7,3), "RAVUresize: Update AviSynth+ version")
Assert(isFloat(w2) || isFloat(h2), "RAVUresize: Width/Height type not supported")
isUHD2 = (w2 > 2599 || h2 > 1499)
w2 = isInt(w2) && w2<=10 ? float(w2) : isFloat(w2) && w2>10. ? int(w2) : w2
h2 = isInt(h2) && h2<=10 ? float(h2) : isFloat(h2) && h2>10. ? int(h2) : h2
w2 = w2<=10. ? w*w2 : w2 w2 = nmod(w2,mod)
h2 = h2<=10. ? h*h2 : h2 h2 = nmod(h2,mod)
w2 = w2 == 0 || wu ? nmod((w*(h2/float(h))),mod) : w2
h2 = h2 == 0 || hu ? nmod((h*(w2/float(w))),mod) : h2
rw = w2/float(w)
rh = h2/float(h)
gr = Default(grain, rw>1.25 && rh>1.25 ? 0.3 : 0 ) # Grain strength. >0 Add grain to big upscales as a mean of cheap hallucination
gpuid = Default(gpuid, 0)
factor = max(rw,rh) < 3 ? 2 : 4
rfactor = rw<factor && rh<factor
krnn = rfactor ? "ZoptiN" : "Blackman6" # hard coded final resize: 'ZoptiN' for down 'Blackman6' for up
a
isy ? mskY_to_YYY(last, last, false, false, 128, bi) : last
ConvertBits(16)
libplacebo_Shader(pt,width()*factor,height()*factor,filter="lanczos",radius=2,device=max(0,gpuid))
isy ? ExtractY() : last
ConvertBits(bi, dither=-1)
shf = factor==2 ? [-0.5] : [0]
ConvertFormat(w2,h2,fmt_out=isy?"":PixelType(a),cs_out="",EOTFi="",src_left=shf,src_top=shf,kernel=krnn,kernel_c=is4?"Precise":"Didee",tv_in=!fs,tv_out=!fs,gpuid=-1) # cubics and sincs are slow in avs_libplacebo
size = 1.5 * ( 0.000173*w2 + 0.667 )
grain = gr * ( 0.000260*w2 + 0.500 )
sharp = min (-0.000156*w2 + 1.3,1 )
gr > 0 ? FilmGrainPlus(size=size,str=grain,strc=isUHD2?0:Undefined(),sharpness=sharp,lo=0.7,hi=0.9,preblur=0,temp=0.2,tv_range=!fs) : last
}
#
# FSRresize()
#
# Wrapper for libplacebo_Shader() with AMD's FSR upscaler (v1.0).
#
# Dependencies:
# avs_libplacebo
# ExTools
# TransformsPack
# FilmGrain+ (for grain>0)
#
function FSRresize(clip a, val "width", val "height", float "grain", string "path", int "gpuid") {
pt = Default(path, "C:\Program Files (x86)\AviSynth+\plugins64+\Shaders\avslibplacebo\FSR.glsl")
Assert(IsVersionOrGreater(3,7,3), "FSRresize: Update AviSynth+ version")
Assert(isFloat(width) || isFloat(height), "FSRresize: Width/Height type not supported")
RAVUresize(a, width, height, grain, pt, gpuid) }
#
# waifu2xresize()
#
# Replacement wrapper for w2xncnnvk() upscaler. Runs VERY slow ~1 fps (GTX 1070)
# * For anime (model=0) this is better (and faster) at keeping corner details than 2x_Waifaux-NL3-SuperLite,
# but it won't denoise as much, so you might need a denoiser and possibly a deringing on top.
# * w2xncnnvk has a known bug which causes to cast a green tint
#
# Dependencies:
# w2xncnnvk
# ExTools
# TransformsPack
# FilmGrain+ (for grain>0)
# MasksPack (for model=1)
#
function waifu2xresize(clip a, val "width", val "height", int "model", int "noise", float "grain", bool "soothe", bool "tv_range", int "gpuid") {
pID = color_propGet(a)
bi = pID[7]
pri = pID[2]
FC = FrameCount(a)>1
wu = !Defined(width)
hu = !Defined(height)
w = width (a)
h = height(a)
isy = isy (a)
rgb = isRGB (a)
is4 = is444 (a)
rgbp = isPlanarRGB (a)
mod = rgb || is4 || isy ? 1 : 2
w2 = Default(width, w)
h2 = Default(height, h)
Assert(IsVersionOrGreater(3,7,3), "waifu2xresize: Update AviSynth+ version")
Assert(isFloat(w2) || isFloat(h2), "waifu2xresize: Width/Height type not supported")
w2 = isInt(w2) && w2<=10 ? float(w2) : isFloat(w2) && w2>10. ? int(w2) : w2
h2 = isInt(h2) && h2<=10 ? float(h2) : isFloat(h2) && h2>10. ? int(h2) : h2
w2 = w2<=10. ? w*w2 : w2 w2 = nmod(w2,mod)
h2 = h2<=10. ? h*h2 : h2 h2 = nmod(h2,mod)
w2 = w2 == 0 || wu ? nmod((w*(h2/float(h))),mod) : w2
h2 = h2 == 0 || hu ? nmod((h*(w2/float(w))),mod) : h2
rw = w2/float(w)
rh = h2/float(h)
factor = max(rw,rh) < 3 ? 2 : 4
rfactor= rw<factor && rh<factor
krnn = rfactor ? "Didee" : "Blackman6" # hard coded final resize: 'Didée' for down 'Blackman6' for up
isHD = (w > 1099 || h > 599)
isUHD = (w > 2599 || h > 1499)
isUHD2 = (w2 > 2599 || h2 > 1499)
tilew = isUHD ? w/4 : isHD ? w/2 : Undefined()
tileh = isUHD ? h/3 : isHD ? h/2 : Undefined()
md = Default(model, 1) # model: 0 - for Anime or lineart, 1 - for photos or live action
tv = Default(tv_range, pID[6])
gid = Default(gpuid, 0)
so = Default(soothe, md==1) # Temporal stabilize sharpening for less temporal jitter
ns = Default(noise, 0) # From 0 (no denoise) to 4 full denoise
gr = Default(grain, rw>1.25 && rh>1.25 ? 0.3 : 0 ) # Grain strength. >0 Add grain to big upscales as a mean of cheap hallucination
!isy ? a : ConvertBits(a, 32, fulls=!tv, fulld=true)
rgb ? rgbp ? last : ConvertToPlanarRGB() : isy ? MergeRGB(last,last,last) : ConvertFormat(1,1,"YUV","RGB",cs_in=pri,kernel_c="Precise")
!isy ? ConvertBits( 32, fulls=true, fulld=true) : last
for (i = 1, factor/2, 1) {
w2xncnnvk(noise=ns-1, scale=2, tile_w=tilew, tile_h=tileh, model=md, tta=factor<4, fp32=false, gpu_id=max(0,gid), gpu_thread=isHD ? 4 : 2) # 2: CUnet is too slow for video
}
isy ? ExtractR().ConvertBits(bi, dither=1, fulls=true, fulld=!tv) : \
!rgb ? MatchClip(a,matrix=pri,size=false) : last
# so && FC && rw>1.25 && rh>1.25 ? Soothe(a.nnedi3wrap(factor,gpuid=gid),tv_range=tv) : last # Disabled due to low speed
ConvertFormat(w2,h2,cs_out="",EOTFi="",kernel=krnn,kernel_c=is4?"Precise":"Didee",tv_in=tv,tv_out=tv,gpuid=-1)
size = 1.5 * ( 0.000173*w2 + 0.667 )
grain = gr * ( 0.000260*w2 + 0.500 )
sharp = min (-0.000156*w2 + 1.3,1 )
gr > 0 ? FilmGrainPlus(size=size,str=grain,strc=isUHD2?0:Undefined(),sharpness=sharp,lo=0.7,hi=0.9,preblur=0,temp=0.2,tv_range=tv) : last
}
#
# SmoothMotion()
# https://github.com/mpv-player/mpv/wiki/Interpolation#smoothmotion
#
# Port of SmoothMotion from MPV, also called "OverSample".
# Converts 24fps or 23.976fps clips to 60fps or 59.940fps respectively.
# by displaying each frame exactly 2.5 times for real-time playback.
# Note that it still might exhibit some judder on camera pans.
#
# In comparison, ChangeFPS() produces stutter and ConvertFPS(), blends all frames.
#
function SmoothMotion (clip a) {
a
den = FrameRateDenominator()
Blend = Merge(SelectEven(),SelectOdd())
BendI = Interleave(Blend,Blend)
Inter = Interleave(last,last,BendI)
SelectEvery(Inter,6, 0,1,2,3,4)
propSet("_DurationDen", 60000)
propSet("_DurationNum", den)
}
#
# RIFEwrap()
#
# Wrapper around RIFE port by Asd-g
#
# Examples:
# RIFEwrap() # Default for doubling framerate for live action (model="4.18")
# RIFEwrap(model="4.15",anime=true) # for 2D animation
#
# Dependencies:
# RIFE
# ExTools
# TransformsPack
#
function RIFEwrap(clip a, string "model", int "FrameNum", int "FrameDen", bool "FrameDouble", bool "ensemble", bool "fast", bool "Anime", bool "sc", bool "UHD", int "gpuid") {
isy = isy (a)
rgb = isRGB(a)
rgbp = isPlanarRGB(a)
w = width (a)
h = height(a)
numD = Defined(FrameNum)
denD = Defined(FrameDen)
UHD = (w > 2599 || h > 1499)
numFD = propNumElements (a,"_DurationDen") > 0
num = FrameRateNumerator (a)
den = FrameRateDenominator(a)
fps = num/float(den)
fs = propNumElements (a,"_ColorRange" ) > 0 ? \
propGetInt (a,"_ColorRange" )== 0 : rgb
pID = color_propGet(a)
bi = pID[7]
pri = pID[2]
isHD = (width (a) > 1099 || height(a) > 599)
Assert(IsVersionOrGreater(3,7,3),"RIFEwrap: Update AviSynth+ version")
/* https://github.com/nihui/rife-ncnn-vulkan/issues/50#issuecomment-1229203013
"The rife architecture has two parameters called ensembling and fastmode integrated.
You can't just export rife into one single model without such parameters.
Nihui always just exports the fastest model (ensemble False, Fast True), while the other ones can result in a better image.
Ensembling combines the flow of two different interpolations within the model and if fastmode is false it calls contextnet"
4.9 good all around for weak GPUs or UHD
4.18 > 4.15 (and lite) for live action
4.25 > 4.15 > 4.6 Live or Anime */
tta = Default(Anime, false)
md = Default(model,tta?"4.15":"4.18") # 'anime', 4.6<4.15<4.25 - for Anime or lineart; 4.9<4.15<4.18 - for live action
num = Default(FrameNum, num) # models folder must be located in the same folder as RIFE.dll.
den = Default(FrameDen, den)
fd = Default(FrameDouble, !(numD || denD))
ens = Default(ensemble, false) # Ensembling combines the flow of 2 different interpolations within the model. Allows smooth predictions in areas where the estimation fails.
fst = Default(fast, true) # Use the lite model (disables contextnet) for faster inference.
UHD = Default(UHD, UHD) # Downcales the to-be-interpolated frames for UHD inputs
gid = Default(gpuid, 0)
sc = Default(sc, true) # Avoid interpolating frames over scene changes.
nfps = (float(num)/den)/fps
fd = fd || string(nfps,"%.1f")=="2.0"
md = LCase(md)
md = md == "1.2"||md=="rife" ? 0 : \
md == "1.5"||FindStr(md,"hd") >0 ? 1 : \
md == "1.6"||FindStr(md,"uhd") >0 ? 2 : \
md == "1.8"||FindStr(md,"anime")>0 ? 3 : \
md == "2.0" ? 4 : \
md == "2.3" ? 5 : \
md == "2.4" ? 6 : \
md == "3.0" ? 7 : \
md == "3.1" ? 8 : \
md == "3.9" && !ens && fst ? 9 : \
md == "3.9" && ens && !fst ? 10 : \
md == "4.0" && !ens && fst ? 11 : \
md == "4.0" && ens && !fst ? 12 : \
md == "4.1" && !ens && fst ? 13 : \
md == "4.1" && ens && !fst ? 14 : \
md == "4.2" && !ens && fst ? 15 : \
md == "4.2" && ens && !fst ? 16 : \
md == "4.3" && !ens && fst ? 17 : \
md == "4.3" && ens && !fst ? 18 : \
md == "4.4" && !ens && fst ? 19 : \
md == "4.4" && ens && !fst ? 20 : \
md == "4.5" ? !ens || fst ? 21 : 22 : \
md == "4.6" ? !ens || fst ? 23 : 24 : \
md == "4.7" ? !ens || fst ? 25 : 26 : \
md == "4.8" ? !ens || fst ? 27 : 28 : \
md == "4.9" ? !ens || fst ? 29 : 30 : \
md == "4.10" ? !ens || fst ? 31 : 32 : \
md == "4.11" ? !ens || fst ? 33 : 34 : \
md == "4.12" ? !fst ? !ens ? 35 : 36 : !ens ? 37 : 38 : \
md == "4.13" ? !fst ? !ens ? 39 : 40 : !ens ? 41 : 42 : \
md == "4.14" ? !fst ? !ens ? 43 : 44 : !ens ? 45 : 46 : \
md == "4.15" ? !fst ? !ens ? 47 : 48 : !ens ? 49 : 50 : \
md == "4.16_lite" ? !ens || fst ? 51 : 52 : \
md == "4.17" ? !fst ? !ens ? 53 : 54 : !ens ? 55 : 56 : \
md == "4.18" ? !ens || fst ? 57 : 58 : \
md == "4.19-beta" ? !ens || fst ? 59 : 60 : \
md == "4.20" ? !ens || fst ? 61 : 62 : \
md == "4.21" ? !ens || fst ? 63 : 64 : \
md == "4.22" && !ens ? !fst ? 69 : 65 : \
md == "4.23" && !ens || fst ? 70 : \
md == "4.24" && !ens || fst ? 71 : \
md == "4.25" && !ens ? !fst ? 72 : 73 : \
md == "4.26" && !ens ? !fst ? 74 : 75 : \
md == "sudo_rife4" && !ens && fst ? 66 : \
md == "sudo_rife4" && ens && !fst ? 67 : \
md == "sudo_rife4" && ens && fst ? 68 : Assert(true, "RIFEwrap: Invalid mode")
# Asd-g needs to implement the following:
# 69 rife-v4.22_ensembleFalse
# 70 rife-v4.23_ensembleFalse
# 71 rife-v4.24_ensembleFalse
# 72 rife-v4.25_ensembleFalse
# rife-v4.25-heavy_ensembleFalse
# 73 rife-v4.25-lite_ensembleFalse
# 74 rife-v4.26-large_ensembleFalse
# 75 rife-v4.26_ensembleFalse
!isy ? a : ConvertBits(a, 32, fulls=!tv, fulld=true)
rgb ? rgbp ? last : ConvertToPlanarRGB() : isy ? MergeRGB(last,last,last) : ConvertFormat(1,1,"YUV","RGB",cs_in=pri,kernel_c="Precise")
isy ? last : ConvertBits( 32, fulls=true, fulld=true)
RIFE(model=fd ? md : max(md,9), sc=sc, sc_threshold=0.15, skip=tta, fps_num=fd ? Undefined() : num, fps_den=fd ? Undefined() : den, tta=tta, gpu_id=max(0,gid), gpu_thread=isHD ? 4 : 2, UHD=UHD)
isy ? ExtractR().ConvertBits(bi, dither=1, fulls=true, fulld=!tv) : \
!rgb ? MatchClip (a,matrix=pri,size=false,props=false) : last
fd ? numFD ? Interleave(a.ScriptClip(function[]() {
propSet("_DurationDen" ,propGetInt("_DurationDen") * 2 )
propSet("_DurationNum" ,propGetInt("_DurationNum") )
} ), SelectOdd()) : Interleave(a, SelectOdd()) : last
propCopy(a,true,props=["_AbsoluteTime","_DurationNum","_DurationDen","_PictType"], exclude=true) }
#
# nnedi3wrap()
#
# Replacement wrapper for nnedi3(), nnedi3_rpow2() and NNEDI3CL() based on 'field' and 'gpuid' values.
# Adds "_rpow2" functionality and its arguments to NNEDI3CL().
# Maintains frame properties when nnedi3() or nnedi3_rpow2() is used.
# Decouples 'rfactor' into 'xfactor' and 'yfactor' and sets new reasonable defaults.
# Finally it automatically fixes center shift for both plugins, set cshift="none" to disable.
#
# Dependencies:
# ExTools
# NNEDI3CL (requires at least AVS+ v3.7.3)
# or
# nnedi3
#
function nnedi3wrap(clip a, int "xfactor", int "yfactor", int "field", int "nsize", int "nns", int "qual", int "etype", int "pscrn", string "cshift", int "fwidth", int "fheight", float "src_left", float "src_top", int_array "planes", bool "HBD", float "sharpness", bool "props", int "threads", int "cores", int "gpuid") {
a
w = width ()
h = height()
isy = isY()
FC = FrameCount()>1
bi = BitsPerComponent()
fb = GetParity() ? 2 : 1
fb = propNumElements( "_FieldBased") > 0 ? \
propGetInt ( "_FieldBased") : IsFrameBased() ? 0 : fb
fs = propNumElements( "_ColorRange") > 0 ? \
propGetInt ( "_ColorRange") == 0 : isRGB()
cpl = propNumElements( "_ChromaLocation") > 0 ? \
propGetInt ( "_ChromaLocation") : 0
dd = propNumElements( "_DurationDen") > 0
fmt = isy ? 0 : isYV411() ? 1 : is420() ? 2 : is422() ? 3 : 4
fld = Defined(field) ? -1 < field < 2 : false
field = Default(field, -1) /* -2 = interlaced (automatic order) */ # Override source field order
fd = field==-2 ? max(1, fb)+1 : /* -1 = auto */
\ field==-1 ? fb==0 ? 0 : fb +1 : /* 0 = progressive bottom-field first */
\ field /* 1 = progressive top-field first */
/* 2 = interlaced bottom-field first */
in = fd>1 /* 3 = interlaced top-field first */
xf = Default(xfactor, !in ? 2 : 1) # powers of 2; 2, 4, 8....
yf = Default(yfactor, xf)
xf = int(pow(2,round(Log(xf)/Log(2)))) # force power steps
yf = int(pow(2,round(Log(yf)/Log(2)))) # force power steps
xyf = max(xf,yf)
Assert(IsVersionOrGreater(3,7,3), "nnedi3wrap: Update AviSynth+ version")
in ? Assert(xyf==1, "nnedi3wrap: Field must be 0 or 1 for scaling") : nop()
ws = xf == 1
hs = yf == 1
w1 = w*xf
h1 = h*yf
oned = ws || hs
nsize = Default(nsize, in ? 3 : oned ? 6 : 0)
nns = Default(nns, in || !oned ? 3 : 1)
mul = Default(sharpness, 0)
qual = Default(qual, 1)
etype = Default(etype, 0)
pscrn = Default(pscrn, 2)
HBD = Default(HBD, false) # Force source HBD (slower)
src_l = Default(src_left, 0)
src_t = Default(src_top, 0)
dfw = Defined(fwidth)
dfh = Defined(fheight)
w2 = Default(fwidth, w1)
h2 = Default(fheight, h1)
pp = Default(props, true) # Write runtime frameprops (or not)
gpuid = Default(gpuid, 0) # Set to -1 for "cpu" nnedi3
threads = Default(threads, 8) # Only for gpuid=-1 ("cpu" nnedi3)
cores = Default(cores,nmod(threads/2,2,4)) # Only for gpuid=-1 ("cpu" nnedi3)
# Internal arg for signaling chroma Y planes from ConvertFormat()
pln = Default(planes,isy ? [3] : [3,fmt,fmt]) # [3,2] means process luma, and chroma as 420 (id 2 for 420, 3 for 422, 4 for 444 and 1 for 411. 0 for no chroma)
pln = ArraySize(pln) == 1 ? [pln[0], fmt,fmt] : ArraySize(pln)==2 ? ArrayAdd(pln,pln[1]) : pln
sm = w2 == w && h1 == h
rw = w2/float(w)
rh = h2/float(h)
factor = max(rw,rh) < 2.5 ? 2 : max(rw,rh) < 6 ? 4 : 8
rfactor = rw<factor && rh<factor
krnn = Default(cshift, sm ? "spline16" : rfactor ? "ZoptiN" : "Blackman") # kernel used for fwidth or fheight, otherwise only for pixel shift (set to "none" to disable shift fix)
coeffs = bicubic_coeffs(krnn)
krnn2 = coeffs[0]>-2 && coeffs[1]>-2 ? "Bicubic" : krnn
ep0 = krnn2=="Bicubic" ? coeffs[0] : gpuid==-1 ? krnn2=="Blackman" ? 6 : 4 : Undefined() # NNEDI3 in CPU mode is limited in cshift modes, so hardcode some values here.
ep1 = krnn2=="Bicubic" ? coeffs[1] : Undefined()
!HBD ? ConvertBits(a, 8, dither=-1, fulls=fs, fulld=fs) : a
if (gpuid<0) {
if (in || oned) {
hs && !in ? TurnRight() : last
for (i = 1, in?1:xyf/2, 1) {
nnedi3(field=fd, dh=!in, nns=nns,nsize=nsize,qual=qual,etype=etype,pscrn=pscrn,threads=cores,prefetch=(threads+cores)/2,range=fs?1:2)
}
hs && !in ? TurnLeft () : last
} else {
nnedi3_rpow2(rfactor=xyf, nns=nns,nsize=nsize,qual=qual,etype=etype,pscrn=pscrn,threads=cores,prefetch=(threads+cores)/2,range=fs?1:2,mpeg2=cpl!=1,fwidth=w2,fheight=h2,cshift=krnn2=="none"?Undefined():krnn2+"resize",ep0=ep0,ep1=ep1)
}
} else {
for (i = 1, in?1:xyf/2, 1) {
NNEDI3CL( fd, dh=!in||!hs, dw=!ws, nns=nns,nsize=nsize,qual=qual,etype=etype,pscrn=pscrn,device=gpuid)
}
}
gpuid<0 ? in ? propCopy(a,true,props=["_AbsoluteTime"],exclude=true) : propCopy(a) : last
in || fld ? propSet("_FieldBased",0).propSet("_Field",fd%2) : last
in ? dd && pp ? propSet("_Combed",0).ScriptClip(function[a]() {
propSet("_DurationDen",propGetInt(a,"_DurationDen")*2)
propSet("_DurationNum",propGetInt(a,"_DurationNum") )
} ) : propSet("_Combed",0) : \
mul>0 ? LSFplus(preset="LSF",strength=2*mul,Smode=4,Lmode=2,edgemode=0,soothe=FC,overshoot=0,soft=-2,keep=0,tv_range=!fs) : last
# For final scaling and/or fix for pixel center shift
if (krnn!="none" && !in && (((dfw||dfh) && !(w2 == w && h2 == h) && !(src_l == 0 && src_t == 0)) || (oned || gpuid>-1))) {
ym = max(yf,min(rh,8))
xm = max(xf,rw)
krnn_c = FindStr(krnn2, "Blackman") > 0 ? "lanczos3" : krnn
cht = pln[1]==1 || pln[1]==3 ? 0.5 : 1
chl = pln[1]==1 ? 0.58 : pln[1]==4 ? min(1,(4./xm)) : 1
cy = isy && pln[1]>0
cslc = xm == 16 ? 380 : 0.100*pow(xm,2.585)+0.9
cstc = ym == 16 ? 270 : 0.067*pow(ym,2.585)+0.6
csl = xm == 16 ? 127.5 : 0.034*pow(xm,2.585)+0.3
cst = ym == 16 ? 127.5 : 0.034*pow(ym,2.585)+0.3
cslc = (pln[1]==4 ? csl : cslc)*chl
cstc = (pln[1]==4 ? cst : cstc)*cht
csl = !cy ? src_l+csl : pln[1]==4 ? cslc+src_l : pln[1]==1 ? 0.625-0.375*((cslc+src_l)*rw) : (cslc+src_l)*0.5
cst = !cy ? src_t+cst : pln[1]==4 || pln[1]==1 || pln[1]==3 ? cstc+src_t : (cstc+src_t)*0.5
ConvertFormat(w2,h2,cs_out="",EOTFi="",kernel=krnn,kernel_c=krnn_c,tv_in=!fs,tv_out=!fs, \
src_left=[csl,cslc+src_l], \
src_top =[cst,cstc+src_t],gpuid=-1) # -1 because 'sincs' or 'cubics' in avs_libplacebo are slow
}
!HBD ? ConvertBits(bi, fulls=fs, fulld=fs) : last
ws && hs && !in && sm ? a : last }
#
# EEDI3wrap()
#
# Replacement wrapper for eedi3(), eedi3_rpow2() and EEDI3CL() based on 'field' and 'gpuid' values.
# Adds "_rpow2" functionality and its arguments to EEDI3CL().
# Maintains frame properties when eedi3() or eedi3_rpow2() is used.
# Decouples 'rfactor' into 'xfactor' and 'yfactor' and sets new reasonable defaults.
# Finally it automatically fixes center shift for both plugins, set cshift="none" to disable.
#
# Dependencies:
# ExTools
# EEDI3CL / eedi3 (requires at least AVS+ v3.7.3 for EEDI3CL)
#
function EEDI3wrap(clip a, int "xfactor", int "yfactor", int "field", float "alpha", float "beta", float "gamma", int "nrad", int "mdis", int "vcheck", bool "hp", bool "ucubic", bool "cost3", string "cshift", int "fwidth", int "fheight", float "src_left", float "src_top", int_array "planes", bool "HBD", float "sharpness", clip "sclip", bool "props", int "gpuid") {
a
w = width ()
h = height()
isy = isY()
FC = FrameCount()>1
bi = BitsPerComponent()
fb = GetParity() ? 2 : 1
fb = propNumElements( "_FieldBased") > 0 ? \
propGetInt ( "_FieldBased") : IsFrameBased() ? 0 : fb
fs = propNumElements( "_ColorRange") > 0 ? \
propGetInt ( "_ColorRange") == 0 : isRGB()
cpl = propNumElements( "_ChromaLocation") > 0 ? \
propGetInt ( "_ChromaLocation") : 0
dd = propNumElements( "_DurationDen") > 0
fmt = isy ? 0 : isYV411() ? 1 : is420() ? 2 : is422() ? 3 : 4
fld = Defined(field) ? -1 < field < 2 : false
field = Default(field, -1) /* -2 = interlaced (automatic order) */ # Override source field order
fd = field==-2 ? max(1, fb)+1 : /* -1 = auto */
\ field==-1 ? fb==0 ? 0 : fb +1 : /* 0 = progressive bottom-field first */
\ field /* 1 = progressive top-field first */
/* 2 = interlaced bottom-field first */
in = fd>1 /* 3 = interlaced top-field first */
xf = Default(xfactor, !in ? 2 : 1) # powers of 2; 2, 4, 8....
yf = Default(yfactor, xf)
xf = int(pow(2,round(Log(xf)/Log(2)))) # force power steps
yf = int(pow(2,round(Log(yf)/Log(2)))) # force power steps
xyf = max(xf,yf)
Assert(IsVersionOrGreater(3,7,3), "EEDI3wrap: Update AviSynth+ version")
in ? Assert(xyf==1, "EEDI3wrap: Field must be 0 or 1 for scaling") : nop()
ws = xf == 1
hs = yf == 1
w1 = w*xf
h1 = h*yf
oned = ws || hs
mul = Default(sharpness, 0)
nrad = Default(nrad, 2)
mdis = Default(mdis, 20)
alpha = Default(alpha, 0.2)
beta = Default(beta, 0.25)
gamma = Default(gamma, 20.0)
vcheck = Default(vcheck, 2)
hp = Default(hp, false)
ucubic = Default(ucubic, true)
cost3 = Default(cost3, true)
HBD = Default(HBD, false) # Force source HBD (slower), only for EEDI3CL
src_l = Default(src_left, 0)
src_t = Default(src_top, 0)
dfw = Defined(fwidth)
dfh = Defined(fheight)
w2 = Default(fwidth, w1)
h2 = Default(fheight, h1)
pp = Default(props, true) # Write runtime frameprops (or not)
gpuid = Default(gpuid, 0) # Set to -1 for "cpu" eedi3
# Internal arg for signaling chroma Y planes from ConvertFormat()
pln = Default(planes,isy ? [3] : [3,fmt,fmt]) # [3,2] means process luma, and chroma as 420 (id 2 for 420, 3 for 422, 4 for 444 and 1 for 411. 0 for no chroma)
pln = ArraySize(pln) == 1 ? [pln[0], fmt,fmt] : ArraySize(pln)==2 ? ArrayAdd(pln,pln[1]) : pln
sm = w2 == w && h1 == h
rw = w2/float(w)
rh = h2/float(h)
factor = max(rw,rh) < 2.5 ? 2 : max(rw,rh) < 6 ? 4 : 8
rfactor = rw<factor && rh<factor
krnn = Default(cshift, sm ? "spline16" : rfactor ? "ZoptiN" : "Blackman") # kernel used for fwidth or fheight, otherwise only for pixel shift (set to "none" to disable shift fix)
coeffs = bicubic_coeffs(krnn)
krnn2 = coeffs[0]>-2 && coeffs[1]>-2 ? "Bicubic" : krnn
ep0 = krnn2=="Bicubic" ? coeffs[0] : gpuid==-1 ? krnn2=="Blackman" ? 6 : 4 : Undefined() # EEDI3 in CPU mode is limited in cshift modes, so hardcode some values here.
ep1 = krnn2=="Bicubic" ? coeffs[1] : Undefined()
!HBD || gpuid<0 ? ConvertBits(a, 8, dither=-1, fulls=fs, fulld=fs) : a
if (gpuid<0) {
if (in || oned) {
hs && !in ? TurnRight() : last
for (i = 1, in?1:xyf/2, 1) {
eedi3(field=fd, dh=!in, alpha=alpha,beta=beta,gamma=gamma,nrad=nrad,mdis=mdis,hp=hp,ucubic=ucubic,cost3=cost3,threads=0,sclip=sclip)
}
hs && !in ? TurnLeft () : last