Skip to content

Commit eddbb06

Browse files
committed
Remove some Scene references from SceneFileWriter
1 parent d9eee53 commit eddbb06

File tree

2 files changed

+29
-11
lines changed

2 files changed

+29
-11
lines changed

manim/renderer/cairo_renderer.py

Lines changed: 21 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,5 +1,5 @@
11
import numpy as np
2-
from .. import camera_config, file_writer_config, logger
2+
from .. import config, camera_config, file_writer_config, logger
33
from ..utils.iterables import list_update
44
from ..utils.exceptions import EndSceneEarlyException
55
from ..utils.hashing import get_hash_from_play_call, get_hash_from_wait_call
@@ -88,7 +88,25 @@ class CairoRenderer:
8888

8989
def __init__(self, scene, camera):
9090
self.camera = camera
91+
92+
# All of the following are set to EITHER the value passed via kwargs,
93+
# OR the value stored in the global config dict at the time of
94+
# _instance construction_. Before, they were in the CONFIG dict, which
95+
# is a class attribute and is defined at the time of _class
96+
# definition_. This did not allow for creating two Cameras with
97+
# different configurations in the same session.
98+
self.video_quality_config = {}
99+
for attr in [
100+
"pixel_height",
101+
"pixel_width",
102+
"frame_height",
103+
"frame_width",
104+
"frame_rate",
105+
]:
106+
self.video_quality_config[attr] = camera_config.get(attr, config[attr])
107+
91108
self.file_writer = SceneFileWriter(
109+
self.video_quality_config,
92110
scene,
93111
**file_writer_config,
94112
)
@@ -220,4 +238,6 @@ def revert_to_original_skipping_status(self):
220238
def finish(self):
221239
file_writer_config["skip_animations"] = False
222240
self.file_writer.finish()
241+
if file_writer_config["save_last_frame"]:
242+
self.file_writer.save_final_image(self.camera.get_image())
223243
logger.info(f"Rendered {str(self.scene)}\nPlayed {self.num_plays} animations")

manim/scene/scene_file_writer.py

Lines changed: 8 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ class SceneFileWriter(object):
3939
The file-type extension of the outputted video.
4040
"""
4141

42-
def __init__(self, scene, **kwargs):
42+
def __init__(self, video_quality_config, scene, **kwargs):
4343
digest_config(self, kwargs)
44+
self.video_quality_config = video_quality_config
4445
self.scene = scene
4546
self.stream_lock = False
4647
self.init_output_directories()
@@ -167,8 +168,8 @@ def get_resolution_directory(self):
167168
:class:`str`
168169
The name of the directory.
169170
"""
170-
pixel_height = self.scene.camera.pixel_height
171-
frame_rate = self.scene.camera.frame_rate
171+
pixel_height = self.video_quality_config["pixel_height"]
172+
frame_rate = self.video_quality_config["frame_rate"]
172173
return "{}p{}".format(pixel_height, frame_rate)
173174

174175
# Directory getters
@@ -369,7 +370,7 @@ def idle_stream(self):
369370
self.add_frame(*[frame] * n_frames)
370371
b = datetime.datetime.now()
371372
time_diff = (b - a).total_seconds()
372-
frame_duration = 1 / self.scene.camera.frame_rate
373+
frame_duration = 1 / self.video_quality_config["frame_rate"]
373374
if time_diff < frame_duration:
374375
sleep(frame_duration - time_diff)
375376

@@ -389,9 +390,6 @@ def finish(self):
389390
self.flush_cache_directory()
390391
else:
391392
self.clean_cache()
392-
if file_writer_config["save_last_frame"]:
393-
self.scene.update_frame(ignore_skipping=True)
394-
self.save_final_image(self.scene.camera.get_image())
395393

396394
def open_movie_pipe(self):
397395
"""
@@ -408,9 +406,9 @@ def open_movie_pipe(self):
408406
self.partial_movie_file_path = file_path
409407
self.temp_partial_movie_file_path = temp_file_path
410408

411-
fps = self.scene.camera.frame_rate
412-
height = self.scene.camera.pixel_height
413-
width = self.scene.camera.pixel_width
409+
fps = self.video_quality_config["frame_rate"]
410+
height = self.video_quality_config["pixel_height"]
411+
width = self.video_quality_config["pixel_width"]
414412

415413
command = [
416414
FFMPEG_BIN,

0 commit comments

Comments
 (0)