Communitygithub.com

z-motion-video

Turn a script, article, or set of key points into an animated explainer video (MP4). Write a story.json, pick a template and a few lines of narration per scene, and the visual elements will animate in sync with keywords in the narration. Subtitles, page numbers, progress bars, and transitions are all auto-generated.

What is z-motion-video?

z-motion-video is a powerful AI agent skill that transforms written scripts into polished animated explainer videos in MP4 format. It is designed for developers and content creators who want to quickly produce motion graphic videos for knowledge sharing, product introductions, tutorials, data analysis, opinion pieces, book reviews, and lifestyle content. The skill works by parsing a `story.json` file—where each scene selects a template, defines on-screen text, and provides narration—and then generates an HTML/CSS animation, captures it frame by frame, and assembles the MP4. It supports three aspect ratios (3:4, 9:16, 16:9) and offers 15 built-in visual styles (e.g., grid notebook, rice paper, color-block poster, magazine porcelain, ivory clay, night terminal, newspaper extra, assembly manual, scrapbook, Swiss grid, comic panels, risograph, shopping receipt, film, metro map), each with its own layout design and a sample demo script. Narration can be generated via macOS `say` or Microsoft `edge-tts`, or you can supply your own audio files with word-level timestamps. The tool exports all frames of the video simultaneously, ensuring consistent frames throughout, and supports multi-process parallel export and frame-by-frame verification. Commands are available for checking the environment, creating a new project, previewing, rendering, and verifying the output.

Works with~Claude Code~Codex CLI~Cursor
npx skills add https://github.com/tjxj/z-motion-video/tree/HEAD

Ask in your favorite AI

Open a new chat with this agent skill pre-loaded.

Documentation

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.

  1. 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 showcase to generate an overview image of all styles' demo scripts. To see the same script in all styles, run compare with the user's script.
  2. 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 --style is omitted, it copies the leap-year example.
  3. Write story.json: Split the script into scenes, pick a template for each scene (see quick reference below), write on-screen text, and say narration lines. See the next section for writing rules.
  4. Check layout with snapshots: python3 $SK/tools/mv.py snap ./my-video. Open out/sheet-<style>-<ratio>.png for an overview. Address all ⚠ warnings in the terminal (content overflow, scaled to xx%, title too long) by deleting text, splitting scenes, or switching templates.
  5. 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 uses timing --audio voice.wav; word-level timestamps use timing --words words.json --voice voice.wav.
    • Machine TTS: tts ./my-video (macOS say, 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.
  6. Preview (optional): preview ./my-video. Open the URL shown in the terminal in a browser; press Space to play.
  7. Export: render ./my-video. The output is out/<name>-<style>-<3x4|9x16|16x9>.mp4. Use --ratio all to export all three aspect ratios at once. Use --bgm music.mp3 to add background music (default -18 dB, with fade-in and fade-out).
  8. 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 xxAt to 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 use ending. Insert a chapter every 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 say will 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

typeUsageMain Fields
coverCover pagekicker, title, sub, tags, image, meta
chapterSection pagenum, title, sub, note
statementOne-line quote / opiniontext (use \n for multiple lines)
bignumOne big numbervalue, unit, label, note
stats2–6 data cardsitems[{value, unit, label, note, on}]
listBullet points / numbered / check / cross listmode (bullet, number, check, cross), items
stepsStep-by-step with connecting arrowsitems[{title, text}], dir
cardsConcept / feature / option cardsitems[{tag, title, text, icon}], cols
compareLeft–right comparisonleft, right{label, value, unit, points, win}, verdict
barsHorizontal bar chartitems[{label, value, unit, on}], scale: log
timelineTimelineitems[{time, text}], dir
quoteQuotationtext, source
codeCode, typed line by linecode, lang, file, hl
formulaFormula (KaTeX)tex, items
imageImage / screenshot with optional bullet pointsimage, frame, cap, points
endingEnd pagetitle, tags, cta, byline
customCustom HTMLhtml, css

All templates can have kicker, title, sub, note, and say. Complete field documentation at docs/templates.md.

Styles

StyleNameHighlightDemo ScriptBest For
grid-notebookGrid NotebookGrid notebook, left red margin notes, handwritten WenKai font, red pen circles and checksFeynman TechniqueKnowledge sharing, concept explanations, study methods, book notes
rice-paperSong-style Rice PaperSong dynasty scroll painting, right-side vertical calligraphy, light ink distant mountains, black-line hand scroll, cinnabar seal24 Solar TermsTraditional culture, humanities, history, solar terms, poetry
color-blockColor-block PosterAthletic poster: diagonal high-saturation color blocks, oversized cut-out text, sticker badges, four-color diagonal stripe transitionsFirst 5K RunFitness, opinion pieces, listicles, event announcements
porcelainMagazine Porcelain BlueBlue-and-white porcelain lifestyle magazine: full-width header, double-line fret frame, double-page spread, dotted-line table of contentsHow Blue-and-White Porcelain is MadeCulture, crafts, lifestyle, brand stories, interviews
ivory-clayIvory ClayAI product launch: alternating light/dark pages, Song-style large titles, chat interface cards, settings panelWriting Good PromptsAI tutorials, product introductions, tech explainers, productivity
night-docNight DocumentLate-night terminal & IDE: tab bar, line numbers, command prompt, git log, red/green diffs, split screenGit Undo CommitTech tutorials, developer tools, AI programming, architecture
newsprintNewspaper ExtraOld newspaper front page: double-line header, multi-column vertical-line body, halftone wire photo, extra stampFirst Moon LandingHistorical stories, news analysis, trending topics, biographies
manualAssembly ManualIKEA-style manual: bold black frames, large step numbers, technical line drawings, parts list, do/don't examplesBike Tire RepairHow-to guides, DIY instructions, product setup, comparison
scrapbookScrapbookTravel journal: coil dot-grid paper, Polaroid and washi tape, torn ticket stubs, hand-drawn route, postmark stampWeekend in XiamenTravel guides, lifestyle, food reviews, product recommendations
swiss-gridSwiss Grid12-column grid with coordinate annotations, offset bold black titles, geometric data devices, full-page red/black chapterWater on EarthData analysis, information design, brand introductions, industry trends
comicComic PanelsColor webcomic: thick black frames, speech bubbles, explosive onomatopoeia, speed lines, halftone dotsA Package's JourneyStorytelling explainers, process breakdowns, fun facts, visual guides
risoRisographTwo-color risograph: fluorescent pink + riso blue, misregistration, coarse halftone, recycled paper posterFirst Music FestivalMusic, performances, lifestyle, city guides, creative explainers
receiptShopping ReceiptThermal receipt: jagged tear edge, monospaced numbers, dotted-line itemization, red pen total, barcodeHow Much a Cup of Coffee Costs in a YearBudgeting, data interpretation, everyday science, list comparisons
filmFilm35mm sprocket holes, 2.39:1 widescreen mask, clapperboard, countdown leader, 24fps timecodeWhy 24 Frames per SecondFilm & TV explainers, cultural history, in-depth commentary, biographies
metroMetro MapColor-coded line map, interchange stations, station name signs, carriage LED bar, exit yellow signsPython Learning RoadmapLearning 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:

StyleFields
grid-notebookScene margin for red margin note (false to disable); cover layout: "split" for left–right split
rice-paperstory.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"
porcelainstory.masthead: publication name; story.column: column name; `bg: "light"
ivory-clay`bg: "light"
night-docScene accent: "#7CF3C8" to change accent color (auto-changes per chapter if omitted); cover layout: "compact"
newsprintstory.masthead: newspaper name (defaults to series); `bg: "light"
manual`bg: "light"
scrapbook`bg: "light"
swiss-grid`bg: "light"
comicstory.mascot: "box" enables the cardboard box character "Xiao Xiang"; scene `mood: "happy"
risoScene motif: "festival" overlays stage, speaker, and crowd silhouettes; `bg: "light"
receiptstory.masthead: receipt header; story.date: receipt date (e.g., "2026-03-08"; defaults to 2026-11-23); `bg: "wood"
filmcover leaderNum: countdown leader number; layout: "split" for left–right split
metrostory.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

RatioDimensionsCommon Use
3:41080×1440WeChat Official Accounts, Xiaohongshu
9:161080×1920Douyin, Video Accounts, Kuaishou
16:91920×1080Bilibili, 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:

CommandOutput
snapout/sheet-<style>-<ratio>.png (overview), out/snap/<style>-<ratio>/sNN.png (per-page)
compareout/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 / timingaudio/lines/NNN.wav, audio/voice.wav, timing.json
renderout/<name>-<style>-<ratio>.mp4
verifyout/verify/ comparison frames

Important Notes

  • After modifying say, re-run tts or timing. 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 of say sentences, sorted by the numeric part of the filenames. Keep your own recordings in a separate directory like recordings/—do not place them in audio/lines/, as tts clears that directory on each run.
  • Both timing --audio and timing --words require at least one say per scene. --audio splits by pauses; if pauses are unclear, use per-line recordings or word-level timestamps for better accuracy.
  • By default, render uses (CPU cores − 2) parallel processes (max 8). If your machine is slow, reduce with --workers.
  • Placing custom.css or custom.js in 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.

Related Skills