Skip to content

armgit / manim

Public Imported from GitHub
0

A community-maintained Python framework for creating mathematical animations.

Remove some Scene references from SceneFileWriter

Devin Nealeddbb06e25a1
diff --git a/manim/renderer/cairo_renderer.py b/manim/renderer/cairo_renderer.py
index 1d3c2d38c..a7b8c278f 100644
--- a/manim/renderer/cairo_renderer.py
+++ b/manim/renderer/cairo_renderer.py
@@ -1,5 +1,5 @@
import numpy as np
-from .. import camera_config, file_writer_config, logger
+from .. import config, camera_config, file_writer_config, logger
from ..utils.iterables import list_update
from ..utils.exceptions import EndSceneEarlyException
from ..utils.hashing import get_hash_from_play_call, get_hash_from_wait_call
@@ -88,7 +88,25 @@ class CairoRenderer:
def __init__(self, scene, camera):
self.camera = camera
+
+ # All of the following are set to EITHER the value passed via kwargs,
+ # OR the value stored in the global config dict at the time of
+ # _instance construction_. Before, they were in the CONFIG dict, which
+ # is a class attribute and is defined at the time of _class
+ # definition_. This did not allow for creating two Cameras with
+ # different configurations in the same session.
+ self.video_quality_config = {}
+ for attr in [
+ "pixel_height",
+ "pixel_width",
+ "frame_height",
+ "frame_width",
+ "frame_rate",
+ ]:
+ self.video_quality_config[attr] = camera_config.get(attr, config[attr])
+
self.file_writer = SceneFileWriter(
+ self.video_quality_config,
scene,
**file_writer_config,
)
@@ -220,4 +238,6 @@ class CairoRenderer:
def finish(self):
file_writer_config["skip_animations"] = False
self.file_writer.finish()
+ if file_writer_config["save_last_frame"]:
+ self.file_writer.save_final_image(self.camera.get_image())
logger.info(f"Rendered {str(self.scene)}\nPlayed {self.num_plays} animations")
diff --git a/manim/scene/scene_file_writer.py b/manim/scene/scene_file_writer.py
index 4c269a368..20d48e833 100644
--- a/manim/scene/scene_file_writer.py
+++ b/manim/scene/scene_file_writer.py
@@ -39,8 +39,9 @@ class SceneFileWriter(object):
The file-type extension of the outputted video.
"""
- def __init__(self, scene, **kwargs):
+ def __init__(self, video_quality_config, scene, **kwargs):
digest_config(self, kwargs)
+ self.video_quality_config = video_quality_config
self.scene = scene
self.stream_lock = False
self.init_output_directories()
@@ -167,8 +168,8 @@ class SceneFileWriter(object):
:class:`str`
The name of the directory.
"""
- pixel_height = self.scene.camera.pixel_height
- frame_rate = self.scene.camera.frame_rate
+ pixel_height = self.video_quality_config["pixel_height"]
+ frame_rate = self.video_quality_config["frame_rate"]
return "{}p{}".format(pixel_height, frame_rate)
# Directory getters
@@ -369,7 +370,7 @@ class SceneFileWriter(object):
self.add_frame(*[frame] * n_frames)
b = datetime.datetime.now()
time_diff = (b - a).total_seconds()
- frame_duration = 1 / self.scene.camera.frame_rate
+ frame_duration = 1 / self.video_quality_config["frame_rate"]
if time_diff < frame_duration:
sleep(frame_duration - time_diff)
@@ -389,9 +390,6 @@ class SceneFileWriter(object):
self.flush_cache_directory()
else:
self.clean_cache()
- if file_writer_config["save_last_frame"]:
- self.scene.update_frame(ignore_skipping=True)
- self.save_final_image(self.scene.camera.get_image())
def open_movie_pipe(self):
"""
@@ -408,9 +406,9 @@ class SceneFileWriter(object):
self.partial_movie_file_path = file_path
self.temp_partial_movie_file_path = temp_file_path
- fps = self.scene.camera.frame_rate
- height = self.scene.camera.pixel_height
- width = self.scene.camera.pixel_width
+ fps = self.video_quality_config["frame_rate"]
+ height = self.video_quality_config["pixel_height"]
+ width = self.video_quality_config["pixel_width"]
command = [
FFMPEG_BIN,