-
Notifications
You must be signed in to change notification settings - Fork 7
/
Copy pathwebmarizer.py
1452 lines (1306 loc) · 64.7 KB
/
webmarizer.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
import subprocess
import glob
import os, sys
import platform
from PyQt5 import QtGui, QtCore, QtWidgets
# Command for creating pyinstaller executable:
# sudo pyinstaller -F --add-data 'ffmpeg:.' --add-data 'ffprobe:.' webmarizer.py
# CD to the current directory of the script/executable
os.chdir(os.path.dirname(os.path.abspath(sys.argv[0])))
# We'll need this to access ffmpeg & ffprobe once pyinstaller has created one-file executable
# Returns some sort of temp directory
def resource_path(relative_path):
""" Get absolute path to resource, works for dev and for PyInstaller """
base_path = getattr(sys, '_MEIPASS', os.path.dirname(os.path.abspath(__file__)))
path = os.path.join(base_path, relative_path)
return path
# Here's where we can find ffmpeg & ffprobe. Check platform first, though.
def getDependencyPath(dependency):
if (platform.system() == 'Windows'):
if (dependency == 'ffmpeg'):
path = resource_path('ffmpeg.exe')
else:
path = resource_path('ffprobe.exe')
else:
if (dependency == 'ffmpeg'):
path = resource_path('ffmpeg')
else:
path = resource_path('ffprobe')
return path
# Generates the file name for output, creates sub directory if specified
def generateOuput_filename(params, fileName, extension, numFiles):
if params['output_to_subdir']:
if not os.path.isdir(params['output_dir_name']):
os.makedirs(params['output_dir_name'])
return os.path.join(params['output_dir_name'], os.path.splitext(fileName)[0] + '_' + str(numFiles) + '.' + extension)
else:
return os.path.splitext(fileName)[0] + '_' + str(numFiles) + '.' + extension
# Create a GIF by first creating a palette, then making GIF from that palette
# To-do: add option to control framerate
def createGif(params):
fileName_gif = generateOuput_filename(params=params,
fileName=str(params['fileName']),
extension='gif',
numFiles=params['numFiles'])
# Set the size of the GIF and filters
scaleString = 'scale=' + str(params['outputWidth']) + ':-2'
filters='fps=20,scale=' + str(params['outputWidth']) + ':-1:flags=lanczos'
# 1st Generate a pallete with ffmpeg
paletteArgs = [
'-ss', str(params['startTime']),
'-t', str(params['outputDuration']),
'-i' , params['fileName'],
'-vf', filters+",palettegen",
'-y', 'palette.png'
]
# 2nd Generate the gif using the palette
gifArgs = [
'-ss', str(params['startTime']),
'-t' , str(params['outputDuration']),
'-i' , params['fileName'],
'-i' , 'palette.png'
]
# Options if the user has requested specific GIF size
gifOptsWithFileSize = [
'-fs', str(params['fileSize']/1000) + "M",
'-lavfi', filters+"[x];[x][1:v]paletteuse",
'-y', fileName_gif
]
# Options if the user has not requested specific GIF size
gifOptsWithoutFileSize = [
'-lavfi', filters+"[x];[x][1:v]paletteuse",
'-y', fileName_gif
]
# Append either of above options to args array, depending on whether
# file size is set
if GUI.getFileSizeCheckboxState():
gifArgs.extend(gifOptsWithFileSize)
else:
gifArgs.extend(gifOptsWithoutFileSize)
GUI.setStatusText("Currently creating: " + fileName_gif)
# Set channel so we can see FFmpeg output
params['FFmpegProcess'].setProcessChannelMode(QtCore.QProcess.MergedChannels)
app.processEvents()
# Currently, no way of stopping FFmpeg from GUI since GUI is frozen
# See multithreading for potential solution
if (params['stopped'] == False):
params['FFmpegProcess'].execute(params['ffmpeg_path'], paletteArgs)
params['FFmpegProcess'].waitForFinished(-1)
params['FFmpegProcess'].execute(params['ffmpeg_path'], gifArgs)
params['FFmpegProcess'].waitForFinished(-1)
os.remove("palette.png")
# Use ffmpeg to create WEBM and read its stdout. To-Do:Use some regex later for progress bar
def createWebm(params):
fileName_webm = generateOuput_filename(params=params,
fileName=str(params['fileName']),
extension='webm',
numFiles=params['numFiles'])
scaleString = 'scale=' + str(params['outputWidth']) + ':-2'
# General arguments to pass to FFmpeg
args = [
'-y' ,
'-ss' , str(params['startTime']),
'-t' , str(params['outputDuration']),
'-i' , params['fileName'],
'-vf' , scaleString,
'-c:v', 'libvpx',
'-b:v', str(params['bitrate'])+"K",
'-b:a', '96K',
'-c:a', 'libvorbis'
]
# If audio is not enabled, set FFmpeg's -an flag
if not params['audioEnabled']:
args.append('-an')
# Set FFmpeg's output name
args.append(fileName_webm)
GUI.setStatusText("Currently creating: " + fileName_webm)
params['FFmpegProcess'].setProcessChannelMode(QtCore.QProcess.MergedChannels)
app.processEvents()
if (params['stopped'] == False):
params['FFmpegProcess'].execute(params['ffmpeg_path'], args)
params['FFmpegProcess'].waitForFinished(-1)
params['FFmpegProcess'].kill() # When we're done, kill process
# Searches current directory for .mp4,.wmv,.avi, .mpeg, and .mkv videos
def createVideoList():
videosList = []
for fileType in ["*.mp4", "*.wmv","*.avi", "*.mpeg", "*.mkv"]:
aVideo = glob.glob(fileType)
if (len(aVideo) > 0):
videosList.extend(aVideo)
return (videosList)
'''
Join Videos Algorithm:
Let [] represent a video clip. Example: For a 3x3 thumbnail, our matrix will have 9 of these clips.
To create this matrix, we start by creating 3 individual rows with 3 clips per row.
# Creating a row looks like this:
[] + [] = [][] --> [][] + [] = [][][].
We do this 3 times to create 3 rows.
Then we concatenate 3 rows in a similar way: Start by taking 2 rows and concatenating them.
[][][] (Row 1)
+ [][][] (Row 2)
Then, we add the third row to the 2 already concatenated rows:
[][][] (Row 1)
[][][] (Row 2)
+ [][][] (Row 3)
'''
# Handles joining videos together for thumbnail mode option
def join_videos(params):
# Set GUI message while we stich WEBMs together & set channel so we can see FFmpeg output in terminal
GUI.setStatusText("Stitching WEBMs. This may take a while.")
params['FFmpegProcess'].setProcessChannelMode(QtCore.QProcess.MergedChannels)
app.processEvents()
# Use this to keep track of which video we are currently appending
fileCount = 1
# For each video in the row, we'll make one video row that gets progressively wider
previousColumnOutput = ''
# At the end of each column, we're going to add the finished row to the rowArray
rowArray = []
# Create rows first
for row in range((params['thumbnailNumTilesSide'])):
firstInColumn = True
for column in range(0,(params['thumbnailNumTilesSide']-1)):
# Special case: If we are in first column, concat 2 individual clips together
if firstInColumn:
fileName1 = os.path.splitext(params['fileName'])[0] + '_' + str(fileCount) + '.webm'
fileCount = fileCount + 1
# If not in first column, use previously concatenated clips in the row and add new clip
else:
fileName1 = previousColumnOutput
fileName2 = os.path.splitext(params['fileName'])[0] + '_' + str(fileCount) + '.webm'
output = os.path.splitext(params['fileName'])[0] + '_' + str(fileCount) + '_' + str(row) + '.webm'
# Save previous column output so that we can use it as fileName1 in next iteration
previousColumnOutput = output
# General FFmpeg settings
args = [
'-y' ,
'-i' , fileName1,
'-i' , fileName2,
'-c:v', 'libvpx',
'-b:v', str(params['bitrate'])+"K",
'-b:a', '96K',
'-c:a', 'libvorbis'
]
# Settings when audio enabled
extendSettings1 = [
'-filter_complex', '[0:v][1:v]hstack[v];[0:a][1:a]amerge=inputs=2[a]',
'-map', '[v]',
'-map', '[a]',
'-ac', '2'
]
# Setting when audio disabled
extendSettings2 = [
'-filter_complex', 'hstack'
]
# Append correct settings depending on whether audio is enabled
if not params['audioEnabled']:
args.append('-an')
for setting in extendSettings2:
args.append(setting)
else:
for setting in extendSettings1:
args.append(setting)
# Add what we'd like output to be called to FFmpeg args array
args.append(output)
# Execute the concatenation process
params['FFmpegProcess'].execute(params['ffmpeg_path'], args)
params['FFmpegProcess'].waitForFinished(-1)
# Increment fileCount so we know which WEBM to use as input
fileCount = fileCount + 1
firstInColumn = False
# If we've reached end of the row, add that completed row to the row array so
# we can concatenate rows later
if (column == (params['thumbnailNumTilesSide']-1)-1):
rowArray.append(output)
print(rowArray)
firstPair = True # Serves same purpose as firstInColumn above (handling special case)
previousRow = ''
# Concatenate all the rows together
for row in range(len(rowArray)-1):
if firstPair:
fileName1 = rowArray[row]
else:
fileName1 = previousRow
firstPair = False
# If we haven't reached last row, let 2nd input file be next row
if (row < len(rowArray) - 1):
fileName2 = rowArray[row+1]
output = os.path.splitext(params['fileName'])[0] + '_row_' + str(row) + '.webm'
# If we've reached the last 2 rows, set output to be videoName_thumbnail.webm
if (row == (len(rowArray) - 2)):
output = os.path.splitext(params['fileName'])[0] + '_THUMBNAIL.webm'
previousRow = output
# General FFmpeg settings
args2 = [
'-y' ,
'-i' , fileName1,
'-i' , fileName2,
'-c:v', 'libvpx',
'-b:v', str(params['bitrate'])+"K",
'-b:a', '96K',
'-c:a', 'libvorbis'
]
# Settings when audio is enabled
extendSettings1 = [
'-filter_complex', '[0:v][1:v]vstack[v];[0:a][1:a]amerge=inputs=2[a]',
'-map', '[v]',
'-map', '[a]',
'-ac', '2'
]
# Settings when audio is disabled
extendSettings2 = [
'-filter_complex', 'vstack'
]
# Append appropriate settings depending on audio
if not params['audioEnabled']:
args2.append('-an')
for setting in extendSettings2:
args2.append(setting)
else:
for setting in extendSettings1:
args2.append(setting)
# Add what we'd like output to be called to FFmpeg args array
args2.append(output)
# Execute the vertical stacking of rows
params['FFmpegProcess'].execute(params['ffmpeg_path'], args2)
params['FFmpegProcess'].waitForFinished(-1)
# Create a parameter dictionary to hold media information
# Useful so we don't have to pass a bunch of vars between functions
def composeMediaParamDictionary(aVideo):
# Initialize dictionary
params = {}
# Get the path to ffmpeg & probe executables
ffmpeg_path = getDependencyPath('ffmpeg')
ffprobe_path = getDependencyPath('ffprobe')
# Compose param array for FFprobe to use
FFprobeArgs = [
ffprobe_path ,
'-v' , 'quiet',
'-show_entries' , 'format=duration',
'-of' , 'csv=%s' % ("p=0"),
'-i' , aVideo
]
# Spawn process
FFmpegProcess = QtCore.QProcess()
# Pass process to Qt
GUI.setProcess(FFmpegProcess)
# Check how many WEBMs/GIFs user wants
numOutputs = GUI.getNumOutputs()
# Keep track of current WEBM number for naming purposes. Init to 0
numFiles = 0
# Get width of WEBM/GIF
outputWidth = GUI.getWidth()
# Check what duration user wants for WEBM/GIF
outputDuration = GUI.getOutputDuration()
# We can use FFprobe to check the number of seconds in the video
totalSeconds = subprocess.check_output(FFprobeArgs)
# Y u do dis? Have to look into why decoding this is necessary.
totalSeconds = float(totalSeconds.decode("utf-8"))
# Get the bitrate
bitrate = GUI.getBitrate()
# Get the target file size if targetFileSize is enabled
# Only used for GIFs, since bitrate will determine file size for WEBMs
if GUI.getFileSizeCheckboxState():
fileSize = GUI.getFileSize()
else:
fileSize = -1
# Check whether audio is enabled
audioEnabled = GUI.getAudioEnabledState()
# Makes sure WEBM length "L" isn't created at startTime + L > Length of video
lenLimit = getLenLimit(totalSeconds, outputDuration)
# Check value of wadsworth constant
wadsworthConstant = GUI.getWadsworth()
# Check if single mode is on or off
single_mode = GUI.getSingleModeState()
# Set the time where WEBM/GIF starts
if single_mode:
startTime = GUI.getCustomStartTime()
else:
startTime = ( (totalSeconds) * wadsworthConstant) / 100
# Calculate time interval between WEBMs/GIFs
interval = ( int(totalSeconds) - startTime ) / numOutputs
# Check what kind of output user wants
output_type = GUI.getOutputType()
# Check if thumbnail mode is on or off
thumbnailMode = GUI.getThumbnailModeState()
# In case thumbnail mode is enabled, get number of tiles per side of thumbnail
thumbnailNumTilesSide = GUI.getNumVideoTilesSide()
# Recalculate custom interval and output number if thumbnailMode is enabled
if thumbnailMode:
interval = ( int(totalSeconds) - startTime ) / (thumbnailNumTilesSide**2)
numOutputs = GUI.getNumVideoTilesSide() ** 2
# If we're only creating single WEBM/GIF, set output num to 1
if single_mode:
numOutputs = 1
# Use this to check if user has stopped the program
stopped = GUI.getProcessStoppedStatus()
# output dir feature
output_to_subdir = GUI.output_to_subdir
output_dir_name = GUI.output_dir_name
# Set all key:value pairs for param dictionary
params = {
'fileName' : aVideo,
'ffmpeg_path' : ffmpeg_path,
'ffprobe_path' : ffprobe_path,
'FFmpegProcess' : FFmpegProcess,
'numOutputs' : numOutputs,
'numFiles' : numFiles,
'outputWidth' : outputWidth,
'fileSize' : fileSize,
'outputDuration' : outputDuration,
'totalSeconds' : totalSeconds,
'lenLimit' : lenLimit,
'wadsworthConstant' : wadsworthConstant,
'single_mode' : single_mode,
'startTime' : startTime,
'interval' : interval,
'output_type' : output_type,
'thumbnailMode' : thumbnailMode,
'bitrate' : bitrate,
'audioEnabled' : audioEnabled,
'stopped' : stopped,
'thumbnailNumTilesSide' : thumbnailNumTilesSide,
'output_to_subdir' : output_to_subdir,
'output_dir_name' : output_dir_name
}
return params
# Takes video name, splits video into intervals, creates WEBM or GIF starting at each interval
def processVideo(aVideo):
# Check to make sure user has selected a video
if aVideo == '':
GUI.setStatusText("Please select a video from list when creating WEBM/GIF from single video.")
return
params = composeMediaParamDictionary(aVideo)
# Check if user has stopped the program
if params['stopped']:
app.processEvents()
GUI.setStatusText("Process killed.")
return
# Iteratively create the number of GIFs/WEBMs that user requested
for output in range(params['numOutputs']):
app.processEvents()
params['numFiles'] += 1
# If we're trying to create output past the end of video, break
if params['startTime'] >= params['lenLimit']:
break
if params['output_type'] == 'WEBM':
createWebm(params)
elif params['output_type'] == 'GIF':
createGif(params)
params['startTime'] += params['interval']
if params['thumbnailMode']:
join_videos(params)
# Makes sure WEBM length "L" isn't created at startTime + L > Length of video
def getLenLimit(totalSeconds, outputDuration):
lenLimit = totalSeconds - outputDuration - 1
return lenLimit
# Starts going through all the videos in our list and initiates WEBM/GIF creation process
def init(videosList):
for video in videosList:
# If video making not cancelled, process vid
if not GUI.getProcessStoppedStatus():
processVideo(video)
else:
app.processEvents()
GUI.setStatusText("Process killed.")
if not GUI.getProcessStoppedStatus():
GUI.setStatusText("Finished!")
# Form implementation generated from reading ui file 'webmarizer_template.ui'
# Created by: PyQt5 UI code generator 5.10.1
class Ui_MainWindow(object):
def setupUi(self, MainWindow):
#===================================================================#
MainWindow.setObjectName("MainWindow")
MainWindow.resize(829, 330)
MainWindow.setDocumentMode(False)
MainWindow.setTabShape(QtWidgets.QTabWidget.Triangular)
MainWindow.setUnifiedTitleAndToolBarOnMac(True)
MainWindow.setStyleSheet("""
background-color: rgb(255, 255, 255);
padding:0px;
""")
#===================================================================#
self.centralwidget = QtWidgets.QWidget(MainWindow)
self.centralwidget.setObjectName("centralwidget")
#===================================================================#
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
sizePolicy = QtWidgets.QSizePolicy(QtWidgets.QSizePolicy.Fixed, QtWidgets.QSizePolicy.Fixed)
#===================================================================#
spacerItem = QtWidgets.QSpacerItem(20, 25, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
spacerItem1 = QtWidgets.QSpacerItem(20, 25, QtWidgets.QSizePolicy.Minimum, QtWidgets.QSizePolicy.Preferred)
spacerItem2 = QtWidgets.QSpacerItem(40, 20, QtWidgets.QSizePolicy.Expanding, QtWidgets.QSizePolicy.Minimum)
#===================================================================#
self.tabWidget = QtWidgets.QTabWidget(self.centralwidget)
#===================================================================#
self.generalTab = QtWidgets.QWidget()
self.advancedTab = QtWidgets.QWidget()
#===================================================================#
self.layoutWidget = QtWidgets.QWidget(self.generalTab)
self.layoutWidget1 = QtWidgets.QWidget(self.advancedTab)
self.layoutWidget_2 = QtWidgets.QWidget(self.advancedTab)
#===================================================================#
self.verticalLayout = QtWidgets.QVBoxLayout(self.layoutWidget)
self.verticalLayout_2 = QtWidgets.QVBoxLayout(self.layoutWidget_2)
self.verticalLayout_3 = QtWidgets.QVBoxLayout()
self.verticalLayout_4 = QtWidgets.QVBoxLayout()
self.verticalLayout_5 = QtWidgets.QVBoxLayout(self.layoutWidget1)
self.verticalLayout_6 = QtWidgets.QVBoxLayout()
#===================================================================#
self.horizontalLayout = QtWidgets.QHBoxLayout()
self.horizontalLayout_2 = QtWidgets.QHBoxLayout()
self.horizontalLayout_3 = QtWidgets.QHBoxLayout()
self.horizontalLayout_4 = QtWidgets.QHBoxLayout()
self.horizontalLayout_7 = QtWidgets.QHBoxLayout()
self.horizontalLayout_8 = QtWidgets.QHBoxLayout()
#===================================================================#
self.videoListTitleLabel = QtWidgets.QLabel(self.generalTab)
self.statusLabel = QtWidgets.QLabel(self.centralwidget)
self.durationLabel = QtWidgets.QLabel(self.layoutWidget)
self.widthLabel = QtWidgets.QLabel(self.layoutWidget)
self.numOutputsLabel = QtWidgets.QLabel(self.layoutWidget)
self.startTimeLabel = QtWidgets.QLabel(self.layoutWidget1)
self.gifModeLabel = QtWidgets.QLabel(self.layoutWidget1)
self.enableAudioLabel = QtWidgets.QLabel(self.layoutWidget1)
self.thumbnailModeLabel = QtWidgets.QLabel(self.layoutWidget1)
self.targetSizeCheckmarkLabel = QtWidgets.QLabel(self.layoutWidget1)
self.bitrateLabel = QtWidgets.QLabel(self.layoutWidget_2)
self.targetFileSizeLabel = QtWidgets.QLabel(self.layoutWidget_2)
self.wadsworthLabel = QtWidgets.QLabel(self.layoutWidget1)
#===================================================================#
self.numOutputsSlider = QtWidgets.QSlider(self.layoutWidget)
self.durationSlider = QtWidgets.QSlider(self.layoutWidget)
self.widthSlider = QtWidgets.QSlider(self.layoutWidget)
self.fileSizeSlider = QtWidgets.QSlider(self.layoutWidget_2)
self.bitRateSlider = QtWidgets.QSlider(self.layoutWidget_2)
#===================================================================#
self.stopBtn = QtWidgets.QPushButton(self.centralwidget)
self.startSingleBtn = QtWidgets.QPushButton(self.centralwidget)
self.createBtn = QtWidgets.QPushButton(self.centralwidget)
#===================================================================#
self.timeEdit = QtWidgets.QTimeEdit(self.layoutWidget1)
#===================================================================#
self.listWidget = QtWidgets.QListWidget(self.generalTab)
#===================================================================#
self.thumbnailModeCheckBox = QtWidgets.QCheckBox(self.layoutWidget1)
self.startTimeCheckBox = QtWidgets.QCheckBox(self.layoutWidget1)
self.gifModeCheckBox = QtWidgets.QCheckBox(self.layoutWidget1)
self.audioCheckBox = QtWidgets.QCheckBox(self.layoutWidget1)
self.targetFileSizeCheckBox = QtWidgets.QCheckBox(self.layoutWidget1)
self.wadsworthCheckBox = QtWidgets.QCheckBox(self.layoutWidget1)
#===================================================================#
self.thumbnailDropdown = QtWidgets.QComboBox(self.layoutWidget1)
#===================================================================#
font = QtGui.QFont()
#===================================================================#
self.stopBtn.setObjectName("stopBtn")
self.statusLabel.setObjectName("statusLabel")
self.thumbnailModeLabel.setObjectName("thumbnailModeLabel")
self.thumbnailModeCheckBox.setObjectName("thumbnailModeCheckBox")
self.startTimeCheckBox.setObjectName("startTimeCheckBox")
self.horizontalLayout_7.setObjectName("horizontalLayout_7")
self.horizontalLayout_2.setObjectName("horizontalLayout_2")
self.horizontalLayout.setObjectName("horizontalLayout")
self.verticalLayout_6.setObjectName("verticalLayout_6")
self.verticalLayout_4.setObjectName("verticalLayout_4")
self.verticalLayout_3.setObjectName("verticalLayout_3")
self.verticalLayout_2.setObjectName("verticalLayout_2")
self.verticalLayout.setObjectName("verticalLayout")
self.layoutWidget.setObjectName("layoutWidget")
self.tabWidget.setObjectName("tabWidget")
self.generalTab.setObjectName("generalTab")
self.durationLabel.setObjectName("durationLabel")
self.durationSlider.setObjectName("durationSlider")
self.widthLabel.setObjectName("sizeLabel")
self.widthSlider.setObjectName("sizeSlider")
self.numOutputsLabel.setObjectName("numOutputsLabel")
self.numOutputsSlider.setObjectName("numOutputsSlider")
self.videoListTitleLabel.setObjectName("videoListTitleLabel")
self.advancedTab.setObjectName("advancedTab")
self.layoutWidget_2.setObjectName("layoutWidget_2")
self.verticalLayout_5.setObjectName("verticalLayout_5")
self.horizontalLayout_3.setObjectName("horizontalLayout_3")
self.horizontalLayout_8.setObjectName("horizontalLayout_8")
self.bitrateLabel.setObjectName("bitrateLabel")
self.bitRateSlider.setObjectName("bitRateSlider")
self.targetFileSizeLabel.setObjectName("targetFileSizeLabel")
self.fileSizeSlider.setObjectName("fileSizeSlider")
self.layoutWidget1.setObjectName("layoutWidget1")
self.targetFileSizeCheckBox.setObjectName("targetFileSizeCheckBox")
self.targetSizeCheckmarkLabel.setObjectName("targetSizeCheckmarkLabel")
self.audioCheckBox.setObjectName("audioCheckBox")
self.enableAudioLabel.setObjectName("enableAudioLabel")
self.gifModeCheckBox.setObjectName("gifModeCheckBox")
self.gifModeLabel.setObjectName("gifModeLabel")
self.startTimeLabel.setObjectName("startTimeLabel")
self.timeEdit.setObjectName("timeEdit")
self.wadsworthCheckBox.setObjectName("wadsworthCheckBox")
self.horizontalLayout_4.setObjectName("horizontalLayout_4")
self.createBtn.setObjectName("createBtn")
self.startSingleBtn.setObjectName("startSingleBtn")
#===================================================================#
tabStyleString = """
QTabBar::tab {
width: 300px;
}
QTabWidget::tab-bar {
top:30;
padding-left:0;
background:transparent;
width:835px;
}
QTabWidget::pane {
border: 0 solid white;
}
"""
sliderStyleString = """
QSlider::handle:horizontal {
background: qlineargradient(x1:0, y1:0, x2:1, y2:1, stop:0 #9595ff, stop:1 #1e95ff);
border: 1px solid #5c5c5c;
width: 18px;
margin: -2px 0;
border-radius: 3px;
}
QSlider::groove:horizontal {
border: 1px solid #999999;
height: 9px;
background: qlineargradient(x1:0, y1:0, x2:0, y2:1, stop:0 #B1B1B1, stop:1 #c4c4c4);
margin: 2px 0;
}
"""
#===================================================================#
font.setFamily("Thonburi")
font.setBold(False)
font.setWeight(50)
#===================================================================#
self.tabWidget.setFont(font)
self.tabWidget.setLayoutDirection(QtCore.Qt.LeftToRight)
self.tabWidget.setAutoFillBackground(False)
self.tabWidget.setTabShape(QtWidgets.QTabWidget.Rounded)
self.tabWidget.setDocumentMode(False)
self.tabWidget.setGeometry(QtCore.QRect(0, -30, 831, 341))
self.tabWidget.addTab(self.generalTab, "")
self.tabWidget.addTab(self.advancedTab, "")
self.tabWidget.setStyleSheet(tabStyleString)
#===================================================================#
self.generalTab.setAutoFillBackground(False)
self.generalTab.setStyleSheet("""
QTabBar {
qproperty-drawBase: 0;
}
""")
#===================================================================#
self.layoutWidget.setGeometry(QtCore.QRect(20, 40, 381, 211))
#===================================================================#
sizePolicy.setHeightForWidth(self.wadsworthCheckBox.sizePolicy().hasHeightForWidth())
self.wadsworthCheckBox.setSizePolicy(sizePolicy)
self.wadsworthCheckBox.setText("")
#===================================================================#
self.wadsworthLabel.setEnabled(True)
self.wadsworthLabel.setFont(font)
self.wadsworthLabel.setTextFormat(QtCore.Qt.RichText)
self.wadsworthLabel.setObjectName("wadsworthLabel")
#===================================================================#
self.durationLabel.setEnabled(True)
self.durationLabel.setFont(font)
self.durationLabel.setStyleSheet("")
self.durationLabel.setTextFormat(QtCore.Qt.RichText)
#===================================================================#
self.durationSlider.setMinimum(1)
self.durationSlider.setMaximum(30)
self.durationSlider.setOrientation(QtCore.Qt.Horizontal)
self.durationSlider.setStyleSheet(sliderStyleString)
#===================================================================#
self.widthLabel.setEnabled(True)
self.widthLabel.setFont(font)
self.widthLabel.setTextFormat(QtCore.Qt.RichText)
#===================================================================#
self.widthSlider.setMinimum(300)
self.widthSlider.setMaximum(3000)
self.widthSlider.setOrientation(QtCore.Qt.Horizontal)
self.widthSlider.setStyleSheet(sliderStyleString)
#===================================================================#
self.numOutputsLabel.setEnabled(True)
self.numOutputsLabel.setFont(font)
self.numOutputsLabel.setTextFormat(QtCore.Qt.RichText)
#===================================================================#
self.numOutputsSlider.setMinimum(1)
self.numOutputsSlider.setMaximum(50)
self.numOutputsSlider.setOrientation(QtCore.Qt.Horizontal)
self.numOutputsSlider.setStyleSheet(sliderStyleString)
#===================================================================#
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.listWidget.sizePolicy().hasHeightForWidth())
#===================================================================#
self.listWidget.setGeometry(QtCore.QRect(430, 70, 381, 171))
self.listWidget.setSizePolicy(sizePolicy)
self.listWidget.setFont(font)
self.listWidget.setWordWrap(True)
self.listWidget.setObjectName("listWidget")
self.listWidget.setStyleSheet("""
background-color:#fff;
border:1px solid black;
""")
#===================================================================#
self.videoListTitleLabel.setGeometry(QtCore.QRect(580, 40, 81, 21))
self.videoListTitleLabel.setFont(font)
#===================================================================#
self.layoutWidget_2.setGeometry(QtCore.QRect(420, 40, 371, 102))
#===================================================================#
self.verticalLayout.setContentsMargins(0, 0, 0, 0)
self.verticalLayout.addWidget(self.durationLabel)
self.verticalLayout.addWidget(self.durationSlider)
self.verticalLayout.addItem(spacerItem)
self.verticalLayout.addWidget(self.numOutputsLabel)
self.verticalLayout.addWidget(self.numOutputsSlider)
self.verticalLayout.addItem(spacerItem1)
self.verticalLayout.addWidget(self.widthLabel)
self.verticalLayout.addWidget(self.widthSlider)
#===================================================================#
self.verticalLayout_2.setContentsMargins(0, 0, 0, 0)
self.verticalLayout_2.addLayout(self.verticalLayout_4)
#===================================================================#
self.verticalLayout_3.addLayout(self.horizontalLayout_7)
self.verticalLayout_3.addLayout(self.horizontalLayout_8)
#===================================================================#
self.verticalLayout_4.addLayout(self.verticalLayout_6)
self.verticalLayout_4.addWidget(self.targetFileSizeLabel)
self.verticalLayout_4.addWidget(self.fileSizeSlider)
#===================================================================#
self.verticalLayout_5.addLayout(self.verticalLayout_3)
self.verticalLayout_5.addLayout(self.horizontalLayout)
self.verticalLayout_5.addLayout(self.horizontalLayout_2)
self.verticalLayout_5.addLayout(self.horizontalLayout_4)
self.verticalLayout_5.addLayout(self.horizontalLayout_3)
self.verticalLayout_5.setContentsMargins(0, 0, 0, 0)
#===================================================================#
self.verticalLayout_6.addWidget(self.bitrateLabel)
self.verticalLayout_6.addWidget(self.bitRateSlider)
#===================================================================#
self.horizontalLayout.addWidget(self.gifModeCheckBox)
self.horizontalLayout.addWidget(self.gifModeLabel)
#===================================================================#
self.horizontalLayout_2.addWidget(self.startTimeCheckBox)
self.horizontalLayout_2.addWidget(self.startTimeLabel)
self.horizontalLayout_2.addWidget(self.timeEdit)
self.horizontalLayout_2.addItem(spacerItem2)
#===================================================================#
self.horizontalLayout_3.addWidget(self.thumbnailModeCheckBox)
self.horizontalLayout_3.addWidget(self.thumbnailModeLabel)
self.horizontalLayout_3.addWidget(self.thumbnailDropdown)
#===================================================================#
self.horizontalLayout_4.addWidget(self.wadsworthCheckBox)
self.horizontalLayout_4.addWidget(self.wadsworthLabel)
#===================================================================#
self.thumbnailDropdown.setIconSize(QtCore.QSize(16, 16))
self.thumbnailDropdown.setObjectName("thumbnailDropdown")
self.thumbnailDropdown.addItem("")
self.thumbnailDropdown.addItem("")
self.thumbnailDropdown.addItem("")
self.thumbnailDropdown.addItem("")
self.thumbnailDropdown.addItem("")
self.thumbnailDropdown.setStyleSheet('''
QComboBox {
border-style: solid;
selection-color:black;
background-color:#f9f9f9;
border:1px solid black;
border-radius: 5;
padding: 1px 0px 1px 10px;
}
QComboBox::down-arrow {
width: 14px;
color:white;
}
''')
#===================================================================#
self.horizontalLayout_7.addWidget(self.targetFileSizeCheckBox)
self.horizontalLayout_7.addWidget(self.targetSizeCheckmarkLabel)
#===================================================================#
self.horizontalLayout_8.addWidget(self.audioCheckBox)
self.horizontalLayout_8.addWidget(self.enableAudioLabel)
#===================================================================#
self.bitrateLabel.setEnabled(True)
self.bitrateLabel.setFont(font)
self.bitrateLabel.setTextFormat(QtCore.Qt.RichText)
#===================================================================#
self.bitRateSlider.setStyleSheet(sliderStyleString)
self.bitRateSlider.setMinimum(20)
self.bitRateSlider.setMaximum(15000)
self.bitRateSlider.setOrientation(QtCore.Qt.Horizontal)
#===================================================================#
self.targetFileSizeLabel.setEnabled(True)
self.targetFileSizeLabel.setFont(font)
self.targetFileSizeLabel.setTextFormat(QtCore.Qt.RichText)
#===================================================================#
self.fileSizeSlider.setStyleSheet(sliderStyleString)
self.fileSizeSlider.setMinimum(50)
self.fileSizeSlider.setMaximum(15000)
self.fileSizeSlider.setOrientation(QtCore.Qt.Horizontal)
#===================================================================#
self.layoutWidget1.setGeometry(QtCore.QRect(10, 40, 401, 221))
#===================================================================#
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.targetFileSizeCheckBox.sizePolicy().hasHeightForWidth())
#===================================================================#
self.targetFileSizeCheckBox.setSizePolicy(sizePolicy)
self.targetFileSizeCheckBox.setText("")
#===================================================================#
self.targetSizeCheckmarkLabel.setEnabled(True)
self.targetSizeCheckmarkLabel.setFont(font)
self.targetSizeCheckmarkLabel.setTextFormat(QtCore.Qt.RichText)
#===================================================================#
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.audioCheckBox.sizePolicy().hasHeightForWidth())
#===================================================================#
self.audioCheckBox.setSizePolicy(sizePolicy)
self.audioCheckBox.setText("")
#===================================================================#
self.enableAudioLabel.setEnabled(True)
self.enableAudioLabel.setFont(font)
self.enableAudioLabel.setTextFormat(QtCore.Qt.RichText)
#===================================================================#
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.gifModeCheckBox.sizePolicy().hasHeightForWidth())
#===================================================================#
self.gifModeCheckBox.setSizePolicy(sizePolicy)
self.gifModeCheckBox.setText("")
#===================================================================#
self.gifModeLabel.setEnabled(True)
self.gifModeLabel.setFont(font)
self.gifModeLabel.setTextFormat(QtCore.Qt.RichText)
#===================================================================#
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.startTimeCheckBox.sizePolicy().hasHeightForWidth())
#===================================================================#
self.startTimeCheckBox.setSizePolicy(sizePolicy)
self.startTimeCheckBox.setText("")
#===================================================================#
self.startTimeLabel.setEnabled(True)
self.startTimeLabel.setFont(font)
self.startTimeLabel.setTextFormat(QtCore.Qt.RichText)
#===================================================================#
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.timeEdit.sizePolicy().hasHeightForWidth())
#===================================================================#
self.timeEdit.setSizePolicy(sizePolicy)
self.timeEdit.setFont(font)
self.timeEdit.setInputMethodHints(QtCore.Qt.ImhNone)
self.timeEdit.setDateTime(QtCore.QDateTime(QtCore.QDate(2000, 1, 1), QtCore.QTime(0, 0, 0)))
self.timeEdit.setCurrentSection(QtWidgets.QDateTimeEdit.HourSection)
self.timeEdit.setCalendarPopup(False)
self.timeEdit.setTimeSpec(QtCore.Qt.LocalTime)
#===================================================================#
sizePolicy.setHorizontalStretch(0)
sizePolicy.setVerticalStretch(0)
sizePolicy.setHeightForWidth(self.thumbnailModeCheckBox.sizePolicy().hasHeightForWidth())
#===================================================================#
self.thumbnailModeCheckBox.setSizePolicy(sizePolicy)
self.thumbnailModeCheckBox.setText("")
#===================================================================#
self.thumbnailModeLabel.setEnabled(True)
self.thumbnailModeLabel.setFont(font)
self.thumbnailModeLabel.setTextFormat(QtCore.Qt.RichText)
#===================================================================#
self.statusLabel.setGeometry(QtCore.QRect(430, 270, 351, 31))
self.statusLabel.setText("")
self.statusLabel.setWordWrap(True)
#===================================================================#
self.createBtn.setGeometry(QtCore.QRect(10, 260, 123, 61))
self.createBtn.setFont(font)
#===================================================================#
self.startSingleBtn.setGeometry(QtCore.QRect(140, 260, 131, 61))
self.startSingleBtn.setFont(font)
#===================================================================#
self.stopBtn.setGeometry(QtCore.QRect(280, 260, 131, 61))
self.stopBtn.setFont(font)
#===================================================================#
MainWindow.setCentralWidget(self.centralwidget)
self.retranslateUi(MainWindow)
self.tabWidget.setCurrentIndex(0)
QtCore.QMetaObject.connectSlotsByName(MainWindow)
# Connect functions to GUI inputs
self.listWidget.itemSelectionChanged.connect(self.setSelected)
self.listWidget.setAttribute(QtCore.Qt.WA_MacShowFocusRect, 0)
self.durationSlider.valueChanged.connect(self.editDurationLabel)
self.widthSlider.valueChanged.connect(self.editWidthLabel)
self.numOutputsSlider.valueChanged.connect(self.editnumOutputsLabel)
self.createBtn.clicked.connect(self.createMedia)
self.startSingleBtn.clicked.connect(self.createSelectedMedia)
self.bitRateSlider.valueChanged.connect(self.editBitrateLabel)
self.audioCheckBox.stateChanged.connect(self.editAudioCheckBox)
self.gifModeCheckBox.stateChanged.connect(self.enableGifMode)
self.targetFileSizeCheckBox.stateChanged.connect(self.editTargetFileSizeCheckBox)
self.fileSizeSlider.valueChanged.connect(self.editTargetFileSizeSliderLabel)
self.startTimeCheckBox.stateChanged.connect(self.singleMode)
self.thumbnailModeCheckBox.stateChanged.connect(self.thumbnailMode)
self.wadsworthCheckBox.stateChanged.connect(self.enableWadsworth)
self.timeEdit.timeChanged.connect(self.singleMode)
self.stopBtn.clicked.connect(self.stopProcess)
self.thumbnailDropdown.currentIndexChanged.connect(self.editThumbnailMode)
# Set a few default values
self.videos_array = createVideoList() # Gets videos in current folder
self.stopped = False # Check if user has interrupted the program
self.outputDuration = 10 # Check length of WEBM/GIF
self.numOutputs = 5 # Check number of outputs
self.wadsworthConstant = True # Check if we're skipping first 30% of the video
self.time_array = [0, 0, 0] # Used for calculating a custom start time in single mode
self.customStartTime = 0 # Calculated from time_array, inits to 0
self.single_mode = False # Check if user wants a single webm at specific time
self.thumbnailNumTilesSide = 2 # Used to calculate total number of tiles in NxN grid
self.output_type = 'WEBM' # Check what kind of output, WEBM or GIF, user wants
self.thumbnailMode = False # Used to check if we're making a big N by N thumbnail
self.targetSizeSet = False # Check if user has enabled a target file size
self.audioEnabled = True # Used to check if user wants audio in WEBM or not
self.bitrate = 1500 # Helps specify what bitrate user needs for WEBM
self.selectedVideo = "" # Used to save selected video from list widget
self.output_to_subdir = False # sets if output is to be to a sub folder or not
self.output_dir_name = 'output' # Destination sub directory
# Set defaults for GUI slider positions, checkboxes, and labels
self.durationSlider.setSliderPosition(10)
self.widthSlider.setSliderPosition(500)
self.numOutputsSlider.setSliderPosition(5)
self.bitRateSlider.setSliderPosition(1500)
self.fileSizeSlider.setSliderPosition(4000)
self.wadsworthCheckBox.setChecked(True)
self.editTargetFileSizeCheckBox()
self.populateListLabel()
self.editDurationLabel()
self.editWidthLabel()
self.editnumOutputsLabel()
self.editBitrateLabel()
self.editTargetFileSizeSliderLabel()
def retranslateUi(self, MainWindow):
_translate = QtCore.QCoreApplication.translate
MainWindow.setWindowTitle(_translate("MainWindow", "WEBMARIZER"))
#===================================================================#
self.durationLabel.setText(_translate("MainWindow",'''
<html>
<head/>
<body>
<p><span style=\" font-size:16pt;\">WEBM Duration: </span></p>
</body>
</html>
'''))
#===================================================================#
self.widthLabel.setText(_translate("MainWindow", '''
<html>
<head/>
<body>
<p><span style=\" font-size:16pt;\">WEBM Width:</span></p>
</body>
</html>