mirror of
https://github.com/3b1b/manim.git
synced 2025-09-01 00:48:45 +00:00
make media, tex, and video directories configurable via flags
This commit is contained in:
parent
caa4577cd1
commit
f81c275631
7 changed files with 61 additions and 35 deletions
|
@ -1,5 +1,6 @@
|
|||
#!/usr/bin/env python
|
||||
import manimlib.config
|
||||
import manimlib.constants
|
||||
import manimlib.extract_scene
|
||||
import manimlib.stream_starter
|
||||
|
||||
|
@ -8,6 +9,7 @@ def main():
|
|||
args = manimlib.config.parse_cli()
|
||||
if not args.livestream:
|
||||
config = manimlib.config.get_configuration(args)
|
||||
manimlib.constants.initialize_directories(config)
|
||||
manimlib.extract_scene.main(config)
|
||||
else:
|
||||
manimlib.stream_starter.start_livestream(
|
||||
|
|
|
@ -112,6 +112,18 @@ def parse_cli():
|
|||
action="store_true",
|
||||
help="Leave progress bars displayed in terminal",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--media_dir",
|
||||
help="directory to write media",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--video_dir",
|
||||
help="directory to write video",
|
||||
)
|
||||
parser.add_argument(
|
||||
"--tex_dir",
|
||||
help="directory to write tex",
|
||||
)
|
||||
|
||||
# For live streaming
|
||||
module_location.add_argument(
|
||||
|
@ -192,7 +204,10 @@ def get_configuration(args):
|
|||
"start_at_animation_number": args.start_at_animation_number,
|
||||
"end_at_animation_number": None,
|
||||
"sound": args.sound,
|
||||
"leave_progress_bars": args.leave_progress_bars
|
||||
"leave_progress_bars": args.leave_progress_bars,
|
||||
"media_dir": args.media_dir,
|
||||
"video_dir": args.video_dir,
|
||||
"tex_dir": args.tex_dir,
|
||||
}
|
||||
|
||||
# Camera configuration
|
||||
|
|
|
@ -1,32 +1,40 @@
|
|||
import numpy as np
|
||||
import os
|
||||
|
||||
# Initialize directories
|
||||
env_MEDIA_DIR = os.getenv("MEDIA_DIR")
|
||||
if env_MEDIA_DIR:
|
||||
MEDIA_DIR = env_MEDIA_DIR
|
||||
elif os.path.isfile("media_dir.txt"):
|
||||
with open("media_dir.txt", 'rU') as media_file:
|
||||
MEDIA_DIR = media_file.readline().strip()
|
||||
else:
|
||||
MEDIA_DIR = os.path.join(
|
||||
os.path.expanduser('~'),
|
||||
"Dropbox (3Blue1Brown)/3Blue1Brown Team Folder"
|
||||
)
|
||||
if not os.path.isdir(MEDIA_DIR):
|
||||
MEDIA_DIR = "./media"
|
||||
print(
|
||||
f"Media will be stored in {MEDIA_DIR + os.sep}. You can change "
|
||||
"this behavior by writing a different directory to media_dir.txt."
|
||||
)
|
||||
MEDIA_DIR = ""
|
||||
VIDEO_DIR = ""
|
||||
TEX_DIR = ""
|
||||
|
||||
VIDEO_DIR = os.path.join(MEDIA_DIR, "video")
|
||||
ASSETS_DIR = os.path.join(MEDIA_DIR, "assets")
|
||||
TEX_DIR = os.path.join(MEDIA_DIR, "Tex")
|
||||
def initialize_directories(config):
|
||||
global MEDIA_DIR
|
||||
global VIDEO_DIR
|
||||
global TEX_DIR
|
||||
if not (config["video_dir"] and config["tex_dir"]):
|
||||
if config["media_dir"]:
|
||||
MEDIA_DIR = config["media_dir"]
|
||||
else:
|
||||
MEDIA_DIR = os.path.join(
|
||||
os.path.expanduser('~'),
|
||||
"Dropbox (3Blue1Brown)/3Blue1Brown Team Folder"
|
||||
)
|
||||
if not os.path.isdir(MEDIA_DIR):
|
||||
MEDIA_DIR = "./media"
|
||||
print(
|
||||
f"Media will be written to {MEDIA_DIR + os.sep}. You can change "
|
||||
"this behavior with the --media_dir flag."
|
||||
)
|
||||
else:
|
||||
if config["media_dir"]:
|
||||
print(
|
||||
"Ignoring --media_dir, since --video_dir and --tex_dir were "
|
||||
"both passed"
|
||||
)
|
||||
VIDEO_DIR = config["video_dir"] or os.path.join(MEDIA_DIR, "video")
|
||||
TEX_DIR = config["tex_dir"] or os.path.join(MEDIA_DIR, "Tex")
|
||||
|
||||
for folder in [VIDEO_DIR, ASSETS_DIR, TEX_DIR]:
|
||||
if not os.path.exists(folder):
|
||||
os.makedirs(folder)
|
||||
for folder in [VIDEO_DIR, TEX_DIR]:
|
||||
if not os.path.exists(folder):
|
||||
os.makedirs(folder)
|
||||
|
||||
TEX_USE_CTEX = False
|
||||
TEX_TEXT_TO_REPLACE = "YourTextHere"
|
||||
|
|
|
@ -9,6 +9,7 @@ import sys
|
|||
from colour import Color
|
||||
import numpy as np
|
||||
|
||||
import manimlib.constants as consts
|
||||
from manimlib.constants import *
|
||||
from manimlib.container.container import Container
|
||||
from manimlib.utils.color import color_gradient
|
||||
|
@ -109,7 +110,7 @@ class Mobject(Container):
|
|||
|
||||
def save_image(self, name=None):
|
||||
self.get_image().save(
|
||||
os.path.join(VIDEO_DIR, (name or str(self)) + ".png")
|
||||
os.path.join(consts.VIDEO_DIR, (name or str(self)) + ".png")
|
||||
)
|
||||
|
||||
def copy(self):
|
||||
|
|
|
@ -7,11 +7,11 @@ import _thread as thread
|
|||
from time import sleep
|
||||
import datetime
|
||||
|
||||
import manimlib.constants as consts
|
||||
from manimlib.constants import FFMPEG_BIN
|
||||
from manimlib.constants import STREAMING_IP
|
||||
from manimlib.constants import STREAMING_PORT
|
||||
from manimlib.constants import STREAMING_PROTOCOL
|
||||
from manimlib.constants import VIDEO_DIR
|
||||
from manimlib.utils.config_ops import digest_config
|
||||
from manimlib.utils.file_ops import guarantee_existence
|
||||
from manimlib.utils.file_ops import add_extension_if_not_present
|
||||
|
@ -50,7 +50,7 @@ class SceneFileWriter(object):
|
|||
scene_name = self.file_name or self.get_default_scene_name()
|
||||
if self.save_last_frame:
|
||||
image_dir = guarantee_existence(os.path.join(
|
||||
VIDEO_DIR,
|
||||
consts.VIDEO_DIR,
|
||||
module_directory,
|
||||
scene_name,
|
||||
"images",
|
||||
|
@ -61,7 +61,7 @@ class SceneFileWriter(object):
|
|||
)
|
||||
if self.write_to_movie:
|
||||
movie_dir = guarantee_existence(os.path.join(
|
||||
VIDEO_DIR,
|
||||
consts.VIDEO_DIR,
|
||||
module_directory,
|
||||
scene_name,
|
||||
self.get_resolution_directory(),
|
||||
|
|
|
@ -1,9 +1,9 @@
|
|||
import os
|
||||
import hashlib
|
||||
|
||||
from manimlib.constants import TEX_DIR
|
||||
from manimlib.constants import TEX_TEXT_TO_REPLACE
|
||||
from manimlib.constants import TEX_USE_CTEX
|
||||
import manimlib.constants as consts
|
||||
|
||||
|
||||
def tex_hash(expression, template_tex_file_body):
|
||||
|
@ -22,7 +22,7 @@ def tex_to_svg_file(expression, template_tex_file_body):
|
|||
|
||||
def generate_tex_file(expression, template_tex_file_body):
|
||||
result = os.path.join(
|
||||
TEX_DIR,
|
||||
consts.TEX_DIR,
|
||||
tex_hash(expression, template_tex_file_body)
|
||||
) + ".tex"
|
||||
if not os.path.exists(result):
|
||||
|
@ -44,7 +44,7 @@ def tex_to_dvi(tex_file):
|
|||
"latex",
|
||||
"-interaction=batchmode",
|
||||
"-halt-on-error",
|
||||
"-output-directory=" + TEX_DIR,
|
||||
"-output-directory=" + consts.TEX_DIR,
|
||||
tex_file,
|
||||
">",
|
||||
os.devnull
|
||||
|
@ -53,7 +53,7 @@ def tex_to_dvi(tex_file):
|
|||
"-no-pdf",
|
||||
"-interaction=batchmode",
|
||||
"-halt-on-error",
|
||||
"-output-directory=" + TEX_DIR,
|
||||
"-output-directory=" + consts.TEX_DIR,
|
||||
tex_file,
|
||||
">",
|
||||
os.devnull
|
||||
|
|
|
@ -4,8 +4,8 @@ import os
|
|||
import sys
|
||||
import importlib
|
||||
|
||||
import manimlib.constants as consts
|
||||
from manimlib.constants import PRODUCTION_QUALITY_CAMERA_CONFIG
|
||||
from manimlib.constants import VIDEO_DIR
|
||||
from manimlib.config import get_module
|
||||
from manimlib.extract_scene import is_child_scene
|
||||
|
||||
|
@ -43,7 +43,7 @@ def stage_scenes(module_name):
|
|||
# }
|
||||
# TODO, fix this
|
||||
animation_dir = os.path.join(
|
||||
VIDEO_DIR, "ode", "part2", "1440p60"
|
||||
consts.VIDEO_DIR, "ode", "part2", "1440p60"
|
||||
)
|
||||
#
|
||||
files = os.listdir(animation_dir)
|
||||
|
|
Loading…
Add table
Reference in a new issue