Skip to content

Commit

Permalink
[misc] Add filename option to ti.tools.VideoManager. (#5219)
Browse files Browse the repository at this point in the history
* Add filename option to ti.tools.VideoManager.

* [pre-commit.ci] auto fixes from pre-commit.com hooks

for more information, see https://pre-commit.ci

* Remove redundant else block.

Co-authored-by: pre-commit-ci[bot] <66853113+pre-commit-ci[bot]@users.noreply.github.com>
  • Loading branch information
houkensjtu and pre-commit-ci[bot] authored Jun 24, 2022
1 parent 1295fb6 commit fc6e467
Showing 1 changed file with 9 additions and 1 deletion.
10 changes: 9 additions & 1 deletion python/taichi/tools/video.py
Original file line number Diff line number Diff line change
Expand Up @@ -59,6 +59,7 @@ class VideoManager:
Args:
output_dir (str): directory to save the frames.
video_filename (str): filename for the video. default filename is video.mp4.
width, 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
Expand All @@ -81,6 +82,7 @@ class VideoManager:
"""
def __init__(self,
output_dir,
video_filename=None,
width=None,
height=None,
post_processor=None,
Expand All @@ -95,6 +97,7 @@ def __init__(self,
os.makedirs(self.frame_directory)
except:
pass
self.video_filename = video_filename
self.next_video_checkpoint = 4
self.framerate = framerate
self.post_processor = post_processor
Expand All @@ -103,7 +106,12 @@ def __init__(self,
self.automatic_build = automatic_build

def get_output_filename(self, suffix):
return os.path.join(self.directory, 'video' + suffix)
if not self.video_filename:
return os.path.join(self.directory, 'video' + suffix)
filename, extension = os.path.splitext(self.video_filename)
if extension is not None:
print(f'Warning: file extension {extension} will be disregarded!')
return os.path.join(self.directory, filename + suffix)

def write_frame(self, img):
"""Write an `numpy.ndarray` `img` to an image file.
Expand Down

0 comments on commit fc6e467

Please sign in to comment.