mirror of
https://github.com/3b1b/manim.git
synced 2025-08-21 05:44:04 +00:00
Make it an option (default to false) to prerun a scene to calculate its number of frames
This commit is contained in:
parent
7c561d3757
commit
b25f022859
3 changed files with 16 additions and 7 deletions
|
@ -160,6 +160,12 @@ def parse_cli():
|
|||
action="store_true",
|
||||
help="Show progress bar for each animation",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--prerun",
|
||||
action="store_true",
|
||||
help="Calculate total framecount, to display in a progress bar, by doing " + \
|
||||
"an initial run of the scene which skips animations."
|
||||
)
|
||||
parser.add_argument(
|
||||
"--video_dir",
|
||||
help="Directory to write video",
|
||||
|
@ -489,6 +495,7 @@ def get_configuration(args: Namespace) -> dict:
|
|||
"presenter_mode": args.presenter_mode,
|
||||
"leave_progress_bars": args.leave_progress_bars,
|
||||
"show_animation_progress": args.show_animation_progress,
|
||||
"prerun": args.prerun,
|
||||
"embed_exception_mode": custom_config["embed_exception_mode"],
|
||||
"embed_error_sound": custom_config["embed_error_sound"],
|
||||
}
|
||||
|
|
|
@ -61,13 +61,15 @@ def get_scene_config(config):
|
|||
}
|
||||
|
||||
|
||||
def compute_total_frames(scene_class, scene_config):
|
||||
def compute_total_frames(scene_class, scene_config, config):
|
||||
"""
|
||||
When a scene is being written to file, a copy of the scene is run with
|
||||
skip_animations set to true so as to count how many frames it will require.
|
||||
This allows for a total progress bar on rendering, and also allows runtime
|
||||
errors to be exposed preemptively for long running scenes.
|
||||
"""
|
||||
if not config["prerun"]:
|
||||
return -1
|
||||
pre_config = copy.deepcopy(scene_config)
|
||||
pre_config["file_writer_config"]["write_to_movie"] = False
|
||||
pre_config["file_writer_config"]["save_last_frame"] = False
|
||||
|
@ -90,7 +92,7 @@ def get_scenes_to_render(scene_classes, scene_config, config):
|
|||
if scene_class.__name__ == scene_name:
|
||||
fw_config = scene_config["file_writer_config"]
|
||||
if fw_config["write_to_movie"]:
|
||||
fw_config["total_frames"] = compute_total_frames(scene_class, scene_config)
|
||||
fw_config["total_frames"] = compute_total_frames(scene_class, scene_config, config)
|
||||
scene = scene_class(**scene_config)
|
||||
result.append(scene)
|
||||
found = True
|
||||
|
@ -109,7 +111,7 @@ def get_scenes_to_render(scene_classes, scene_config, config):
|
|||
for scene_class in scene_classes:
|
||||
fw_config = scene_config["file_writer_config"]
|
||||
if fw_config["write_to_movie"]:
|
||||
fw_config["total_frames"] = compute_total_frames(scene_class, scene_config)
|
||||
fw_config["total_frames"] = compute_total_frames(scene_class, scene_config, config)
|
||||
scene = scene_class(**scene_config)
|
||||
result.append(scene)
|
||||
return result
|
||||
|
|
|
@ -46,7 +46,7 @@ class SceneFileWriter(object):
|
|||
show_file_location_upon_completion: bool = False,
|
||||
quiet: bool = False,
|
||||
total_frames: int = 0,
|
||||
progress_description_len: int = 40,
|
||||
progress_description_len: int | None = None,
|
||||
):
|
||||
self.scene: Scene = scene
|
||||
self.write_to_movie = write_to_movie
|
||||
|
@ -62,7 +62,8 @@ class SceneFileWriter(object):
|
|||
self.show_file_location_upon_completion = show_file_location_upon_completion
|
||||
self.quiet = quiet
|
||||
self.total_frames = total_frames
|
||||
self.progress_description_len = progress_description_len
|
||||
self.progress_description_len = progress_description_len or \
|
||||
40 if total_frames > 0 else 80
|
||||
|
||||
# State during file writing
|
||||
self.writing_process: sp.Popen | None = None
|
||||
|
@ -278,10 +279,9 @@ class SceneFileWriter(object):
|
|||
command += [self.temp_file_path]
|
||||
self.writing_process = sp.Popen(command, stdin=sp.PIPE)
|
||||
|
||||
if self.total_frames > 0 and not self.quiet:
|
||||
if not self.quiet:
|
||||
self.progress_display = ProgressDisplay(
|
||||
range(self.total_frames),
|
||||
# bar_format="{l_bar}{bar}|{n_fmt}/{total_fmt}",
|
||||
leave=False,
|
||||
ascii=True if platform.system() == 'Windows' else None,
|
||||
dynamic_ncols=True,
|
||||
|
|
Loading…
Add table
Reference in a new issue