Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Fixed the ffmpeg empty partial movie file red error

MysaaJava0bc665ebfe85
diff --git a/docs/source/manim_directive.py b/docs/source/manim_directive.py
index 7e0fb3cdb..4b8df6f4f 100644
--- a/docs/source/manim_directive.py
+++ b/docs/source/manim_directive.py
@@ -104,8 +104,9 @@ class ManimDirective(Directive):
hide_source = "hide_source" in self.options
save_as_gif = "save_as_gif" in self.options
save_last_frame = "save_last_frame" in self.options
+ write_to_movie = not save_last_frame
assert not (save_as_gif and save_last_frame)
-
+
frame_rate = 30
pixel_height = 480
pixel_width = 854
@@ -178,6 +179,7 @@ class ManimDirective(Directive):
f'file_writer_config["text_dir"] = "{text_dir}"',
f'file_writer_config["video_dir"] = "{video_dir}"',
f'file_writer_config["save_last_frame"] = {save_last_frame}',
+ f'file_writer_config["write_to_movie"] = {write_to_movie}',
f'file_writer_config["save_as_gif"] = {save_as_gif}',
f'file_writer_config["output_file"] = "{output_file}"',
]
diff --git a/manim/scene/scene_file_writer.py b/manim/scene/scene_file_writer.py
index e11647715..bb6906c91 100644
--- a/manim/scene/scene_file_writer.py
+++ b/manim/scene/scene_file_writer.py
@@ -77,46 +77,48 @@ class SceneFileWriter(object):
)
if file_writer_config["write_to_movie"]:
- if file_writer_config["video_dir"]:
- if not file_writer_config["custom_folders"]:
- movie_dir = guarantee_existence(
- os.path.join(
- file_writer_config["video_dir"],
- module_directory,
- self.get_resolution_directory(),
- )
- )
- else:
- movie_dir = guarantee_existence(
- os.path.join(file_writer_config["video_dir"])
- )
- self.movie_file_path = os.path.join(
- movie_dir,
- add_extension_if_not_present(
- default_name, file_writer_config["movie_file_extension"]
- ),
- )
- self.gif_file_path = os.path.join(
- movie_dir,
- add_extension_if_not_present(default_name, GIF_FILE_EXTENSION),
- )
+ pass
+ if file_writer_config["video_dir"]:
if not file_writer_config["custom_folders"]:
- self.partial_movie_directory = guarantee_existence(
+ movie_dir = guarantee_existence(
os.path.join(
- movie_dir,
- "partial_movie_files",
- default_name,
+ file_writer_config["video_dir"],
+ module_directory,
+ self.get_resolution_directory(),
)
)
else:
- self.partial_movie_directory = guarantee_existence(
- os.path.join(
- file_writer_config["media_dir"],
- "temp_files",
- "partial_movie_files",
- default_name,
- )
+ movie_dir = guarantee_existence(
+ os.path.join(file_writer_config["video_dir"])
)
+ self.movie_file_path = os.path.join(
+ movie_dir,
+ add_extension_if_not_present(
+ default_name, file_writer_config["movie_file_extension"]
+ ),
+ )
+ self.gif_file_path = os.path.join(
+ movie_dir,
+ add_extension_if_not_present(default_name, GIF_FILE_EXTENSION),
+ )
+ # The partial movie directory has to be set even if we do not write to movie
+ if not file_writer_config["custom_folders"]:
+ self.partial_movie_directory = guarantee_existence(
+ os.path.join(
+ movie_dir,
+ "partial_movie_files",
+ default_name,
+ )
+ )
+ else:
+ self.partial_movie_directory = guarantee_existence(
+ os.path.join(
+ file_writer_config["media_dir"],
+ "temp_files",
+ "partial_movie_files",
+ default_name,
+ )
+ )
def add_partial_movie_file(self, hash_animation):
"""Adds a new partial movie file path to scene.partial_movie_files from an hash. This method will compute the path from the hash.
@@ -482,11 +484,14 @@ class SceneFileWriter(object):
:class:`bool`
Whether the file exists.
"""
- path = os.path.join(
- self.partial_movie_directory,
- "{}{}".format(hash_invocation, self.movie_file_extension),
- )
- return os.path.exists(path)
+ if hasattr(self,'partial_movie_directory'):
+ path = os.path.join(
+ self.partial_movie_directory,
+ "{}{}".format(hash_invocation, self.movie_file_extension),
+ )
+ return os.path.exists(path)
+ else:
+ return False # If there is no partial movie directory, then the file is not cached
def combine_movie_files(self):
"""