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)
 
        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].
        
Matting/ppmatting/utils/video.py