MCPcopy Create free account
hub / github.com/apple/ml-pointersect / create_video

Function create_video

plib/render.py:794–841  ·  view source on GitHub ↗

Create a video from the images Args: images: (n, h, w, 3) or list of (h, w, 3), float, range = 0-1 filename: filename of the output video

(
        images: T.Union[torch.Tensor, np.ndarray, T.List[torch.Tensor], T.List[np.ndarray]],
        filename: str,
        fps: float,
        color_format: str = 'rgb',
        val_range: str = '01',
)

Source from the content-addressed store, hash-verified

792
793
794def create_video(
795 images: T.Union[torch.Tensor, np.ndarray, T.List[torch.Tensor], T.List[np.ndarray]],
796 filename: str,
797 fps: float,
798 color_format: str = 'rgb',
799 val_range: str = '01',
800):
801 """
802 Create a video from the images
803
804 Args:
805 images:
806 (n, h, w, 3) or list of (h, w, 3), float, range = 0-1
807 filename:
808 filename of the output video
809 """
810 if isinstance(images, torch.Tensor):
811 images = images.detach().cpu().numpy()
812
813 # read images
814 if len(images) == 0:
815 return
816
817 height, width, layers = images[0].shape
818 fourcc = cv2.VideoWriter_fourcc(*'mp4v')
819 video = cv2.VideoWriter(filename, fourcc, fps, (width, height))
820
821 for i in range(len(images)):
822 img = images[i]
823 if isinstance(img, torch.Tensor):
824 img = img.detach().cpu().numpy()
825
826 if img.dtype != np.uint8:
827 if val_range == '01':
828 img = np.clip(img, a_min=0, a_max=0.9999) * 255
829 elif val_range == '0255':
830 img = np.clip(img, a_min=0, a_max=255)
831 else:
832 img = img / np.max(img) * 255
833 # img = np.clip(img, a_min=0, a_max=0.9999) * 255
834 img = img.astype(np.uint8)
835
836 if color_format == 'rgb':
837 img = cv2.cvtColor(img, cv2.COLOR_RGB2BGR)
838 video.write(img)
839
840 cv2.destroyAllWindows()
841 video.release()
842
843
844def remesh_file(

Callers

nothing calls this directly

Calls 1

detachMethod · 0.45

Tested by

no test coverage detected