Manim Animation Cn

v1.0.3

Create mathematical animations with synchronized voiceover narration and subtitles using Manim Community and manim-voiceover. Use when users want to create a...

0· 199·0 current·0 all-time

Install

OpenClaw Prompt Flow

Install with OpenClaw

Best for remote or guided setup. Copy the exact prompt, then paste it into OpenClaw for hzsunzixiang/manim-animation-cn.

Previewing Install & Setup.
Prompt PreviewInstall & Setup
Install the skill "Manim Animation Cn" (hzsunzixiang/manim-animation-cn) from ClawHub.
Skill page: https://clawhub.ai/hzsunzixiang/manim-animation-cn
Keep the work scoped to this skill only.
After install, inspect the skill metadata and help me finish setup.
Use only the metadata you can verify from ClawHub; do not invent missing requirements.
Ask before making any broader environment changes.

Command Line

CLI Commands

Use the direct CLI path if you want to install manually and keep every step visible.

OpenClaw CLI

Bare skill slug

openclaw skills install manim-animation-cn

ClawHub CLI

Package manager switcher

npx clawhub@latest install manim-animation-cn
Security Scan
VirusTotalVirusTotal
Benign
View report →
OpenClawOpenClaw
Benign
high confidence
Purpose & Capability
Name/description match the provided artifacts. The SKILL.md, reference guide, and the two scripts all focus on generating Manim animations with TTS and subtitles. Required tools (manim, ffmpeg, Python) and Python packages (manim-voiceover[gtts]) are exactly what this functionality needs; no unrelated credentials or binaries are requested.
Instruction Scope
Runtime instructions are narrowly scoped to: check environment, generate/render Manim scene files, optionally burn SRT subtitles, and post-process (speed-up/copy). This is coherent. Important security note: running the pipeline involves invoking manim on user-supplied Python scene files (manim will execute that Python code). Executing untrusted scene.py files can run arbitrary code on the host — this is expected for a renderer but is a meaningful operational risk users should be aware of.
Install Mechanism
No install spec is embedded (instruction-only), so nothing is automatically downloaded or executed by the skill itself. The documentation recommends installing packages via pip/homebrew/conda — standard, low-risk guidance. No remote download-from-random-URL install steps are present.
Credentials
The skill declares no required environment variables or credentials. The only network usage acknowledged is optional gTTS (Google TTS) for TTS synthesis; an offline fallback (pyttsx3) is documented. The check scripts suggest setting proxy env vars only as a troubleshooting measure — reasonable and proportional.
Persistence & Privilege
always is false and disable-model-invocation is not set; the skill does not request persistent, system-wide privileges nor modify other skills. It operates on local media/ and output directories only, which is standard for a local rendering pipeline.
Assessment
This skill appears to do what it says: render Manim scenes with TTS and subtitles locally. Things to consider before installing/using: - The skill runs manim on Python scene files you provide. Manim will execute those Python files — do not render untrusted scene.py files unless you accept the risk of arbitrary code execution. Review any scene code before rendering. - gTTS (Google TTS) is the default network-backed TTS engine; if you need purely offline operation, install/use the pyttsx3 option described in the docs. - The scripts call ffmpeg and other local commands (grep, fc-list). Ensure ffmpeg on your system is built with libx264 and libass if you want subtitle burn-in; the environment check script helps verify this. - The project does not request secrets or modify system configuration, and it does not auto-install arbitrary remote binaries. If you plan to run on a multi-user or CI environment, isolate the rendering process and verify scene files. If you want higher confidence: inspect any scene.py files you will render, and run the included check_environment.py in a controlled environment first to verify dependencies.

Like a lobster shell, security has layers — review code before you run it.

latestvk97fvy1cma4y07ydtv156n3rt983g49n
199downloads
0stars
4versions
Updated 1mo ago
v1.0.3
MIT-0

Manim Animation: 动画 + 配音 + 字幕 生成器

Author: ericksun(孙自翔)

概述

本技能使用 Manim Community 生成数学/教育动画,并通过 manim-voiceover 插件集成 TTS 语音旁白和同步字幕。所有处理均在本地运行,无需付费 API。

核心能力:

  • 🎬 动画生成:使用 Manim 创建数学公式、几何图形、图表等动画
  • 🎙️ 语音旁白:通过 manim-voiceover 插件集成 TTS,动画与语音自动同步
  • 📝 字幕系统:画面内字幕(Manim Text)+ SRT 外挂字幕(ffmpeg 烧录)
  • 🔄 一键流水线:描述需求 → 生成代码 → 渲染视频 → 烧录字幕

TTS 引擎(优先 gTTS):

  • gTTS(推荐):Google 免费 TTS,支持中文,无需 API Key
  • pyttsx3(备选):离线 TTS,无需网络
  • Azure/OpenAI/ElevenLabs(高质量):需付费 API Key

前置条件

🔍 一键环境检查

首次使用前,运行环境检查脚本确认所有依赖已就绪:

python3 {SKILL_DIR}/scripts/check_environment.py

该脚本检查:

  • ✅ Manim Community 安装(manim 命令)
  • ✅ manim-voiceover + gTTS 插件
  • ✅ FFmpeg + libx264 编码器(Manim 硬编码依赖,必需
  • ✅ FFmpeg + libass(用于 SRT 字幕烧录)
  • ✅ Python 依赖
  • ✅ 中文字体可用性

必需的系统工具

  • Manim Communitypip install manim
  • FFmpeg(含 libx264 + libass):Manim 硬编码使用 libx264 编码器渲染视频,字幕烧录需要 libass
    • macOS(Homebrew):brew install ffmpeg(默认包含 x264 和 libass)
    • macOS(Conda):conda install x264 -c conda-forge⚠️ conda 的 ffmpeg 默认不含 libx264
    • Linux:sudo apt install ffmpeg libx264-dev libass-dev
  • Python 3.9+ 及 pip

必需的 Python 包

# Core
pip install manim

# Voiceover + TTS
pip install "manim-voiceover[gtts]"

可选(增强功能)

  • pyttsx3:离线 TTS(pip install "manim-voiceover[pyttsx3]"

⚡ 快速安装

pip install manim "manim-voiceover[gtts]"

# macOS (Homebrew) — 推荐,自带 libx264 + libass
brew install ffmpeg

# macOS (Conda) — 需额外安装 x264,否则 Manim 渲染会报错 UnknownCodecError: libx264
conda install x264 -c conda-forge

# 验证 ffmpeg 支持 libx264 和 libass
ffmpeg -codecs 2>&1 | grep libx264     # 应显示 encoders: libx264
ffmpeg -filters 2>&1 | grep subtitles  # 应显示 subtitles filter

工作流程

快速开始 — 一键运行

用户描述需求后,使用流水线脚本一键完成:

python3 {SKILL_DIR}/scripts/run_pipeline.py \
    --scene_file <场景文件.py> \
    --scene_name <SceneName> \
    --quality high \
    --burn_subtitles

常用选项:

选项默认值说明
--scene_file必需Manim 场景 Python 文件
--scene_name必需场景类名
--qualityhigh渲染质量:low/medium/high/production
--burn_subtitlesFalse是否用 ffmpeg 烧录 SRT 字幕
--speed1.35播放倍速(如 1.35 表示加速到 1.35 倍,设为 1.0 则不加速)
--previewFalse渲染后自动打开预览
--output_dir./output输出目录

完整工作流程(4 步)

步骤 1:理解用户需求并生成 Manim 场景代码

根据用户描述,生成 Manim 场景 Python 文件。场景代码需遵循以下模式:

无配音模式(纯动画):

from manim import *

class MyScene(Scene):
    def construct(self):
        title = Text("标题", font_size=48, color=BLUE)
        self.play(Write(title))
        self.wait(1)

配音模式(动画 + 语音 + 字幕):

from manim import *
from manim_voiceover import VoiceoverScene
from manim_voiceover.services.gtts import GTTSService

class MyScene(VoiceoverScene):
    def _make_subtitle(self, text_str):
        """Create subtitle with dark background at bottom of screen."""
        sub = Text(text_str, font_size=22, color=WHITE, weight=BOLD)
        # Prevent subtitle from overflowing left/right edges
        max_width = config.frame_width - 1.0  # 0.5 margin each side
        if sub.width > max_width:
            sub.scale_to_fit_width(max_width)
        sub.to_edge(DOWN, buff=0.4)
        bg = BackgroundRectangle(sub, color=BLACK, fill_opacity=0.6, buff=0.15)
        return VGroup(bg, sub)

    def construct(self):
        self.set_speech_service(GTTSService(lang="zh"))

        sub_text = "欢迎来到演示"
        with self.voiceover(text=sub_text) as tracker:
            sub = self._make_subtitle(sub_text)
            title = Text("演示", font_size=48)
            self.play(Write(title), FadeIn(sub), run_time=tracker.duration)

        self.play(FadeOut(sub))
        self.wait(0.3)

关键模式 — voiceover 上下文管理器:

with self.voiceover(text="语音文本") as tracker:
    # tracker.duration = TTS 语音时长(秒)
    # 在此块内的动画会与语音自动同步
    self.play(SomeAnimation(), run_time=tracker.duration)

with self.voiceover(text=...) as tracker 做了三件事:

  1. 调用 TTS 引擎生成语音
  2. 自动计算语音时长
  3. 提供 tracker.duration 让动画与语音同步

字幕最佳实践:

  • 画面内字幕:使用 _make_subtitle() 辅助函数,在屏幕底部显示带暗背景的白色粗体文字
  • 防止溢出_make_subtitle() 会自动检测字幕宽度,超出画面时等比缩放(scale_to_fit_width),使用 font_size=22 以适配长文本
  • 字幕同步:在 voiceover 块内的第一个 self.play() 中就 FadeIn(sub),确保字幕与声音同步出现,不要延后
  • 每个 voiceover 块开始时 FadeIn 字幕,结束后 FadeOut
  • 字幕文本应与 voiceover text 相同

⚠️ 避免双字幕: 如果场景代码中已使用 _make_subtitle() 渲染了画面内字幕,则 不要 再用 --burn_subtitles 烧录 SRT 字幕,否则画面上会出现两层重叠的字幕。两种字幕方案只能选其一:

  • 方案 A(推荐):代码内使用 _make_subtitle() 渲染字幕,不烧录 SRT
  • 方案 B:代码内不渲染字幕,通过 --burn_subtitles 烧录 SRT

步骤 2:配置渲染参数

在场景文件同目录创建 manim.cfg

[CLI]
quality = high_quality
preview = False

[ffmpeg]
video_codec = h264

质量对照表:

质量标志分辨率FPSmanim.cfg 值
Low-ql480p15low_quality
Medium-qm720p30medium_quality
High-qh1080p60high_quality
Production-qp2160p60production_quality

步骤 3:渲染视频

manim render <scene_file.py> <SceneName>

输出路径模式:media/videos/<file>/<resolution>/<SceneName>.mp4

步骤 4:烧录 SRT 字幕(可选)

manim-voiceover 会自动在视频同目录生成 .srt 字幕文件。使用 ffmpeg 烧录:

ffmpeg -y -i <video.mp4> \
    -vf "subtitles=<subtitle.srt>:force_style='FontSize=22,PrimaryColour=&H00FFFFFF,OutlineColour=&H00000000,Outline=2,BackColour=&H80000000,BorderStyle=4,MarginV=30'" \
    -c:a copy \
    <output_subtitled.mp4>

⚠️ 双字幕陷阱:如果场景 Python 代码中已经用 _make_subtitle() 渲染了画面内字幕,就 不要 再烧录 SRT 字幕,否则会出现两层重叠字幕。

注意:ffmpeg 需要 libass 支持。macOS 用 brew install ffmpeg 通常已包含。Conda 环境需额外安装 conda install x264 -c conda-forge

步骤 5:加速视频(可选)

使用 ffmpeg 对视频进行倍速处理,默认加速到 1.35 倍:

SPEED=1.35
ffmpeg -y -i <input.mp4> \
    -filter_complex "[0:v]setpts=PTS/${SPEED}[v];[0:a]atempo=${SPEED}[a]" \
    -map "[v]" -map "[a]" \
    <output_fast.mp4>

注意:加速应在最终输出步骤执行。如果场景代码已有画面内字幕(_make_subtitle),加速输入应使用原始视频(非 SRT 烧录版),避免双字幕。run_pipeline.py--speed 参数已自动处理此逻辑。

Manim 常用动画速查

创建/显示动画

  • Write(text) — 书写文字
  • Create(mobject) — 绘制形状
  • FadeIn(mobject) / FadeOut(mobject) — 淡入淡出
  • DrawBorderThenFill(mobject) — 先画边框再填充

变换动画

  • Transform(source, target) — 变形
  • ReplacementTransform(source, target) — 替换变形
  • TransformMatchingShapes(source, target) — 形状匹配变形

移动/缩放

  • mobject.animate.to_edge(UP) — 移动到边缘
  • mobject.animate.shift(RIGHT * 2) — 平移
  • mobject.animate.scale(2) — 缩放
  • Rotate(mobject, angle=PI) — 旋转

常用对象

  • Text("文字", font_size=48, color=BLUE) — 文字
  • MathTex(r"e^{i\pi}+1=0") — LaTeX 公式
  • Circle(radius=1, color=RED) — 圆
  • Square(side_length=2, color=GREEN) — 正方形
  • Arrow(start, end) — 箭头
  • NumberPlane() — 坐标平面
  • Axes(x_range, y_range) — 坐标轴

分组与排列

  • VGroup(obj1, obj2) — 垂直分组
  • group.arrange(RIGHT, buff=0.5) — 水平排列
  • BackgroundRectangle(obj, color=BLACK, fill_opacity=0.6) — 背景矩形

已知问题与解决方案

⚠️ libx264 编解码器缺失(最常见问题)

症状UnknownCodecError: libx264

根因:Manim 在 scene_file_writer.py硬编码使用 libx264 编码器(无法通过 config/cfg 覆盖),但 conda 环境的 ffmpeg 编译时 --disable-gpl,不包含 GPL 许可的 libx264。

解决

# Conda 环境(最常见场景)
conda install x264 -c conda-forge
# 安装后 conda-forge 的 ffmpeg 会自动重新链接 x264 库

# 验证
ffmpeg -codecs 2>&1 | grep libx264
# 应输出包含: encoders: libx264 libx264rgb

注意brew install ffmpeg 安装的 ffmpeg 自带 x264,但 conda 环境优先使用自己安装的 ffmpeg,不会使用 Homebrew 版本。

setuptools 兼容性

manim-voiceover 依赖 pkg_resources,Python 3.12+ 可能报错:

pip install "setuptools>=69.0,<72.0"

ffmpeg 缺少 libass

SRT 字幕烧录需要 libass。macOS:

brew install ffmpeg
# 验证
ffmpeg -filters 2>&1 | grep subtitles

Linux:

sudo apt install libass-dev
# 可能需要重新编译 ffmpeg

gTTS 网络问题

gTTS 需要访问 Google TTS 服务,如网络不通可切换为 pyttsx3 离线引擎:

from manim_voiceover.services.pyttsx3 import Pyttsx3Service
self.set_speech_service(Pyttsx3Service())

中文字体

Manim 使用系统字体渲染 Text 对象,确保系统有中文字体:

  • macOS:PingFang SC(系统自带)
  • Linux:sudo apt install fonts-noto-cjk
  • 指定字体:Text("文字", font="PingFang SC")

相关资源

  • GitHub 仓库https://github.com/hzsunzixiang/manim-animation-skill
  • Manim 技术指南references/manim_guide.md — 详细的 Manim + voiceover + 字幕技术文档
  • 环境检查脚本scripts/check_environment.py — 一键检查所有依赖
  • 渲染流水线脚本scripts/run_pipeline.py — 一键渲染 + 字幕烧录

Comments

Loading comments...