Skip to content

Commit 3de4bfa

Browse files
author
arch
committed
add parameter to limit the plaback speed
1 parent c72aadd commit 3de4bfa

File tree

1 file changed

+12
-0
lines changed

1 file changed

+12
-0
lines changed

funscript_editor/algorithms/funscriptgenerator.py

Lines changed: 12 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -2,6 +2,7 @@
22

33
import cv2
44
import json
5+
import time
56
import logging
67

78
from threading import Thread
@@ -409,10 +410,16 @@ def tracking(self) -> str:
409410
trackerMen = StaticVideoTracker(first_frame, bboxMen)
410411
self.bboxes['Men'].append(bboxMen)
411412

413+
if self.params.max_playback_fps > 2:
414+
cycle_time_in_ms = (float(1000) / float(self.params.max_playback_fps)) * (self.params.skip_frames+1)
415+
else:
416+
cycle_time_in_ms = 0
417+
412418
status = "End of video reached"
413419
self.clear_keypress_queue()
414420
last_frame, frame_num = None, 1 # first frame is was init frame
415421
while video.isOpen():
422+
cycle_start = time.time()
416423
frame = video.read()
417424
frame_num += 1
418425

@@ -463,6 +470,11 @@ def tracking(self) -> str:
463470

464471
last_frame = frame
465472

473+
if cycle_time_in_ms > 0:
474+
wait = cycle_time_in_ms - (time.time() - cycle_start)*float(1000)
475+
if wait > 0: time.sleep(wait/float(1000))
476+
477+
466478
video.stop()
467479
self.__logger.info(status)
468480
return status

0 commit comments

Comments
 (0)