mirror of
https://github.com/jeertmans/manim-slides.git
synced 2025-08-06 14:19:52 +08:00
correct lag playback compensation
This commit is contained in:
@ -116,6 +116,8 @@ class Display:
|
|||||||
self.state = State.PLAYING
|
self.state = State.PLAYING
|
||||||
self.lastframe = None
|
self.lastframe = None
|
||||||
self.current_presentation_i = 0
|
self.current_presentation_i = 0
|
||||||
|
|
||||||
|
self.lag = 0
|
||||||
self.last_time = now()
|
self.last_time = now()
|
||||||
|
|
||||||
@property
|
@property
|
||||||
@ -141,6 +143,8 @@ class Display:
|
|||||||
self.handle_key()
|
self.handle_key()
|
||||||
|
|
||||||
def show_video(self):
|
def show_video(self):
|
||||||
|
self.lag = now() - self.last_time
|
||||||
|
self.last_time = now()
|
||||||
cv2.imshow("Video", self.lastframe)
|
cv2.imshow("Video", self.lastframe)
|
||||||
|
|
||||||
def show_info(self):
|
def show_info(self):
|
||||||
@ -186,9 +190,7 @@ class Display:
|
|||||||
|
|
||||||
def handle_key(self):
|
def handle_key(self):
|
||||||
sleep_time = math.ceil(1000/self.current_presentation.fps)
|
sleep_time = math.ceil(1000/self.current_presentation.fps)
|
||||||
lag = now() - self.last_time
|
key = cv2.waitKey(fix_time(sleep_time - self.lag)) & 0xFF
|
||||||
self.last_time = now()
|
|
||||||
key = cv2.waitKey(fix_time(sleep_time - lag)) & 0xFF
|
|
||||||
|
|
||||||
if key == Config.QUIT_KEY:
|
if key == Config.QUIT_KEY:
|
||||||
self.quit()
|
self.quit()
|
||||||
|
Reference in New Issue
Block a user