默认情况下成片文件名就是场景类名,同一脚本里换个场景就要重新找文件。-o 让你直接指定输出名,目录结构保持不变。

完整代码

1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
from manim import *
class OutputFileDemo(Scene):
"""-o / --output_file:自定义输出文件名"""
def construct(self):
title = Text("-o 自定义输出文件名,路径结构不变", font_size=31).to_edge(UP, buff=0.4)
self.play(Write(title))
def tree_block(flag, scene_name, file_name, color, tag):
head = Text(flag, font_size=22, color=color)
lines = [
("media/", 0, GREY_B),
("|-- videos/", 1, GREY_B),
("| `-- my_file/", 2, GREY_B),
("| `-- 480p15/", 3, GREY_B),
("| `-- " + file_name, 4, color),
("`-- images/", 1, GREY_B),
]
body = VGroup()
for txt, depth, c in lines:
t = Text(txt, font="Consolas", font_size=18, color=c)
t.shift(RIGHT * depth * 0.42)
body.add(t)
body.arrange(DOWN, buff=0.08, aligned_edge=LEFT)
note = Text(tag, font_size=18, color=color)
return VGroup(head, body, note).arrange(DOWN, buff=0.22, aligned_edge=LEFT)
left = tree_block("默认", "MyScene", "MyScene.mp4", BLUE_B, "文件名 = 场景类名")
right = tree_block("加 -o demo", "MyScene", "demo.mp4", GREEN_B, "文件名 = 你给的名字")
pair = VGroup(left, right).arrange(RIGHT, buff=1.6, aligned_edge=UP)
pair.next_to(title, DOWN, buff=0.5)
self.play(FadeIn(left, shift=UP * 0.2))
self.play(FadeIn(right, shift=UP * 0.2))
self.wait(0.5)
codes = VGroup(
Text("manim -qh demo.py MyScene", font="Consolas", font_size=19,
color=BLUE_B),
Text("manim -qh demo.py MyScene -o demo", font="Consolas", font_size=19,
color=GREEN_B),
Text("带扩展名会覆盖推断:-o demo.mp4 / -o demo.png", font_size=18,
color=YELLOW),
).arrange(DOWN, buff=0.14, aligned_edge=LEFT).next_to(pair, DOWN, buff=0.55)
self.play(LaggedStart(*[FadeIn(c, shift=RIGHT * 0.15) for c in codes],
lag_ratio=0.25))
self.wait(1.8)

演示视频

下载 Python 脚本

要点

  • -o demo 把成片改名 demo.mp4,仍落在 media/videos/{脚本名}/{画质}/ 下
  • 带扩展名会覆盖推断:-o demo.png 出图片、-o demo.gif 出动图,按扩展名决定产物类型
  • 同一脚本里有多个场景时,用 -o 分别命名,避免批量渲染时产物互相覆盖

代码来源:Manim Community 官方文档 Tutorials / Manim’s Output Settings(MIT),示例代码按 Manim CE 0.20.1 编写并实跑验证。