-
-
Notifications
You must be signed in to change notification settings - Fork 5
/
TheAnimeScripter.jsx
1032 lines (865 loc) · 39.1 KB
/
TheAnimeScripter.jsx
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
var panelGlobal = this;
var TheAnimeScripter = (function () {
var scriptName = "TheAnimeScripter";
var scriptVersion = "v1.8.6";
// Default Values for the settings
var outputFolder = app.settings.haveSetting(scriptName, "outputFolder") ? app.settings.getSetting(scriptName, "outputFolder") : "undefined";
var theAnimeScripterPath = app.settings.haveSetting(scriptName, "theAnimeScripterPath") ? app.settings.getSetting(scriptName, "theAnimeScripterPath") : "undefined";
var segmentValue = 0;
var autoClipValue = 0;
var depthValue = 0;
var customModelPath = "undefined";
var consentData = app.settings.haveSetting(scriptName, "consentData") ? app.settings.getSetting(scriptName, "consentData") : false;
var exeFile = theAnimeScripterPath + "\\main.exe";
// THEANIMESCRIPTER
// ================
var TheAnimeScripter = (panelGlobal instanceof Panel) ? panelGlobal : new Window("palette");
if (!(panelGlobal instanceof Panel)) TheAnimeScripter.text = "TheAnimeScripter";
TheAnimeScripter.orientation = "column";
TheAnimeScripter.alignChildren = ["center", "top"];
TheAnimeScripter.spacing = 10;
TheAnimeScripter.margins = 10;
// PANELCHAIN
// ==========
var panelChain = TheAnimeScripter.add("panel", undefined, undefined, {
name: "panelChain"
});
panelChain.text = "Chain";
panelChain.orientation = "column";
panelChain.alignChildren = ["left", "top"];
panelChain.spacing = 10;
panelChain.margins = 10;
var buttonStartProcess = panelChain.add("button", undefined, undefined, {
name: "buttonStartProcess"
});
buttonStartProcess.text = "Start Process";
buttonStartProcess.preferredSize.width = 104;
buttonStartProcess.alignment = ["center", "top"];
var checkboxValues = {};
function createCheckboxField(panel, text, name, helpTip) {
var group = panel.add("group", undefined, {
name: "group" + name
});
group.orientation = "row";
group.alignChildren = ["left", "top"];
group.spacing = 0;
group.margins = 0;
var checkbox = group.add("checkbox", undefined, undefined, {
name: "checkbox" + name
});
checkbox.helpTip = helpTip;
var savedValue = app.settings.haveSetting(scriptName, name) ? (app.settings.getSetting(scriptName, name) === "true") : false;
checkbox.value = savedValue;
var staticText = group.add("statictext", undefined, undefined, {
name: "text" + name
});
staticText.text = text;
checkbox.onClick = function () {
checkboxValues[name] = checkbox.value;
app.settings.saveSetting(scriptName, name, checkbox.value.toString());
}
checkboxValues[name] = savedValue;
return checkbox;
}
createCheckboxField(panelChain, "Resize", "checkboxResize", "Resize by a desired factor before further processing, meant as an substitute for upscaling on lower end GPUs");
createCheckboxField(panelChain, "Deduplicate", "checkboxDeduplicate", "Deduplicate the video using a desired method, useful for removing duplicate frames and reducing file size");
createCheckboxField(panelChain, "Denoise", "checkboxDenoise", "Denoise using a desired model");
createCheckboxField(panelChain, "Upscale", "checkboxUpscale", "Upscale using a desired model and factor");
createCheckboxField(panelChain, "Interpolate", "checkboxInterpolate", "Interpolate using a desired model and factor");
createCheckboxField(panelChain, "Sharpen", "checkboxSharpen", "Sharpen the video using a desired factor");
var checkboxResizeValue = function () {
return checkboxValues["checkboxResize"];
};
var checkboxDeduplicateValue = function () {
return checkboxValues["checkboxDeduplicate"];
};
var checkboxDenoiseValue = function () {
return checkboxValues["checkboxDenoise"];
};
var checkboxUpscaleValue = function () {
return checkboxValues["checkboxUpscale"];
};
var checkboxInterpolateValue = function () {
return checkboxValues["checkboxInterpolate"];
};
var checkboxSharpenValue = function () {
return checkboxValues["checkboxSharpen"];
};
// panelPostProcess
// ==========
var panelPostProcess = TheAnimeScripter.add("panel", undefined, undefined, {
name: "panelPostProcess"
});
panelPostProcess.text = "Post Process";
panelPostProcess.orientation = "column";
panelPostProcess.alignChildren = ["left", "top"];
panelPostProcess.spacing = 10;
panelPostProcess.margins = 10;
var buttonDepthMap = panelPostProcess.add("button", undefined, undefined, {
name: "buttonDepthMap"
});
buttonDepthMap.text = "Depth Map";
buttonDepthMap.preferredSize.width = 105;
buttonDepthMap.alignment = ["center", "top"];
var buttonSegment = panelPostProcess.add("button", undefined, undefined, {
name: "buttonSegment"
});
buttonSegment.text = "Rotobrush";
buttonSegment.preferredSize.width = 105;
buttonSegment.alignment = ["center", "top"];
var buttonAutoClip = panelPostProcess.add("button", undefined, undefined, {
name: "buttonAutoClip"
});
buttonAutoClip.text = "Auto Cut";
buttonAutoClip.preferredSize.width = 105;
buttonAutoClip.alignment = ["center", "top"];
buttonGetVideo = panelPostProcess.add("button", undefined, undefined, {
name: "buttonGetVideo"
});
buttonGetVideo.text = "Get Video";
buttonGetVideo.preferredSize.width = 105;
buttonGetVideo.alignment = ["center", "top"];
buttonGetVideo.helpTip = "Get Video from Youtube using YT-DLP";
textGetVideo = panelPostProcess.add("edittext", undefined, undefined, {
name: "textGetVideo"
});
textGetVideo.text = " Add Youtube URL";
textGetVideo.preferredSize.width = 105;
textGetVideo.alignment = ["center", "top"];
// PANELMORE
// =========
var panelMore = TheAnimeScripter.add("panel", undefined, undefined, {
name: "panelMore"
});
panelMore.text = "More";
panelMore.orientation = "column";
panelMore.alignChildren = ["left", "top"];
panelMore.spacing = 10;
panelMore.margins = 10;
var buttonPreRender = panelMore.add("button", undefined, "Pre-Render", {
name: "buttonPreRender"
});
buttonPreRender.text = "Pre-Render";
buttonPreRender.alignment = ["left", "center"];
buttonPreRender.helpTip = "Pre-Render the video before further processing, useful for already modified videos or multi layered compositions";
buttonPreRender.preferredSize.width = 105;
var buttonSettings = panelMore.add("button", undefined, undefined, {
name: "buttonSettings"
});
buttonSettings.text = "Settings";
buttonSettings.preferredSize.width = 105;
buttonSettings.alignment = ["center", "top"];
var buttonCheckForUpdate = panelMore.add("button", undefined, undefined, {
name: "buttonCheckForUpdate"
});
buttonCheckForUpdate.text = "Check for Update";
buttonCheckForUpdate.preferredSize.width = 105;
buttonCheckForUpdate.alignment = ["center", "top"];
var textScriptVersion = panelMore.add("statictext", undefined, undefined, {
name: "textScriptVersion"
});
textScriptVersion.text = "Script Version: " + scriptVersion;
TheAnimeScripter.layout.layout(true);
TheAnimeScripter.layout.resize();
TheAnimeScripter.onResizing = TheAnimeScripter.onResize = function () {
this.layout.resize();
}
var settingsWindow = new Window("palette", undefined, undefined, {
resizable: true,
closeButton: false
});
settingsWindow.text = "Settings";
settingsWindow.orientation = "column";
settingsWindow.alignChildren = ["center", "top"];
settingsWindow.spacing = 10;
settingsWindow.margins = 10;
// PANELONFIRSTRUN
// ===============
var panelOnFirstRun = settingsWindow.add("panel", undefined, undefined, {
name: "panelOnFirstRun"
});
panelOnFirstRun.text = "On First Run";
panelOnFirstRun.orientation = "column";
panelOnFirstRun.alignChildren = ["left", "top"];
panelOnFirstRun.spacing = 10;
panelOnFirstRun.margins = 10;
// GROUP1
// ======
var group1 = panelOnFirstRun.add("group", undefined, {
name: "group1"
});
group1.orientation = "row";
group1.alignChildren = ["left", "center"];
group1.spacing = 10;
group1.margins = 0;
var buttonFolder = group1.add("button", undefined, undefined, {
name: "buttonFolder"
});
buttonFolder.helpTip = "Set it to wherever The Anime Scripter folder is situated.";
buttonFolder.text = "Set TAS Folder";
buttonFolder.preferredSize.width = 100;
var buttonOutput = group1.add("button", undefined, undefined, {
name: "buttonOutput"
});
buttonOutput.text = "Set Output";
buttonOutput.preferredSize.width = 100;
buttonOutput.helpTip = "Set it to wherever you want the output to be saved.";
var group2 = panelOnFirstRun.add("group", undefined, {
name: "group2"
});
var buttonCustomModel = group2.add("button", undefined, undefined, {
name: "buttonCustomModel"
});
buttonCustomModel.text = "Custom Upscaler";
buttonCustomModel.preferredSize.width = 100;
buttonCustomModel.alignment = ["center", "top"];
buttonCustomModel.helpTip = "Add a custom model to utilize, can be either .pth or .onnx, this will override the custom model of your choice in the dropdown, it has to be one of the supported architectures ( Shufflecugan, Cugan ... ) and it also relies on the upscale multiplier to match the model";
var buttonOfflineMode = group2.add("button", undefined, undefined, {
name: "buttonOfflineMode"
});
buttonOfflineMode.text = "Offline Mode";
buttonOfflineMode.preferredSize.width = 100;
buttonOfflineMode.alignment = ["center", "top"];
buttonOfflineMode.helpTip = "This will download all available models and place them in the correct directory, it will take a while and is not recommended for users with slow internet connections, but it will make the script work 100% offline with the exception of Youtube Downloads and Depth Maps";
// GENERALPANEL
// ============
var generalPanel = settingsWindow.add("panel", undefined, undefined, {
name: "generalPanel"
});
generalPanel.text = "General Settings";
generalPanel.orientation = "column";
generalPanel.alignChildren = ["left", "top"];
generalPanel.spacing = 10;
generalPanel.margins = 10;
var labelValues = {};
function createSlider(panel, text, name, defaultValue) {
var savedValue = app.settings.haveSetting(scriptName, name) ? app.settings.getSetting(scriptName, name) : defaultValue;
var group = panel.add("group", undefined, {
name: "group" + name
});
group.orientation = "column";
group.alignChildren = ["fill", "center"];
var labelGroup = group.add("group", undefined, {
name: "labelGroup" + name
});
labelGroup.orientation = "row";
labelGroup.alignChildren = ["left", "center"];
var staticText = labelGroup.add("statictext", undefined, text, {
name: "text" + name
});
staticText.justify = "center";
staticText.alignment = ["left", "center"];
var label = labelGroup.add("statictext", undefined, savedValue + "%", { // Append "%" to the initial value
name: "label" + name
});
label.alignment = ["right", "center"];
var slider = group.add("slider", undefined, savedValue, 0, 100, {
name: "slider" + name
});
slider.preferredSize.width = 212;
slider.alignment = ["center", "top"];
labelValues[name] = savedValue;
slider.onChange = function () {
var value = Math.round(slider.value);
label.text = value + "%"; // Append "%" to the value set by the slider
labelValues[name] = value;
app.settings.saveSetting(scriptName, name, value);
}
}
createSlider(generalPanel, "Sharpenening Sensitivity", "SharpenSens", 50);
createSlider(generalPanel, "Deduplication Sensitivity", "DedupSens", 50);
createSlider(generalPanel, "Auto Cut Sensitivity", "AutoClipSens", 50);
var sharpenSensValue = function () {
return labelValues["SharpenSens"];
};
var sceneChangeSensValue = function () {
return labelValues["AutoClipSens"];
};
var dedupSensValue = function () {
return labelValues["DedupSens"];
};
var fieldValues = {}
function createMultiplierField(panel, text, name, defaultValue) {
var group = panel.add("group", undefined, {
name: "group" + name
});
group.orientation = "row";
group.alignChildren = ["fill", "center"];
group.spacing = 0;
group.margins = 0;
var staticText = group.add("statictext", undefined, undefined, {
name: "text" + name
});
staticText.text = text;
staticText.preferredSize.width = 172;
staticText.alignment = ["left", "center"];
var filler = group.add("statictext", undefined, "", {
name: "filler" + name
});
filler.alignment = ["fill", "center"];
var savedValue = app.settings.haveSetting(scriptName, name) ? app.settings.getSetting(scriptName, name) : defaultValue;
var editText = group.add('edittext {justify: "center", properties: {name: "' + name + '"}}');
editText.text = savedValue;
editText.preferredSize.width = 40;
editText.alignment = ["right", "center"];
editText.onChange = function () {
fieldValues[name] = editText.text;
app.settings.saveSetting(scriptName, name, editText.text);
}
fieldValues[name] = savedValue;
return editText;
}
createMultiplierField(generalPanel, "Resize Multiplier", "ResizeMultiplier", "2");
createMultiplierField(generalPanel, "Interpolation Multiplier", "InterpolateMultiplier", "2");
createMultiplierField(generalPanel, "Upscale Multiplier", "UpscaleMultiplier", "2");
createMultiplierField(generalPanel, "Number of Threads", "ThreadsMultiplier", "1"); // Ik this is not a multiplier but it fits the theme
var consentGroup = generalPanel.add("group", undefined, {
name: "groupConsent"
});
var resizeValue = function () {
return fieldValues["ResizeMultiplier"];
};
var interpolateValue = function () {
return fieldValues["InterpolateMultiplier"];
};
var upscaleValue = function () {
return fieldValues["UpscaleMultiplier"];
};
var threadsValue = function () {
return fieldValues["ThreadsMultiplier"];
};
consentGroup.orientation = "row";
consentGroup.alignChildren = ["left", "center"];
consentGroup.spacing = 0;
consentGroup.margins = 0;
createCheckboxField(generalPanel, "Help Improve the Script", "checkboxConsent", "By enabling this option, you allow the script to send anonymous data for improvement purposes. The data includes the output found in the generated log.txt and is used solely to enhance the script's functionality. This data is not shared with any third parties. You can review the data being sent in the consent.json file located in the script directory. You can disable this option at any time.");
createCheckboxField(generalPanel, "Rife Ensemble", "checkboxEnsemble", "Use Rife Ensemble to interpolate frames, this will increase the quality of the video but also the processing time");
var checkboxConsentValue = function () {
return checkboxValues["checkboxConsent"];
}
var checkboxEnsembleValue = function () {
return checkboxValues["checkboxEnsemble"];
}
// PANEL1
// ======
var panel1 = settingsWindow.add("panel", undefined, undefined, {
name: "panel1"
});
panel1.text = "Advanced Settings";
panel1.orientation = "column";
panel1.alignChildren = ["left", "top"];
panel1.spacing = 10;
panel1.margins = 10;
var dropdownValues = {}
function createDropdownField(panel, text, name, dropdownArray, helpTip) {
var group = panel.add("group", undefined, {
name: "group" + name
});
group.orientation = "row";
group.alignChildren = ["left", "center"];
group.spacing = 0;
group.margins = 0;
var staticText = group.add("statictext", undefined, undefined, {
name: "text" + name
});
staticText.text = text;
staticText.preferredSize.width = 103;
var dropdown = group.add("dropdownlist", undefined, undefined, {
name: "dropdown" + name,
items: dropdownArray
});
dropdown.helpTip = helpTip;
var savedValue = app.settings.haveSetting(scriptName, name) ? String(app.settings.getSetting(scriptName, name)) : dropdownArray[0];
var index = indexOf(dropdownArray, savedValue);
dropdown.selection = index !== -1 ? dropdown.items[index] : dropdown.items[0];
dropdown.preferredSize.width = 109;
dropdown.preferredSize.height = 5;
dropdown.onChange = function () {
dropdownValues[name] = dropdown.selection.text;
app.settings.saveSetting(scriptName, name, dropdown.selection.text); // Save the setting when it changes
}
dropdownValues[name] = savedValue;
return dropdown;
}
function indexOf(arr, item) {
for (var i = 0; i < arr.length; i++) {
if (arr[i] === item) {
return i;
}
}
return -1;
}
createDropdownField(panel1, "Upscale Model", "Model", [
"ShuffleCugan",
"Cugan",
"Compact",
"UltraCompact",
"SuperUltraCompact",
"Span",
"ShuffleCugan-TensorRT",
"Span-TensorRT",
"Compact-TensorRT",
"UltraCompact-TensorRT",
"SuperUltraCompact-TensorRT",
"Cugan-DirectML",
"Compact-DirectML",
"UltraCompact-DirectML",
"SuperUltraCompact-DirectML",
"Span-DirectML",
"ShuffleCugan-NCNN",
"Span-NCNN",
], "Choose which model you want to utilize, read more in INFO, for AMD users choose DirectML or NCNN models");
createDropdownField(panel1, "Interpolate Model", "Interpolate", ["Rife4.17", "Rife4.17-Lite", "Rife4.16-Lite", "Rife4.15", "Rife4.15-Lite", "Rife4.6", "Rife4.17-TensorRT", "Rife4.15-TensorRT", "Rife4.15-Lite-TensorRT", "Rife4.6-TensorRT", "Rife4.16-Lite-NCNN", "Rife4.15-NCNN", "Rife4.15-Lite-NCNN", "Rife4.6-NCNN", "GMFSS"], "Choose which interpolation model you want to utilize, read more in readme.txt, for AMD users choose DirectML or NCNN models, TensorRT is for NVIDIA RTX 2000 and above GPUs");
createDropdownField(panel1, "Depth Model", "Depth", ["Small", "Base", "Large", "Small-TensorRT", "Base-TensorRT", "Large-TensorRT", "Small-DirectML", "Base-DirectML", "Large-DirectML"], "Choose which depth map model you want to utilize, ordered by speed, read more in INFO");
createDropdownField(panel1, "Encoder", "Encoder", ["X264", "X264_10Bit", "X264_Animation", "X264_Animation_10Bit", "X265", "X265_10Bit", "NVENC_H264", "NVENC_H265", "NVENC_H265_10Bit", "NVENC_AV1", "QSV_H264", "QSV_H265", "QSV_H265_10Bit", "H264_AMF", "HEVC_AMF", "HEVC_AMF_10Bit", "AV1"], "Choose which encoder you want to utilize, in no specific order, NVENC for NVidia GPUs, AMF for AMD GPUs and QSV for Intel iGPUs");
createDropdownField(panel1, "Resize Method", "Resize", ["Fast_Bilinear", "Bilinear", "Bicubic", "Experimental", "Neighbor", "Area", "Bicublin", "Gauss", "Sinc", "Lanczos", "Spline", "Spline16", "Spline36"], "Choose which resize method you want to utilize, For upscaling I would suggest Lanczos or Spline, for downscaling I would suggest Area or Bicubic");
createDropdownField(panel1, "Dedup Method", "Dedup", ["SSIM", "MSE", "SSIM-CUDA"], "Choose which deduplication method you want to utilize, SSIM-CUDA is for NVIDIA Only whilst the rest will work on any system.");
createDropdownField(panel1, "Denoise Method", "Denoise", ["SCUNet", "NAFNet", "DPIR"]);
var upscaleModel = function () {
return dropdownValues["Model"];
};
var interpolateModel = function () {
return dropdownValues["Interpolate"];
};
var depthModel = function () {
return dropdownValues["Depth"];
};
var encoderMethod = function () {
return dropdownValues["Encoder"];
};
var resizeMethod = function () {
return dropdownValues["Resize"];
};
var dedupMethod = function () {
return dropdownValues["Dedup"];
};
var denoiseMethod = function () {
return dropdownValues["Denoise"];
};
var panelCustomSettings = settingsWindow.add("panel", undefined, undefined, {
name: "panelCustomSettings"
});
panelCustomSettings.text = "Custom FFMPEG Encoding Parameters";
panelCustomSettings.orientation = "column";
panelCustomSettings.alignChildren = ["left", "top"];
var textCustomEncoder = panelCustomSettings.add("edittext", [0, 0, 202, 25], undefined, {
name: "textCustomEncoder"
});
textCustomEncoder.text = "";
textCustomEncoder.preferredSize.width = 105;
textCustomEncoder.alignment = ["center", "top"];
textCustomEncoder.helpTip = "Add custom FFMPEG encoding parameters, this will override the encoding method of your choice in the dropdown, you need to declare every new option including codec, video and filters that you might like to use, for example: -c:v libx264 -crf 23 -preset veryfast -tune animation -vf \"scale=1920:1080\"";
var buttonSettingsClose = settingsWindow.add("button", undefined, undefined, {
name: "buttonSettingsClose"
});
buttonSettingsClose.text = "Close";
buttonSettingsClose.onClick = function () {
settingsWindow.hide();
}
checkIfPathSaved = function () {
if (theAnimeScripterPath == "undefined" || theAnimeScripterPath == null) {
alert("The Anime Scripter directory has not been selected, please go to settings");
return;
}
}
buttonOfflineMode.onClick = function () {
checkIfPathSaved();
var exeFile = theAnimeScripterPath + "\\main.exe";
var exeFilePath = new File(exeFile);
if (!exeFilePath.exists) {
alert("Cannot find main.exe, please make sure you have selected the correct folder in settings!");
return;
}
var attempt = [
"cd", "\"" + theAnimeScripterPath + "\"",
"&&",
"\"" + exeFile + "\"",
"--offline",
];
var command = attempt.join(" ");
callCommand(command);
}
buttonCheckForUpdate.onClick = function () {
checkIfPathSaved();
var exeFile = theAnimeScripterPath + "\\main.exe";
var exeFilePath = new File(exeFile);
if (!exeFilePath.exists) {
alert("Cannot find main.exe, please make sure you have selected the correct folder in settings!");
return;
};
try {
var command = [
"cd", "\"" + theAnimeScripterPath + "\"",
"&&",
"\"" + exeFile + "\"",
"--update",
].join(" ");
callCommand(command);
} catch (error) {
alert(error.toString());
}
var discordServer = "https://discord.gg/CdRD9GwS8J";
var dialog2 = new Window('dialog', 'Open URL');
dialog2.add('statictext', undefined, 'Do you want to join the Discord server?');
dialog2.yesButton = dialog2.add('button', undefined, 'Yes', {
name: 'yes'
});
dialog2.noButton = dialog2.add('button', undefined, 'No', {
name: 'no'
});
dialog2.yesButton.onClick = function () {
system.callSystem('cmd.exe /c start "" "' + discordServer + '"');
dialog2.close();
}
dialog2.noButton.onClick = function () {
dialog2.close();
}
dialog2.show();
};
buttonOutput.onClick = function () {
var folder = Folder.selectDialog("Select Output folder");
if (folder != null) {
outputFolder = folder.fsName;
app.settings.saveSetting(scriptName, "outputFolder", outputFolder);
textOutputFolderValue.text = outputFolder;
}
alert("Output folder set to: " + outputFolder);
};
buttonFolder.onClick = function () {
var folder = Folder.selectDialog("Select The Anime Scripter folder");
if (folder != null) {
theAnimeScripterPath = folder.fsName;
app.settings.saveSetting(scriptName, "theAnimeScripterPath", theAnimeScripterPath);
textTheAnimeScripterFolderValue.text = theAnimeScripterPath;
}
alert("The Anime Scripter folder set to: " + theAnimeScripterPath);
};
buttonSettings.onClick = function () {
settingsWindow.show();
};
buttonAutoClip.onClick = function () {
autoClipValue = 1;
startChain();
}
buttonDepthMap.onClick = function () {
depthValue = 1;
startChain();
}
buttonSegment.onClick = function () {
segmentValue = 1;
startChain();
}
buttonStartProcess.onClick = function () {
startChain();
}
buttonGetVideo.onClick = function () {
if (textGetVideo.text == "Add Youtube URL") {
alert("Please add a Youtube URL");
return;
}
startDownload();
}
buttonPreRender.onClick = function () {
preRender();
}
buttonCustomModel.onClick = function () {
var customModel = File.openDialog("Select a Custom Model", "*.pth", false);
if (customModel != null) {
customModelPath = customModel.fsName;
customModelName = customModel.name;
alert("Custom Model set to: " + customModelName);
}
}
function callCommand(command) {
try {
if (command) {
var cmdCommand = 'cmd.exe /c "' + command + '"';
system.callSystem(cmdCommand);
} else {
throw new Error("Command is undefined");
}
} catch (error) {
return alert(error.toString());
}
return null;
}
function preRender() {
if (typeof outputFolder === 'undefined') {
alert("The output folder has not been selected, please go to settings");
return;
}
var comp = app.project.activeItem;
var selectedLayers = comp.selectedLayers;
var minStartTime = Infinity;
var maxEndTime = 0;
for (var i = 0; i < selectedLayers.length; i++) {
var layer = selectedLayers[i];
var startTime = layer.startTime;
var endTime = layer.outPoint;
if (startTime < minStartTime) {
minStartTime = startTime;
}
if (endTime > maxEndTime) {
maxEndTime = endTime;
}
}
var newCompDuration = maxEndTime - minStartTime;
var newComp = app.project.items.addComp('New Composition', comp.width, comp.height, comp.pixelAspect, newCompDuration, comp.frameRate);
for (var i = 0; i < selectedLayers.length; i++) {
var layer = selectedLayers[i];
var newLayer = newComp.layers.add(layer.source);
newLayer.startTime = layer.startTime - minStartTime;
newLayer.inPoint = layer.inPoint - minStartTime;
newLayer.outPoint = layer.outPoint - minStartTime;
newLayer.enabled = layer.enabled;
newLayer.solo = layer.solo;
newLayer.shy = layer.shy;
newLayer.locked = layer.locked;
newLayer.name = layer.name;
// Copy transformations
newLayer.position.setValue(layer.position.value);
newLayer.scale.setValue(layer.scale.value);
newLayer.rotation.setValue(layer.rotation.value);
newLayer.opacity.setValue(layer.opacity.value);
for (var j = 1; j <= layer.effect.numProperties; j++) {
var effect = layer.effect(j);
var newEffect = newLayer.effect.addProperty(effect.matchName);
for (var k = 1; k <= effect.numProperties; k++) {
newEffect.property(k).setValue(effect.property(k).value);
}
}
}
var renderQueue = app.project.renderQueue;
var render = renderQueue.items.add(newComp);
var outputModule = render.outputModule(1);
outputModule.bitrate = '50';
randomNumbers = Math.floor(Math.random() * 1000);
var outputFileExtension = (parseFloat(app.version) >= 23.0) ? ".mp4" : ".mov";
var outputName = outputFolder + "/TAS_" + randomNumbers + outputFileExtension;
outputModule.file = new File(outputName);
renderQueue.render();
var importedFile = app.project.importFile(new ImportOptions(new File(outputName)));
var newLayer = comp.layers.add(importedFile);
newComp.remove();
}
function startChain() {
if (((!app.project) || (!app.project.activeItem)) || (app.project.activeItem.selectedLayers.length < 1)) {
alert("Please select one layer.");
return;
}
if (outputFolder == "undefined" || outputFolder == null) {
alert("The output folder has not been selected, please go to settings");
return;
}
checkIfPathSaved();
var exeFile = theAnimeScripterPath + "\\main.exe";
var exeFilePath = new File(exeFile);
if (!exeFilePath.exists) {
alert("Cannot find main.exe, please make sure you have selected the correct folder in settings!");
return;
}
var comp = app.project.activeItem;
var i = 0;
var selectedLayers = comp.selectedLayers.slice();
while (i < selectedLayers.length) {
var layer = selectedLayers[i];
var activeLayerPath = layer.source.file.fsName;
var activeLayerName = layer.name;
var sourceInPoint, sourceOutPoint;
sourceInPoint = layer.inPoint - layer.startTime;
sourceOutPoint = layer.outPoint - layer.startTime;
if (layer.inPoint > sourceInPoint) {
sourceInPoint = layer.inPoint - layer.startTime;
}
if (layer.outPoint < sourceOutPoint) {
sourceOutPoint = layer.outPoint - layer.startTime;
}
if (segmentValue == 1) {
var outputFileExtension = ".mov";
} else {
var outputFileExtension = ".mp4";
}
randomNumbers = Math.floor(Math.random() * 1000);
outputName = outputFolder + "\\" + activeLayerName.replace(/\.[^\.]+$/, '') + "-" + randomNumbers + outputFileExtension;
try {
var attempt = [
"cd", "\"" + theAnimeScripterPath + "\"",
"&&",
"\"" + exeFile + "\"",
"--input", "\"" + activeLayerPath + "\"",
"--output", "\"" + outputName + "\"",
"--interpolate_factor", interpolateValue(),
"--interpolate_method", interpolateModel().toLowerCase(),
"--upscale_factor", upscaleValue(),
"--upscale_method", upscaleModel().toLowerCase(),
"--dedup_sens", dedupSensValue(),
"--dedup_method", dedupMethod().toLowerCase(),
"--half",
"--inpoint", sourceInPoint,
"--outpoint", sourceOutPoint,
"--sharpen_sens", sharpenSensValue(),
"--depth_method", depthModel().toLowerCase(),
"--encode_method", encoderMethod().toLowerCase(),
"--autoclip_sens", sceneChangeSensValue(),
"--resize_method", resizeMethod().toLowerCase(),
"--resize_factor", resizeValue(),
"--nt", threadsValue(),
"--denoise_method", denoiseMethod().toLowerCase(),
"--ae",
];
if (checkboxInterpolateValue()) {
attempt.push("--interpolate");
}
if (checkboxUpscaleValue()) {
attempt.push("--upscale");
}
if (checkboxDeduplicateValue()) {
attempt.push("--dedup");
}
if (checkboxSharpenValue()) {
attempt.push("--sharpen");
}
if (checkboxEnsembleValue()) {
attempt.push("--ensemble");
}
if (checkboxResizeValue()) {
attempt.push("--resize");
}
if (checkboxDenoiseValue()) {
attempt.push("--denoise");
}
if (checkboxConsentValue()) {
attempt.push("--consent");
}
if (segmentValue == 1) {
attempt.push("--segment");
}
if (depthValue == 1) {
attempt.push("--depth");
}
if (autoClipValue == 1) {
attempt.push("--autoclip");
}
if (customModelPath && customModelPath !== "undefined") {
attempt.push("--custom_model", customModelPath);
}
if (textCustomEncoder.text && textCustomEncoder.text !== "") {
attempt.push("--custom_encoder", '"' + textCustomEncoder.text + '"');
}
var command = attempt.join(" ");
callCommand(command);
} catch (error) {
alert(error);
}
while (true) {
if (autoClipValue == 1) {
var autoClipLogPath = theAnimeScripterPath + "\\autoclipresults.txt";
var autoClipLog = new File(autoClipLogPath);
autoClipLog.open("r");
inPoint = layer.inPoint;
outPoint = layer.outPoint;
while (!autoClipLog.eof) {
var line = autoClipLog.readln();
var timestamp = parseFloat(line) + inPoint;
var duplicateLayer = layer.duplicate();
layer.outPoint = timestamp;
duplicateLayer.inPoint = timestamp;
layer = duplicateLayer;
}
autoClipLog.close();
break;
} else {
var maxAttempts = 3;
var importSuccessful = false;
for (var attempt = 0; attempt < maxAttempts; attempt++) {
if (importSuccessful) {
break;
}
$.sleep(1000); // Sleeping for a second, metadata is not always written instantly
try {
var importOptions = new ImportOptions(File(outputName));
var importedFile = app.project.importFile(importOptions);
var inputLayer = comp.layers.add(importedFile);
inputLayer.startTime = layer.inPoint;
inputLayer.moveBefore(layer);
if (checkboxUpscaleValue() == true || checkboxResizeValue() == true) {
var compWidth = comp.width;
var compHeight = comp.height;
var layerWidth = inputLayer.source.width;
var layerHeight = inputLayer.source.height;
var scaleX = (compWidth / layerWidth) * 100;
var scaleY = (compHeight / layerHeight) * 100;
inputLayer.property("Scale").setValue([scaleX, scaleY, 100]);
} else {
var layerWidth = layer.width;
var layerHeight = layer.height;
var scaleX = (layerWidth / inputLayer.source.width) * 100;
var scaleY = (layerHeight / inputLayer.source.height) * 100;
inputLayer.property("Scale").setValue([scaleX, scaleY, 100]);
}
importSuccessful = true;
} catch (error) {
if (attempt == maxAttempts - 1) {
alert("Failed to import file after " + maxAttempts + " attempts: " + outputName);
alert("Error: " + error.toString());
}
}
}
break;
}
}
i++;
}
autoClipValue = 0;
segmentValue = 0;
depthValue = 0;
}
function startDownload() {
if (outputFolder == "undefined" || outputFolder == null) {
alert("The output folder has not been selected, please go to settings");
return;
}
checkIfPathSaved();
if (app.preferences.getPrefAsLong("Main Pref Section v2", "Pref_SCRIPTING_FILE_NETWORK_SECURITY") != 1) {
alert("Please tick the \"Allow Scripts to Write Files and Access Network\" checkbox in Scripting & Expressions");
return app.executeCommand(2359);
}
var exeFile = theAnimeScripterPath + "\\main.exe";
var exeFilePath = new File(exeFile);
if (!exeFilePath.exists) {
alert("Cannot find main.exe, please make sure you have selected the correct folder in settings!");
return;
}
var randomNumbers = Math.floor(Math.random() * 10000);
var outputName = outputFolder + "\\" + "TAS" + "_YTDLP_" + randomNumbers + ".mp4";
try {
var attempt = [
"cd", "\"" + theAnimeScripterPath + "\"",