-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathmain.py
More file actions
56 lines (45 loc) · 1.26 KB
/
main.py
File metadata and controls
56 lines (45 loc) · 1.26 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
import videoManager as vm
import window as ww
import tkinter as tk
import io
import sys
import glfw
import time
class Main:
def __init__(self):
fileName = ""
if len(sys.argv) < 2:
fileName = "test.mp4"
# raise Exception ("Please enter the ")
else:
fileName = sys.argv[1]
if fileName:
self.currVideo = vm.VideoManager(fileName)
else:
sys.exit(0)
initFrame = self.currVideo.nextFrame()
print(initFrame.shape)
self.window = ww.Window(initFrame.shape[1], initFrame.shape[0], )
def runVideo(self):
fps = self.currVideo.meta["fps"]
prevTime = time.time()
# Admire this in its full 4 fps beauty
while not glfw.window_should_close(self.window.window):
currFrame = self.currVideo.nextFrame()[::-1]
if not len(currFrame):
glfw.terminate()
sys.exit(0)
img_byte_arr = currFrame.tobytes()
# currFrame.save(img_byte_arr, format='PNG')
# img_byte_arr = img_byte_arr.getvalue()
self.window.currFrame = img_byte_arr
self.window.renderScreen()
glfw.poll_events()
# Time-related stuff
# print (f"FPS: {1/(time.time()-prevTime)}; target: {fps}")
remainingTickTime = max(1/fps - (time.time() - prevTime), 0)
time.sleep(remainingTickTime)
prevTime = time.time()
glfw.terminate()
main = Main()
main.runVideo()