-
Notifications
You must be signed in to change notification settings - Fork 0
/
gooey.py
152 lines (105 loc) · 4.3 KB
/
gooey.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
from tkinter import *
from tkinter import messagebox
from tkinter import filedialog
import PIL.Image, PIL.ImageTk
import cv2, cv
from pathlib import Path
from ffpyplayer.player import MediaPlayer
class videoGUI:
def __init__(self, window, window_title):
self.window = window
self.window.title(window_title)
top_frame = Frame(self.window)
top_frame.pack(side=TOP, pady=5)
bottom_frame = Frame(self.window)
bottom_frame.pack(side=BOTTOM, pady=5)
self.pause = False # Parameter that controls pause button
self.play = False
self.canvas = Canvas(top_frame)
self.canvas.pack()
# Select Button
self.btn_select = Button(bottom_frame, text="aed", width=12, command=self.open_file0)
self.btn_select.grid(row=0, column=0)
self.btn_select = Button(bottom_frame, text="ems", width=12, command=self.open_file1)
self.btn_select.grid(row=0, column=1)
self.btn_select = Button(bottom_frame, text="drone", width=12, command=self.open_file2)
self.btn_select.grid(row=0, column=2)
# Play Button
self.btn_play = Button(bottom_frame, text="Play", width=12, command=self.play_video)
self.btn_play.grid(row=0, column=3)
# Pause Button
self.btn_pause = Button(bottom_frame, text="Pause", width=12, command=self.pause_video)
self.btn_pause.grid(row=0, column=4)
self.delay = 3 # ms
self.window.mainloop()
def open_file0(self):
self.pause = False
self.filename = str(Path().absolute()) + '/aed.mp4'
print(self.filename)
# Open the video file
self.cap = cv2.VideoCapture(self.filename)
self.player = MediaPlayer(self.filename)
self.width = self.cap.get(cv2.CAP_PROP_FRAME_WIDTH)
self.height = self.cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
self.canvas.config(width=self.width, height=self.height)
def open_file1(self):
self.pause = False
self.filename = str(Path().absolute()) + '/ems.mp4'
print(self.filename)
# Open the video file
self.cap = cv2.VideoCapture(self.filename)
self.player = MediaPlayer(self.filename)
# self.width = self.cap.get(cv2.CAP_PROP_FRAME_WIDTH)
# self.height = self.cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
self.width = 1000
self.height = 500
self.canvas.config(width=self.width, height=self.height)
def open_file2(self):
self.pause = False
self.filename = str(Path().absolute()) + '/drone.mp4'
print(self.filename)
# Open the video file
self.cap = cv2.VideoCapture(self.filename)
self.player = MediaPlayer(self.filename)
# self.width = self.cap.get(cv2.CAP_PROP_FRAME_WIDTH)
# self.height = self.cap.get(cv2.CAP_PROP_FRAME_HEIGHT)
self.width = 1000
self.height = 500
self.canvas.config(width=self.width, height=self.height)
def getFrame(self): # get only one frame
try:
if self.cap.isOpened():
ret, frame = self.cap.read()
return (ret, cv2.cvtColor(frame, cv2.COLOR_BGR2RGB))
except:
messagebox.showerror(title='Video file not found', message='Please select a video file.')
def play_video(self):
# Get a frame from the video source, and go to the next frame automatically
audio_frame, val = self.player.get_frame()
ret, frame = self.getFrame()
self.play = True
if ret:
self.photo = PIL.ImageTk.PhotoImage(image=PIL.Image.fromarray(frame))
self.canvas.create_image(0, 0, image=self.photo, anchor=NW)
if not self.pause:
self.window.after(self.delay, self.play_video)
if self.pause == True:
self.pause = False
return
def pause_video(self):
if self.pause == False:
self.pause = True
else:
self.pause = False
self.play_video()
# Addition
def resume_video(self):
self.pause = False
self.play_video()
# Release the video source when the object is destroyed
def __del__(self):
if self.cap.isOpened():
self.cap.release()
##### End Class #####
# Create a window and pass it to videoGUI Class
videoGUI(Tk(), "aed")