-
Notifications
You must be signed in to change notification settings - Fork 1
/
Copy pathvid_process.py
256 lines (208 loc) · 10.8 KB
/
vid_process.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
# h3avren
"""
This file contains all the code for the video processing part of the application
"""
import os
import tkinter as tk
from tkinter import messagebox
from tkinter import filedialog
from tkinter import ttk
import time
from moviepy.editor import VideoFileClip,concatenate_videoclips
from interfaces import CFrame, StandardWindow
# a class to implement the functionality to mute for extract audio
class Mute(CFrame):
def __init__(self,parent,controller):
CFrame.__init__(self,parent,controller)
self.label = tk.Label(self,text = '---Empty Selection---',
padx = 10,pady = 5,bg = '#ee3456')
self.label.grid(row = 0,column = 0,padx = 10,pady = 10)
self.add = tk.Button(self,text = 'Select File',command = self.browse,
bg = '#2abc8d',relief = 'flat',activebackground = '#aabc8d',width = 10)
self.add.grid(row = 0, column = 1,padx = 10,pady = 10)
self.mute = tk.Button(self,text= 'Mute',
command = lambda: self.run_thread(self.mute_file),
bg = '#2abc8d',relief = 'flat',activebackground = '#aabc8d',width = 10)
self.mute.grid(row = 1,columnspan = 2,padx = 10,pady = 20)
self.status = tk.Label(self,text = 'No process..!',
width = 20,pady = 5,bg = '#ae34d9',fg = 'White',relief = 'sunken')
self.status.grid(row = 2,column = 0,padx = 10,pady = 15)
self.queue = tk.Label(self,text = 'Queued : 0',
width = 10,pady = 5,bg = '#ae34d9',fg = 'White',relief = 'sunken')
self.queue.grid(row = 2,column = 1,padx = 10,pady = 15)
def run_thread(self,target_func):
CFrame.run_thread(self,target_func)
if(self.thread >= 2):
self.mute.config(state = tk.DISABLED)
def mute_file(self):
if(self.filename):
save_as = filedialog.asksaveasfilename(defaultextension = f'.mp4',
filetypes = ((f'.mp4 files',f'*.mp4'),))
if(save_as):
try:
self.status.config(text = 'Processing...',bg = '#2a8d12')
self.queue.config(text = f'Queued : {self.thread}',bg = '#2a8d12')
clip = VideoFileClip(self.filename)
self.filename = ''
self.label.config(text = '---Empty Selection---')
clip.write_videofile(self.filename,audio = False)
self.status.config(text = 'Success..!',bg = '#2a8d12')
except:
self.status.config(text = 'Failed..!',bg = '#ee3456')
else:
messagebox.showerror(title = 'File Error',message = 'Select a File First..!')
self.thread -= 1
if(self.thread < 2):
self.mute.config(state = tk.NORMAL)
self.queue.config(text = f'Queued : {self.thread}')
if(self.thread == 0):
time.sleep(1)
self.queue.config(bg = '#ae34d9')
self.status.config(text = 'No Process..!',bg = '#ae34d9')
class Extract(CFrame):
def __init__(self,parent,controller):
CFrame.__init__(self,parent,controller)
self.label = tk.Label(self,text = '---Empty Selection---',
padx = 10,pady = 5,bg = '#ee3456')
self.label.grid(row = 0,column = 0,padx = 10,pady = 10)
self.add = tk.Button(self,text = 'Select File',command = self.browse,
bg = '#2abc8d',relief = 'flat',activebackground = '#aabc8d',width = 10)
self.add.grid(row = 0, column = 1,padx = 10)
self.export_as = ttk.Combobox(self,
values = ('mp3','flv','ogg','wav','wma','avi'),state = 'readonly')
self.export_as.grid(row = 1, column = 0,padx = 10,pady = 20)
self.export_as.current(0)
self.extract = tk.Button(self,text= 'Extract',
command = lambda: self.run_thread(self.extract_file),
bg = '#2abc8d',relief = 'flat',activebackground = '#aabc8d',width = 10)
self.extract.grid(row = 1,column = 1,padx = 10,pady = 20)
self.status = tk.Label(self,text = 'No process..!',
width = 20,pady = 5,bg = '#ae34d9',fg = 'White',relief = 'sunken')
self.status.grid(row = 2,column = 0,padx = 10,pady = 15)
self.queue = tk.Label(self,text = 'Queued : 0',
width = 10,pady = 5,bg = '#ae34d9',fg = 'White',relief = 'sunken')
self.queue.grid(row = 2,column = 1,padx = 10,pady = 15)
def run_thread(self,target_func):
CFrame.run_thread(self,target_func)
if(self.thread >= 2):
self.extract.config(state = tk.DISABLED)
def extract_file(self):
if(self.filename):
ext = self.export_as.get()
save_as = filedialog.asksaveasfilename(defaultextension = f'.{ext}',
filetypes = ((f'.{ext} files',f'*.{ext}'),))
if(save_as):
self.status.config(text = 'Processing...',bg = '#2a8d12')
self.queue.config(text = f'Queued : {self.thread}',bg = '#2a8d12')
try:
clip = VideoFileClip(self.filename)
self.filename = ''
self.label.config(text = '---Empty Selection---')
clip.audio.write_audiofile(save_as)
self.status.config(text = 'Success..!',bg = '#2a8d12')
except:
self.status.config(text = 'Failed..!',bg = '#ee3456')
else:
messagebox.showerror(title = 'File Error',message = 'Select a File First..!')
self.thread -= 1
if(self.thread < 2):
self.extract.config(state = tk.NORMAL)
self.queue.config(text = f'Queued : {self.thread}')
if(self.thread == 0):
time.sleep(1)
self.queue.config(bg = '#ae34d9')
self.status.config(text = 'No Process..!',bg = '#ae34d9')
# a class to implement the join of two video files
class JoinVideo(CFrame):
def __init__(self,parent,controller):
CFrame.__init__(self,parent,controller)
self.filename_1,self.filename_2 = None,None
self.filelabel_1 = tk.Label(self,text = '---Empty Selection---',
padx = 10,pady = 5,bg = '#ee3456')
self.filelabel_1.grid(row = 0,column = 0,padx = 10,pady = 10)
self.add_1 = tk.Button(self,text = 'Select File',command = lambda: self.browse(1),
bg = '#2abc8d',relief = 'flat',activebackground = '#aabc8d',width = 10)
self.add_1.grid(row = 0, column = 1,padx = 10)
self.filelabel_2 = tk.Label(self,text = '---Empty Selection---',
padx = 10,pady = 5,bg = '#ee3456')
self.filelabel_2.grid(row = 1,column = 0,padx = 10,pady = 10)
self.add_2 = tk.Button(self,text = 'Select File',command = lambda: self.browse(2),
bg = '#2abc8d',relief = 'flat',activebackground = '#aabc8d',width = 10)
self.add_2.grid(row = 1, column = 1,padx = 10)
self.join = tk.Button(self,text= 'Join',
command = lambda: self.run_thread(self.join_file),
bg = '#2abc8d',relief = 'flat',activebackground = '#aabc8d',width = 10)
self.join.grid(row = 2,columnspan = 2,padx = 20)
self.status = tk.Label(self,text = 'No process..!',
width = 20,pady = 5,bg = '#ae34d9',fg = 'White',relief = 'sunken')
self.status.grid(row = 3,column = 0,padx = 10,pady = 10)
self.queue = tk.Label(self,text = 'Queued : 0',
width = 10,pady = 5,bg = '#ae34d9',fg = 'White',relief = 'sunken')
self.queue.grid(row = 3,column = 1,padx = 10,pady = 10)
def run_thread(self,target_func):
CFrame.run_thread(self,target_func)
if(self.thread >= 2):
self.join.config(state = tk.DISABLED)
def browse(self,num):
CFrame.browse(self,0)
if(num == 1):
self.filename_1 = self.filename
if(self.filename_1):
self.filelabel_1.config(text = os.path.split(self.filename_1)[1])
if(num == 2):
self.filename_2 = self.filename
if(self.filename_2):
self.filelabel_2.config(text = os.path.split(self.filename_1)[1])
def join_file(self):
if(self.filename_1 and self.filename_2):
save_as = filedialog.asksaveasfilename(defaultextension = '.mp4',filetypes = (('.mp4 files','*.mp4'),))
if(save_as):
try:
self.status.config(text = 'Processing...',bg = '#2a8d12')
self.queue.config(text = f'Queued : {self.thread}',bg = '#2a8d12')
clip_1 = VideoFileClip(self.filename_1)
self.filename_1 = ''
self.filelabel_1.config(text = '---Empty Selection---')
clip_2 = VideoFileClip(self.filename_2)
self.filename_2 = ''
self.filelabel_2.config(text = '---Empty Selection---')
final_clip = concatenate_videoclips([clip_1,clip_2])
final_clip.write_videofile(save_as,threads = 4,progress_bar = False)
self.status.config(text = 'Success..!',bg = '#2a8d12')
except:
self.filelabel_1.config(text = '---Empty Selection---')
self.filelabel_2.config(text = '---Empty Selection---')
self.status.config(text = 'Failed..!',bg = '#ee3456')
else:
messagebox.showerror(title = 'Error',message = 'Provide a file name to save the output')
else:
messagebox.showerror(title = 'Error..!',message = 'Select the files to join..!')
self.thread -= 1
if(self.thread < 2):
self.join.config(state = tk.NORMAL)
self.queue.config(text = f'Queued : {self.thread}')
if(self.thread == 0):
time.sleep(1)
self.queue.config(bg = '#ae34d9')
self.status.config(text = 'No Process..!',bg = '#ae34d9')
# this class implements the video tools window
class VideoEditor(StandardWindow):
def __init__(self,parent,controller):
StandardWindow.__init__(self,parent,controller)
mute = tk.Button(self,text = 'Mute',bg = '#2abc8d',
activebackground = '#aabc8d',relief = 'flat',width = 5,
command = lambda: self.show_frame('Mute','Video Tools','Mute'))
mute.place(x = 30,y = 30)
extract = tk.Button(self,text = 'Extract',bg = '#2abc8d',
activebackground = '#aabc8d',relief = 'flat',width = 5,
command = lambda: self.show_frame('Extract','Video Tools','Extract'))
extract.place(x = 130,y = 30)
join_video = tk.Button(self,text = 'Join',bg = '#2abc8d',
activebackground = '#aabc8d',relief = 'flat',width = 5,
command = lambda: self.show_frame('JoinVideo','Video Tools','Join'))
join_video.place(x = 230,y = 30)
for f in (Extract,JoinVideo,Mute):
page_name = f.__name__
frame = f(parent = self.container,controller = self)
self.frames[page_name] = frame
frame.grid(row = 0,column = 0,sticky = 'nesw')