diff --git a/manimlib/config.py b/manimlib/config.py index e3e9342048..e8a2680959 100644 --- a/manimlib/config.py +++ b/manimlib/config.py @@ -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"], } diff --git a/manimlib/extract_scene.py b/manimlib/extract_scene.py index 66c27a2b9b..8f1a36abd5 100644 --- a/manimlib/extract_scene.py +++ b/manimlib/extract_scene.py @@ -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 diff --git a/manimlib/scene/scene_file_writer.py b/manimlib/scene/scene_file_writer.py index d288e7dd5c..bd2e9b192d 100644 --- a/manimlib/scene/scene_file_writer.py +++ b/manimlib/scene/scene_file_writer.py @@ -46,7 +46,7 @@ def __init__( 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 @@ def __init__( 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 @@ def open_movie_pipe(self, file_path: str) -> None: 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,