z-motion-video Motion Video
Turn a script into an animated explainer video. The pipeline is: story.json (scenes + narration) → web page (HTML/CSS animation) → frame-by-frame capture → MP4.
Below, $SK refers to the directory containing this skill, and ./my-video refers to the user's project directory.
Environment
pip install playwright && python3 -m playwright install chromium
You'll also need ffmpeg (macOS: brew install ffmpeg). For full-audio timing and per-line audio with silence removal, you need pip install numpy. For online TTS, use pip install edge-tts. All are optional.
python3 $SK/tools/mv.py check
Fonts are automatically downloaded on first build (open-source fonts like Source Han Serif, Source Han Sans, LXGW WenKai, Inter, etc., under the OFL license) to ~/.cache/z-motion-video. If the fonts are already installed locally, they are used directly.
Workflow
Follow these steps in order. Each step produces an output you can check.
- Ask three things: What to talk about (script or key points), where it will be posted (determines the aspect ratio), and preferred style. If unsure about the style, first run
showcaseto generate an overview image of all styles' demo scripts. To see the same script in all styles, runcomparewith the user's script. - Create project:
python3 $SK/tools/mv.py new ./my-video --style <style>. This copies the chosen style's demo script as a starting point (the demo script uses various layouts of that style, the fastest way to adapt). If--styleis omitted, it copies the leap-year example. - Write story.json: Split the script into scenes, pick a template for each scene (see quick reference below), write on-screen text, and
saynarration lines. See the next section for writing rules. - Check layout with snapshots:
python3 $SK/tools/mv.py snap ./my-video. Openout/sheet-<style>-<ratio>.pngfor an overview. Address all ⚠ warnings in the terminal (content overflow, scaled to xx%, title too long) by deleting text, splitting scenes, or switching templates. - Narration and timing (choose one of three; you can render a silent version without narration):
- Your own recordings: per-line files use
timing --lines DIR; a single audio file usestiming --audio voice.wav; word-level timestamps usetiming --words words.json --voice voice.wav. - Machine TTS:
tts ./my-video(macOSsay, local synthesis);tts ./my-video --engine edge(edge-tts, sends text to Microsoft's online speech service—get user consent first). - None: skip; the engine estimates time based on word count.
- Your own recordings: per-line files use
- Preview (optional):
preview ./my-video. Open the URL shown in the terminal in a browser; press Space to play. - Export:
render ./my-video. The output isout/<name>-<style>-<3x4|9x16|16x9>.mp4. Use--ratio allto export all three aspect ratios at once. Use--bgm music.mp3to add background music (default -18 dB, with fade-in and fade-out). - Verify:
verify ./my-video. It compares 6 frames against the rendered page frame-by-frame; PSNR must be ≥ 30 dB for all frames.
If --style or --ratio is omitted, the values are read from the style and ratio fields in story.json. If those are missing, defaults are grid-notebook and 3:4.
Rules for Writing story.json
- One thing per page: Each scene should have 1–3 narration sentences, ideally 5–15 seconds. If there's too much information, split into two pages.
- Screen text is a summary of the narration: Titles should be 6–14 characters; lists 3–5 items, one line each. Narration covers details; the screen shows only keywords, numbers, and conclusions.
- Maintain consistent order: The order of items in lists, cards, steps, and timelines must match the order they are mentioned in the narration. The engine will animate them in sync with the spoken words.
- Highlight keywords: Use
【】around words to emphasize on screen. When the narration says the word, it will be highlighted. If【】is also used in the narration, that word will be highlighted in the subtitles as well. - Manual timing when auto-matching fails: If automatic matching fails, add
xxAtto an element (e.g.,"titleAt": "leap year","at": "3.5s","at": "60%"). See docs/story.md for details. - Start and end: The first scene should use
cover; the last scene should useending. Insert achapterevery 3–5 pages as a section break; the header will display the current section name. - Images: Place images in the project's
assets/directory, and use relative paths like"image": "assets/xxx.png". - Narration sentences should not contain on-screen descriptions: The text in
saywill be used directly for TTS and subtitles.
Minimal example:
{
"title": "Compound Interest in 3 Minutes",
"name": "compound",
"series": "Finance 101",
"byline": "@your_handle",
"ratio": "9:16",
"style": "ivory-clay",
"scenes": [
{ "type": "cover", "kicker": "Finance 101", "title": "Compound Interest\nin 3 Minutes", "say": "How powerful is compound interest? Let me explain in three minutes." },
{ "type": "bignum", "value": "37.8", "unit": "times", "label": "Improve by 1% daily, after one year", "say": "If you improve by one percent every day, after a year you'll be 37.8 times better." },
{ "type": "list", "title": "Three ingredients for compound interest", "mode": "number",
"items": ["Principal", "Rate of return", "【Time】"],
"say": ["Compound interest needs three things: principal, rate of return,", "and most importantly, 【time】."] },
{ "type": "ending", "title": "Start as early as possible", "cta": "Follow me for the next video on DCA", "say": "So, start as early as possible." }
]
}
Full example at $SK/examples/leap-year/story.json (17 scenes, using most templates).
Template Quick Reference
| type | Usage | Main Fields |
|---|---|---|
cover | Cover page | kicker, title, sub, tags, image, meta |
chapter | Section page | num, title, sub, note |
statement | One-line quote / opinion | text (use \n for multiple lines) |
bignum | One big number | value, unit, label, note |
stats | 2–6 data cards | items[{value, unit, label, note, on}] |
list | Bullet points / numbered / check / cross list | mode (bullet, number, check, cross), items |
steps | Step-by-step with connecting arrows | items[{title, text}], dir |
cards | Concept / feature / option cards | items[{tag, title, text, icon}], cols |
compare | Left–right comparison | left, right{label, value, unit, points, win}, verdict |
bars | Horizontal bar chart | items[{label, value, unit, on}], scale: log |
timeline | Timeline | items[{time, text}], dir |
quote | Quotation | text, source |
code | Code, typed line by line | code, lang, file, hl |
formula | Formula (KaTeX) | tex, items |
image | Image / screenshot with optional bullet points | image, frame, cap, points |
ending | End page | title, tags, cta, byline |
custom | Custom HTML | html, css |
All templates can have kicker, title, sub, note, and say. Complete field documentation at docs/templates.md.
Styles
| Style | Name | Highlight | Demo Script | Best For |
|---|---|---|---|---|
grid-notebook | Grid Notebook | Grid notebook, left red margin notes, handwritten WenKai font, red pen circles and checks | Feynman Technique | Knowledge sharing, concept explanations, study methods, book notes |
rice-paper | Song-style Rice Paper | Song dynasty scroll painting, right-side vertical calligraphy, light ink distant mountains, black-line hand scroll, cinnabar seal | 24 Solar Terms | Traditional culture, humanities, history, solar terms, poetry |
color-block | Color-block Poster | Athletic poster: diagonal high-saturation color blocks, oversized cut-out text, sticker badges, four-color diagonal stripe transitions | First 5K Run | Fitness, opinion pieces, listicles, event announcements |
porcelain | Magazine Porcelain Blue | Blue-and-white porcelain lifestyle magazine: full-width header, double-line fret frame, double-page spread, dotted-line table of contents | How Blue-and-White Porcelain is Made | Culture, crafts, lifestyle, brand stories, interviews |
ivory-clay | Ivory Clay | AI product launch: alternating light/dark pages, Song-style large titles, chat interface cards, settings panel | Writing Good Prompts | AI tutorials, product introductions, tech explainers, productivity |
night-doc | Night Document | Late-night terminal & IDE: tab bar, line numbers, command prompt, git log, red/green diffs, split screen | Git Undo Commit | Tech tutorials, developer tools, AI programming, architecture |
newsprint | Newspaper Extra | Old newspaper front page: double-line header, multi-column vertical-line body, halftone wire photo, extra stamp | First Moon Landing | Historical stories, news analysis, trending topics, biographies |
manual | Assembly Manual | IKEA-style manual: bold black frames, large step numbers, technical line drawings, parts list, do/don't examples | Bike Tire Repair | How-to guides, DIY instructions, product setup, comparison |
scrapbook | Scrapbook | Travel journal: coil dot-grid paper, Polaroid and washi tape, torn ticket stubs, hand-drawn route, postmark stamp | Weekend in Xiamen | Travel guides, lifestyle, food reviews, product recommendations |
swiss-grid | Swiss Grid | 12-column grid with coordinate annotations, offset bold black titles, geometric data devices, full-page red/black chapter | Water on Earth | Data analysis, information design, brand introductions, industry trends |
comic | Comic Panels | Color webcomic: thick black frames, speech bubbles, explosive onomatopoeia, speed lines, halftone dots | A Package's Journey | Storytelling explainers, process breakdowns, fun facts, visual guides |
riso | Risograph | Two-color risograph: fluorescent pink + riso blue, misregistration, coarse halftone, recycled paper poster | First Music Festival | Music, performances, lifestyle, city guides, creative explainers |
receipt | Shopping Receipt | Thermal receipt: jagged tear edge, monospaced numbers, dotted-line itemization, red pen total, barcode | How Much a Cup of Coffee Costs in a Year | Budgeting, data interpretation, everyday science, list comparisons |
film | Film | 35mm sprocket holes, 2.39:1 widescreen mask, clapperboard, countdown leader, 24fps timecode | Why 24 Frames per Second | Film & TV explainers, cultural history, in-depth commentary, biographies |
metro | Metro Map | Color-coded line map, interchange stations, station name signs, carriage LED bar, exit yellow signs | Python Learning Roadmap | Learning paths, step-by-step tutorials, process breakdowns, knowledge guides |
Run python3 $SK/tools/mv.py styles anytime to list them. Each style's color palette, layouts, and design decisions are documented in styles/<style>/DESIGN.md.
Demo scripts: Located in styles/<style>/demo/. They are tailored to each style's theme and use as many of its exclusive layouts as possible. new --style copies this demo; showcase also uses it. Prices, step counts, etc., are for layout demo only—use verified numbers in your own videos.
Changing backgrounds and layouts: Most styles allow setting "bg" in a scene to switch between light/dark/background color. Some templates like cover support "layout" for layout variants. If omitted, the template auto-selects. All fields below are optional:
| Style | Fields |
|---|---|
grid-notebook | Scene margin for red margin note (false to disable); cover layout: "split" for left–right split |
rice-paper | story.seal: 2–4 characters, shown on cover and ending as a vermilion seal; bg: "ink" for ink-black page; cover layout: "center" for centered plaque; list layout: "scroll" (vertical scroll) or "rows" (horizontal rows); cards layout: "wheel" seasonal wheel, center text via centerLabel |
color-block | `bg: "ink" |
porcelain | story.masthead: publication name; story.column: column name; `bg: "light" |
ivory-clay | `bg: "light" |
night-doc | Scene accent: "#7CF3C8" to change accent color (auto-changes per chapter if omitted); cover layout: "compact" |
newsprint | story.masthead: newspaper name (defaults to series); `bg: "light" |
manual | `bg: "light" |
scrapbook | `bg: "light" |
swiss-grid | `bg: "light" |
comic | story.mascot: "box" enables the cardboard box character "Xiao Xiang"; scene `mood: "happy" |
riso | Scene motif: "festival" overlays stage, speaker, and crowd silhouettes; `bg: "light" |
receipt | story.masthead: receipt header; story.date: receipt date (e.g., "2026-03-08"; defaults to 2026-11-23); `bg: "wood" |
film | cover leaderNum: countdown leader number; layout: "split" for left–right split |
metro | story.lineCode: line code (max 3 characters); cover stations: array of station names (4–7, defaults from chapter and scene titles); chapter en: English station name; `bg: "light" |
To create a new style, copy an existing style directory and modify it. The interface is documented in docs/styles.md. Styles can completely rewrite any template's layout and can also register custom entry animations.
Aspect Ratios
| Ratio | Dimensions | Common Use |
|---|---|---|
3:4 | 1080×1440 | WeChat Official Accounts, Xiaohongshu |
9:16 | 1080×1920 | Douyin, Video Accounts, Kuaishou |
16:9 | 1920×1080 | Bilibili, YouTube, horizontal playback |
The same story.json can be exported to all three ratios directly. The 9:16 frame reserves about 560px at the bottom for platform buttons and title bar, with subtitles above. 16:9 automatically lays out lists, cards, and steps in multiple columns or rows. The character capacity differs per ratio—re-run snap after switching ratios.
Command Quick Reference
python3 $SK/tools/mv.py check Check environment
python3 $SK/tools/mv.py styles List styles
python3 $SK/tools/mv.py new <project> [--style S | --example leap-year] Create project
python3 $SK/tools/mv.py fonts [--style S | --all] Pre-download fonts
python3 $SK/tools/mv.py tts <project> [--engine say|edge] [--voice V] [--rate R]
python3 $SK/tools/mv.py timing <project> [--estimate | --lines DIR | --audio FILE | --words JSON --voice FILE]
python3 $SK/tools/mv.py snap <project> [--style S] [--ratio R] [--at 3.5,8]
python3 $SK/tools/mv.py compare <project> [--ratio R] [--styles a,b] [--scene N]
python3 $SK/tools/mv.py showcase [--ratio R] [--styles a,b] [--pages 3] [--out DIR]
python3 $SK/tools/mv.py preview <project> [--style S] [--ratio R] [--port 8765]
python3 $SK/tools/mv.py render <project> [--style S] [--ratio R|all] [--workers N] [--fps 30] [--bgm FILE] [--bgm-db -18]
python3 $SK/tools/mv.py verify <project> [--style S] [--ratio R]
Output locations:
| Command | Output |
|---|---|
snap | out/sheet-<style>-<ratio>.png (overview), out/snap/<style>-<ratio>/sNN.png (per-page) |
compare | out/compare-<ratio>.png, out/compare/<ratio>/<style>.png |
showcase | <DIR>/showcase-<ratio>.png (one row per style: cover + content page), <DIR>/showcase-covers-<ratio>.png, <DIR>/showcase-<style>-<ratio>.png |
tts / timing | audio/lines/NNN.wav, audio/voice.wav, timing.json |
render | out/<name>-<style>-<ratio>.mp4 |
verify | out/verify/ comparison frames |
Important Notes
- After modifying
say, re-runttsortiming. Estimation mode automatically re-estimates. For audio-based timing, an error will be raised if the number of sentences doesn't match. - For
timing --lines, the number of audio files must match the number ofsaysentences, sorted by the numeric part of the filenames. Keep your own recordings in a separate directory likerecordings/—do not place them inaudio/lines/, asttsclears that directory on each run. - Both
timing --audioandtiming --wordsrequire at least onesayper scene.--audiosplits by pauses; if pauses are unclear, use per-line recordings or word-level timestamps for better accuracy. - By default,
renderuses(CPU cores − 2)parallel processes (max 8). If your machine is slow, reduce with--workers. - Placing
custom.cssorcustom.jsin the project directory will load them after the style, allowing fine-tuning without modifying the skill itself. - Do not include on-screen descriptions, parenthetical notes, or URLs in
say—they will be spoken aloud.