Skip to content

Commit 3ec231f

Browse files
committed
add video_output_dir flag
1 parent 7d596d0 commit 3ec231f

File tree

3 files changed

+44
-18
lines changed

3 files changed

+44
-18
lines changed

manimlib/config.py

Lines changed: 7 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -116,8 +116,13 @@ def parse_cli():
116116
"--media_dir",
117117
help="directory to write media",
118118
)
119-
parser.add_argument(
119+
video_group = parser.add_mutually_exclusive_group()
120+
video_group.add_argument(
120121
"--video_dir",
122+
help="directory to write file tree for video",
123+
)
124+
video_group.add_argument(
125+
"--video_output_dir",
121126
help="directory to write video",
122127
)
123128
parser.add_argument(
@@ -207,6 +212,7 @@ def get_configuration(args):
207212
"leave_progress_bars": args.leave_progress_bars,
208213
"media_dir": args.media_dir,
209214
"video_dir": args.video_dir,
215+
"video_output_dir": args.video_output_dir,
210216
"tex_dir": args.tex_dir,
211217
}
212218

manimlib/constants.py

Lines changed: 18 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -3,13 +3,26 @@
33

44
MEDIA_DIR = ""
55
VIDEO_DIR = ""
6+
VIDEO_OUTPUT_DIR = ""
67
TEX_DIR = ""
78

89
def initialize_directories(config):
910
global MEDIA_DIR
1011
global VIDEO_DIR
12+
global VIDEO_OUTPUT_DIR
1113
global TEX_DIR
12-
if not (config["video_dir"] and config["tex_dir"]):
14+
15+
video_path_specified = config["video_dir"] or config["video_output_dir"]
16+
if not video_path_specified:
17+
VIDEO_DIR = os.path.join(MEDIA_DIR, "videos")
18+
elif config["video_output_dir"]:
19+
VIDEO_OUTPUT_DIR = config["video_output_dir"]
20+
else:
21+
VIDEO_DIR = config["video_dir"]
22+
23+
TEX_DIR = config["tex_dir"] or os.path.join(MEDIA_DIR, "Tex")
24+
25+
if not (video_path_specified and config["tex_dir"]):
1326
if config["media_dir"]:
1427
MEDIA_DIR = config["media_dir"]
1528
else:
@@ -26,14 +39,12 @@ def initialize_directories(config):
2639
else:
2740
if config["media_dir"]:
2841
print(
29-
"Ignoring --media_dir, since --video_dir and --tex_dir were "
30-
"both passed"
42+
"Ignoring --media_dir, since both --tex_dir and a video "
43+
"directory were both passed"
3144
)
32-
VIDEO_DIR = config["video_dir"] or os.path.join(MEDIA_DIR, "videos")
33-
TEX_DIR = config["tex_dir"] or os.path.join(MEDIA_DIR, "Tex")
3445

35-
for folder in [VIDEO_DIR, TEX_DIR]:
36-
if not os.path.exists(folder):
46+
for folder in [VIDEO_DIR, VIDEO_OUTPUT_DIR, TEX_DIR]:
47+
if folder != "" and not os.path.exists(folder):
3748
os.makedirs(folder)
3849

3950
TEX_USE_CTEX = False

manimlib/scene/scene_file_writer.py

Lines changed: 19 additions & 10 deletions
Original file line numberDiff line numberDiff line change
@@ -49,21 +49,30 @@ def init_output_directories(self):
4949
module_directory = self.output_directory or self.get_default_module_directory()
5050
scene_name = self.file_name or self.get_default_scene_name()
5151
if self.save_last_frame:
52-
image_dir = guarantee_existence(os.path.join(
53-
consts.VIDEO_DIR,
54-
module_directory,
55-
"images",
56-
))
52+
if consts.VIDEO_DIR != "":
53+
image_dir = guarantee_existence(os.path.join(
54+
consts.VIDEO_DIR,
55+
module_directory,
56+
"images",
57+
))
58+
else:
59+
image_dir = guarantee_existence(os.path.join(
60+
consts.VIDEO_OUTPUT_DIR,
61+
"images",
62+
))
5763
self.image_file_path = os.path.join(
5864
image_dir,
5965
add_extension_if_not_present(scene_name, ".png")
6066
)
6167
if self.write_to_movie:
62-
movie_dir = guarantee_existence(os.path.join(
63-
consts.VIDEO_DIR,
64-
module_directory,
65-
self.get_resolution_directory(),
66-
))
68+
if consts.VIDEO_DIR != "":
69+
movie_dir = guarantee_existence(os.path.join(
70+
consts.VIDEO_DIR,
71+
module_directory,
72+
self.get_resolution_directory(),
73+
))
74+
else:
75+
movie_dir = guarantee_existence(consts.VIDEO_OUTPUT_DIR)
6776
self.movie_file_path = os.path.join(
6877
movie_dir,
6978
add_extension_if_not_present(

0 commit comments

Comments
 (0)