MCPcopy
hub / github.com/huggingface/diffusers / postprocess_video

Method postprocess_video

src/diffusers/video_processor.py:93–118  ·  view source on GitHub ↗

r""" Converts a video tensor to a list of frames for export. Keyword arguments will be forwarded to `VaeImageProcessor.postprocess`. Args: video (`torch.Tensor`): The video as a tensor. output_type (`str`, defaults to `"np"`): Output type of the postp

(
        self, video: torch.Tensor, output_type: str = "np", **kwargs
    )

Source from the content-addressed store, hash-verified

91 return video
92
93 def postprocess_video(
94 self, video: torch.Tensor, output_type: str = "np", **kwargs
95 ) -> np.ndarray | torch.Tensor | list[PIL.Image.Image]:
96 r"""
97 Converts a video tensor to a list of frames for export. Keyword arguments will be forwarded to
98 `VaeImageProcessor.postprocess`.
99
100 Args:
101 video (`torch.Tensor`): The video as a tensor.
102 output_type (`str`, defaults to `"np"`): Output type of the postprocessed `video` tensor.
103 """
104 batch_size = video.shape[0]
105 outputs = []
106 for batch_idx in range(batch_size):
107 batch_vid = video[batch_idx].permute(1, 0, 2, 3)
108 batch_output = self.postprocess(batch_vid, output_type, **kwargs)
109 outputs.append(batch_output)
110
111 if output_type == "np":
112 outputs = np.stack(outputs)
113 elif output_type == "pt":
114 outputs = torch.stack(outputs)
115 elif not output_type == "pil":
116 raise ValueError(f"{output_type} does not exist. Please choose one of ['np', 'pt', 'pil']")
117
118 return outputs
119
120 @staticmethod
121 def classify_height_width_bin(height: int, width: int, ratios: dict) -> tuple[int, int]:

Callers 15

postprocess_decodeFunction · 0.80
__call__Method · 0.80
__call__Method · 0.80
__call__Method · 0.80
__call__Method · 0.80
__call__Method · 0.80
__call__Method · 0.80
__call__Method · 0.80
__call__Method · 0.80

Calls 1

postprocessMethod · 0.45

Tested by 3