用 manim 把 lrc 歌词文件转成视频

博客分类: 技术 阅读次数: comments

用 manim 把 lrc 歌词文件转成视频

从音频制作 lrc 歌词文件

https://lrc-maker.github.io/

注意把每句之间都空起一行,用来记录句子的结束时间

manim 场景

LrcScene.py

from manim import *
import pylrc


class LrcText(Scene):
    with open("you_lun.lrc", encoding="utf-8") as lrc_file:
        lrc_string = ''.join(lrc_file.readlines())
    subs = pylrc.parse(lrc_string)

    for sub in subs:
        print(sub.text)
        sub.color = '#aaccff'
        sub.coor = (0, 0)

    def construct(self):
        for sub, next_sub, third_sub in zip(self.subs[:-1], self.subs[1:], self.subs[2:] + [self.subs[-1]]):
            if sub.text:
                text = Text(sub.text).set_color(color=sub.color)
                text.shift(sub.coor[0] * RIGHT + sub.coor[1] * UP)

                self.add(text)
                play_time = next_sub.time - sub.time
                wait_time = third_sub.time - next_sub.time
                self.play(Write(text, run_time=play_time * .97))
                self.play(Uncreate(text, run_time=play_time * .03))
                self.wait(wait_time)

编译设置

manim.cfg 配置为

[CLI]
output_file = lyrics_scene
transparent = True

预览和运行

manim LrcScene.py LrcText -pql      # For previewing
manim LrcScene.py LrcText -ptqh   # Produce .mov file with transparent background

生成透明背景的视频,剪辑叠到底图上即可。

剪辑

Premiere 里导入mov 文件遇到问题,需要更改项目设置为 Only Mercury Playback Engine,但这样这台电脑的速度就无法渲染出这个视频了。暂时的解决是放弃透明背景,转成avi文件,更改混合模式模仿透明的效果。