Communitygithub.com

HycJack/edu-explainer-video-skill

Turn a maths / physics problem into an animated explainer video where the figure and the narration stay in lockstep. Use when asked to make a 讲解视频, 解题视频, explainer video, animated solution, or animated walkthrough for a problem — 立体几何, 解析几何, 函数与导数, 数列, 概率, 物理受力, or any problem with a diagram. Silent by default; when the user wants a voice, generate edge-tts narration with frame-accurate sync, and ship an interactive HTML stepper (with/without audio) alongside. The framework lives in assets/framework. Read this before writing a single line of content.

edu-explainer-video-skill 是什么?

edu-explainer-video-skill is a Claude Code agent skill that turn a maths / physics problem into an animated explainer video where the figure and the narration stay in lockstep. Use when asked to make a 讲解视频, 解题视频, explainer video, animated solution, or animated walkthrough for a problem — 立体几何, 解析几何, 函数与导数, 数列, 概率, 物理受力, or any problem with a diagram. Silent by default; when the user wants a voice, generate edge-tts narration with frame-accurate sync, and ship an interactive HTML stepper (with/without audio) alongside. The framework lives in assets/framework. Read this before writing a single line of content.

兼容平台~Claude Code~Codex CLI~Cursor
npx skills add HycJack/edu-explainer-video-skill

在你喜欢的 AI 中提问

打开一个已预加载此 Agent Skill 的新对话。

文档

Problem explainer videos

A framework where a problem is a data file, not a component. Give it chapters, steps and the numbers each step drives the figure to; a compiler works out every frame number and every transition.

The one hard rule

No frame numbers anywhere in a content file. No from, no durationInFrames, no interpolate(frame, …).

A step declares only two things: the words on screen, and what changed on the figure.

{
  id: "ad1",
  eyebrow: "Proof of Perpendicularity · Step 2",
  heading: "Compute vector AD₁ and dot product",
  params: { "aux:B1E": 1, "aux:AD1": 1 },   // ← only what changed
  lines: [
    { mark: "5", node: <M size={33}><Vec><Nm>A</Nm><Nm sub="1">D</Nm></Vec> = <Nm sub="1">D</Nm> − <Nm>A</Nm></M> },
  ],
}

The compiler derives: how long the step runs (from how many lines it has), how the figure travels from the previous step to this one, and the total runtime.

params is incremental. Anything you don't mention is inherited from the previous step. So "turn off the CD highlight, turn on AD₁ and B₁E" is { "aux:CD": 0, "aux:AD1": 1, "aux:B1E": 1 } — never a full state dump.

Check the environment first — always

This pipeline shells out to three things npm cannot install for you. A render that reaches the last step and discovers one missing has burnt several minutes for nothing, so check before writing content:

npm run doctor              # the tools every render needs
npm run doctor -- --voice   # adds the ones only narration needs

It names each missing tool, prints its official download page, and exits non-zero. Where to send the user:

MissingGet it from
ffmpeg / ffprobehttps://ffmpeg.org/download.html (both files in the same archive; extract and add the directory to PATH)
Node.js (includes npm, 18+)https://nodejs.org/en/download
Python 3https://www.python.org/downloads/
edge-ttsAfter installing Python: pip3 install edge-tts; homepage https://github.com/rany2/edge-tts

The rules that follow from this:

  • Tell the user what is missing and where to get it, then stop. Report the list from doctor verbatim.
  • Do not install system tools for them, not even with a package manager. These are machine-level installs with their own admin prompts and licence decisions; quietly running brew/apt on someone's laptop is worse than asking.
  • Do not carry on past a failed check. Everything downstream assumes ffmpeg and ffprobe sit on PATH — the muxer in particular fails halfway through a file it has already written.
  • Not having edge-tts does not block a silent film. Say which dependency blocks which deliverable: no ffmpeg → no video at all; no edge-tts → no voice. Then ask, rather than deciding for them.

npm run check and npm run tts run the doctor for you (precheck / pretts hooks), so a normal build cannot skip it.

Setup

npm run doctor                            # pre-check: clearly state what's missing
cp -r <skill>/assets/framework ./edu-explainer   # framework is read-only here
cd edu-explainer
npm install
npx remotion browser ensure                   # one-time Chrome download

npm install pulls Remotion. The fonts are already vendored in public/fonts. If doctor failed, hand the list to the user and wait — do not proceed on the assumption it can be sorted out later.

Adding a problem

  1. Pick a figure. Check assets/framework/src/framework/builders/ first:

    BuilderDraws
    cuboid.tsRectangular / cubic prism, point/line/plane, vectors and dot product
    conic.tsConic sections: ellipse, chords, foci
    pyramid.tsPyramids: sphere center, cross-section, skew lines
    rotate.tsSolids of revolution and invariants during rotation
    river.tsShortest path on a plane (general's drinking problem type)
    mechanics.tsPhysics forces: blocks, inclined planes, ice/rough surfaces, springs
    circle.tsCircles and triangles: incenter, angle bisector, arc midpoint, similar triangles
    graph.tsCoordinate system and function graphs: tangent, secant, integral shading, extrema
    numberline.tsNumber line and solution sets: interval sliding, open/closed endpoints
    triangle.tsGeneral triangles: median, altitude, angle bisector, midsegment, A-shape similarity
    quad.tsQuadrilateral family: parallelogram → rectangle → rhombus → trapezoid continuous morph
    twocircles.tsTwo-circle positional relationships: five types changing continuously with center distance
    sphere.tsSphere and cross-section: section circle moves along axis, r² = R² − h² visible in real time
    vector.tsPlane vectors: parallelogram law, orthogonal decomposition, λ scaling
    stats.tsStatistical charts: bar chart, frequency polygon, moving average line
    optics.tsGeometric optics: reflection, refraction (real-time Snell), total internal reflection
    kinematics.tsKinematics: v-t / s-t graphs, area = displacement, pursuit/encounter
    projectile.tsProjectiles: horizontal / oblique launch, velocity decomposition, trajectory, range
    lever.tsLevers: fulcrum, effort/resistance, lever arm, F₁l₁ = F₂l₂
    pulley.tsPulley systems: fixed/movable pulleys, number of rope segments n, mechanical advantage G/n
    buoyancy.tsBuoyancy: displaced fluid, Archimedes' principle, float/sink conditions
    circuit.tsElectric circuits: power source / bulb / resistor / meter, series/parallel, variable resistor
    atom.tsAtomic structure: nucleus, electron shell configuration, ion electron gain/loss
    molecule.tsMolecules: ball-and-stick model, covalent bonds, Lewis electron dot (water / sodium chloride)
    lab.tsLab apparatus: iron stand / alcohol burner / test tube / delivery tube / gas collection bottle / funnel, combinable
    solubility.tsSolubility curves: multiple curves, temperature slider, saturation points

    Each builder's parameter keys are documented in its own file header comment. Real rendered results are in references/gallery/*.png — each image is a real rendered frame from the corresponding builder.

    If none matches, write one — see references/building-figures.md.

  2. Write the content file in src/content/<id>.tsx, call registerContent at module scope, and import it from src/index.ts.

  3. Register the composition in src/Root.tsx:

<Composition
  id="my-problem"
  component={ProofVideo}
  width={1920} height={1080} fps={30}
  durationInFrames={filmFrames(getContent("my-problem"), FPS)}   // cards included
  defaultProps={{ contentId: "my-problem" }}
/>

filmFrames, never compile(...).total — unless you pass the narration: compile(content, narration, FPS).total is the whole film, cards included (the compiler lays the cards out as _statement / _outro pseudo-steps). filmFrames(content, FPS) is the narration-less spelling of the same call. Timing a narrated film without its narration clips the last sentence (references/lessons-learned.md #5).

Then npm run render:my-problem.

ProofVideo takes a content id, never a content object: a Composition's defaultProps are serialised into the bundle and a Content carries React nodes and functions that would not survive the trip.

Symbol system

Chinese textbooks write three kinds of thing differently, and mixing them up is the most common way to make a maths video look wrong. Use the right component:

ComponentStands forLooks like
Nmpoint / segment nameupright: B₁E, AD₁, 平面 B₁AE
Vecvectoroblique + arrow: EB₁, n
Vvitalic scalara, t, k
Many maths runsets size and colour
Tupa tuple( a/2, 1, 0 )

AD₁ set in Vv reads as a·d₁. That single mistake costs more credibility than any animation bug.

Before you render anything

Never go straight to the full render. Both expensive mistakes caught so far were invisible until late.

npm run check                              # charset gate + tsc
npx remotion still my-problem out/f.png --frame=420

Look at the still. Then sample the whole timeline:

npx remotion render my-problem out/frames --frames=0,120,300,480,700 --image-format=png

Details in references/lessons-learned.md.

Fonts

Chinese uses Google Fonts text= subsets vendored in public/fonts — two variable woff2 files, ~76 KB and ~100 KB instead of 10 MB. Rendering never touches the network.

  • After editing any copy, run npm run fonts. It scans the sources for every non-ASCII character and rebuilds the subset.
  • npm run check fails if the sources contain a character the subset lacks. Missing glyphs render as tofu boxes mid-video, so this gate is worth running.
  • Subsets have no italic. The oblique on maths variables is synthesised by the browser, which is right for single letters and wrong for running prose.

Voice it — TTS narration (edge-tts)

Ask first. Narration triples the runtime and is a different deliverable, so offer it as a question before doing it — "Would you like narration?" — and default to silent when the user does not answer. When they do want it:

narration/<id>.json ──▶ npm run tts ──▶ public/narration/<id>/*.mp3 (trimmed)
                                     └▶ src/narration/<id>.json (measured)
                                            │
content + measured ──▶ compile ──▶ timeline (each sentence's appearance frame)
                                            │
        render (silent, but at narration duration) ──▶ mux ──▶ verify ──▶ out/<id>-voiced.mp4

The one rule: the timeline is fitted to the audio, never the reverse. The compiler reads measured durations (src/narration/<id>.json), so the picture and the voice are two consumers of one set of numbers and cannot drift.

  1. Write narration/<id>.json — one entry per step id, one string per on-screen line, counts must match exactly (npm run check gates this; a mismatch shifts every later sentence against its own audio without erroring). Write speakable Chinese: ½∠A → 二分之一角A, x² → x的平方, ∽ → 相似于. voice_id picks the edge-tts voice (zh-CN-XiaoxiaoNeural is a good teaching default), rate its pace (-4% slightly slow), gapAfterLineSec the silence between lines.
  2. npm run tts -- <id> — synthesises per line with edge-tts (no API key; install with pip install edge-tts, or point TTS_BIN at it), trims the ~0.2 s of leading silence every clip ships with, then measures with ffprobe. Trim before measuring: an untrimmed pad puts the text on screen a fifth of a second before the voice, outside the 45–80 ms humans tolerate. Re-runs are safe with --skip-existing.
  3. npm run check:narration -- <id> — the count gate.
  4. npm run timeline -- <id> — snapshot the compiled schedule to out/.audio/<id>-timeline.json. The muxer reads this file instead of recompiling, so two processes cannot disagree.
  5. Render the silent video at the narrated length to out/.audio/<id>-silent.mp4 — not to out/<id>.mp4, which is the short silent cut. remotion render <id> already picks up the narration from src/narration/, so the same command produces the long cut.
  6. npm run mux -- <id> — per-line adelay onto one track (amix with normalize=0, then apad), -c:v copy into the video.
  7. npm run verify:sync -- <id> — mechanical check, sampled across the runtime: speech energy must jump out of the gap at each cue (~−91 dB → ~−16 dB) and the panel must change against its own control. Ship the numbers, not "looks in sync".

One command does 3–7: npm run voiced:circle (rename per problem).

Report the measured duration and say the voice id. Speech needs the room — a 46 s silent cut becoming 3 min 50 s of narration is correct, not a bug. To shorten it, cut sentences; never push the rate past natural.

Also ship it as something clickable

npm run player         # -> out/player/  (bundle + fonts + voice.m4a)
npm run serve:player   # -> http://localhost:8080/  (Range-capable server)

src/player/App.tsx renders the same ProofVideo with remotion aliased, at bundle time, to src/player/runtime.tsx — a ~250-line Remotion-compatible runtime. Nothing is redrawn for the web, so the stepper cannot drift from the MP4. It offers two cuts of the same problem: 带配音 (narrated, audio is the clock) and 不带配音 (silent, shorter because nothing waits on a voice) — a mode, not a mute button.

Rules baked into the player that are easy to get wrong:

  • Audio leads; the frame follows. Never a wall-clock loop correcting the audio toward itself — that replays the same sentence whenever rendering lags.
  • Scale the 1920×1080 composition as a whole (transform: scale), never re-layout it with CSS.
  • The server must support HTTP Range or the audio cannot be seeked and the player looks broken while the page is innocent. python3 -m http.server does NOT; use npm run serve:player.
  • Jumping lands on the step's first spoken line, not its first frame — the panel fades in, so from + 1 is an empty box.

Deliverables

H.264 / yuv420p / CRF 18, 1920×1080, 30 fps. Silent unless narration was asked for; then also ship out/<id>-voiced.mp4 with the verification numbers, and state the voice id. The interactive player is a third deliverable when the user wants something clickable — out/player/ plus the serve command.

References

  • references/content-api.md — the full Content type, every field
  • references/building-figures.md — writing a new figure builder
  • references/lessons-learned.md — the four bugs that hit during the build, and the rule each one produced

相关技能