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
from PyQt5.QtWidgets import QApplication, QWidget, QFileDialog
from PyQt5.QtCore import Qt, QUrl, QDir
from PyQt5.QtGui import QPalette
from PyQt5.uic import loadUi
from PyQt5 import uic
from media import CMultiMedia
from moviepy.video.io.ffmpeg_tools import ffmpeg_extract_subclip
import sys
import datetime
import cv2
import numpy as np
QApplication.setAttribute(Qt.AA_EnableHighDpiScaling, True)
class CWidget(QWidget):
def __init__(self):
super().__init__()
loadUi('mainPage.ui', self)
# Multimedia Object
self.mp = CMultiMedia(self, self.view)
# video background color
pal = QPalette()
pal.setColor(QPalette.Background, Qt.black)
self.view.setAutoFillBackground(True)
self.view.setPalette(pal)
# play time
self.duration = ''
# signal
self.btn_play.clicked.connect(self.clickPlay)
self.btn_stop.clicked.connect(self.clickStop)
self.btn_pause.clicked.connect(self.clickPause)
self.btn_tracking.clicked.connect(self.startTracking)
self.btn_back.clicked.connect(self.beforeCut)
self.btn_open.clicked.connect(self.openFile)
self.btn_quit.clicked.connect(self.exitCall)
self.btn_cut.clicked.connect(self.cutVideo)
self.bar.sliderMoved.connect(self.barChanged)
def openFile(self):
fName, _ = QFileDialog.getOpenFileName(self, "Open Full Cam", QDir.homePath())
if fName != '':
self.mp.openFile(fName)
self.route.setText(fName)
def exitCall(self):
sys.exit(app.exec_())
def beforeCut(self):
self.mp.back(self.route)
self.btn_back.setEnabled(False)
self.btn_tracking.setEnabled(False)
def cutVideo(self):
self.mp.cutVideo(self.route, self.startTime, self.endTime)
self.btn_back.setEnabled(True)
self.btn_tracking.setEnabled(True)
def clickPlay(self):
self.mp.playMedia()
def clickStop(self):
self.mp.stopMedia()
def clickPause(self):
self.mp.pauseMedia()
def barChanged(self, pos):
print(pos)
self.mp.posMoveMedia(pos)
def updateState(self, msg):
self.state.setText(msg)
def updateBar(self, duration):
self.bar.setRange(0, duration)
self.bar.setSingleStep(int(duration / 10))
self.bar.setPageStep(int(duration / 10))
self.bar.setTickInterval(int(duration / 10))
td = datetime.timedelta(milliseconds=duration)
stime = str(td)
idx = stime.rfind('.')
self.duration = stime[:idx]
def updatePos(self, pos):
self.bar.setValue(pos)
td = datetime.timedelta(milliseconds=pos)
stime = str(td)
idx = stime.rfind('.')
stime = f'{stime[:idx]} / {self.duration}'
self.playtime.setText(stime)
def startTracking(self):
self.mp.startTracking(self.route)
if __name__ == '__main__':
app = QApplication(sys.argv)
w = CWidget()
w.resize(1280, 720)
w.show()
sys.exit(app.exec_())