Fix timing issue
This commit is contained in:
parent
7e3ba9acd2
commit
ba4d2f7909
1 changed files with 8 additions and 8 deletions
|
@ -99,7 +99,7 @@ class FrameEmitter:
|
|||
logger.info(f"Play from '{str(video_path)}'")
|
||||
video = cv2.VideoCapture(str(video_path))
|
||||
fps = video.get(cv2.CAP_PROP_FPS)
|
||||
frame_duration = 1./fps
|
||||
target_frame_duration = 1./fps
|
||||
logger.info(f"Emit frames at {fps} fps")
|
||||
|
||||
prev_time = time.time()
|
||||
|
@ -126,13 +126,13 @@ class FrameEmitter:
|
|||
self.frame_sock.send(pickle.dumps(frame))
|
||||
|
||||
# defer next loop
|
||||
new_frame_time = time.time()
|
||||
time_diff = (new_frame_time - prev_time)
|
||||
if time_diff < frame_duration:
|
||||
time.sleep(frame_duration - time_diff)
|
||||
new_frame_time += frame_duration - time_diff
|
||||
else:
|
||||
prev_time = new_frame_time
|
||||
now = time.time()
|
||||
time_diff = (now - prev_time)
|
||||
if time_diff < target_frame_duration:
|
||||
time.sleep(target_frame_duration - time_diff)
|
||||
now += target_frame_duration - time_diff
|
||||
|
||||
prev_time = now
|
||||
|
||||
i += 1
|
||||
|
||||
|
|
Loading…
Reference in a new issue