Skip to content

Commit facf608

Browse files
author
arch
committed
add time to tracking window
1 parent df9d495 commit facf608

File tree

2 files changed

+36
-1
lines changed

2 files changed

+36
-1
lines changed

funscript_editor/algorithms/funscriptgenerator.py

Lines changed: 34 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -143,6 +143,39 @@ def drawFPS(self, img: np.ndarray) -> np.ndarray:
143143
return annotated_img
144144

145145

146+
def drawTime(self, img: np.ndarray, frame_num: int) -> np.ndarray:
147+
""" Draw Time on the image/frame
148+
149+
Args:
150+
img (np.ndarray): opencv image
151+
img (int): current absolute frame number
152+
153+
Returns:
154+
np.ndarray: opencv image with Time Text
155+
"""
156+
annotated_img = img.copy()
157+
current_timestamp = FFmpegStream.millisec_to_timestamp(
158+
self.frame_to_millisec(frame_num, self.video_info.fps)
159+
)
160+
current_timestamp = ''.join(current_timestamp[:-4])
161+
162+
if self.params.end_frame < 1:
163+
end_timestamp = FFmpegStream.millisec_to_timestamp(
164+
self.frame_to_millisec(self.video_info.length, self.video_info.fps)
165+
)
166+
end_timestamp = ''.join(end_timestamp[:-4])
167+
else:
168+
end_timestamp = FFmpegStream.millisec_to_timestamp(
169+
self.frame_to_millisec(self.params.end_frame, self.video_info.fps)
170+
)
171+
end_timestamp = ''.join(end_timestamp[:-4])
172+
173+
txt = current_timestamp + ' / ' + end_timestamp
174+
cv2.putText(annotated_img, txt, (max(( 0, img.shape[1] - self.x_text_start - round(len(txt)*17*self.font_size) )), 50),
175+
cv2.FONT_HERSHEY_SIMPLEX, self.font_size, (0,0,255), 2)
176+
return annotated_img
177+
178+
146179
def drawText(self, img: np.ndarray, txt: str, y :int = 50, color :tuple = (0,0,255)) -> np.ndarray:
147180
""" Draw text to an image/frame
148181
@@ -619,6 +652,7 @@ def tracking(self) -> str:
619652
last_frame = self.drawFPS(last_frame)
620653
cv2.putText(last_frame, "Press 'q' if the tracking point shifts or a video cut occured",
621654
(self.x_text_start, 75), cv2.FONT_HERSHEY_SIMPLEX, self.font_size, (255,0,0), 2)
655+
last_frame = self.drawTime(last_frame, frame_num + self.params.start_frame)
622656
cv2.imshow(self.window_name, self.preview_scaling(last_frame))
623657

624658
if self.was_key_pressed('q') or cv2.waitKey(1) == ord('q'):

funscript_editor/data/ffmpegstream.py

Lines changed: 2 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -175,7 +175,8 @@ def frame_to_millisec(self, frame_number) -> int:
175175
return int(round(float(frame_number)*float(1000)/self.video_info.fps))
176176

177177

178-
def millisec_to_timestamp(self, millis :int)->str:
178+
@staticmethod
179+
def millisec_to_timestamp(millis :int)->str:
179180
""" Convert milliseconds to timestamp
180181
181182
Args:

0 commit comments

Comments
 (0)