clips_at_regular_timestamps¶
- torchcodec.samplers.clips_at_regular_timestamps(decoder, *, seconds_between_clip_starts: float, num_frames_per_clip: int = 1, seconds_between_frames: Optional[float] = None, sampling_range_start: Optional[float] = None, sampling_range_end: Optional[float] = None, policy: Literal['repeat_last', 'wrap', 'error'] = 'repeat_last') FrameBatch [源码]¶
在规则(等间隔)时间戳处采样clips。
注意
为了与现有的采样 API(如 torchvision)保持一致,此采样器接受
seconds_between_clip_starts
参数而不是num_clips
。如果您发现支持num_clips
会很有用,请通过打开功能请求告诉我们。- 参数:
decoder (VideoDecoder) – 用于从中采样 clips 的
VideoDecoder
实例。seconds_between_clip_starts (float) – 每个 clip 开始之间的间隔(以秒为单位)。
num_frames_per_clip (int, 可选) – 每个 clip 的帧数。默认为:1。
seconds_between_frames (float 或 None, 可选) – clip 中每帧之间的时间(以秒为单位)。更准确地说,这定义了*帧采样点*之间的时间,即我们采样帧的时间戳。由于帧跨越时间间隔,因此 clip 中帧的实际开始时间可能不精确地间隔
seconds_between_frames
- 但平均而言,它们会是。默认为 None,设置为平均帧持续时间(1/average_fps
)。sampling_range_start (float 或 None, 可选) – 采样范围的开始,定义了 clip 可能*开始*的第一个时间戳(以秒为单位)。默认值:None,对应于视频的开始。(注意:有些视频以负值开始,因此默认值不是 0)。
sampling_range_end (float 或 None, 可选) – 采样范围的结束,定义了 clip 可能*开始*的最后一个时间戳(以秒为单位)。此值是排他的,即 clip 只能在 [
sampling_range_start
,sampling_range_end
) 中开始。如果为 None(默认),则自动设置该值,以确保 clips 永远不会超出视频的结尾,即设置为end_video_seconds - (num_frames_per_clip - 1) * seconds_between_frames
。当 clip 超出视频结尾时,policy
参数定义了如何构造此类 clip。policy (str, 可选) –
定义如何构造超出视频结尾的 clips。最好通过示例来描述:假设视频中最后一个可行的(可跳转的)时间戳为 10.9,并且一个 clip 被采样为从时间戳 10.5 开始,
num_frames_per_clip=5
和seconds_between_frames=0.2
,那么 clip 中帧的采样时间戳应为 [10.5, 10.7, 10.9, 11.1, 11.2]。但是 11.1 和 11.2 是无效的时间戳,因此policy
参数定义了如何用有效采样时间戳替换这些帧。”repeat_last”:重复 clip 的最后一帧。我们将获得采样时间戳为 [10.5, 10.7, 10.9, 10.9, 10.9] 的帧。
”wrap”:循环到 clip 的开头。我们将获得采样时间戳为 [10.5, 10.7, 10.9, 10.5, 10.7] 的帧。
“error”:引发错误。
默认为“repeat_last”。请注意,当
sampling_range_end
=None(默认)时,此 policy 参数不太可能相关。
- 返回:
采样到的 clips,作为 5D
FrameBatch
。data
字段的形状为(num_clips
,num_frames_per_clips
, ...),其中 ... 为(H, W, C)或(C, H, W),具体取决于VideoDecoder
的dimension_order
参数。pts_seconds
和duration_seconds
字段的形状为(num_clips
,num_frames_per_clips
)。- 返回类型:
clips_at_regular_timestamps
的用法示例