-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathmain.py
6278 lines (4920 loc) · 283 KB
/
main.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
#region imports
import PySimpleGUI as sg
from PIL import Image,ImageTk
from moviepy.editor import AudioFileClip, VideoFileClip
from util.print_color import style,cprint
import util.code_testing as code_testing
import util.time_converter as tc
import util.json_tools as jt
import util.progress_bar_custom as cpbar
from threading import Thread
import re
import io
import os
import cv2
import uuid
import shlex
import subprocess
import textwrap
import shutil
from os.path import splitext
import mediapipe as mp
import numpy as np
import pandas as pd
from datetime import datetime as dt ,timedelta
from timeit import default_timer as timer
import webbrowser
#endregion imports
#region init vars
ver = '0.4.9.6'
jt.create_preferences_init()
sg.theme('Dark Gray 15')
global show_preview_generate_cuts_video_preview
global show_generated_preview_cuts
global preview_cuts_tab_index
global close_preview_cut_video_player
show_preview_generate_cuts_video_preview = True
show_generated_preview_cuts = False
cancel_loading_generate_preview_cuts = False
cancel_generate_preview_cuts = False
is_verbose_create_media_list_item = False
close_preview_cut_video_player = True
preview_cuts_tab_index = 1
TAB_SPLIT_SET = 100
clip_cuts_threshold_var = 0.1
INPUT_FILE_NAME_LENGTH_LIMIT = 200
PREVIEW_CUTS_TITLE = 'Preview Cuts: ( 0 ) '
#region colors
COLOR_GREEN = '#43CD80'
COLOR_DARK_GREEN2 = '#78BA04'
COLOR_DARK_GREEN = '#74a549'
# COLOR_DARK_RED = 'A5494F'
COLOR_BLUE = '#69b1ef'
COLOR_DARK_BLUE = '#4974a5'
# COLOR_RED = '#E74555'
COLOR_RED = '#A5494F'
COLOR_RED_ORANGE = '#C13515'
COLOR_GRAY_9900 = '#0A0A0A'
COLOR_ORANGE ='#FE7639'
COLOR_PURPLE = '#a501e8'
COLOR_DARK_PURPLE = '#7a49a5'
COLOR_DARK_GRAY = '#1F1F1F'
#endregion
PREVIEW_CUT_TRIM_TRSH = 200
# PREVIEW_CUT_TRIM_MS_CUT_TIME = 500
INPUT_VISIBILITY = True
SELECTED_CLIPS_FRAME_TITLE = ' Selected Clips '
listed_folder_list = ['c:/videos/']
unsorted_folder_name = 'Unsorted'
sorted_folder_name = 'Sorted'
#region input_file_ext
image_file_ext = {
("IMAGE Files", "*.png"),
("IMAGE Files", "*.jpg"),
("IMAGE Files", "*.jpeg"),
}
video_file_ext = {
("Video Files", "*.mp4"),
("Video Files", "*.webm"),
("Video Files", "*.gif"),
("Video Files", "*.json"),
("Video Files", "*.mkv"),
}
video_delogo_file_ext = {
("Video Files", "*.mp4"),
("Video Files", "*.webm"),
("Video Files", "*.gif"),
}
#endregion input_file_ext
#endregion init vars
#region preference
def save_preference(values,preference_key):
preference_value = values[f'-{preference_key}-']
jt.save_preference(preference_key,preference_value)
def load_preference(preference_key):
preference = jt.get_preference()
try:
preference_value=preference[preference_key]
return preference_value
except KeyError as e:
# print('setup','preference not set yet',preference_key)
pass
def load_preference_set_elements_values_slider(window,slider_key,input_key,type_='float'):
value = load_preference(slider_key)
set_elements_values(window,slider_key,value,type_)
set_elements_values(window,input_key,value,type_)
return value
def load_preference_set_elements_values(window,key):
value = load_preference(key)
set_elements_values(window,key,value)
return value
def set_elements_values(window,preference_key,preference_value,type_='float'):
if not None:
if type_ == 'int':
preference_value = int(preference_value)
window[f'-{preference_key}-'].update(value=preference_value)
#endregion preference
#region display_notification
# -------------------------------------------------------------------
USE_FADE_IN = True
WIN_MARGIN = 60
# colors
WIN_COLOR = "#282828"
TEXT_COLOR = "#ffffff"
DEFAULT_DISPLAY_DURATION_IN_MILLISECONDS = 10000
# Base64 Images to use as icons in the window
img_error = b'iVBORw0KGgoAAAANSUhEUgAAACAAAAAgCAMAAABEpIrGAAAAA3NCSVQICAjb4U/gAAAACXBIWXMAAADlAAAA5QGP5Zs8AAAAGXRFWHRTb2Z0d2FyZQB3d3cuaW5rc2NhcGUub3Jnm+48GgAAAIpQTFRF////20lt30Bg30pg4FJc409g4FBe4E9f4U9f4U9g4U9f4E9g31Bf4E9f4E9f4E9f4E9f4E9f4FFh4Vdm4lhn42Bv5GNx5W575nJ/6HqH6HyI6YCM6YGM6YGN6oaR8Kev9MPI9cbM9snO9s3R+Nf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9bumna344+cQofdNtM/sFWvvG5EDOjgi9vtnn2P3dDkIXZDWz+qJ8bu46SyaRRIpUEls5/tw9x4z/vYiCVRimvRHKewIvgivBOTfOKdVVVRVXVU7id7XH9LB4eFD4bCkxIhDjU0sPtve9BqgcR0zFmNyCtcgzfoXXA5r6ftMJQN8RCEI5zLG+iT6xFURR0E/b15dm3bwByQ+hxnY7e47R3Z9ArpiJ0g8B3EUj0khAfDft864XDMNxbiDkRHbUsiRKOY2iCwTx856VO6O8C1Ucpi6FPnA2RGB3d/bSmcmgl1ehmBFTJkf4MHW059MQUtHAE6bnnB1zTNIQQrFmzhrKyMjo6OrAsa+TY9sJ17pDiBRRirGWg10+HoHZkIqVjAxJNB6bVgFJ7ciAyAEUhcB3wPHRThanFOqB6eVQJ6DVIzwHfQyJASnRDwPRaENMKcVgIEAqB54DrFlZETSXUVhf6pigEgQ92DqGBXmqBXkrgu+A4qCqoJRHQS5C+C54LY5znjAJeDCFNTU3k83ksy8KyLIIguOjAVVUgEVy9fhfDB/ZBVD0Bxh8JN6fJcyjskoy+V5ghcPOjyx37tP6MqFi3mFKeek9SgIZ7wuaZ9oLT25VjlZ3npgkQjUaJRqMA5/WUOb7O4uEUxvrhoWMIP446sRTpeQXPPUt7F13ndKSLZ1OTUr4NXHPRWhylswNHgmIqEEsWlruX56QXf4IkAVX8UlNV9Xue5/06gBtIKcYNS65zRu8+gXLF9zVN037hed4iKeVjwBwu8nspp7wmkUFKS366/rUvvpeyR6jqA9IJtv8Pox7WnXQ/LA4AAAAASUVORK5CYII='
GRAY_9900 = '#0A0A0A'
def display_notification(title, message, icon, display_duration_in_ms=DEFAULT_DISPLAY_DURATION_IN_MILLISECONDS, use_fade_in=True, alpha=0.9, location=None):
"""
Function that will create, fade in and out, a small window that displays a message with an icon
The graphic design is similar to other system/program notification windows seen in Windows / Linux
:param title: (str) Title displayed at top of notification
:param message: (str) Main body of the noficiation
:param icon: (str) Base64 icon to use. 2 are supplied by default
:param display_duration_in_ms: (int) duration for the window to be shown
:param use_fade_in: (bool) if True, the window will fade in and fade out
:param alpha: (float) Amount of Alpha Channel to use. 0 = invisible, 1 = fully visible
:param location: Tuple[int, int] location of the upper left corner of window. Default is lower right corner of screen
"""
# Compute location and size of the window
message = textwrap.fill(message, 50)
win_msg_lines = message.count("\n") + 1
screen_res_x, screen_res_y = sg.Window.get_screen_size()
win_margin = WIN_MARGIN # distance from screen edges
win_width, win_height = 500, 100 + (14.8 * win_msg_lines)
win_location = location if location is not None else (screen_res_x - win_width - win_margin, screen_res_y - win_height - win_margin)
layout = [[sg.Graph(canvas_size=(win_width, win_height), graph_bottom_left=(0, win_height), graph_top_right=(win_width, 0), key="-GRAPH-",
background_color=WIN_COLOR, enable_events=True)]]
window = sg.Window(title, layout, background_color=WIN_COLOR, no_titlebar=True,
location=win_location, keep_on_top=True, alpha_channel=0, margins=(0, 0), element_padding=(0, 0),
finalize=True)
window["-GRAPH-"].draw_rectangle((win_width, win_height), (-win_width, -win_height), fill_color=WIN_COLOR, line_color=WIN_COLOR)
window["-GRAPH-"].draw_image(data=icon, location=(20, 20))
window["-GRAPH-"].draw_text(title, location=(64, 20), color=TEXT_COLOR, font=("Arial", 12, "bold"), text_location=sg.TEXT_LOCATION_TOP_LEFT)
window["-GRAPH-"].draw_text(message, location=(64, 44), color=TEXT_COLOR, font=("Arial", 9), text_location=sg.TEXT_LOCATION_TOP_LEFT)
# change the cursor into a "hand" when hovering over the window to give user hint that clicking does something
window['-GRAPH-'].set_cursor('hand2')
if use_fade_in == True:
for i in range(1,int(alpha*100)): # fade in
window.set_alpha(i/100)
event, values = window.read(timeout=20)
if event != sg.TIMEOUT_KEY:
window.set_alpha(1)
break
event, values = window(timeout=display_duration_in_ms)
if event == sg.TIMEOUT_KEY:
for i in range(int(alpha*100),1,-1): # fade out
window.set_alpha(i/100)
event, values = window.read(timeout=20)
if event != sg.TIMEOUT_KEY:
break
else:
window.set_alpha(alpha)
event, values = window()
window.close()
#endregion display_notification
#region util funcs
def display_image(event_name,image,size):
image_bio_data = get_img_data(image,size)
event_name.update(data=image_bio_data)
def save_image_from_video(window,video_file,thumbnail_path,thumbnail_key,thumbnail_size,display_image_bol=True):
clip = VideoFileClip(video_file)
duration = clip.duration
time = 1
if duration > 30:
time = 30
else :
time = 1
# print(style.RED,'save_image_from_video','duration',duration,style.RE)
if not os.path.isfile(thumbnail_path):
try:
# print('create new thumbnail')
clip.save_frame(thumbnail_path, t=time)
except OSError:
print(f"Creation of thumbnail' %s failed" % thumbnail_path)
elif os.path.isfile(thumbnail_path):
try:
# print('dont create new thumbnail')
pass
except OSError:
# print(f"Creation of thumbnail' %s failed" % new_video_file)
pass
if display_image_bol:
display_image(window[thumbnail_key],thumbnail_path,thumbnail_size)
window.visibility_changed()
def image_bio(filename,size):
if os.path.exists(filename):
image1 = Image.open(filename)
if size[0]>0:
image1.thumbnail(size)
# image1.resize(size)
bio = io.BytesIO()
image1.save(bio,format="PNG")
del image1
return bio.getvalue()
def image_bio_video_player(image,size):
image1 = image
image1.thumbnail(size)
bio = io.BytesIO()
image1.save(bio,format="ppm")
del image1
return bio.getvalue()
def get_img_data(filename,size, first=False):
"""Generate image data using PIL"""
try:
img = Image.open(filename)
except:
img = Image.open('./media/no_image_placeholder.png')
print('No Image found')
img.thumbnail(size)
if first:
bio = io.BytesIO()
img.save(bio, format="jpg")
del img
return bio.getvalue()
return ImageTk.PhotoImage(img)
def format_sec(sec):
formated_sec_step_1 = str(timedelta(seconds=sec))
formated_sec = pd.to_datetime(formated_sec_step_1).strftime('%H:%M:%S')
return formated_sec
def timer_it(name,start):
end = timer()
start_end = (end - start)
time_string = tc.format_seconds_to_time_string(start_end,False)
print(f'{style.GREEN_BRIGHT}Time it: {name} - Took {time_string} ',style.RE)
def subprocess_with_msg(call):
N = 3 # for 3 lines of output
p = subprocess.Popen(call,
stdout=subprocess.PIPE, stderr=subprocess.PIPE, universal_newlines=True)
stdout, stderr = p.communicate()
if p.returncode != 0:
return False
else:
return True
def browse_layout(frame_name,file_name_,type_,visible_,disabled=False):
file_name=f'-{file_name_}-'
file_names=f'-{file_name_}s-'
last_file_name = f'-last_{file_name_}-'
# clear_history= f'-clear_history_{file_name_}s-'
if type_ == 'image':
browse_type = sg.FileBrowse(initial_folder='./demo_file',k=f'-{file_name_}_FileBrowse-',file_types=(image_file_ext),disabled=disabled)
if type_ == 'video':
browse_type = sg.FileBrowse(initial_folder='./demo_file',k=f'-{file_name_}_FileBrowse-',file_types=(video_file_ext),disabled=disabled)
type_ = 'image'
if type_ == 'folder':
browse_type = sg.FolderBrowse(disabled=disabled)
layout = sg.Frame(frame_name,[
[
sg.Combo(sorted(sg.user_settings_get_entry(file_names, [])),
default_value=sg.user_settings_get_entry(last_file_name, ''), size=(50, 1), key=file_name,expand_x=True,enable_events=True,disabled=disabled),
browse_type
],
# [
# sg.B('Clear History',k=clear_history,disabled=disabled)
# ]
],expand_x=True,k=f'-{file_name_}_frame_{type_}-',visible=visible_,relief=sg.RELIEF_SOLID,border_width=0,background_color=COLOR_DARK_GRAY)
return layout
def get_checkbox_values(checkbox_key,window,values):
get_checkbox_values_dict = {}
for k,v in window.key_dict.items():
if str(k).startswith(checkbox_key):
if v:
get_checkbox_values_dict[k] = values[k]
return get_checkbox_values_dict
def checkbox_if_one_item_checked(checkbox_values_dict):
for k,v in checkbox_values_dict.items():
if v:
return True
# else:
# return False
pass
def get_videofile_info(video_file):
try:
clip = VideoFileClip(video_file)
duration_full = format_sec(clip.duration)
fps = round(clip.fps)
frame_count = int(clip.fps * clip.duration)
splitted_duration_full = duration_full.split(':')
duration_hours =splitted_duration_full[0]
duration_min = splitted_duration_full[1]
duration_sec = splitted_duration_full[2]
size = clip.size
width = clip.size[0]
hight = clip.size[1]
info = {
'duration':{
'full':duration_full,
'splitted':{
'hours':duration_hours,
'min':duration_min,
'sec':duration_sec,
}
},
'frame_count':frame_count,
'fps':fps,
'size':{
'full':clip.size,
'width':width,
'hight':hight,
}
}
return duration_full , duration_hours , duration_min, duration_sec ,frame_count , fps ,size ,width ,hight
except:
print('get_videofile_info No file')
def sanitize_filename_remove_ext(file_name):
new_str_slice = file_name[:-4]
new_str = new_str_slice.replace(".","_")
new_str = re.sub('\W+','_', new_str)
return new_str
def remove_special_characters_from_text(text,underline=False,case='raw'):
if case=='lower':
text = re.sub(r"[^a-zA-Z0-9]"," ",text.lower())
if case=='upper':
text = re.sub(r"[^a-zA-Z0-9]"," ",text.upper())
if case=='capitalize':
text = re.sub(r"[^a-zA-Z0-9]"," ",text.capitalize())
if case=='title':
text = re.sub(r"[^a-zA-Z0-9]"," ",text.title())
if case=='raw':
text = re.sub(r"[^a-zA-Z0-9]"," ",text)
underline_char = "_"
space_char = " "
if underline:
text = re.sub(" +", underline_char, text)
else:
text = re.sub(" +", " ", text)
text_start = text[:1]
text_end = text[-1:]
if text_start == underline_char and text_end == underline_char:
return text[1:-1]
if text_start == underline_char:
return text[1:]
if text_end == underline_char:
return text[:-1]
if text_start == space_char and text_end == space_char:
return text[1:-1]
if text_start == space_char:
return text[1:]
if text_end == space_char:
return text[:-1]
else:
return text
def is_number_positive(number):
num = float(f'{number}')
if num > 0:
return True
elif num == 0:
return False
else:
return False
def retrun_if_positive_number(number):
num = float(f'{number}')
if num > 0:
return number
elif num == 0:
return 0
else:
return 0
def clean_file_path(file_path,prefix='',underline=True):
file_name = os.path.basename(file_path)
dirname = os.path.dirname(file_path)
file_name,extension = splitext(file_name)
clean_file_name = remove_special_characters_from_text(file_name,underline=underline,case='lower')
is_file_name_not_empty = len(clean_file_name)
if is_file_name_not_empty:
if prefix == '':
clean_file_path = f'{dirname}/{clean_file_name}{extension}'
if not prefix == '':
clean_file_path = f'{dirname}/{prefix}_{clean_file_name}{extension}'
clean_file_path_dict = {
'file_path':file_path,
'file_name':file_name,
'ext':extension,
'dirname':dirname,
'clean_file_name':clean_file_name,
'clean_file_path':clean_file_path,
}
return clean_file_path_dict
else:
return False
def clean_file_name(file_path,prefix='',underline=False):
file_name = os.path.basename(file_path)
dirname = os.path.dirname(file_path)
file_name,extension = splitext(file_name)
clean_underline_file_name = remove_special_characters_from_text(file_name,underline=underline,case='lower')
return clean_underline_file_name
def isfile_exist_check(file_path):
if os.path.isfile(file_path):
return True
if not os.path.isfile(file_path):
return False
def append_new_line_to_file_text(file_name, text_to_append):
"""Append given text as a new line at the end of file"""
with open(file_name, "a+") as file_object:
file_object.seek(0)
data = file_object.read(100)
if len(data) > 0:
file_object.write("\n")
file_object.write(text_to_append)
def read_file_text(text_fie_path):
f = open(text_fie_path, "r")
return f
def read_file_text_return_list(text_fie_path):
try:
f = read_file_text(text_fie_path)
print(f.readline())
except NameError:
print(NameError.args)
#need to implament
def video_player(file_name,start_time,end_time):
#region video_forcheck.audio
video_forcheck = VideoFileClip(file_name)
if video_forcheck.audio is None:
no_audio = True
else:
no_audio = False
del video_forcheck
if not no_audio:
video_audio_clip = AudioFileClip(file_name)
#endregion video_forcheck.audio
cap = cv2.VideoCapture(file_name)
fps = cap.get(cv2.CAP_PROP_FPS)
cur_frame = 0
milliseconds = 1000
milliseconds_timeout_speed = 500
default_time_string = '00:00:00.000000'
end_time_string = tc.format_milliseconds_to_time_string(end_time)
start_time_string = tc.format_milliseconds_to_time_string(start_time)
try:
duration_time_string = tc.format_milliseconds_to_time_string((end_time - start_time))
except :
duration_time_string = default_time_string
new_start_time_frame_count = (((start_time/milliseconds)*fps))
# print('new_start_time_frame_count',int(new_start_time_frame_count))
new_end_time_frame_count = (((end_time/milliseconds)*fps))
# print('new_end_time_frame_count',int(new_end_time_frame_count))
# ---===--- define the window layout --- #
font='Helvetica 12'
frame_title_string = ''
timeout = milliseconds_timeout_speed//fps # time in ms to use for window reads
layout = [
[
sg.Frame(frame_title_string,[
[sg.Image(key='-video_player_image-')],
[
sg.Frame('',[
[
sg.Push(),
sg.Text(default_time_string, size=(15, 1), font=font,key='-run_time_info-',text_color=COLOR_GREEN,justification='l'),
sg.Text(f'{duration_time_string}', size=(15, 1), font=font,key='-run_time_duration_info-',justification='c',text_color=COLOR_BLUE,expand_x=False),
sg.Text(f'{duration_time_string}', size=(15, 1), font=font,key='-duration_time_info-',justification='c',text_color=COLOR_BLUE,expand_x=False),
sg.Text(f'{end_time_string}', size=(15, 1), font=font,key='-time_left_info-',justification='r',text_color=COLOR_RED),
sg.Push(),
],
],relief=sg.RELIEF_SOLID,expand_x=True)
],
[
sg.Frame('',
[
[
sg.Text(f'{start_time_string}', size=(16, 1), font=font,key='-start_time_info-',text_color=COLOR_GREEN,justification='l'),
[sg.Slider(range=(0, 10), size=(50, 20), orientation='h',
key='-video_player_slider-', expand_x=True, disable_number_display=True,
visible=True, background_color=color.LIGHT_GRAY, relief=sg.RELIEF_FLAT, border_width=1)],
# sg.Text(f'{end_time_string}', size=(16, 1), font=font,key='-end_time_info-',text_color=COLOR_RED,justification='r'),
],
],relief=sg.RELIEF_SOLID)
],
#region buttons
# [
# sg.Text(f'{duration_time_string}', size=(15, 1), font=font,key='-duration_time_info-',justification='c',text_color=COLOR_BLUE),
# ],
# [
# # sg.Push(),
# sg.Button('Play', font='Helvetica 14',expand_x=True,disabled=True),
# sg.Button('Pause', font='Helvetica 14',expand_x=True,disabled=True),
# sg.Button('Stop', font='Helvetica 14',expand_x=True,disabled=True),
# sg.Button('Reset', font='Helvetica 14',expand_x=True,key='-reset-'),
# sg.Button('Exit', font='Helvetica 14',expand_x=True,disabled=False),
# # sg.Push(),
# ]
#endregion buttons
],expand_y=True,element_justification='c',font=font,title_color=COLOR_BLUE)#,relief=sg.RELIEF_FLAT
]
]
# create the window and show it without the plot
window = sg.Window(f'Video Player - ({file_name})', layout, no_titlebar=False, location=(0, 0),keep_on_top=True,return_keyboard_events=True,use_default_focus=False)
# locate the elements we'll be updating. Does the search only 1 time
video_player_image_widget = window['-video_player_image-']
run_time_info_widget = window['-run_time_info-']
# run_time_frames_info_widget = window['-run_time_frames_info-']
time_left_info_widget = window['-time_left_info-']
run_time_duration_info_widget = window['-run_time_duration_info-']
video_player_slider_widget = window['-video_player_slider-']
cap.set(cv2.CAP_PROP_POS_MSEC, start_time)
while cap.isOpened():
while cap.get(cv2.CAP_PROP_POS_MSEC)<=end_time:
success, image = cap.read()
if success:
pass
if not success:
break
event, values = window.read(timeout=timeout)
# cv2.waitKey(5000)
if event in ('Exit','Stop','Escape:27', None):
# window.close()
break
if event == '-reset-':
cap.set(cv2.CAP_PROP_POS_MSEC, start_time)
start = tc.format_milliseconds_to_time_string(cap.get(cv2.CAP_PROP_POS_MSEC),True)
run_time_info_widget.update(start)
try:
elapsed = tc.format_milliseconds_to_time_string((end_time-(cap.get(cv2.CAP_PROP_POS_MSEC))))
except :
elapsed = default_time_string
try:
time_left_info = tc.format_milliseconds_to_time_string(((cap.get(cv2.CAP_PROP_POS_MSEC) - start_time)))
except :
time_left_info = default_time_string
time_left_info_widget.update(elapsed)
run_time_duration_info_widget.update(time_left_info)
#region slider
if int(values['-video_player_slider-']) != cur_frame-1:
cur_frame = int(values['-video_player_slider-'])
cap.set(cv2.CAP_PROP_POS_FRAMES, cur_frame+1)
video_player_slider_widget.update(cur_frame)
#endregion slider
#region display_video
imgbytes = cv2.imencode('.ppm', image)[1].tobytes() # can also use png. ppm found to be more efficient
image = Image.open(io.BytesIO(imgbytes))
video_player_image_widget.update(data=image_bio_video_player(image,(768,432)))
# video_player_image_widget.update(data=imgbytes)
#endregion
cur_frame += 1
# cv2.waitKey(1) #try to pause
if close_preview_cut_video_player:
window.close()
if not close_preview_cut_video_player:
run_time_info_widget.update(end_time_string)
run_time_duration_info_widget.update(duration_time_string)
# video_player_slider_widget.background_color=COLOR_RED
# window['-video_player_slider-'].update(background_color='red',text_color='green')
# video_player_slider_widget.Widget.config(color=COLOR_RED)
pass
cap.release()
cv2.destroyAllWindows()
def video_player_t(file_name,start_time,end_time):
Thread(target=video_player(file_name,start_time,end_time), daemon=True).start()
def delogo(file_path=None,save_final_video_file_path=None,is_file_loaded_final_cut=False): #MAIN
#region vars
WIDTH = 1280
HIGHT = 720
DELOGO_PREVIEW_IMAGE_PATH = './delogo/delogo_preview.jpg'
video_info_text_default = f'Dimensions: 0 x 0 | Ratio: 0 | Duration: 00:00:00 | FPS: 0 | Frame Count: 0 '
delogo_rectangle_list = []
video_start_time_spin = '1','3','5','10','15','20','25','60','90','120'
#endregion
#region layout
canvas_layout = [
sg.Graph(
canvas_size=(WIDTH, HIGHT),
graph_bottom_left=(0, HIGHT),
graph_top_right=(WIDTH, 0),
key="-GRAPH-",
enable_events=True,
background_color=COLOR_DARK_GRAY,
drag_submits=True,
right_click_menu=[[],['Clear Mark']],
# expand_x=True,
# expand_y=True
),
]
layout=[
[
sg.Frame(f'',[
[
sg.Frame('',[
[
sg.Frame('File',[
[
sg.B('Load final_cut',k='-set_start_time_spin-',disabled=True,visible=False),
sg.Input(key='-input_delogo_file-',enable_events=True,expand_x=True),
sg.FileBrowse(k=f'-input_delogo_FileBrowse-',file_types=(video_delogo_file_ext)),
sg.Spin(values=(video_start_time_spin), initial_value='1', key='-start_time_spin-',s=(3,1),enable_events=True),
sg.B('Set',k='-set_start_time_spin-',disabled=True,visible=False),
],
],expand_x=True,expand_y=False,relief=sg.RELIEF_SOLID,border_width=0,visible=True,element_justification='c',background_color=COLOR_GRAY_9900,title_color=COLOR_ORANGE)
],
[
sg.Frame(' Video Info',[
[sg.Text(video_info_text_default,key='-video_info-', expand_x=True)],
],expand_x=True,expand_y=False,relief=sg.RELIEF_SOLID,border_width=0,visible=True,element_justification='c',background_color=COLOR_GRAY_9900,title_color=COLOR_ORANGE)
],
[
sg.Frame('',[
canvas_layout
],expand_x=False,expand_y=False,relief=sg.RELIEF_SOLID,border_width=0,visible=True,element_justification='c')
],
[
sg.Frame(' Marking Info',[
# [
# sg.Text('Supported video resolutions include 1280x720, 1920x1080, 2880x1620, 3840x2160, and higher', expand_x=True)
# ],
[
sg.B('Erase Marks',k='-erase_all_marks_buttons-',expand_x=False,disabled=True,button_color=(COLOR_RED,None)),
sg.R('Mark The Logo Area', 1, key='-mark_logo_area-', enable_events=True,default=True,visible=False),
sg.R('Erase Mark', 1, key='-erase_mark-', enable_events=True,visible=False),
sg.Text('',key='-marking_info-', expand_x=True)
],
],expand_x=True,expand_y=False,relief=sg.RELIEF_SOLID,border_width=0,visible=True,element_justification='c',background_color=COLOR_GRAY_9900,title_color=COLOR_ORANGE)
],
[
sg.Frame('',[
[
# sg.R('Mark The Logo Area', 1, key='-mark_logo_area-', enable_events=True,default=True,visible=False),
sg.R('Move Mark', 1, key='-MOVE-', enable_events=True,visible=False),
sg.R('Erase Mark', 1, key='-erase_mark-', enable_events=True,visible=False),
sg.R('Erase all Marks', 1, key='-erase_all_marks-', enable_events=True,visible=False),
# sg.B('Erase all Marks',k='-erase_all_marks_buttons-'),
],
[
sg.Input('',key='-input_save_video-',expand_x=True),sg.FileSaveAs(k=f'-save_delogo_FileBrowse-',file_types=(video_delogo_file_ext),disabled=True) ,
],
[
# sg.Text('Show Marking',text_color=COLOR_DARK_GREEN),
sg.Checkbox(text='Show preview marking on video',text_color=COLOR_DARK_GREEN,default=False,enable_events=True,k="-show_delogo_checkbox-"),
sg.B('Play Video',k='-input_play_video-',expand_x=True,button_color=(COLOR_DARK_GREEN,None)),
sg.B('Preview Delogo',k='-delogo_preview_start-',expand_x=True,disabled=True),
sg.B('Display Image',k='-delogo_show_image-',expand_x=True,disabled=True,visible=False),
sg.B('Play Preview Video',k='-delogo_play_preview_video-',expand_x=True,disabled=True,button_color=(COLOR_DARK_GREEN,None)),
sg.B('Delogo',k='-delogo_start-',expand_x=True,disabled=True),
sg.B('Play Delogoed Video',k='-delogo_play_video-',expand_x=True,disabled=True,button_color=(COLOR_DARK_GREEN,None)),
],
],expand_x=True,expand_y=False,relief=sg.RELIEF_SOLID,border_width=1,visible=True)
],
],expand_x=False,expand_y=False,relief=sg.RELIEF_SOLID,border_width=0,visible=INPUT_VISIBILITY)
],
],expand_x=False,expand_y=False,key=f'-delogo_frame-',visible=True,element_justification='c',relief=sg.RELIEF_SOLID,border_width=1),
]
]
#endregion
#region setup
window = sg.Window(f'Delogo', layout, no_titlebar=False,resizable=True, location=(0, 0),return_keyboard_events=True,finalize=True,size=(1380,1000),element_justification='c')
graph = window["-GRAPH-"] # type: sg.Graph
image_canvas_id = graph.draw_image(data=image_bio('',(WIDTH,HIGHT)), location=(0,0))
#region widgeting and flating
input_delogo_file_widget = window["-input_delogo_file-"]
input_delogo_FileBrowse_widget = window["-input_delogo_FileBrowse-"]
save_delogo_FileBrowse_widget = window["-save_delogo_FileBrowse-"]
input_save_video_widget = window["-input_save_video-"]
show_delogo_checkbox_widget = window["-show_delogo_checkbox-"]
delogo_preview_start_widget = window["-delogo_preview_start-"]
delogo_start_widget = window["-delogo_start-"]
delogo_show_image_widget = window["-delogo_show_image-"]
video_info_widget = window["-video_info-"]
erase_all_marks_widget = window["-erase_all_marks_buttons-"]
start_time_spin_widget = window["-start_time_spin-"]
set_start_time_spin_widget = window["-set_start_time_spin-"]
delogo_play_preview_video_widget = window["-delogo_play_preview_video-"]
delogo_play_video_widget = window["-delogo_play_video-"]
marking_info_widget = window["-marking_info-"]
delogo_frame_widget = window["-delogo_frame-"]
input_play_video_widget = window["-input_play_video-"]
marking_info_widget.update(text_color='white')
marking_info_widget.update(value='Logo area is outside of the frame.')
delogo_frame_widget.ParentRowFrame.config(background=COLOR_DARK_GRAY)
# delogo_frame_widget.Widget.config(background=COLOR_RED)
# frame_widget.Widget.config(highlightbackground='#2eb068')
# frame_widget.Widget.config(highlightcolor='#2eb068')
widgets = {
input_delogo_file_widget,
input_delogo_FileBrowse_widget,
save_delogo_FileBrowse_widget,
input_save_video_widget,
show_delogo_checkbox_widget,
delogo_preview_start_widget,
delogo_start_widget,
delogo_show_image_widget,
delogo_play_video_widget,
erase_all_marks_widget,
start_time_spin_widget,
set_start_time_spin_widget,
delogo_play_preview_video_widget,
input_play_video_widget
}
for widget in widgets:
widget.Widget.config(relief='flat')
#endregion
dragging = False
start_point = end_point = prior_rect = None
is_file_loaded = False
#endregion
#region funcs
def set_image_preview(file_path,start_time,clear=True,image_canvas_id_old='',delogo_rectangle_list=[]):
duration_full , duration_hours , duration_min, duration_sec ,frame_count , fps ,size ,width ,hight = get_videofile_info(file_path)
video_info_text = f'Dimensions: {width} x {hight} | Ratio: {(width/hight)} | Duration: {duration_full} | FPS: {fps} | Frame Count: {frame_count}'
video_info_widget.update(video_info_text)
clip = VideoFileClip(file_path)
try:
# print('create new thumbnail')
clip.save_frame(DELOGO_PREVIEW_IMAGE_PATH, t=start_time)
# print('thumbnail created')
except:
#print('fail to create thumbnail')
pass
if clear:
graph.erase()
delogo_rectangle_list = []
else:
if image_canvas_id_old:
graph.delete_figure(image_canvas_id_old)
# graph.set_size((width, hight))
graph.change_coordinates((0,hight), (width, 0))
image_canvas_id = graph.draw_image(data=image_bio(DELOGO_PREVIEW_IMAGE_PATH,(WIDTH,HIGHT)), location=(0,0))
if delogo_rectangle_list:
graph.send_figure_to_back(image_canvas_id)
for delogo_rectangle_item in delogo_rectangle_list:
if not delogo_rectangle_item['id'] == image_canvas_id:
graph.bring_figure_to_front(delogo_rectangle_item['id'])
return image_canvas_id
def delogo_procc(file_path,delogo_rectangle_list,start_time,is_preview):
delogo_str = ''
i = 0
for delogo_rectangle_item in delogo_rectangle_list:
delogo_x=delogo_rectangle_item['x']
delogo_y=delogo_rectangle_item['y']
delogo_width=delogo_rectangle_item['width']
delogo_hight=delogo_rectangle_item['hight']
show_delogo = values['-show_delogo_checkbox-']
delogo_file_output ='delogo_preview.mp4'
save_video_path = values["-input_save_video-"]
if not is_preview:
show_delogo = 0
if i == 0:
delogo_str = delogo_str + f'delogo=x={delogo_x}:y={delogo_y}:w={delogo_width}:h={delogo_hight}:show={show_delogo}'
if i > 0:
delogo_str = delogo_str + f',delogo=x={delogo_x}:y={delogo_y}:w={delogo_width}:h={delogo_hight}:show={show_delogo}'
i = i + 1
if is_preview:
code = f"ffmpeg -y -ss {start_time} -t 1 -i '{file_path}' -vf '{delogo_str}' delogo/{delogo_file_output}"
else:
code = f"ffmpeg -y -i '{file_path}' -vf '{delogo_str}' {save_video_path}"
call = shlex.split(code)
def subprocess_thread():
# subprocess.call(call)
process_res = subprocess_with_msg(call)
if process_res:
window.write_event_value('-delogo_succeed-','')
else:
window.write_event_value('-delogo_failed-','')
if is_preview:
window.write_event_value('-delogo_preview_finished-','')
if not is_preview:
window.write_event_value('-delogo_finished-','')
# subprocess_thread()
Thread(target=subprocess_thread, args=(), daemon=True).start()
window.write_event_value('-delogo_started-','')
#endregion
is_file_loaded_final_cut = is_file_loaded_final_cut
if is_file_loaded_final_cut:
if save_final_video_file_path==None:
window.write_event_value('-input_load_file-','')
else:
window.write_event_value('-load_final_cut-','')
while True:
event, values = window.read()
# print(event, values )
if event in ('Exit','Escape:27', None):
break
if event == '-load_final_cut-':
save_file_path = clean_file_path(file_path)['clean_file_path']
original_file_name = os.path.basename(clean_file_path(save_final_video_file_path)['clean_file_path'])
folder_path = f"{save_file_path.split('/final_clip')[0]}/final_video/"
save_file_path = os.path.join(folder_path,original_file_name)
input_delogo_file_widget.update(file_path)
input_save_video_widget.update(save_file_path)
is_file_loaded = True
start_time = int(values['-start_time_spin-'])
image_canvas_id = set_image_preview(file_path,start_time)
is_file_loaded_final_cut = False
delogo_play_preview_video_widget.update(disabled=True)
delogo_play_video_widget.update(disabled=True)
marking_info_widget.update(value='')
if event == '-input_load_file-':
save_file_path = clean_file_path(file_path,prefix='delogo')['clean_file_path']
input_save_video_widget.update(save_file_path)
input_delogo_file_widget.update(file_path)
is_file_loaded = True
start_time = int(values['-start_time_spin-'])
image_canvas_id = set_image_preview(file_path,start_time)
delogo_play_preview_video_widget.update(disabled=True)
delogo_play_video_widget.update(disabled=True)
marking_info_widget.update(value='')
window.write_event_value('-disable_buttons-','')
delogo_rectangle_list = []
if event == '-input_delogo_file-':
# if not save_final_video_file_path==None:
file_path = values['-input_delogo_file-']
save_file_path = clean_file_path(file_path,prefix='delogo')['clean_file_path']
input_save_video_widget.update(save_file_path)
is_file_loaded = True
start_time = int(values['-start_time_spin-'])
image_canvas_id = set_image_preview(file_path,start_time)