Animaku — 代码驱动的画布动画工作室
使用Animaku HTML5 Canvas 2D引擎、edge-tts神经语音旁白以及无头Playwright + FFmpeg渲染,通过代码创建精美的短动画视频。
工作流
1. 规划故事板与旁白(script.json)
在 projects/<slug>/(或 examples/<slug>/)下创建项目文件夹,并编写 script.json:
- 从 presets.md 中选择语音(例如:
id-ID-ArdiNeural、id-ID-GadisNeural、en-US-GuyNeural)。 - 将强调的关键词包裹在
*星号*中,以便动态字幕自动将其高亮为黄色(例如:"Nahan *fantasi* liar")。 - 添加
pauseAfter(秒)以控制语气停顿。
{
"voice": "id-ID-ArdiNeural",
"rate": "+6%",
"cues": [
{ "id": "c1", "text": "Nahan *fantasi* liar", "pauseAfter": 0.25 },
{ "id": "c2", "text": "Padahal masih *ngecat* tembok!", "pauseAfter": 0.3 }
]
}
2. 生成旁白音频及精确时间戳
运行 narrator.py 以合成 narrator.mp3 和 timing.json:
python .agents/skills/animaku/scripts/narrator.py --script projects/<slug>/script.json --out-dir projects/<slug>
3. 编写动画画布场景(scene.js)
编写 projects/<slug>/scene.js,并从 ../../engine/animaku.js 导入辅助函数(参见 canvas-api.md):
- 导出
meta(width、height、fps),使其与所需画幅比例匹配(默认竖屏1080x1920)。 - 导出
init({ width, height, timing, duration })以便预先构建确定性粒子系统或背景道具。 - 导出
render(ctx, { width, height, t, duration, timing, state }):- 背景:使用
VFX.drawBlurredLayer(...)绘制景深效果的房间、门廊或渐变。 - 摄像机:将世界空间元素包裹在
cam.begin(ctx, width, height, t)...cam.end(ctx)之间,实现平滑平移/缩放以及冲击trauma震动。 - 角色与道具:使用
drawCharacter(ctx, cfg, state, t),样式可选'flat-glow'或'stickman-toon',并添加边缘发光效果,配合VFX.drawMotionLines(...)或VFX.drawSweatDrop(...)。 - 特效与后期处理:添加
VFX.drawParticles(...)和VFX.drawPostProcess(ctx, width, height, { vignette, lightLeak, grain, t })。 - 动态字幕:在摄像机变换之外调用
drawKineticSubtitles(ctx, width, height, timing.cues, t),使字幕保持清晰居中。
- 背景:使用
4. 渲染为 MP4
运行 render.mjs 以通过无头Edge/Chrome捕获确定性帧,并使用FFmpeg编码:
node .agents/skills/animaku/scripts/render.mjs --scene projects/<slug>/scene.js --timing projects/<slug>/timing.json --audio projects/<slug>/narrator.mp3 --out projects/<slug>/output.mp4 --w 1080 --h 1920 --fps 30
可选:传递 --bgm path/to/music.mp3 以在旁白下混入背景音乐,音量设置为18%。
5. 验证输出
确认渲染的视频具有有效的视频和音频流,且时长不为零:
ffprobe -v error -show_entries format=duration -show_entries stream=codec_type,width,height -of default=noprint_wrappers=1 projects/<slug>/output.mp4