2018-04-29 10:52:48 -07:00
|
|
|
import inspect
|
|
|
|
import os
|
|
|
|
|
2018-12-24 12:37:51 -08:00
|
|
|
from manimlib.constants import THIS_DIR
|
|
|
|
from manimlib.constants import VIDEO_DIR
|
2018-04-29 10:52:48 -07:00
|
|
|
|
|
|
|
|
|
|
|
def add_extension_if_not_present(file_name, extension):
|
|
|
|
# This could conceivably be smarter about handling existing differing extensions
|
|
|
|
if(file_name[-len(extension):] != extension):
|
|
|
|
return file_name + extension
|
|
|
|
else:
|
|
|
|
return file_name
|
|
|
|
|
|
|
|
|
2018-05-01 01:53:59 -07:00
|
|
|
def guarantee_existance(path):
|
|
|
|
if not os.path.exists(path):
|
|
|
|
os.makedirs(path)
|
|
|
|
return path
|
|
|
|
|
|
|
|
|
2018-04-29 10:52:48 -07:00
|
|
|
def get_scene_output_directory(scene_class):
|
2019-01-09 12:49:43 -08:00
|
|
|
return guarantee_existance(os.path.join(
|
|
|
|
VIDEO_DIR,
|
|
|
|
scene_class.__module__.replace(".", os.path.sep)
|
|
|
|
))
|
2018-04-29 10:52:48 -07:00
|
|
|
|
|
|
|
|
|
|
|
def get_movie_output_directory(scene_class, camera_config, frame_duration):
|
|
|
|
directory = get_scene_output_directory(scene_class)
|
|
|
|
sub_dir = "%dp%d" % (
|
2018-05-21 12:11:46 -07:00
|
|
|
camera_config["pixel_height"],
|
2018-04-29 10:52:48 -07:00
|
|
|
int(1.0 / frame_duration)
|
|
|
|
)
|
2018-05-01 01:53:59 -07:00
|
|
|
return guarantee_existance(os.path.join(directory, sub_dir))
|
2018-04-29 10:52:48 -07:00
|
|
|
|
|
|
|
|
|
|
|
def get_image_output_directory(scene_class, sub_dir="images"):
|
2018-05-01 01:53:59 -07:00
|
|
|
directory = get_scene_output_directory(scene_class)
|
|
|
|
return guarantee_existance(os.path.join(directory, sub_dir))
|