-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathvideo2gif_GUI.py
145 lines (107 loc) · 4.43 KB
/
video2gif_GUI.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
""" To make the exe file, Enter the command:
`pyinstaller -w -F video2gif_GUI.py`
"""
# https://wikidocs.net/21928
from cProfile import label
import sys
import numpy as np
from PyQt5.QtWidgets import *
from PyQt5.QtCore import *
from PyQt5.QtGui import *
from moviepy.editor import *
import argparse
import subprocess
class MyApp(QMainWindow):
def __init__(self):
super().__init__()
self.initUI()
def initUI(self):
# Geometry
self.setWindowTitle('Video2GIF')
self.resize(400, 200)
self.center()
# self.bFileName = False
# Load data button
self.pushButton = QPushButton('Open File', self)
self.pushButton.move(290, 35)
self.pushButton.clicked.connect(self.pushButtonClicked)
# statusbar (status bar)
self.statusbar = QStatusBar(self) # QStatusBar 객체 생성
self.setStatusBar(self.statusbar) # 위젯 배치
self.statusbar.showMessage("READY")
# Label
self.label = QLabel(
" "*75, self)
self.label.setStyleSheet(
"border: 1px;" "border-color: #727272;" "border-style: solid;" "background-color: white;")
self.label.adjustSize()
self.label.move(10, 40)
self.labels = []
# Label (Loading icon)
#self.loadingLabel = QLabel("For Loading")
# adding label to status bar
# self.statusBar().addPermanentWidget(self.loadingLabel)
def center(self):
qr = self.frameGeometry()
cp = QDesktopWidget().availableGeometry().center()
qr.moveCenter(cp)
self.move(qr.topLeft())
def startAnimation(self):
self.movie.start()
def stopAnimation(self):
self.movie.stop()
def pushButtonClicked(self):
self.fileNames = QFileDialog.getOpenFileNames(
self, "open file", "./",
"mp4 file(*.mp4) ;; avi file(*.avi) ;; mov file(*.mov) ;; wmv file (*.wmv) ;; mpeg-ps file (*.mpeg) ;; mkv file (*.mkv)")
if self.fileNames[0]:
files = self.fileNames[0]
for i in range(len(files)):
label = QLabel(
" "*75, self)
label.setStyleSheet(
"border: 1px;" "border-color: #727272;" "border-style: solid;" "background-color: white;")
label.adjustSize()
label.move(10, 40 * i)
self.labels.append(label)
self.labels[i].setText(
files[i]) # Show file location
self.statusbar.showMessage("Converting...") # Show status label
QApplication.processEvents()
# To show the loading icon
#self.movie = QMovie("./assets/loader.gif")
# self.loadingLabel.setMovie(self.movie)
# self.startAnimation()
QApplication.processEvents()
for i, file in enumerate(files):
outputName = file.replace(file[file.find('.'):], '')
outputName = outputName + '.gif'
QApplication.processEvents()
clip = VideoFileClip(file)
# # Want to know video's number of frame
# frames = int(clip.fps * clip.duration)
# print(frames)
QApplication.processEvents()
resized_clip = clip.resize(0.3)
if i+1 == len(files):
self.statusbar.setStyleSheet("color: red;")
self.statusbar.showMessage("Done!")
QApplication.processEvents()
else:
self.statusbar.setStyleSheet("color: red;")
self.statusbar.showMessage("%d/%d Converted!" %(i+1, len(files)))
QApplication.processEvents()
resized_clip.write_gif(outputName, fps=40, fuzz=1, opt='nq', program='ffmpeg')
QApplication.processEvents()
subprocess.run(['gifsicle', '-O2', '--lossy=85', outputName, '-o', outputName])
QApplication.processEvents()
else:
self.label.setText("")
self.statusbar.setStyleSheet("color: blue;")
self.statusbar.showMessage("No file selected")
if __name__ == '__main__':
app = QApplication(sys.argv)
ex = MyApp()
# print(str(ex.label.isVisible()))
ex.show()
sys.exit(app.exec_())