-
Notifications
You must be signed in to change notification settings - Fork 0
/
main.py
145 lines (115 loc) · 4.87 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
#!/usr/bin/python3
import subprocess
import tkinter as tk
from os import path
from tkinter import messagebox as msg
from tkinter import ttk
global newpath
newpath = "{}\\".format(path.dirname(path.abspath(__file__)))
class Application(tk.Tk):
def __init__(self, parent):
tk.Tk.__init__(self, parent)
self.parent = parent
self.initialize()
def initialize(self):
self.grid()
# Values
resolution_values = ['1920x1080', '1280x720', '720x480']
bitrate_values = ['12000k', '5000k', '500k']
fps_values = ['60', '29.97', '23.976']
gop_values = ['50', '25', '15', '5']
# Variables
resolution = tk.StringVar()
bitrate = tk.StringVar()
fps = tk.StringVar()
gop = tk.StringVar()
pause = tk.IntVar()
# Objects
self.comboBox1 = ttk.Combobox(self, values=resolution_values,
textvariable=resolution,
width=15, height=20)
self.comboBox2 = ttk.Combobox(self, values=bitrate_values,
textvariable=bitrate,
width=15, height=20)
self.comboBox3 = ttk.Combobox(self, values=fps_values,
textvariable=fps,
width=15, height=20)
self.comboBox4 = ttk.Combobox(self, values=gop_values,
textvariable=gop,
width=15, height=20)
self.checkBox1 = tk.Checkbutton(self, text='Pause', variable=pause)
self.label1 = tk.Label(self, text='Resolution')
self.label2 = tk.Label(self, text='Bitrate')
self.label3 = tk.Label(self, text='FPS')
self.label4 = tk.Label(self, text='GOP')
# Position
self.comboBox1.grid(column=0, row=0, padx=10, pady=10)
self.comboBox2.grid(column=0, row=1, padx=10)
self.comboBox3.grid(column=0, row=2, padx=10, pady=10)
self.comboBox4.grid(column=0, row=3, padx=5)
self.checkBox1.grid(column=0, row=4, sticky='WE', padx=5, pady=12)
self.label1.grid(column=1, row=0, sticky='W')
self.label2.grid(column=1, row=1, sticky='W')
self.label3.grid(column=1, row=2, sticky='W')
self.label4.grid(column=1, row=3, sticky='W')
def on_click():
create_execute(resolution, bitrate, fps, gop)
def create_execute(resolution, bitrate, fps, gop):
commands = ['@set curpath=%~dp0', '@cd /d %curpath%', '@echo %curpath%', 'set \"cont=mp4\"',
'for %%i in (../in/*.*) do (']
# Read variables values
bitrate = bitrate.get()
resolution = resolution.get()
fps = fps.get()
gop = gop.get()
# Show error if bitrate is empty
if not bitrate:
msg.showwarning('Error!', 'Specify video bit rate.')
return
if not resolution:
pass
else:
resolution = " -s " + resolution + ""
if not fps:
pass
else:
fps = " -r " + fps + ""
if not gop:
pass
else:
gop = " -g " + gop + ""
commands.append(
"ffmpeg -i \"../in/%%i\" -vcodec h264" + resolution + "" +
fps + "" + gop + " -b " + bitrate + " -bt " + bitrate +
" -acodec mp3 -ar 44100 -ab 128k \"../out/%%~ni.%cont%\")")
if pause.get():
commands.append("pause")
commands.append("@del %0")
with open(newpath + 'Bin\\convert.bat', 'w',
encoding='utf-8') as myfile:
for item in commands:
myfile.write('%s\n' % item)
# Execute .bat file
subprocess.Popen("Bin\\convert.bat",
creationflags=subprocess.CREATE_NEW_CONSOLE)
# "Create and execute" button
self.button1 = tk.Button(self, text='Create and execute',
command=on_click)
self.button1.grid(column=1, row=4, pady=10, sticky='W')
if __name__ == '__main__':
app = Application(None)
app.title("pyCoder v1.0") # Title
app.resizable(False, False) # Disable resize
w = 250 # Width of the window
h = 180 # Height of the window
# Get the path to program and set the icon
app.iconbitmap(newpath + 'th06r.ico')
# Center screen
ws = app.winfo_screenwidth() # width of the screen
hs = app.winfo_screenheight() # height of the screen
# Calculates x and y coordinates for the main window
x = (ws / 2) - (w / 2)
y = (hs / 2) - (h / 2)
# App's size and start position on the screen
app.geometry('%dx%d+%d+%d' % (w, h, x, y))
app.mainloop()