ManimCE教程(2)Manim 输出设置

Manim 输出文件夹

上节,我们执行了以下命令

manim -pql scene.py SquareToCircle

剖析代码执行过程:首先,此命令在文件 scene.py 上执行 manim,该文件包含动画代码。此外,该命令告诉 manim 要渲染的场景,也就是 SquareToCircle。这是必要的,因为单个场景文件可能包含多个场景。接下来,-p 命令 manim 渲染后播放,而 -ql 命令 manim 以低质量渲染该场景。

视频渲染后,您将看到 manim 生成了一些新文件,项目文件夹将如下所示:

project/
├─scene.py
└─media
  ├─videos
  |  └─scene
  |     └─480p15
  |        ├─SquareToCircle.mp4
  |        └─partial_movie_files
  ├─text
  └─Tex

主要输出在 media/videos/scene/480p15/SquareToCircle.mp4 中。默认情况下,media 将包含 manim 的所有输出文件,media/videos 包含渲染的视频,在我们的例子中,由于我们使用了 -l 标志,视频是以每秒 15 帧的 480 分辨率从 scene.py 文件中生成的。因此,可以在 media/videos/scene/480p15 中找到输出。

您可以通过执行以下命令来了解 manim 是如何使用这些生成的文件夹的

manim -pqh scene.py SquareToCircle

-ql 表示低质量,-qh 表示高质量,Manim 将花费相当长的时间来渲染这个文件,因为我们使用 -p,输出应该如下所示:
ManimCE教程(2)Manim 输出设置_第1张图片

文件夹结构应如下所示。

project/
├─scene.py
└─media
  ├─videos
  | └─scene
  |   ├─480p15
  |   | ├─SquareToCircle.mp4
  |   | └─partial_movie_files
  |   └─1080p60
  |     ├─SquareToCircle.mp4
  |     └─partial_movie_files
  ├─text
  └─Tex

Manim 创建了一个新的文件夹 media/videos/1080p60,它对应于 1080 分辨率和 60 帧。在其中,您可以找到新的 SquareToCircle.mp4。此外,当添加标志 -s 时,manim 可以选择输出场景的最后一帧,这样可以快速获得场景预览,相应的文件夹结构如下所示:

project/
├─scene.py
└─media
  ├─images
  | └─scene
  |   ├─SquareToCircle.png
  ├─videos
  | └─scene
  |   ├─480p15
  |   | ├─SquareToCircle.mp4
  |   | └─partial_movie_files
  |   └─1080p60
  |     ├─SquareToCircle.mp4
  |     └─partial_movie_files
  ├─text
  └─Tex

使用 -s 保存最后一帧可以与不同分辨率组合使用,例如 -s -ql-s -qh

片段

除了直接输出之外,还可以输出片段

def construct(self):
    # play the first animations...
    # you don't need a section in the very beginning as it gets created automatically
    self.next_section()
    # play more animations...
    self.next_section("this is an optional name that doesn't have to be unique")
    # play even more animations...
    self.next_section("this is a section without any animations, it will be removed")

其中两个切割之间的所有动画都输出到视频文件中。请注意,每个部分至少需要一个动画。例如,这不会创建输出视频:

def construct(self):
    self.next_section()
    # this section doesn't have any animations and will be removed
    # but no error will be thrown
    # feel free to tend your flock of empty sections if you so desire
    self.add(Circle())
    self.next_section()

解决此问题的一种方法是等待一会:

def construct(self):
    self.next_section()
    self.add(Circle())
    # now we wait 1sec and have an animation to satisfy the section
    self.wait()
    self.next_section()

对于要为每个片段创建的视频,您必须将标志添加到 Manim 调用中,如下所示:–save_sections

manim --save_sections scene.py

如果执行此操作,media 文件夹将如下所示:

media
├── images
│   └── simple_scenes
└── videos
    └── simple_scenes
        └── 480p15
            ├── ElaborateSceneWithSections.mp4
            ├── partial_movie_files
            │   └── ElaborateSceneWithSections
            │       ├── 2201830969_104169243_1331664314.mp4
            │       ├── 2201830969_398514950_125983425.mp4
            │       ├── 2201830969_398514950_3447021159.mp4
            │       ├── 2201830969_398514950_4144009089.mp4
            │       ├── 2201830969_4218360830_1789939690.mp4
            │       ├── 3163782288_524160878_1793580042.mp4
            │       └── partial_movie_file_list.txt
            └── sections
                ├── ElaborateSceneWithSections_0000.mp4
                ├── ElaborateSceneWithSections_0001.mp4
                ├── ElaborateSceneWithSections_0002.mp4
                └── ElaborateSceneWithSections.json

也可以跳过渲染属于某个片段的所有动画,如下所示:

def construct(self):
    self.next_section(skip_animations=True)
    # play some animations that shall be skipped...
    self.next_section()
    # play some animations that won't get skipped...

常用的命令行标志

执行命令时

manim -pql scene.py SquareToCircle

必须指定要渲染的类 Scene。这是因为一个文件可以包含多个类 Scene。如果文件包含多个类 Scene,并且要全部渲染它们,则可以使用 -a 标志。

如前所述,-ql 指定低渲染质量,它对快速原型设计和测试非常有用。指定渲染质量的其他选项分别是 -qm-qh-qk(中、高和 4k )。

-p 标志将在动画渲染后播放该动画,如果要在动画所在的位置打开文件浏览器而不是播放它,可以使用 -f 标志,您也可以省略这两个标志。

最后,默认情况下,manim 将输出 .mp4 文件。如果您希望动画为 .gif 格式,请使用 -i 标志,输出文件将与 .mp4 文件位于同一文件夹中,名称相同但文件扩展名不同。

这是对一些最常见的命令行标志的快速回顾。有关所有可用旗帜的全面审查,请参阅Manim配置系统的主题指南。

你可能感兴趣的:(ManimCE教程,python)