-
Notifications
You must be signed in to change notification settings - Fork 0
/
videer.py
634 lines (509 loc) · 27.6 KB
/
videer.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
import threading
from tkinter import *
from tkinter.ttk import *
import time
import tkinter as tk
import tkinter.messagebox as messagebox
import tkinter.filedialog as fd
import tkinter.scrolledtext as st
import logging.handlers
import subprocess
import multiprocessing
import os
import re
def multiple_replace(string, rep_dict):
pattern = re.compile("|".join([re.escape(k) for k in sorted(rep_dict, key=len, reverse=True)]), flags=re.DOTALL)
return pattern.sub(lambda x: rep_dict[x.group(0)], string)
def assemble_final(fileobj, app_gui):
command = [f'ffmpeg.exe -err_detect crccheck+bitstream+buffer -hide_banner']
if app_gui.codec_var.get() in ["hevc_nvenc", "h264_nvenc"]:
command.append("-hwaccel cuda")
if app_gui.use_avisynth_var.get():
command.append(f'-i "{fileobj.avsfile}" -y')
CreateAvs(fileobj=fileobj)
else:
command.append(f'-i "{fileobj.filename}" -y')
command.append(f'-preset {app_gui.preset_get(int(app_gui.speed.get())).replace(" ", "")}')
command.append(f'-map 0:v -map 0:a? -map 0:s?')
if app_gui.stereo_var.get():
command.append('-ac 2')
if app_gui.codec_var.get() == "copy":
command.append(f'-c:v copy')
v_codec_desc = "copy"
crf_desc = "copy"
else:
command.append(f'-c:v {app_gui.codec_var.get()}')
if app_gui.codec_var.get() in ["hevc_nvenc", "h264_nvenc"]:
command.append(f'-cq {app_gui.crf.get()}')
else:
command.append(f'-crf {app_gui.crf.get()}')
v_codec_desc = app_gui.codec_var.get()
crf_desc = app_gui.crf.get()
if app_gui.audio_codec_var.get() == "copy":
command.append(f'-c:a copy')
abr_desc = "copy"
a_codec_desc = "copy"
else:
command.append(f'-c:a {app_gui.audio_codec_var.get()}')
command.append(f'-b:a {app_gui.abr.get()}k')
abr_desc = f"{app_gui.abr.get()}k"
a_codec_desc = app_gui.audio_codec_var.get()
command.append(f'-c:s copy')
if app_gui.corrupt_var.get():
command.append("-bsf:v h264_mp4toannexb")
command.append(f'{app_gui.extras_value.get()}')
command.append('-metadata comment="Made with Videer https://github.com/hclivess/videer"')
command.append(f'-metadata description="'
f'Video Codec: {v_codec_desc}, '
f'Preset: {app_gui.preset_get(int(app_gui.speed.get())).replace(" ", "")}, '
f'CRF: {crf_desc}, '
f'Audio Codec: {a_codec_desc}, '
f'Audio Bitrate: {abr_desc}"')
command.append('-movflags')
command.append('+faststart')
command.append('-bf 2')
command.append('-flags')
command.append('+cgop')
command.append('-pix_fmt yuv420p')
command.append(f'-f matroska "{fileobj.outputname}"')
command.append('-y')
return " ".join(command)
class File:
def __init__(self, file):
self.number = file[0]
self.filename = file[1] # ..file.avi
self.orig_name = self.filename
self.basename = os.path.splitext(self.filename)[0] # ..file
self.extras = None # .._x265_..
self.extension = ".mkv" # .mkv
self.transcodename = f"{self.basename}.trans.avi" # ..file.temp.avi
self.errorname = f"{self.filename}.error" # ..file.avi.error
self.ffindex = f"{self.filename}.ffindex" # ..file.avi.ffindex
self.tempffindex = f"{self.transcodename}.ffindex" # ..file.avi.ffindex
self.displayname = self.filename.split('/')[-1] # file.avi
self.outputname = f"{self.basename}_{app.crf.get()}{app.codec_var.get()}_{app.audio_codec_var.get()}{app.abr.get()}{self.extension}"
self.dir = os.path.dirname(os.path.realpath(self.filename))
self.ffmpeg_errors = []
self.avsfile = f"{self.basename}.avs"
# self.trf = f"{self.dir}\\{time.time_ns()}.trf".replace("\\", "\\\\").replace(":", "\:")
def create_logger(self):
self.log = get_logger(self.filename)
class CreateAvs:
def __init__(self, fileobj):
with open(fileobj.avsfile, "w") as avsfile:
avsfile.write(f'Loadplugin("{app.path}/plugins/masktools2.dll")')
avsfile.write('\n')
avsfile.write(f'Loadplugin("{app.path}/plugins/mvtools2.dll")')
avsfile.write('\n')
avsfile.write(f'Loadplugin("{app.path}/plugins/nnedi3.dll")')
avsfile.write('\n')
avsfile.write(f'Loadplugin("{app.path}/plugins/ffms2.dll")')
avsfile.write('\n')
avsfile.write(f'Loadplugin("{app.path}/plugins/RgTools.dll")')
avsfile.write('\n')
avsfile.write(f'Import("{app.path}/plugins/QTGMC.avsi")')
avsfile.write('\n')
avsfile.write(f'Import("{app.path}/plugins/Zs_RF_Shared.avsi")')
avsfile.write('\n')
if app.use_ffms2_var.get():
avsfile.write(f'FFmpegSource2("{fileobj.filename}", vtrack = -1, atrack = -1)')
else:
avsfile.write(f'AVISource("{fileobj.filename}", audio=true)')
avsfile.write('\n')
avsfile.write('SetFilterMTMode("FFVideoSource", 3)')
avsfile.write('\n')
avsfile.write('ConvertToYV24(matrix="rec709")')
avsfile.write('\n')
avsfile.write(f'Prefetch({multiprocessing.cpu_count()})')
avsfile.write('\n')
if app.avisynth_extras.get("1.0", END).strip():
avsfile.write(app.avisynth_extras.get("1.0", END))
avsfile.write('\n')
if app.tff_var.get():
avsfile.write('AssumeTFF()')
avsfile.write('\n')
if app.deinterlace_var.get():
if app.reduce_fps_var.get():
avsfile.write(
f'QTGMC(Preset="{app.preset_get(int(app.speed.get()))}", FPSDivisor=2, EdiThreads={multiprocessing.cpu_count()})')
avsfile.write('\n')
else:
avsfile.write(
f'QTGMC(Preset="{app.preset_get(int(app.speed.get()))}", EdiThreads={multiprocessing.cpu_count()})')
avsfile.write('\n')
def info_box_insert(info_box, message, log_message=None, logger=None):
try:
info_box.configure(state='normal')
info_box.insert(END, f"{message}\n")
info_box.configure(state='disabled')
except Exception as e:
print(f"Info window closed: {e}")
if logger:
logger.info(log_message)
class Application(Frame):
def __init__(self, master=None):
super().__init__(master)
self.master = master
self.top = None
self.grid()
self.create_widgets()
self.file_queue = []
self.tempfile = None
self.should_transcode = False
self.process = None
self.workdir = None
self.should_stop = False
self.path = os.getcwd()
def transcode(self, fileobj, transcode_video, transcode_audio):
fileobj.log.info("Transcode process started")
temp_transcode = None
if transcode_video and transcode_audio:
temp_transcode = f'ffmpeg.exe -err_detect crccheck+bitstream+buffer -hide_banner -i "{fileobj.filename}" -preset {self.preset_get(int(self.speed.get())).replace(" ","")} -map 0:v -map 0:a? -map 0:s? -c:a pcm_s32le -c:v rawvideo -c:s copy "{fileobj.transcodename}" -y'
elif transcode_video and not transcode_audio:
temp_transcode = f'ffmpeg.exe -err_detect crccheck+bitstream+buffer -hide_banner -i "{fileobj.filename}" -preset {self.preset_get(int(self.speed.get())).replace(" ","")} -map 0:v -map 0:a? -map 0:s? -c:a copy -c:v rawvideo -c:s copy "{fileobj.transcodename}" -y'
elif transcode_audio and not transcode_video:
temp_transcode = f'ffmpeg.exe -err_detect crccheck+bitstream+buffer -hide_banner -i "{fileobj.filename}" -preset {self.preset_get(int(self.speed.get())).replace(" ","")} -map 0:v -map 0:a? -map 0:s? -c:a pcm_s32le -c:v copy -c:s copy "{fileobj.transcodename}" -y'
self.open_process(temp_transcode, fileobj)
def open_process(self, command_line, fileobj):
fileobj.log.info(f"Executing command {command_line}")
with subprocess.Popen(command_line,
stdout=subprocess.PIPE,
stderr=subprocess.STDOUT,
universal_newlines=True,
encoding="utf8") as self.process:
errors = ["error", "invalid"]
for line in self.process.stdout:
# print(line, end='')
fileobj.log.info(line.strip())
self.status_var.set(multiple_replace(line,
{" ": " ",
" ": " ",
"time=": "",
"bitrate= ": "br:",
"speed": "rate",
"size=": "",
"frame": "f",
"=": ":",
"\n": ""}))
for error in errors:
if error in line.lower():
fileobj.ffmpeg_errors.append(line.strip())
return_code = self.process.wait()
fileobj.log.info(f"Return code: {return_code}")
return return_code
def queue(self, files, info_box):
"""automatically ends on Popen termination"""
for f in enumerate(files):
if self.should_stop:
self.should_stop = False
return
fileobj = File(file=f)
if not self.should_stop:
fileobj.create_logger()
if self.workdir != fileobj.dir:
self.workdir = fileobj.dir
info_box_insert(info_box=info_box,
message=f"Switching directory to: {self.workdir}",
log_message=f"Switching directory to: {self.workdir}",
logger=fileobj.log)
info_box_insert(info_box=info_box,
message=f"Processing {fileobj.number + 1}/{len(files)}: {fileobj.displayname}",
log_message=f"Processing {fileobj.displayname}",
logger=fileobj.log)
should_transcode_video = False
should_transcode_audio = False
if self.transcode_video_var.get():
should_transcode_video = True
if self.transcode_audio_var.get():
should_transcode_audio = True
if should_transcode_video or should_transcode_audio:
self.should_transcode = True
if self.should_transcode and not self.should_stop:
self.transcode(fileobj,
transcode_video=should_transcode_video,
transcode_audio=should_transcode_audio)
if self.should_transcode:
"""use transcoded file as source"""
fileobj.filename = fileobj.transcodename
final_cmd = assemble_final(fileobj, self)
return_code = self.open_process(final_cmd, fileobj) # final go
else:
return_code = 1
if return_code == 0 and not self.should_stop:
"""error code can be None, force numeric check"""
info_box_insert(info_box=info_box,
message=f"Finished {fileobj.displayname}: {int((fileobj.number + 1) / (len(files)) * 100)}%",
log_message=f"Finished {fileobj.displayname}",
logger=fileobj.log)
elif not self.should_stop:
info_box_insert(info_box=info_box,
message=f"Error with {fileobj.displayname}: {int((fileobj.number + 1) / (len(files)) * 100)}%",
log_message=f"Error with {fileobj.displayname}",
logger=fileobj.log)
if os.path.exists(fileobj.outputname) and not self.should_stop:
os.replace(fileobj.outputname, fileobj.errorname)
if fileobj.ffmpeg_errors:
info_box_insert(info_box=info_box,
message="Errors:\n" + '\n'.join(fileobj.ffmpeg_errors),
log_message="Errors:\n " + '\n'.join(fileobj.ffmpeg_errors),
logger=fileobj.log)
if self.replace_button_var.get() and return_code == 0 and not self.should_stop:
self.replace_file(rename_from=fileobj.outputname,
rename_to=fileobj.orig_name,
log=fileobj.log)
if os.path.exists(fileobj.transcodename) and not self.should_stop:
os.remove(fileobj.transcodename)
if os.path.exists(fileobj.ffindex) and not self.should_stop:
os.remove(fileobj.ffindex)
if os.path.exists(fileobj.tempffindex) and not self.should_stop:
os.remove(fileobj.tempffindex)
if os.path.exists(fileobj.avsfile) and not self.should_stop:
os.remove(fileobj.avsfile)
handlers = fileobj.log.handlers[:]
for handler in handlers:
fileobj.log.removeHandler(handler)
handler.close()
if self.should_stop:
info_box_insert(info_box=info_box,
message="Queue stopped")
else:
info_box_insert(info_box=info_box,
message="Queue finished")
self.should_stop = False
def create_info_box(self):
self.top = Toplevel()
self.top.title("Queue Info")
self.top.resizable(False, False)
info_box = st.ScrolledText(self.top, width=100, font=('calibri', 10, 'bold'))
info_box.grid(row=0, pady=0)
info_box.configure(state='disabled')
return info_box
def run_cmd(self):
info_box = self.create_info_box()
file_thread = threading.Thread(target=self.queue, args=(self.file_queue, info_box,))
file_thread.start()
def select_file(self, var):
files = fd.askopenfilename(multiple=True, initialdir="", title="Select file")
del self.file_queue[:]
for file in files:
self.file_queue.append(file)
var.set(self.file_queue)
def on_set_avisynth(self, click):
"""warning, reversed because it takes state at the time of clicking"""
if self.use_avisynth_var.get():
self.tff_var.set(False)
self.use_ffms2_var.set(False)
self.deinterlace_var.set(False)
def on_set_deinterlace(self, click):
"""warning, reversed because it takes state at the time of clicking"""
if not self.deinterlace_var.get() and not self.use_avisynth_var.get():
self.use_avisynth_var.set(True)
elif self.deinterlace_var.get() and self.use_avisynth_var.get() and not self.use_ffms2_var.get():
self.reduce_fps_var.set(False)
self.tff_var.set(False)
elif self.deinterlace_var.get() and self.use_avisynth_var.get():
self.tff_var.set(False)
def on_set_ttf(self, click):
"""warning, reversed because it takes state at the time of clicking"""
if not self.tff_var.get() and not self.deinterlace_var.get():
self.deinterlace_var.set(True)
self.use_avisynth_var.set(True)
def on_set_reduce(self, click):
"""warning, reversed because it takes state at the time of clicking"""
if not self.reduce_fps_var.get() and not self.deinterlace_var.get():
self.deinterlace_var.set(True)
self.use_avisynth_var.set(True)
def on_set_ffms(self, click):
"""warning, reversed because it takes state at the time of clicking"""
if not self.use_avisynth_var.get():
self.use_avisynth_var.set(True)
elif self.use_avisynth_var.get() and not self.deinterlace_var.get():
self.use_avisynth_var.set(False)
def exit(self):
self.stop_process()
self.master.destroy()
def stop_process(self, announce=False):
self.should_stop = True
if self.process:
output = f"Process terminated"
self.process.kill()
else:
output = f"No process assigned"
if announce:
messagebox.showinfo(title="Info", message=output)
if self.top:
self.top.destroy()
def preset_get(self, number: int):
config_dict = {0: "very slow", 1: "slower", 2: "slow", 3: "medium", 4: "faster", 5: "fast", 6: "ultrafast"}
return config_dict.get(number)
def replace_file(self, rename_from, rename_to, log):
log.info(f"Replacing {rename_to} with {rename_from} file as requested")
if os.path.exists(rename_from):
# Get the file extension
_, extension = os.path.splitext(rename_to)
# Create a new filename for the old file, preserving its extension
old_file_name = f"{rename_to}.old{extension}"
os.rename(rename_to, old_file_name)
os.rename(rename_from, rename_to)
def create_widgets(self):
self.deinterlace_var = BooleanVar()
self.deinterlace_var.set(False)
self.deinterlace_button = Checkbutton(self, text="Deinterlace", variable=self.deinterlace_var)
self.deinterlace_button.bind("<Button-1>", self.on_set_deinterlace)
self.deinterlace_button.grid(row=0, column=1, sticky='w', pady=0, padx=0)
self.tff_var = BooleanVar()
self.tff_var.set(False)
self.tff_button = Checkbutton(self, text="Top Field First", variable=self.tff_var)
self.tff_button.bind("<Button-1>", self.on_set_ttf)
self.tff_button.grid(row=1, column=1, sticky='w', pady=0, padx=0)
self.reduce_fps_var = BooleanVar()
self.reduce_fps_var.set(False)
self.reduce_fps_button = Checkbutton(self, text="Reduce Frames", variable=self.reduce_fps_var)
self.reduce_fps_button.bind("<Button-1>", self.on_set_reduce)
self.reduce_fps_button.grid(row=2, column=1, sticky='w', pady=0, padx=0)
self.use_avisynth_var = BooleanVar()
self.use_avisynth_var.set(False)
self.use_avisynth_button = Checkbutton(self, text="Use AviSynth+", variable=self.use_avisynth_var)
self.use_avisynth_button.bind("<Button-1>", self.on_set_avisynth)
self.use_avisynth_button.grid(row=3, column=1, sticky='w', pady=0, padx=0)
self.use_ffms2_var = BooleanVar()
self.use_ffms2_var.set(False)
self.use_ffms2_button = Checkbutton(self, text="Use ffms2 (No Frameserver, 1 Stream)",
variable=self.use_ffms2_var)
self.use_ffms2_button.bind("<Button-1>", self.on_set_ffms)
self.use_ffms2_button.grid(row=4, column=1, sticky='w', pady=0, padx=0)
self.transcode_video_var = BooleanVar()
self.transcode_video_var.set(False)
self.transcode_video_button = Checkbutton(self, text="Raw Transcode Video First",
variable=self.transcode_video_var)
self.transcode_video_button.grid(row=5, column=1, sticky='w', pady=0, padx=0)
self.transcode_audio_var = BooleanVar()
self.transcode_audio_var.set(False)
self.transcode_audio_button = Checkbutton(self, text="Raw Transcode Audio First",
variable=self.transcode_audio_var)
self.transcode_audio_button.grid(row=6, column=1, sticky='w', pady=0, padx=0)
self.corrupt_var = BooleanVar()
self.corrupt_var.set(False)
self.corrupt_var_button = Checkbutton(self, text="Fix AVC (ts) Corruption",
variable=self.corrupt_var)
self.corrupt_var_button.grid(row=7, column=1, sticky='w', pady=0, padx=0)
self.stereo_var = BooleanVar()
self.stereo_var.set(False)
self.stereo_button = Checkbutton(self, text="Reduce to Stereo (be careful)",
variable=self.stereo_var)
self.stereo_button.grid(row=8, column=1, sticky='w', pady=0, padx=0)
self.audio_codec_label = Label(self)
self.audio_codec_label["text"] = "Audio Codec: "
self.audio_codec_var = StringVar()
self.audio_codec_var.set("aac")
self.audio_codec_label.grid(row=9, column=0, sticky='SE', pady=0, padx=0)
self.audio_codec_button = Radiobutton(self, text="LAME MP3", variable=self.audio_codec_var,
value="libmp3lame")
self.audio_codec_button.grid(row=9, column=1, sticky='w', pady=0, padx=0)
self.audio_codec_button = Radiobutton(self, text="AAC", variable=self.audio_codec_var, value="aac")
self.audio_codec_button.grid(row=10, column=1, sticky='w', pady=0, padx=0)
self.audio_codec_button = Radiobutton(self, text="Opus", variable=self.audio_codec_var, value="libopus")
self.audio_codec_button.grid(row=11, column=1, sticky='w', pady=0, padx=0)
self.audio_codec_button = Radiobutton(self, text="PCM32 (Raw)", variable=self.audio_codec_var,
value="pcm_s32le")
self.audio_codec_button.grid(row=12, column=1, sticky='w', pady=0, padx=0)
self.audio_codec_button = Radiobutton(self, text="Copy", variable=self.audio_codec_var, value="copy")
self.audio_codec_button.grid(row=13, column=1, sticky='w', pady=0, padx=0)
self.codec_label = Label(self)
self.codec_label["text"] = "Video Codec: "
self.codec_var = StringVar()
self.codec_var.set("libx265")
self.codec_label.grid(row=15, column=0, sticky='SE', pady=0, padx=0)
self.video_codec_button = Radiobutton(self, text="x264", variable=self.codec_var, value="libx264")
self.video_codec_button.grid(row=15, column=1, sticky='w', pady=0, padx=0)
self.video_codec_button = Radiobutton(self, text="x265", variable=self.codec_var, value="libx265")
self.video_codec_button.grid(row=16, column=1, sticky='w', pady=0, padx=0)
self.video_codec_button = Radiobutton(self, text="CUDA h264 (CQ)", variable=self.codec_var, value="h264_nvenc")
self.video_codec_button.grid(row=17, column=1, sticky='w', pady=0, padx=0)
self.video_codec_button = Radiobutton(self, text="CUDA HEVC (CQ)", variable=self.codec_var, value="hevc_nvenc")
self.video_codec_button.grid(row=18, column=1, sticky='w', pady=0, padx=0)
self.video_codec_button = Radiobutton(self, text="ProRes", variable=self.codec_var, value="prores_ks")
self.video_codec_button.grid(row=19, column=1, sticky='w', pady=0, padx=0)
self.video_codec_button = Radiobutton(self, text="Raw", variable=self.codec_var, value="rawvideo")
self.video_codec_button.grid(row=20, column=1, sticky='w', pady=0, padx=0)
self.video_codec_button = Radiobutton(self, text="Copy", variable=self.codec_var, value="copy")
self.video_codec_button.grid(row=21, column=1, sticky='w', pady=0, padx=0)
self.speed_label = Label(self)
self.speed_label["text"] = "Encoding Speed: "
self.speed_label.grid(row=22, column=0, sticky='SE', pady=0, padx=0)
self.speed = tk.Scale(self, from_=0, to=6, orient=HORIZONTAL, sliderrelief=FLAT)
self.speed.grid(row=22, column=1, sticky='WE', pady=0, padx=0)
self.speed.set(3)
self.infile_value = StringVar()
self.infile_value.set("c:/test.avi")
self.infile_button = Button(self, text="Input File(s):",
command=lambda: self.select_file(self.infile_value))
self.infile_button.grid(row=24, column=0, sticky='SE', padx=0, pady=(5))
self.infile = Entry(self, textvariable=self.infile_value, width=70)
self.infile.grid(row=24, column=1, sticky='W', padx=0)
self.crf_label = Label(self)
self.crf_label["text"] = "CRF: "
self.crf_label.grid(row=25, column=0, sticky='SE', pady=0, padx=0)
self.crf = tk.Scale(self, from_=0, to=51, orient=HORIZONTAL, sliderrelief=FLAT)
self.crf.grid(row=25, column=1, sticky='WE', pady=0, padx=0)
self.crf.set(23)
self.abr_label = Label(self)
self.abr_label["text"] = "Audio ABR: "
self.abr_label.grid(row=26, column=0, sticky='SE', pady=0, padx=0)
self.abr = tk.Scale(self, resolution=16, from_=0, to=512, orient=HORIZONTAL, sliderrelief=FLAT)
self.abr.grid(row=26, column=1, sticky='WE', pady=0, padx=0)
self.abr.set(256)
self.extras_label = Label(self)
self.extras_label["text"] = "FFmpeg Extras: "
self.extras_label.grid(row=27, column=0, sticky='SE', padx=0)
self.extras_value = StringVar()
self.extras_value.set("")
self.extras = Entry(self, textvariable=self.extras_value, width=70)
self.extras.grid(row=27, column=1, sticky='W', pady=0, padx=0)
self.avisynth_extras_label = Label(self)
self.avisynth_extras_label["text"] = "AviSynth+ Extras: "
self.avisynth_extras_label.grid(row=28, column=0, sticky='SE', padx=0)
self.avisynth_extras = Text(self, height=2, width=30)
self.avisynth_extras.grid(row=28, column=1, sticky='WE', pady=0, padx=0)
self.progress_label = Label(self)
self.progress_label["text"] = f"Progress: "
self.progress_label.grid(row=29, column=0, sticky='NE', padx=0)
self.status_var = StringVar()
self.status_var.set("Idle...")
self.status_bar = Label(self, textvariable=self.status_var, width=70)
self.status_bar.grid(row=29, column=1, columnspan=5, sticky='W', pady=0, padx=0)
self.replace_button_var = BooleanVar()
self.replace_button_var.set(False)
self.replace_button = Checkbutton(self, text="Replace Original File(s)",
variable=self.replace_button_var)
self.replace_button.grid(row=30, column=1, sticky='SE', pady=0, padx=0)
self.run = Button(self, text="Run", style='W.TButton', command=lambda: self.run_cmd())
self.run.grid(row=0, column=2, sticky='WE', padx=0)
self.stop = Button(self, text="Stop", style='W.TButton', command=lambda: self.stop_process(True))
self.stop.grid(row=1, column=2, sticky='WE', padx=0)
self.quit = Button(self, text="Quit", style='W.TButton', command=self.exit)
self.quit.grid(row=2, column=2, sticky='WE', padx=0, pady=(0, 5))
def get_logger(filename):
logFormatter = logging.Formatter("%(asctime)s [%(threadName)-12.12s] [%(levelname)-5.5s] %(message)s")
rootLogger = logging.getLogger()
rootLogger.propagate = False
rootLogger.setLevel(logging.INFO)
fileHandler = logging.FileHandler(f"{filename}.log")
fileHandler.setFormatter(logFormatter)
rootLogger.addHandler(fileHandler)
consoleHandler = logging.StreamHandler()
consoleHandler.setFormatter(logFormatter)
rootLogger.addHandler(consoleHandler)
return rootLogger
if __name__ == "__main__":
root = Tk()
root.iconbitmap("icon.ico")
style = Style()
style.configure('W.TButton',
font=('calibri', 10, 'bold'),
foreground='black')
root.wm_title("videer")
root.resizable(False, False)
# operations = Operations()
app = Application(master=root)
app.mainloop()