章节
除了影片输出文件之外,还可以使用章节。每个章节都会生成它自己的输出视频。两个部分之间的剪辑可以像这样设置:
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")
其中两个剪辑之间的所有动画都连接到一个输出video 文件中。请注意,每个部分至少需要一个动画。例如,这不会创建输出视频:
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...
Last updated