Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Have scenes first write to a temporary file path so as to not accidentally write over previous animations

Grant Sandersonfd567bb0f475
diff --git a/scene/scene.py b/scene/scene.py
index 4ff7d1fdc..e66f63767 100644
--- a/scene/scene.py
+++ b/scene/scene.py
@@ -402,7 +402,9 @@ class Scene(object):
def open_movie_pipe(self):
name = str(self)
file_path = self.get_movie_file_path(name, ".mp4")
- print "Writing to %s"%file_path
+ temp_file_path = file_path.replace(".mp4", "Temp.mp4")
+ print "Writing to %s"%temp_file_path
+ self.args_to_rename_file = (temp_file_path, file_path)
fps = int(1/self.frame_duration)
height, width = self.camera.pixel_shape
@@ -421,13 +423,15 @@ class Scene(object):
'-c:v', 'libx264',
'-pix_fmt', 'yuv420p',
'-loglevel', 'error',
- file_path,
+ temp_file_path,
]
self.writing_process = sp.Popen(command, stdin=sp.PIPE)
def close_movie_pipe(self):
self.writing_process.stdin.close()
self.writing_process.wait()
+ os.rename(*self.args_to_rename_file)
+