-
Notifications
You must be signed in to change notification settings - Fork 6
/
R-ESRGAN-AnimeVideo-UI.py
2448 lines (1974 loc) · 121 KB
/
R-ESRGAN-AnimeVideo-UI.py
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
"""
########################################
# #
# R-ESRGAN-AnimeVideo-UI #
# #
# Author : github.com/Nenotriple #
# #
########################################
Description:
-------------
Easily upscale your videos and images using R-ESRGAN AI models.
More info here: https://github.com/Nenotriple/R-ESRGAN-AnimeVideo-UI
Requirements: #
ffmpeg # Included: Auto-download
ffprobe # Included: Auto-download
R-ESRGAN # Included: Auto-download
pillow # Included: Auto-install
"""
VERSION = "v1.18"
FFMPEG = "./bin/ffmpeg.exe"
FFPROBE = "./bin/ffprobe.exe"
REALESRGAN = "./bin/realesrgan-ncnn-vulkan.exe"
##########################################################################################################################################################################
##########################################################################################################################################################################
# #
#region - Imports #
# #
import os
import io
import re
import sys
import glob
import time
import ctypes
import shutil
import datetime
import threading
import mimetypes
import subprocess
import tkinter as tk
from tkinter import ttk, scrolledtext, filedialog, simpledialog, messagebox, Toplevel, Frame, TclError
from subprocess import TimeoutExpired
from PIL import Image, ImageTk, ImageSequence
#endregion
##########################################################################################################################################################################
##########################################################################################################################################################################
# #
#region - AboutWindow #
# #
class AboutWindow(tk.Toplevel):
info_text = (
"Supported Video Types:\n"
" - mp4, gif, avi, mkv, webm, mov, m4v, wmv\n"
"\nNOTE:\n"
" - The Upscale and Merge operations delete the previous frames by default.\n"
" - If you want to keep those frames, make sure to enable the Keep Frames option.\n"
" - The resize operation overwrites frames.\n"
"\nUpscale Frames:\n"
" - Select a upscale model in the options/extra menu. Default= realesr-animevideov3 \n"
" - Select a scaling factor in the options/extra menu. Default= x2 \n"
"\nTools:\n"
" - Batch Upscale: Upscales all images in a folder. The source images are not deleted.\n"
" - Upscale Image: Upscale a single image. The source image is not deleted.\n"
" - Resize: Scale extracted or upscaled frames to any size.\n"
" - Create Sample: Check this to create a short upscale sample of the selected video.\n"
"\nYou can right-click grayed-out buttons to enable them out of sequence.\n"
" - Only use if you know what you're doing!"
)
def __init__(self, master=None):
super().__init__(master=master)
self.title("About")
self.geometry("400x150")
self.set_icon()
self.url_button = tk.Button(self, text="Open: github.com/Nenotriple/R-ESRGAN-AnimeVideo-UI", relief="flat", overrelief="groove", fg="blue", command=self.open_url)
self.url_button.pack(fill="x")
self.made_by_label = tk.Label(self, text=f"{VERSION} - (2023 - 2024) Created by: Nenotriple", font=("Arial", 11))
self.made_by_label.pack(anchor="center", pady=5)
self.credits_text = tk.Label(self, text= ("ffmpeg-6.0-essentials: ffmpeg.org\nReal-ESRGAN_portable: github.com/xinntao/Real-ESRGAN\n\nAnd thank you for using my app! I truly appreciate it (◠‿◠✿)"), justify="left", width=50)
self.credits_text.pack(pady=5)
def open_url(self):
url = 'https://github.com/Nenotriple/R-ESRGAN-AnimeVideo-UI'
import webbrowser
webbrowser.open(url)
print(f"Opening URL: {url}")
def set_icon(root):
if getattr(sys, 'frozen', False):
application_path = sys._MEIPASS
elif __file__:
application_path = os.path.dirname(__file__)
icon_path = os.path.join(application_path, "icon.ico")
try:
root.iconbitmap(icon_path)
except TclError:
pass
#endregion
##########################################################################################################################################################################
##########################################################################################################################################################################
# #
#region - ToolTips #
# #
class ToolTip:
def __init__(self, widget, x_offset=0, y_offset=0):
self.widget = widget
self.tip_window = None
self.x_offset = x_offset
self.y_offset = y_offset
self.id = None
self.hide_time = 0
def show_tip(self, tip_text, x, y):
if self.tip_window or not tip_text:
return
x += self.x_offset
y += self.y_offset
self.tip_window = tw = Toplevel(self.widget)
tw.wm_overrideredirect(True)
tw.wm_geometry(f"+{x}+{y}")
tw.wm_attributes("-topmost", True)
tw.wm_attributes("-disabled", True)
label = tk.Label(tw, text=tip_text, background="#ffffee", relief="ridge", borderwidth=1, justify="left", padx=4, pady=4)
label.pack()
self.id = self.widget.after(20000, self.hide_tip)
def hide_tip(self):
tw = self.tip_window
self.tip_window = None
if tw:
tw.destroy()
self.hide_time = time.time()
@staticmethod
def create_tooltip(widget, text, delay=0, x_offset=0, y_offset=0):
tool_tip = ToolTip(widget, x_offset, y_offset)
def enter(event):
if tool_tip.id:
widget.after_cancel(tool_tip.id)
if time.time() - tool_tip.hide_time > 0.1:
tool_tip.id = widget.after(delay, lambda: tool_tip.show_tip(text, widget.winfo_pointerx(), widget.winfo_pointery()))
def leave(event):
if tool_tip.id:
widget.after_cancel(tool_tip.id)
tool_tip.hide_tip()
widget.bind('<Enter>', enter)
widget.bind('<Leave>', leave)
#endregion
##########################################################################################################################################################################
##########################################################################################################################################################################
# #
#region - Main Class #
# #
print(f"rev-ui {VERSION} - https://github.com/Nenotriple/R-ESRGAN-AnimeVideo-UI\n")
class reav_ui(tk.Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.pack(fill=tk.BOTH, expand=1)
self.app_state = tk.StringVar()
self.scale_type = tk.StringVar()
self.percent_complete = tk.StringVar()
self.resize_resolution = tk.StringVar()
self.sample_start_time = tk.StringVar()
self.skip_upscale = tk.StringVar(value=0)
self.selected_resize_file = tk.StringVar()
self.scale_raw = tk.StringVar(value="50%")
self.scale_factor = tk.StringVar(value="2")
self.b_src_folder_entry_text = tk.StringVar()
self.b_out_folder_entry_text = tk.StringVar()
self.resize_folder_entry_text = tk.StringVar()
self.output_format = tk.StringVar(value="mp4")
self.audio_bitrate = tk.StringVar(value="Auto From Source")
self.video_bitrate = tk.StringVar(value="Auto From Source")
self.scale_upscaled = tk.StringVar(value="50%")
self.output_codec = tk.StringVar(value="libx264")
self.upscale_model = tk.StringVar(value="realesr-animevideov3")
self.resize_factor = tk.DoubleVar()
self.auto_var = tk.IntVar(value=0)
self.keep_raw_var = tk.IntVar(value=0)
self.sample_duration = tk.IntVar(value=5)
self.keep_upscaled_var = tk.IntVar(value=0)
self.generate_sample_var = tk.IntVar(value=0)
self.auto_resize_upscaled_var = tk.IntVar(value=0)
self.auto_resize_extracted_var = tk.IntVar(value=0)
self.single_image_upscale_output = ""
# Create interface
self.create_interface()
self.create_trace()
# Create frame folders
self.create_directory('raw_frames')
self.create_directory('upscaled_frames')
self.about_window = None
self.video_file = []
self.sample_video_file = []
self.process = None
self.process_stopped = False
self.timer_running = False
self.start_time = time.time()
# This is the framerate used if the value can't be retrieved from the video.
self.FALLBACK_FPS = 30
# These buttons are disabled on startup to guide the user to the "Select Video" button.
self.extract_button.config(state='disabled')
self.merge_button.config(state='disabled')
self.upscale_button.config(state='disabled')
# This is where we supply definitions for "mimetypes", so it knows these files are videos.
mimetypes.add_type("video/mkv", ".mkv")
mimetypes.add_type("video/webm", ".webm")
mimetypes.add_type("video/wmv", ".wmv")
mimetypes.add_type("video/3gp", ".3gp")
# This is where we define all supported video types.
self.supported_video_types = ["video/mp4", "video/avi",
"video/mkv", "video/mov",
"video/m4v", "video/wmv",
"video/webm", "image/gif",
"video/3gp"]
# This is where we define all supported image types.
self.supported_image_types = ['.jpg', '.jpeg', '.jpg_large', '.png', '.jfif', '.webp', '.bmp']
# This is used to ensure a graceful shutdown when closing the window.
root.protocol("WM_DELETE_WINDOW", self.on_closing)
def create_interface(self):
self.create_menubar()
self.create_labels()
self.create_primary_notebook()
self.create_video_tab1()
self.create_video_notebook()
self.create_thumbnail_tab1()
self.create_extra_settings_tab2()
self.create_image_tab2()
self.create_info_tab3()
#endregion
##########################################################################################################################################################################
##########################################################################################################################################################################
# #
#region - Menubar #
# #
def create_menubar(self):
self.menubar = tk.Menu(self.master)
self.master.config(menu=self.menubar)
# File Menu
self.fileMenu = tk.Menu(self.menubar, tearoff=0)
self.menubar.add_cascade(label="File", underline=0, menu=self.fileMenu)
self.fileMenu.add_command(label="Open: Extracted Frames", underline=6, command=lambda: os.startfile('raw_frames'))
self.fileMenu.add_command(label="Open: Upscaled Frames", underline=6, command=lambda: os.startfile('upscaled_frames'))
self.fileMenu.add_separator()
self.fileMenu.add_command(label="Clear: Extracted Frames", command=lambda: self.fileMenu_clear_frames('raw_frames'))
self.fileMenu.add_command(label="Clear: Upscaled Frames", command=lambda: self.fileMenu_clear_frames('upscaled_frames'))
# Options Menu
self.optionsMenu = tk.Menu(self.menubar, tearoff=0)
self.menubar.add_cascade(label="Options", underline=0, menu=self.optionsMenu)
# Upscale Model
self.modelMenu = tk.Menu(self.optionsMenu, tearoff=0)
self.optionsMenu.add_cascade(label="Upscale Model", underline=8, menu=self.modelMenu)
for model in ["realesr-animevideov3", "RealESRGAN_General_x4_v3", "realesrgan-x4plus", "realesrgan-x4plus-anime"]:
self.modelMenu.add_radiobutton(label=model, variable=self.upscale_model, value=model)
# Scale Factor
self.scaleMenu = tk.Menu(self.optionsMenu, tearoff=0)
self.optionsMenu.add_cascade(label="Upscale Factor", underline=8, menu=self.scaleMenu)
for i in ["1", "2", "3", "4"]:
self.scaleMenu.add_radiobutton(label="x"+i, underline=1, variable=self.scale_factor, value=i)
self.optionsMenu.add_separator()
# Output Format
self.formatMenu = tk.Menu(self.optionsMenu, tearoff=0)
self.optionsMenu.add_cascade(label="Video Output: Format", underline=15, menu=self.formatMenu)
for format in ["mp4", "HQ gif", "LQ gif"]:
self.formatMenu.add_radiobutton(label=format, variable=self.output_format, value=format)
# Output Codec
self.formatMenu = tk.Menu(self.optionsMenu, tearoff=0)
self.optionsMenu.add_cascade(label="Video Output: Codec", underline=14, menu=self.formatMenu)
for format in ["libx264", "libx265"]:
self.formatMenu.add_radiobutton(label=format, variable=self.output_codec, value=format)
# Output Video Bitrate
self.formatMenu = tk.Menu(self.optionsMenu, tearoff=0)
self.optionsMenu.add_cascade(label="Output: Video Bitrate", underline=14, menu=self.formatMenu)
for format in ["Auto", "Auto From Source", "250k", "500k", "1000k", "1500k", "2500k", "3500k", "5000k", "7500k", "10000k", "20000k", "35000k", "50000k", "80000k"]:
self.formatMenu.add_radiobutton(label=format, variable=self.video_bitrate, value=format)
# Output Audio Bitrate
self.audioFormatMenu = tk.Menu(self.optionsMenu, tearoff=0)
self.optionsMenu.add_cascade(label="Output: Audio Bitrate", underline=14, menu=self.audioFormatMenu)
for format in ["Auto", "Auto From Source", "48k", "64k", "128k", "192k", "256k", "320k"]:
self.audioFormatMenu.add_radiobutton(label=format, variable=self.audio_bitrate, value=format)
# Tools Menu
self.toolsMenu = tk.Menu(self.menubar, tearoff=0)
self.menubar.add_cascade(label="Tools", underline=0, menu=self.toolsMenu)
self.toolsMenu.add_command(label="Batch/Single Image Upscale", underline=0, command=lambda: self.primary_notebook.select(self.primary_tab2))
self.toolsMenu.add_command(label="Upscale a Single Image", underline=10, command=self.select_and_upscale_image)
self.toolsMenu.add_separator()
self.toolsMenu.add_command(label="Resize: Extracted Frames", underline=8, command=lambda: self.confirm_scale("raw_frames"))
self.toolsMenu.add_command(label="Resize: Upscaled Frames", underline=8, command=lambda: self.confirm_scale("upscaled_frames"))
# About Menu
self.menubar.add_command(label="About", underline=0, command=self.toggle_about_window)
#endregion
##########################################################################################################################################################################
##########################################################################################################################################################################
# #
#region - Labels #
# #
def create_labels(self):
self.label_frame = tk.Frame(self)
self.label_frame.pack(side="top", fill="both", expand=True)
# Filename
self.top_label = tk.Label(self.label_frame, wraplength=500, text="Select a video to begin!\n\n")
self.top_label.pack(side="top", fill="x")
self.top_label.bind("<Button-3>", self.copy_to_clipboard)
# Console Output
self.middle_label = tk.Label(self.label_frame, wraplength=500, text="\n")
self.middle_label.pack(side="top", fill="x")
self.middle_label.bind("<Button-3>", self.copy_to_clipboard)
# Operation
self.bottom_label = tk.Label(self.label_frame, wraplength=500, text="\n")
self.bottom_label.pack(side="top", fill="x")
self.bottom_label.bind("<Button-3>", self.copy_to_clipboard)
# Timer
self.timer_label = tk.Label(self.label_frame, wraplength=500, text="\n")
self.timer_label.pack(side="top", fill="x")
# Progress Bar
self.progressbar = ttk.Progressbar(self.label_frame)
self.progressbar.configure(orient="horizontal", variable=self.percent_complete)
self.progressbar.pack(side="bottom", fill="x", padx=4)
#endregion
##########################################################################################################################################################################
##########################################################################################################################################################################
# #
#region - Create Primary Notebook #
# #
def create_primary_notebook(self):
self.primary_notebook = ttk.Notebook(self)
self.primary_tab1 = Frame(self.primary_notebook)
self.primary_tab2 = Frame(self.primary_notebook)
self.primary_notebook.add(self.primary_tab1, text='Video')
self.primary_notebook.add(self.primary_tab2, text='Image')
self.primary_notebook.pack(fill='both')
#endregion
##########################################################################################################################################################################
##########################################################################################################################################################################
# #
#region - Video - tab1 #
# #
def create_video_tab1(self):
self.video_frame = tk.Frame(self.primary_tab1)
self.video_frame.pack(side="top", pady=4, fill="both", expand=True)
# Select Video
self.select_video_frame = tk.Frame(self.video_frame)
self.select_video_frame.pack(fill="x", expand=True)
self.select_video_button = tk.Button(self.select_video_frame, takefocus=False, text="1) Select Video\t", width=57)
self.select_video_button["command"] = self.select_video
self.select_video_button.pack(side="left", fill="x")
self.bind_widget_highlight(self.select_video_button)
# Create Sample
self.generate_sample_check = tk.Checkbutton(self.select_video_frame, text="Create Sample ", takefocus=False, variable=self.generate_sample_var)
self.generate_sample_check.pack(side="left", fill="x")
ToolTip.create_tooltip(self.generate_sample_check,
"Enable this to create a sample from the middle of the video."
" (Video thumbnail also starts at the middle of the video)\n\n"
"Three videos will be created during processing:\n"
" 1.*_SAMPLE.* - Created during extraction - Raw sample video\n"
" 2.*_UPSCALE.mp4 - Created during upscale - Upscaled sample video\n"
" 3.*_HSTACK.mp4 - Created during merge - Raw + Upscaled videos merged in an hstack\n\n"
"Samples cannot be created from gif files.\n"
"Some videos won't create perfect frame time samples."
" In these cases there will be a very small delay between the videos.",250,6,4)
self.bind_widget_highlight(self.generate_sample_check, add="+")
self.button_frame1 = tk.Frame(self.video_frame)
self.button_frame1.pack(fill="x", anchor='center')
# Extract
self.extract_button = tk.Button(self.button_frame1, takefocus=False, text="2) Extract Frames ", justify="left", command=self.extract_frames, width=57, height=1)
self.extract_button.pack(side="left", fill="x", pady=3)
self.extract_button.bind('<Button-3>', lambda event: self.extract_button.config(state='normal'))
self.bind_widget_highlight(self.extract_button)
# Keep raw_frames
self.keep_raw_check = tk.Checkbutton(self.button_frame1, takefocus=False, text="Keep\t ", variable=self.keep_raw_var)
self.keep_raw_check.pack(side="left", fill="x", pady=3)
ToolTip.create_tooltip(self.keep_raw_check, "Enable this before Upscaling or closing the window to save Raw Frames.", 250, 6, 4)
self.bind_widget_highlight(self.keep_raw_check, add="+")
self.button_frame2 = tk.Frame(self.video_frame)
self.button_frame2.pack(fill="x", anchor='center')
# Upscale
self.upscale_button = tk.Button(self.button_frame2, takefocus=False, text="3) Upscale Frames", justify="left", width=57, height=1)
self.upscale_button["command"] = self.upscale_frames
self.upscale_button.pack(side="left", fill="x")
self.upscale_button.bind('<Button-3>', lambda event: self.upscale_button.config(state='normal'))
self.bind_widget_highlight(self.upscale_button)
# Keep upscaled_frames
self.keep_upscaled_check = tk.Checkbutton(self.button_frame2, takefocus=False, text="Keep", variable=self.keep_upscaled_var)
self.keep_upscaled_check.pack(side="left", fill="x", pady=3)
ToolTip.create_tooltip(self.keep_upscaled_check, "Enable this before Merging or closing the window to save Upscaled Frames.", 250, 6, 4)
self.bind_widget_highlight(self.keep_upscaled_check, add="+")
# Skip Upscale
self.skip_upscale_checkbutton = tk.Checkbutton(self.button_frame2, text="Skip ", takefocus=False, variable=self.skip_upscale, command=self.toggle_upscale)
ToolTip.create_tooltip(self.skip_upscale_checkbutton, "Skip the upscale process.\nUseful if you just want to resize a video", 250, 6, 4)
self.skip_upscale_checkbutton.pack(side="left", anchor="w")
self.bind_widget_highlight(self.skip_upscale_checkbutton, add="+")
self.button_frame3 = tk.Frame(self.video_frame)
self.button_frame3.pack(fill="x", anchor='center')
# Merge
self.merge_button = tk.Button(self.button_frame3, takefocus=False, text="4) Merge Frames ", justify="left", command=self.merge_frames, width=57)
self.merge_button.pack(side="left", fill="x")
self.merge_button.bind('<Button-3>', lambda event: self.merge_button.config(state='normal'))
self.bind_widget_highlight(self.merge_button)
# Auto
self.auto_var.trace_add("write", lambda *args: self.toggle_auto_widgets())
self.auto_check = tk.Checkbutton(self.button_frame3, takefocus=False, text="Auto\t ", variable=self.auto_var)
self.auto_check.pack(side="left", fill="x", pady=3)
ToolTip.create_tooltip(self.auto_check, "Enable this to automatically Upscale/Merge Frames after Extracting/Upscaling.", 250, 6, 4)
self.bind_widget_highlight(self.auto_check, add="+")
# Stop
self.stop_button = tk.Button(self.video_frame, takefocus=False, text="STOP", command=self.stop_process)
self.stop_button.pack(side="top", fill="x")
self.bind_widget_highlight(self.stop_button)
#endregion
##########################################################################################################################################################################
##########################################################################################################################################################################
# #
#region - Create Video_notebook #
# #
def create_video_notebook(self):
self.video_notebook = ttk.Notebook(self.primary_tab1, takefocus=False)
self.thumbnail_tab1 = Frame(self.video_notebook)
self.extra_tab2 = Frame(self.video_notebook)
self.info_tab3 = Frame(self.video_notebook)
self.video_notebook.add(self.thumbnail_tab1, text='Video Thumbnail')
self.video_notebook.add(self.extra_tab2, text='Extra Settings')
self.video_notebook.add(self.info_tab3, text='Info')
self.video_notebook.pack(fill='both')
#endregion
##########################################################################################################################################################################
##########################################################################################################################################################################
# #
#region - Create thumbnail_tab1 and info_tab3 #
# #
def create_thumbnail_tab1(self):
self.thumbnail_label = tk.Label(self.thumbnail_tab1)
self.thumbnail_label.pack(side="top", fill="both", expand=True)
self.infotext = scrolledtext.ScrolledText(self.thumbnail_tab1, wrap="word", font=("TkDefaultFont", 9))
self.infotext.insert(tk.INSERT, AboutWindow.info_text)
self.infotext.configure(state='disabled')
self.infotext.pack(side="top", fill="both", expand=True)
def create_info_tab3(self):
infotext = scrolledtext.ScrolledText(self.info_tab3, wrap="word", font=("TkDefaultFont", 9))
infotext.insert(tk.INSERT, AboutWindow.info_text)
infotext.configure(state='disabled')
infotext.pack(side="top", fill="both", expand=True)
#endregion
##########################################################################################################################################################################
##########################################################################################################################################################################
# #
#region - extra_tab2 #
# #
def create_extra_settings_tab2(self):
####### Video Options ##################################################
self.options_frame = tk.Frame(self.extra_tab2)
self.options_frame.pack(side="top", fill="x")
# Upscale Model
self.upscale_model_frame = tk.Frame(self.options_frame)
self.upscale_model_frame.pack(side="left", fill="x", padx=2, pady=2, expand=True)
self.model_label = tk.Label(self.upscale_model_frame, text="Upscale Model")
ToolTip.create_tooltip(self.model_label, "This changes the AI model used for upscaling", 250, 6, 4)
self.model_label.pack(side="top", anchor="w")
self.upscale_model_values = ["realesr-animevideov3", "RealESRGAN_General_x4_v3", "realesrgan-x4plus", "realesrgan-x4plus-anime"]
self.upscale_model_combobox = ttk.Combobox(self.upscale_model_frame, takefocus=False, state="readonly", textvariable=self.upscale_model, values=self.upscale_model_values)
self.upscale_model_combobox.set("realesr-animevideov3")
self.upscale_model_combobox.pack(side="left", fill="x", expand=True)
# Upscale Factor
self.scale_factor_frame = tk.Frame(self.options_frame)
self.scale_factor_frame.pack(side="left", fill="x", padx=2, pady=2, expand=True)
self.scale_label = tk.Label(self.scale_factor_frame, text="Upscale Factor")
ToolTip.create_tooltip(self.scale_label, "This is the scaling factor (2 = x2 image size)", 250, 6, 4)
self.scale_label.pack(side="top", anchor="w")
self.scale_factor_values = ["1", "2", "3", "4"]
self.scale_factor_combobox = ttk.Combobox(self.scale_factor_frame, width="6", takefocus=False, state="readonly", textvariable=self.scale_factor, values=self.scale_factor_values)
self.scale_factor_combobox.set("2")
self.scale_factor_combobox.pack(side="left", fill="x", expand=True)
# Output Format Combobox
self.output_frame = tk.Frame(self.options_frame)
self.output_frame.pack(side="left", fill="x", padx=2, pady=2, expand=True)
self.output_label = tk.Label(self.output_frame, text="Output Format")
ToolTip.create_tooltip(self.output_label, "This is the video output format", 250, 6, 4)
self.output_label.pack(side="top", anchor="w")
self.output_format_values = ["mp4", "HQ gif", "LQ gif"]
self.output_format_combobox = ttk.Combobox(self.output_frame, width="6", takefocus=False, state="readonly", textvariable=self.output_format, values=self.output_format_values)
self.output_format_combobox.set("mp4")
self.output_format_combobox.pack(side="left", fill="x", expand=True)
# Output Codec Combobox
self.output_codec_frame = tk.Frame(self.options_frame)
self.output_codec_frame.pack(side="left", fill="x", padx=2, pady=2, expand=True)
self.output_codec_label = tk.Label(self.output_codec_frame, text="Output Codec")
ToolTip.create_tooltip(self.output_codec_label, "libx264 = Works everywhere / Slightly bigger videos\n\nlibx265 = Saves space, Good for HD / Needs more power, not as much support", 250, 6, 4)
self.output_codec_label.pack(side="top", anchor="w")
self.output_codec_values = ["libx264", "libx265"]
self.output_codec_combobox = ttk.Combobox(self.output_codec_frame, takefocus=False, state="readonly", textvariable=self.output_codec, values=self.output_codec_values)
self.output_codec_combobox.set("libx264")
self.output_codec_combobox.pack(side="left", fill="x", expand=True)
# Options Row 2
self.options_frame2 = tk.Frame(self.extra_tab2)
self.options_frame2.pack(side="top", fill="x", padx=2, pady=2)
# Output video Bitrate
self.output_bitrate_frame = tk.Frame(self.options_frame2)
self.output_bitrate_frame.pack(side="left", fill="x", padx=2, pady=2, expand=True)
self.output_video_bitrate_label = tk.Label(self.output_bitrate_frame, text="Video Bitrate")
ToolTip.create_tooltip(self.output_video_bitrate_label, "(Kilobits per second)\nLow value = Smaller file size and lower quality.\nHigher value = Better video quality and larger file.\nOr enter a custom value.\n\nAuto fs - Attempt to force a higher bitrate based on the source bitrate.\nAuto - Let ffmpeg handle bitrate.", 250, 6, 4)
self.output_video_bitrate_label.pack(side="top", anchor="w")
self.output_bitrate_values = ["Auto", "Auto From Source", "250k", "500k", "1000k", "1500k", "2500k", "3500k", "5000k", "7500k", "10000k", "20000k", "35000k", "50000k", "80000k"]
self.output_video_bitrate_combobox = ttk.Combobox(self.output_bitrate_frame, width="16", takefocus=False, textvariable=self.video_bitrate, values=self.output_bitrate_values)
self.output_video_bitrate_combobox.set("Auto From Source")
self.output_video_bitrate_combobox.pack(side="left", fill="x", expand=True)
# Output audio Bitrate
self.output_audio_bitrate_frame = tk.Frame(self.options_frame2)
self.output_audio_bitrate_frame.pack(side="left", fill="x", padx=2, pady=2, expand=True)
self.output_audio_bitrate_label = tk.Label(self.output_audio_bitrate_frame, text="Audio Bitrate")
ToolTip.create_tooltip(self.output_audio_bitrate_label, "(Kilobits per second)\nLow value = Smaller file size and lower quality.\nHigher value = Better audio quality and larger file.\nOr enter a custom value.\n\nAuto fs - Attempt to force a higher bitrate based on the source bitrate.\nAuto - Let ffmpeg handle bitrate.", 250, 6, 4)
self.output_audio_bitrate_label.pack(side="top", anchor="w")
self.output_audio_bitrate_values = ["Auto", "Auto From Source", "48k", "64k", "128k", "192k", "256k", "320k"]
self.output_audio_bitrate_combobox = ttk.Combobox(self.output_audio_bitrate_frame, width="16", takefocus=False, textvariable=self.audio_bitrate, values=self.output_audio_bitrate_values)
self.output_audio_bitrate_combobox.set("Auto From Source")
self.output_audio_bitrate_combobox.pack(side="left", fill="x", expand=True)
# Sample Duration Combobox
self.sample_duration_frame = tk.Frame(self.options_frame2)
self.sample_duration_frame.pack(side="left", fill="x", padx=2, pady=2, expand=True)
self.sample_duration_label = tk.Label(self.sample_duration_frame, text="Sample Duration", state="disabled")
ToolTip.create_tooltip(self.sample_duration_label, "Sample Duration in seconds\nEnable 'Create Sample' to access.", 250, 6, 4)
self.sample_duration_label.pack(side="top", anchor="w")
self.sample_duration_values = [str(i) for i in range(1, 11)]
self.sample_duration_combobox = ttk.Combobox(self.sample_duration_frame, width="6", takefocus=False, state="disabled", textvariable=self.sample_duration, values=self.sample_duration_values)
self.sample_duration_combobox.set("5")
self.sample_duration_combobox.pack(side="left", fill="x", expand=True)
# Sample Start Time Combobox
self.sample_start_time_frame = tk.Frame(self.options_frame2)
self.sample_start_time_frame.pack(side="left", fill="x", padx=2, pady=2, expand=True)
self.sample_start_time_label = tk.Label(self.sample_start_time_frame, text="Sample Start Time", state="disabled")
ToolTip.create_tooltip(self.sample_start_time_label, "Sample Start Time in seconds\nAuto=Middle of video.\nFormat: 00:00:00 - hours:minutes:seconds\nEnable 'Create Sample' to access.", 250, 6, 4)
self.sample_start_time_label.pack(side="top", anchor="w")
self.sample_start_time_values = ["Auto", "00:00:00", "00:00:30", "00:05:00", "00:10:00"]
self.sample_start_time_combobox = ttk.Combobox(self.sample_start_time_frame, values=self.sample_start_time_values, width="6", takefocus=False, textvariable=self.sample_start_time)
self.sample_start_time.set("Auto")
self.sample_start_time_combobox.config(state="disabled")
self.sample_start_time_combobox.pack(side="left", fill="x", expand=True)
# Reset
self.reset_frame = tk.Frame(self.extra_tab2)
self.reset_frame.pack(side="top", fill="x", padx=2, pady=10)
self.reset_button = tk.Button(self.reset_frame, takefocus=False, text="Reset settings to default", command=lambda: self.reset_settings())
self.reset_button.pack(fill="x", expand=True)
self.bind_widget_highlight(self.reset_button)
####### Scale Options ##################################################
self.scale_frame = tk.Frame(self.extra_tab2, borderwidth=1, relief="groove")
self.scale_frame.pack(side="top", fill="x")
self.extra_title_label = tk.Label(self.scale_frame, text="Auto Resize Frames", font=(None, 14))
ToolTip.create_tooltip(self.extra_title_label, "Enable 'Auto' to interact with these options", 250, 6, 4)
self.extra_title_label.pack(side="top")
# Resize extracted frames
self.scale_raw_frame = tk.Frame(self.scale_frame, borderwidth=1, relief="groove")
self.scale_raw_frame.pack(side="top", fill="x")
self.resize_extracted_check = tk.Checkbutton(self.scale_raw_frame, text="Auto resize extracted frames before upscaling: ", variable=self.auto_resize_extracted_var, takefocus=False, state="disabled")
self.resize_extracted_check.pack(side="left")
ToolTip.create_tooltip(self.resize_extracted_check, "This will resize the extracted frames\nIt may be useful to downscale the image, then upscale to the target resolution", 250, 6, 4)
self.bind_widget_highlight(self.resize_extracted_check, add="+")
self.scale_raw_entry = tk.Entry(self.scale_raw_frame, textvariable=self.scale_raw, takefocus=False, state="disabled")
self.scale_raw_entry.pack(side="right", fill="both", expand=True)
self.spacer_frame3 = tk.Frame(self.scale_frame, height=4)
self.spacer_frame3.pack(fill="x")
# Resize upscaled frames
self.scale_upscaled_frame = tk.Frame(self.scale_frame, borderwidth=1, relief="groove")
self.scale_upscaled_frame.pack(side="top", fill="x")
self.scale_upscaled_check = tk.Checkbutton(self.scale_upscaled_frame, text="Auto resize upscaled frames before merging: ", variable=self.auto_resize_upscaled_var, takefocus=False, state="disabled")
self.scale_upscaled_check.pack(side="left")
ToolTip.create_tooltip(self.scale_upscaled_check, "This will resize the upscaled frames\nIt can be used to set the output video resolution", 250, 6, 4)
self.bind_widget_highlight(self.scale_upscaled_check, add="+")
self.scale_upscaled_entry = tk.Entry(self.scale_upscaled_frame, textvariable=self.scale_upscaled, takefocus=False, state="disabled")
self.scale_upscaled_entry.pack(side="right", fill="both", expand=True)
self.extra_label = tk.Label(self.scale_frame, state="disabled", justify="left", wraplength=480, text="You can enter values in 3 ways:\nPercentage = 10%, 50%, Multiplier = x0.25, x2, Exact Resolution = 100x100 or 200,200")
self.extra_label.pack(side="top", anchor="w")
#endregion
##########################################################################################################################################################################
##########################################################################################################################################################################
# #
#region - Image tab2 #
# #
def create_image_tab2(self):
self.image_options_frame = tk.Frame(self.primary_tab2)
self.image_options_frame.pack(side="top", fill="x", padx=2, pady=2)
self.update_model_menu()
# Upscale Model
self.upscale_model_frame = tk.Frame(self.image_options_frame)
self.upscale_model_frame.pack(side="left", fill="x", padx=2, pady=2, expand=True)
self.model_label_tab2 = tk.Label(self.upscale_model_frame, text="Upscale Model")
ToolTip.create_tooltip(self.model_label_tab2, "This changes the AI model used for upscaling", 250, 6, 4)
self.model_label_tab2.pack(side="top", anchor="w")
self.upscale_model_combobox_tab2 = ttk.Combobox(self.upscale_model_frame, takefocus=False, state="readonly", textvariable=self.upscale_model, values=self.upscale_model_values)
self.upscale_model_combobox_tab2.set("realesr-animevideov3")
self.upscale_model_combobox_tab2.pack(side="left", fill="x", expand=True)
# Upscale Factor
self.scale_factor_frame = tk.Frame(self.image_options_frame)
self.scale_factor_frame.pack(side="left", fill="x", padx=2, pady=2, expand=True)
self.scale_label_tab2 = tk.Label(self.scale_factor_frame, text="Upscale Factor")
ToolTip.create_tooltip(self.scale_label_tab2, "This is the scaling factor (2 = x2 image size)", 250, 6, 4)
self.scale_label_tab2.pack(side="top", anchor="w")
self.scale_factor_combobox_tab2 = ttk.Combobox(self.scale_factor_frame, takefocus=False, state="readonly", textvariable=self.scale_factor, values=self.scale_factor_values)
self.scale_factor_combobox_tab2.set("2")
self.scale_factor_combobox_tab2.pack(side="left", fill="x", expand=True)
####### Single Image ##################################################
self.image_upscale_frame = tk.Frame(self.primary_tab2)
self.image_upscale_frame.pack(side="top", pady=4, fill="x")
self.image_upscale_title_label = tk.Label(self.image_upscale_frame, text="Single Image Upscale", font=(None, 14))
self.image_upscale_title_label.pack(side="top")
self.image_upscale_label = tk.Label(self.image_upscale_frame, text="Select a single image to upscale.\nThe output will be saved in the same directory with '_UP' appened to the filename.")
self.image_upscale_label.pack(side="top")
self.upscale_image_button = tk.Button(self.image_upscale_frame, takefocus=False, text="Select and upscale image", command=lambda: self.select_and_upscale_image())
self.upscale_image_button.pack(fill="x", expand=True)
self.bind_widget_highlight(self.upscale_image_button)
self.open_dir_button = tk.Button(self.image_upscale_frame, text="Open directory of last upscaled image", takefocus=False, command=lambda: self.open_directory(self.single_image_upscale_output))
self.open_dir_button.pack(fill="x", expand=True)
self.bind_widget_highlight(self.open_dir_button)
####### Batch Upscale ##################################################
self.b_upscale_frame = tk.Frame(self.primary_tab2)
self.b_upscale_frame.pack(side="top", pady=4, fill="x")
self.b_upscale_title_label = tk.Label(self.b_upscale_frame, text="Batch Upscale", font=(None, 14))
self.b_upscale_title_label.pack(side="top")
self.b_upscale_label = tk.Label(self.b_upscale_frame, text="Select a folder containing images to upscale.\nIf no output folder is selected, an 'output' folder will be created in the source folder.")
self.b_upscale_label.pack(side="top")
# Source Folder Frame
self.b_src_folder_frame = tk.Frame(self.b_upscale_frame)
self.b_src_folder_frame.pack(side="top", pady=4, fill="x")
self.b_src_folder_label = tk.Label(self.b_src_folder_frame, text="Source Folder:")
self.b_src_folder_label.pack(side="left")
self.b_src_folder_entry = tk.Entry(self.b_src_folder_frame, textvariable=self.b_src_folder_entry_text)
self.b_src_folder_entry.pack(side="left", fill="x", expand=True)
self.b_src_folder_button = tk.Button(self.b_src_folder_frame, text="Browse", command=self.browse_source_folder)
self.b_src_folder_button.pack(side="left")
self.bind_widget_highlight(self.b_src_folder_button)
self.b_src_folder_open_button = tk.Button(self.b_src_folder_frame, text="Open", command=lambda: self.open_directory(self.b_src_folder_entry.get()))
self.b_src_folder_open_button.pack(side="left")
self.bind_widget_highlight(self.b_src_folder_open_button)
self.b_src_folder_clr_button = tk.Button(self.b_src_folder_frame, text="X", command=lambda: self.b_src_folder_entry.delete(0, 'end'))
self.b_src_folder_clr_button.pack(side="left")
self.bind_widget_highlight(self.b_src_folder_clr_button, color='#ffcac9')
# Output Folder Frame
self.b_out_folder_frame = tk.Frame(self.b_upscale_frame)
self.b_out_folder_frame.pack(side="top", pady=4, fill="x")
self.b_out_folder_label = tk.Label(self.b_out_folder_frame, text="Output Folder:")
self.b_out_folder_label.pack(side="left")
self.b_out_folder_entry = tk.Entry(self.b_out_folder_frame, textvariable=self.b_out_folder_entry_text)
self.b_out_folder_entry.pack(side="left", fill="x", expand=True)
self.b_out_folder_button = tk.Button(self.b_out_folder_frame, text="Browse", command=self.browse_output_folder)
self.b_out_folder_button.pack(side="left")
self.bind_widget_highlight(self.b_out_folder_button)
self.b_out_folder_open_button = tk.Button(self.b_out_folder_frame, text="Open", command=lambda: self.open_directory(self.b_out_folder_entry.get()))
self.b_out_folder_open_button.pack(side="left")
self.bind_widget_highlight(self.b_out_folder_open_button)
self.b_out_folder_clr_button = tk.Button(self.b_out_folder_frame, text="X", command=lambda: self.b_out_folder_entry.delete(0, 'end'))
self.b_out_folder_clr_button.pack(side="left")
self.bind_widget_highlight(self.b_out_folder_clr_button, color='#ffcac9')
# Create Run button
self.run_batch_button = tk.Button(self.b_upscale_frame, text="Run - Batch Upscale", command=self.batch_upscale)
self.run_batch_button.pack(side="left", fill="x", expand=True)
self.bind_widget_highlight(self.run_batch_button)
####### Batch Resize Image ##################################################
self.resize_frame = tk.Frame(self.primary_tab2)
self.resize_frame.pack(side="top", pady=4, fill="x")
self.resize_title_label = tk.Label(self.resize_frame, text="Batch Resize Image", font=(None, 14))
self.resize_title_label.pack(side="top")
self.resize_label = tk.Label(self.resize_frame, text="Select a folder, click run, choose a scale/resolution. Images are saved to a new folder")
self.resize_label.pack(side="top")
# Resize Folder Frame
self.resize_folder_frame = tk.Frame(self.resize_frame)
self.resize_folder_frame.pack(side="top", pady=4, fill="x")
self.resize_folder_label = tk.Label(self.resize_folder_frame, text="Batch Folder:")
self.resize_folder_label.pack(side="left")
self.resize_folder_entry = tk.Entry(self.resize_folder_frame, textvariable=self.resize_folder_entry_text)
self.resize_folder_entry.pack(side="left", fill="x", expand=True)
self.resize_folder_button = tk.Button(self.resize_folder_frame, text="Browse", command=self.browse_batch_resize_directory)
self.resize_folder_button.pack(side="left")
self.bind_widget_highlight(self.resize_folder_button)
self.resize_folder_open_button = tk.Button(self.resize_folder_frame, text="Open", command=lambda: self.open_directory(self.resize_folder_entry.get()))
self.resize_folder_open_button.pack(side="left")
self.bind_widget_highlight(self.resize_folder_open_button)
self.resize_folder_clr_button = tk.Button(self.resize_folder_frame, text="X", command=lambda: self.resize_folder_entry.delete(0, 'end'))
self.resize_folder_clr_button.pack(side="left")
self.bind_widget_highlight(self.resize_folder_clr_button, color='#ffcac9')
# Resize Button Frame
self.resize_button_frame = tk.Frame(self.resize_frame)
self.resize_button_frame.pack(side="top", fill="x", expand=True)
self.resize_single_button = tk.Button(self.resize_button_frame, text="Run - Resize Single Image", command=lambda: [self.selected_resize_file.set(filedialog.askopenfilename()), self.confirm_scale(self.selected_resize_file.get()), self.open_directory(self.selected_resize_file.get())])
self.resize_single_button.pack(side="left", fill="x", expand=True)
self.bind_widget_highlight(self.resize_single_button)
self.run_resize_button = tk.Button(self.resize_button_frame, text="Run - Batch Resize Image", command=lambda: self.confirm_scale(self.resize_folder_entry.get()))
self.run_resize_button.pack(side="left", fill="x", expand=True)
self.bind_widget_highlight(self.run_resize_button)
#endregion
##########################################################################################################################################################################
##########################################################################################################################################################################
# #
#region - Threads #
# #
def extract_frames(self):
self.bottom_label["text"] = "Extracting... This may take a while..."
print("\nExtract Frames: Starting...")
thread = threading.Thread(target=self._extract_frames)
thread.daemon = True
thread.start()
def upscale_frames(self):
self.bottom_label["text"] = "Upscaling... This may take a while..."
print("\nUpscale Frames: Starting...")
thread = threading.Thread(target=self._upscale_frames)
thread.daemon = True
thread.start()
def merge_frames(self):
self.bottom_label["text"] = "Merging... This may take a while..."
print("\nMerge Frames: Starting...")
thread = threading.Thread(target=self._merge_frames)
thread.daemon = True
thread.start()
def scale_frames(self, app_state=None):
self.bottom_label["text"] = "Resizing... This may take a while..."
print("\nResize Frames: Starting...")
thread = threading.Thread(target=self._scale_frames, args=(app_state,))
thread.daemon = True
thread.start()
def batch_upscale(self):
self.bottom_label["text"] = "Batch Upscaling... This may take a while..."
print("\nBatch Upscale: Starting...")
thread = threading.Thread(target=self._batch_upscale)
thread.daemon = True
thread.start()
def select_and_upscale_image(self):
self.bottom_label["text"] = "Upscaling Single Image... This may take a while..."
print("\nUpscale Image: Starting...")
thread = threading.Thread(target=self._select_and_upscale_image)
thread.daemon = True
thread.start()
#endregion
##########################################################################################################################################################################
##########################################################################################################################################################################
# #
#region - Monitors #
# #