forked from Eanya-Tonic/MahiroToolbox
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathCommonInterface.py
More file actions
268 lines (226 loc) · 10.4 KB
/
CommonInterface.py
File metadata and controls
268 lines (226 loc) · 10.4 KB
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
# coding:utf-8
from PyQt5.QtCore import Qt, pyqtSignal
from PyQt5.QtGui import QPixmap, QPainter, QColor
from PyQt5.QtWidgets import QWidget,QFileDialog
from qfluentwidgets import InfoBarIcon, InfoBar, PushButton, setTheme, Theme, FluentIcon, InfoBarPosition, InfoBarManager
from functools import partial
import os
from threading import Thread
from UI.Ui_common import Ui_Common
class CommonInterface(QWidget, Ui_Common):
def __init__(self, parent=None):
super().__init__(parent)
self.setupUi(self)
# 音频参数
self.BitrateNum.setValue(128)
self.FpsNum.setValue(24)
self.CrfNum.setValue(24)
# 硬件加速
self.HardAccler.addItem("软解")
self.HardAccler.addItem("Nvidia")
self.HardAccler.addItem("AMD")
self.HardAccler.addItem("Intel")
# 隐藏ProgressBar
self.ProgressBar1.setVisible(0)
self.ProgressBar2.setVisible(0)
self.ProgressBar3.setVisible(0)
# 截取视频
self.StartTimeLine.setText('00:00:00')
self.EndTimeLine.setText('00:00:20')
# 旋转视频
self.OptionChoice.addItem('顺时针90度')
self.OptionChoice.addItem('逆时针90度')
self.OptionChoice.addItem('180度')
self.OptionChoice.addItem('水平翻转')
self.OptionChoice.addItem('垂直翻转')
# 操作开始按钮
self.ProcessStartButton.clicked.connect(self.ProcessFunc)
self.ProcessStartButton.setWindowIconText("")
self.ProcessStartButton.windowIconTextChanged.connect(
self.ProcessComplte)
self.ClipVideoButton.clicked.connect(self.ClipFunc)
self.ClipVideoButton.setWindowIconText("")
self.ClipVideoButton.windowIconTextChanged.connect(self.ClipComplte)
self.TransposeButton.clicked.connect(self.TransposeFunc)
self.TransposeButton.setWindowIconText("")
self.TransposeButton.windowIconTextChanged.connect(
self.TransposeComplte)
# 文件选择
self.InputButton.clicked.connect(
partial(self.FileSelect, self.InputLine, 0, 0))
self.AudioInputButton.clicked.connect(
partial(self.FileSelect, self.AudioInputLine, self.VideoOutputLine_2, 1))
self.VideoOutputButton_2.clicked.connect(
partial(self.FileSelect, self.VideoOutputLine_2, 0, 0))
self.VideoInputButton.clicked.connect(
partial(self.FileSelect, self.VideoInputLine, self.VideoOutputLine, 2))
self.VideoOutputButton.clicked.connect(
partial(self.FileSelect, self.VideoOutputLine, 0, 0))
# 文件选择函数
def FileSelect(self, TargetLine, AutoFill, Type):
dir = QFileDialog()
dir.setDirectory(os.getcwd())
if dir.exec_(): # 判断是否选择了文件
FilePath = dir.selectedFiles()
TargetLine.setText(FilePath[0])
if AutoFill != 0:
FileExt = os.path.splitext(FilePath[0])[1]
FilePath = os.path.splitext(FilePath[0])[0]
if(Type == 1):
NewFilePath = FilePath + '_output.mp4'
elif(Type == 2):
NewFilePath = FilePath + '_output' + FileExt
AutoFill.setText(NewFilePath,)
# 一图流控制
def ProcessFunc(self):
# 地址缺失
if(self.InputLine.text() == '' or self.VideoOutputLine_2.text() == '' or self.AudioInputLine.text() == ''):
InfoBar.error(
title='未定义地址',
content="请确认你是否已经设定了正确的输入输出地址",
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.BOTTOM_RIGHT,
duration=6000,
parent=self
)
return
ProcessCmd = "tools\\ffmpeg -hide_banner -loop 1 "
# 硬件加速
if(self.HardAccler.currentIndex() == 0):
pass
elif(self.HardAccler.currentIndex() == 1):
ProcessCmd += "-hwaccel nvdec "
elif(self.HardAccler.currentIndex() == 2):
ProcessCmd += "-hwaccel amf "
elif(self.HardAccler.currentIndex() == 3):
ProcessCmd += "-hwaccel qsv "
ProcessCmd += "-i \"" + self.InputLine.text() + "\" " + "-i \"" + self.AudioInputLine.text() + "\" -y -shortest "
# 音频参数
ProcessCmd += "-c:a aac -b:a " + str(self.BitrateNum.value()) + "k "
# 视频参数
ProcessCmd += "-r " + str(self.FpsNum.value()) + \
" -crf " + str(self.CrfNum.value()) + " "
thread_01 = Thread(target=self.CmdThread01,
args=(ProcessCmd,))
thread_01.start()
# 多线程编码函数01
def CmdThread01(self, ProcessCmd):
self.ProgressBar1.setVisible(1)
self.ProcessStartButton.setText("正在压制...")
self.ProcessStartButton.setWindowIconText(" ")
self.ProcessStartButton.setDisabled(1)
ProcessCmd += " \"" + self.VideoOutputLine_2.text() + "\""
os.system(ProcessCmd)
self.ProgressBar1.setVisible(0)
self.ProcessStartButton.setText("开始压制")
self.ProcessStartButton.setDisabled(0)
self.ProcessStartButton.setWindowIconText("")
# 压制完成提示
def ProcessComplte(self):
if(self.ProcessStartButton.text() == "开始压制"):
InfoBar.success(
title='任务执行完成',
content="请确认是否压制成功",
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.BOTTOM_RIGHT,
duration=6000,
parent=self
)
# 视频截取控制
def ClipFunc(self):
# 地址缺失
if(self.VideoInputLine.text() == '' or self.VideoOutputLine.text() == ''):
InfoBar.error(
title='未定义地址',
content="请确认你是否已经设定了正确的输入输出地址",
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.BOTTOM_RIGHT,
duration=6000,
parent=self
)
return
ProcessCmd = "tools\\ffmpeg -hide_banner -i \"" + self.VideoInputLine.text() + "\" -y -ss " + self.StartTimeLine.text() + " -to " + self.EndTimeLine.text() + " -c copy \"" + self.VideoOutputLine.text() + "\""
thread_02 = Thread(target=self.CmdThread02,
args=(ProcessCmd,))
thread_02.start()
# 多线程编码函数02
def CmdThread02(self,ProcessCmd):
self.ProgressBar2.setVisible(1)
self.ClipVideoButton.setText("正在截取...")
self.ClipVideoButton.setWindowIconText(" ")
self.ClipVideoButton.setDisabled(1)
self.TransposeButton.setDisabled(1)
os.system(ProcessCmd)
self.ProgressBar2.setVisible(0)
self.ClipVideoButton.setText("开始截取")
self.ClipVideoButton.setDisabled(0)
self.TransposeButton.setDisabled(0)
self.ClipVideoButton.setWindowIconText("")
# 截取完成提示
def ClipComplte(self):
if(self.ClipVideoButton.text() == "开始截取"):
InfoBar.success(
title='任务执行完成',
content="请确认是否截取成功",
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.BOTTOM_RIGHT,
duration=6000,
parent=self
)
# 视频旋转控制
def TransposeFunc(self):
# 地址缺失
if(self.VideoInputLine.text() == '' or self.VideoOutputLine.text() == ''):
InfoBar.error(
title='未定义地址',
content="请确认你是否已经设定了正确的输入输出地址",
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.BOTTOM_RIGHT,
duration=6000,
parent=self
)
return
# 旋转参数
if(self.OptionChoice.currentIndex() == 0):
ProcessCmd = "tools\\ffmpeg -hide_banner -i \"" + self.VideoInputLine.text() + "\" -y -vf \"transpose=1\" \"" + self.VideoOutputLine.text() + "\""
elif(self.OptionChoice.currentIndex() == 1):
ProcessCmd = "tools\\ffmpeg -hide_banner -i \"" + self.VideoInputLine.text() + "\" -y -vf \"transpose=2\" \"" + self.VideoOutputLine.text() + "\""
elif(self.OptionChoice.currentIndex() == 2):
ProcessCmd = "tools\\ffmpeg -hide_banner -i \"" + self.VideoInputLine.text() + "\" -y -vf \"transpose=2,transpose=2\" \"" + self.VideoOutputLine.text() + "\""
elif(self.OptionChoice.currentIndex() == 3):
ProcessCmd = "tools\\ffmpeg -hide_banner -i \"" + self.VideoInputLine.text() + "\" -y -vf \"hflip\" \"" + self.VideoOutputLine.text() + "\""
elif(self.OptionChoice.currentIndex() == 4):
ProcessCmd = "tools\\ffmpeg -hide_banner -i \"" + self.VideoInputLine.text() + "\" -y -vf \"vflip\" \"" + self.VideoOutputLine.text() + "\""
thread_03 = Thread(target=self.CmdThread03,
args=(ProcessCmd, ))
thread_03.start()
# 多线程编码函数03
def CmdThread03(self, ProcessCmd):
self.ProgressBar3.setVisible(1)
self.TransposeButton.setText("正在旋转...")
self.TransposeButton.setWindowIconText(" ")
self.TransposeButton.setDisabled(1)
self.ClipVideoButton.setDisabled(1)
os.system(ProcessCmd)
self.ProgressBar3.setVisible(0)
self.TransposeButton.setText("开始旋转")
self.TransposeButton.setDisabled(0)
self.ClipVideoButton.setDisabled(0)
self.TransposeButton.setWindowIconText("")
# 旋转完成提示
def TransposeComplte(self):
if(self.TransposeButton.text() == "开始旋转"):
InfoBar.success(
title='任务执行完成',
content="请确认是否旋转成功",
orient=Qt.Horizontal,
isClosable=True,
position=InfoBarPosition.BOTTOM_RIGHT,
duration=6000,
parent=self
)