Skip to content

Commit a973083

Browse files
committed
feat(pose_body): add duration_in_frames utility
1 parent 0a6f071 commit a973083

1 file changed

Lines changed: 32 additions & 0 deletions

File tree

src/python/pose_format/pose_body.py

Lines changed: 32 additions & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -630,6 +630,38 @@ def __str__(self):
630630
def __len__(self):
631631
return len(self.data)
632632

633+
def duration_in_frames(self, start_time: Optional[int] = None, end_time: Optional[int] = None) -> int:
634+
"""
635+
Returns the number of frames in the PoseBody based on start and end times.
636+
637+
Parameters
638+
----------
639+
start_time : int, optional
640+
Start time in milliseconds. Default is None.
641+
end_time : int, optional
642+
End time in milliseconds. Default is None.
643+
644+
Returns
645+
-------
646+
int
647+
Number of frames in the PoseBody between the specified start and end times.
648+
"""
649+
start_frame = 0
650+
if start_time is not None:
651+
start_frame = int(start_time / 1000 * self.fps)
652+
assert start_frame >= 0, ValueError(f"Start frame {start_frame} is less than 0")
653+
assert start_frame < len(self), f"Start frame {start_frame} is greater than the number of frames {len(self)}"
654+
655+
end_frame = len(self) - 1
656+
if end_time is not None:
657+
end_frame = int(end_time / 1000 * self.fps)
658+
assert end_frame >= 0, ValueError(f"End frame {end_frame} is less than 0")
659+
assert end_frame < len(self), f"End frame {end_frame} is greater than the number of frames {len(self)}"
660+
assert start_frame <= end_frame, ValueError(f"Start frame {start_frame} is greater than end frame {end_frame}")
661+
662+
return end_frame - start_frame + 1
663+
664+
633665

634666
class EmptyPoseBody(PoseBody):
635667
tensor_reader = 'unpack_empty_tensor' # This returns an empty tensor with the given shape

0 commit comments

Comments
 (0)