ManimCE文档及源码教程笔记--(四)Manim的输出设置

ManimCE文档及源码教程笔记--(四)Manim的输出设置

Manim教程admin2022-08-25 17:01:0872A+A-

Manim的输出设置

本文将重点了解manim的输出文件和一些可用的主要命令行标志。

笔记

教程从Quickstart开始,请在开始本教程之前阅读该文档

Manim输出文件夹

此时,您刚刚执行了以下命令。

manim -pql scene.py SquareToCircle

让我们一步一步地剖析刚刚发生的事情。首先,该命令在文件场景上执行manim.py,其中包含我们的动画代码。此外,该命令准确地告诉manim要渲染的场景scene,在这种情况下,它是方形到圆形的。这是必要的,因为单个场景文件可能包含多个场景。接下来,标志p告诉manim在渲染场景后播放场景,-ql标志告诉manim以低质量渲染场景。

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

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

有相当多的新文件。主要输出在media/videos/scene/480p15/squaretocirle.mp4中。默认情况下,媒体文件夹将包含manim的所有输出文件。“媒体/视频”子文件夹包含渲染的视频。在它里面,你会发现每个不同的视频质量一个文件夹。在我们的例子中,由于我们使用了-l标志,视频以每秒15帧的速度从场景中以480分辨率生成scene.py文件。因此,可以在media/videos/scene/480p15中找到输出。其他文件夹media/videos/scene/480p15/partial_movie_file以及media/textmedia/Tex包含manim内部使用的文件。

通过执行以下命令,您可以看到manim如何利用生成的文件夹结构,

manim -pqh scene.py SquareToCircle

-ql标志(用于低质量)已被-qh标志替换,用于高质量。Manim将花费相当长的时间来渲染此文件,并且它将在完成后播放,因为我们使用了-p标志。输出应如下所示:

文件夹结构应如下所示。

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

Manim创建了一个新文件夹media/videos/1080p60,对应于高分辨率和每秒60帧。在它里面,你可以找到新的方形圆SquareToCircle.mp4以及相应的partial_movie_files

在处理具有多个场景的项目并尝试多个分辨率时,输出目录的结构将使所有视频保持有序。

此外,当添加标志-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()

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

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

正如您所见,每个部分都会在sections目录中接收自己的输出视频。这里的JSON文件包含每个部分的一些有用信息:

[
    {
        "name": "create square",
        "type": "default.normal",
        "video": "ElaborateSceneWithSections_0000.mp4",
        "codec_name": "h264",
        "width": 854,
        "height": 480,
        "avg_frame_rate": "15/1",
        "duration": "2.000000",
        "nb_frames": "30"
    },
    {
        "name": "transform to circle",
        "type": "default.normal",
        "video": "ElaborateSceneWithSections_0001.mp4",
        "codec_name": "h264",
        "width": 854,
        "height": 480,
        "avg_frame_rate": "15/1",
        "duration": "2.000000",
        "nb_frames": "30"
    },
    {
        "name": "fade out",
        "type": "default.normal",
        "video": "ElaborateSceneWithSections_0002.mp4",
        "codec_name": "h264",
        "width": 854,
        "height": 480,
        "avg_frame_rate": "15/1",
        "duration": "2.000000",
        "nb_frames": "30"
    }
]

这些数据可以由第三方应用程序使用,如演示系统或自动视频编辑工具。

也可以跳过渲染属于以下部分的所有动画:

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类。如果文件包含多个场景类,并且要渲染所有场景类,则可以使用-a标志。

如前所述,-ql指定了较低的渲染质量。这看起来不是很好,但对快速原型和测试非常有用。指定渲染质量的其他选项分别是-qm-qh-qk(用于中质量、高质量和4k质量)。

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

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

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

点击这里复制本文地址 以上内容来源于互联网,由爱搜问收集整理,如有侵权请联系站长,核实后立即删除,转载分享时注明本文地址!

支持Ctrl+Enter提交
qrcode

爱搜问 ©2021-2022 吉ICP备2022002266号 Aisouwen.COM.
站点地图1 站点地图2 站点地图3