Diffusers documentation

视频处理器

Hugging Face's logo
Join the Hugging Face community

and get access to the augmented documentation experience

to get started

视频处理器

VideoProcessor 为视频流水线提供了统一的 API,用于在 VAE 编码前准备输入,以及在解码后对输出进行后处理。该类继承自 VaeImageProcessor,因此包含调整大小、归一化以及 PIL Image、PyTorch 和 NumPy 数组之间的转换等变换操作。

VideoProcessor

diffusers.VideoProcessor.preprocess_video

< >

( videoheight: int | None = Nonewidth: int | None = None**kwargs ) → torch.Tensor of shape (batch_size, num_channels, num_frames, height, width)

参数

  • video (list[PIL.Image], list[list[PIL.Image]], torch.Tensor, np.array, list[torch.Tensor], list[np.array]) — 输入视频。可以是以下之一:
    • PIL 图像列表。
    • PIL 图像的列表的列表。
    • 4D Torch 张量(每个张量的预期形状为 (num_frames, num_channels, height, width))。
    • 4D NumPy 数组(每个数组的预期形状为 (num_frames, height, width, num_channels))。
    • 4D Torch 张量列表(每个张量的预期形状为 (num_frames, num_channels, height, width))。
    • 4D NumPy 数组列表(每个数组的预期形状为 (num_frames, height, width, num_channels))。
    • 5D NumPy 数组:每个数组的预期形状为 (batch_size, num_frames, height, width, num_channels)。
    • 5D Torch 张量:每个数组的预期形状为 (batch_size, num_frames, num_channels, height, width)。
  • height (int,可选,默认为 None) — 视频中预处理后帧的高度。如果为 None,将使用 get_default_height_width() 获取默认高度。
  • width (int, optional, defaults to None) -- The width in preprocessed frames of the video. If None, will use get_default_height_width() to get the default width.

返回值

形状为 (batch_size, num_channels, num_frames, height, width) 的 torch.Tensor

一个 5D 张量,保存了批量化的通道优先(channels-first)视频。

对输入视频进行预处理。关键字参数将转发至 VaeImageProcessor.preprocess。

diffusers.VideoProcessor.postprocess_video

< >

( video: Tensoroutput_type: str = 'np'**kwargs )

参数

  • video (torch.Tensor) — 以张量形式表示的视频。
  • output_type (str,默认为 "np") — 后处理 video 张量的输出类型。

将视频张量转换为帧列表以用于导出。关键字参数将转发给 VaeImageProcessor.postprocess。

Update on GitHub