Skip to main content

taichi.tools.video#

class taichi.tools.video.VideoManager(output_dir, video_filename=None, width=None, height=None, post_processor=None, framerate=24, automatic_build=True)#

Utility class for exporting results to mp4 and gif formats. This class relies on ffmpeg.

Parameters:
  • output_dir (str) – directory to save the frames.

  • video_filename (str) – filename for the video. default filename is video.mp4.

  • width (int) – resolution of the video.

  • height (int) – resolution of the video.

  • post_processor (object) – any object that implements the process(img) method, which accepts an image as a numpy.ndarray and returns the process image.

  • framerate (int) – frame rate of the video.

  • automatic_build (bool) – automatically generate the resulting video or not.

Example:

>>> video_manager = ti.tools.VideoManager(output_dir="./output", framerate=24, automatic_build=False)
>>> for i in range(50):
>>> render()
>>> img = pixels.to_numpy()
>>> video_manager.write_frame(img)
>>>
>>> video_manager.make_video(gif=True, mp4=True)
Returns:

An instance of taichi.tools.VideoManager class.

clean_frames(self)#

Delete all previous image files in the saved directory.

get_frame_directory(self)#

Returns path to the directory where the image files are located in.

get_output_filename(self, suffix)#
make_video(self, mp4=True, gif=True)#

Convert the image files to a mp4 or gif animation.

write_frame(self, img)#

Write an numpy.ndarray img to an image file.

The filename will be automatically determined by this manager and the frame counter.

write_frames(self, images)#

Write a list of numpy.ndarray images to image files.