class_docstr: Video writer.
  
  Args:
      path (str): The path to save a video.
      fps (int): The fps of the saved video.
      frame_size (tuple): The frame size (width, height) of the saved video.
      is_color (bool): Whethe to save the video in color format.
class_docstr_tok: ["Video","writer",".","Args",":","path","(","str",")",":","The","path","to","save","a","video",".","fps","(","int",")",":","The","fps","of","the","saved","video",".","frame_size","(","tuple",")",":","The","frame","size","(","width",",","height",")","of","the","saved","video",".","is_color","(","bool",")",":","Whethe","to","save","the","video","in","color","format","."]
docstr: Save frames.
  
  Args:
      frames(Tensor|numpy.ndarray): If `frames` is a tensor, it's shape should be like [N, C, H, W].
          If it is a ndarray, it's shape should be like [H, W, 3] or [H, W]. The value is in [0, 1].
docstr_tok: ["Save","frames",".","Args",":","frames","(","Tensor|numpy.ndarray",")",":","If","`","frames","`","is","a","tensor",",","it","'s","shape","should","be","like","[","N",",","C",",","H",",","W","]",".","If","it","is","a","ndarray",",","it","'s","shape","should","be","like","[","H",",","W",",","3","]","or","[","H",",","W","]",".","The","value","is","in","[","0",",","1","]","."]
code: def write(self, frames):
      """
      Save frames.
  
      Args:
          frames(Tensor|numpy.ndarray): If `frames` is a tensor, it's shape should be like [N, C, H, W].
              If it is a ndarray, it's shape should be like [H, W, 3] or [H, W]. The value is in [0, 1].
      """
      if isinstance(frames, paddle.Tensor):
          if frames.ndim != 4:
              raise ValueError(
                  "The frames should have the shape like [N, C, H, W], but it is {}".format(
                      frames.shape
                  )
              )
          n, c, h, w = frames.shape
          if not (c == 1 or c == 3):
              raise ValueError(
                  "the channels of frames should be 1 or 3, but it is {}".format(
                      c
                  )
              )
          if c == 1 and self.is_color:
              frames = paddle.repeat_interleave(
                  frames, repeats=3, axis=1
              )
  
          frames = (
              frames.transpose((0, 2, 3, 1)).numpy() * 255
          ).astype("uint8")
          for i in range(n):
              frame = frames[i]
              self.cap_out.write(frame)
      else:
          frames = (frames * 255).astype("uint8")
          self.cap_out.write(frames)
  
file_path: PaddleSeg/Matting/ppmatting/utils/video.py
imports: import os
  import warnings
  import cv2
  import paddle
  import numpy
  import ppmatting
  import ppmatting.transforms
label_desc: Use image node_id 2 for calling the VideoWriter obj's underlying member method code with example usage: obj.write(frames) without return types