Communitygithub.com

lhg-plugs/lhg-motion-video

Pure code rendering engine methodology: seek(t) deterministic time function, static frame probe, sub-frame motion blur, headless browser frame-by-frame rendering. Use it when writing rendering code.

What is lhg-motion-video?

This skill, lhg-mv-engine, introduces a deterministic, code-driven approach to motion video rendering for AI developers. It replaces traditional timeline-based editing with a pure JavaScript function `seek(t)` that returns the exact visual state for any given time, ensuring reproducibility and enabling seamless AI collaboration. The methodology emphasizes a 'static frame first' workflow, where 3–5 key frames are rendered as probes for user approval before a full render, drastically reducing rework. It supports headless browser rendering (e.g., Puppeteer) and ffmpeg for frame assembly, with features like sub-frame motion blur for smooth high-speed animations and a strict single-source-of-truth `film.json` configuration. The skill targets developers building programmatic animations, motion graphics, or any video content that needs precise version control, cost efficiency, and AI-friendly iteration—avoiding common anti-patterns like linear easing, external assets, or stateful frame dependencies.

Works with✓Claude Code~Codex CLI~Cursor
npx skills add https://github.com/lhg-plugs/lhg-motion-video/tree/HEAD/skills/lhg-mv-engine

Ask in your favorite AI

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

Documentation

lhg-mv-engine: Pure Code Rendering Engine

Goal: The entire film is a time function; the same input always produces the same frame. Core Discipline: seek(t) is the only source of truth; inspect static frames first, then render the full sequence.

1. When to Use

  • Deciding "how to write this film": Read sections 3.1–3.2 to define the approach
  • Writing rendering code: Follow the seek(t) pattern from section 3.3
  • Before rendering: Generate probe static frames per section 3.4
  • Animation looks blurry/jittery: Check section 3.5 on motion blur and performance

2. Input / Output

Input: A finalized brief.md (including storyboard table and beat grid).

Output: film.json (width/height/fps/duration/scenes—the single source of truth) + rendering HTML (containing seek(t)) + probe/ static frames + full frame sequence.

3. Step-by-Step Methodology

3.1 Why Pure Code Instead of Editing Software

DimensionPure Code (HTML + Headless Browser + ffmpeg)Editing Software
Determinismseek(t) function; fixing scene A doesn't affect BManual timeline dragging, prone to accidental changes
CostFree (browser + ffmpeg are open source)Subscription / purchase fees
AI Collaboration"Make transition 0.2s faster" = change a numberMust reopen project and adjust manually
Version Controlgit diff shows logic changes for every frameBinary project files make diff meaningless

In a word: Motion films are computed, not dragged.

3.2 film.json: The Single Source of Truth

{
  "title": "New Product Launch Animation",
  "width": 1920, "height": 1080, "fps": 30, "duration": 60,
  "caption_safe_margin": 0.9,
  "scenes": [
    {"name": "Opening", "duration": 3, "transition": "dissolve", "desc": "Logo entrance"}
  ]
}

Discipline: Width, height, fps, and duration are defined once in film.json. The rendering HTML and export script both read from it (or manually align; the audit script will verify).

3.3 seek(t): The Whole Film Is a Function

// Pseudocode: time t (seconds) → visual state
function seek(t) {
  const scene = sceneAt(t);        // Which scene does t fall in?
  const lt = t - scene.start;      // Local time within the scene
  drawBackground(lt);
  drawTitle(easeOutCubic(lt / 1.2)); // 1.2-second entrance animation
  if (lt > scene.duration - 0.5) drawTransition(lt); // transition
}

Three Ironclad Rules:

  1. t is the only input: The visual state is determined solely by t. Never accumulate from "previous frame's state" (otherwise fixing one frame requires re-rendering the entire film).
  2. Explicit easing functions: All animations must specify their easing (easeOutCubic for entrance, easeInOut for transitions). No linear hard cuts—linear animation is the #1 source of "AI-generated" motion feel.
  3. Three-phase motion language: Every animated element follows "anticipation (0.2s buildup) → primary motion → settle (0.3s overshoot bounce)", giving the film an instant "breath" feel.

3.4 Static Frames First: Probe Workflow

  1. Render 3–5 keyframe static frames into probe/: Must include the opening tone frame, climax memory frame, and closing action frame.
  2. User confirms: composition, color scheme, typeface, font size. Changing at this step = changing a few numbers; changing after full render = hours of re-rendering.
  3. Full render proceeds only after confirmation. A hook will warn you if you write a render file without a probe/ directory.

3.5 Motion Blur and Performance

  • Sub-frame blending: Fast-moving elements appearing blurry is physically correct. For fast elements, sample 2–4 sub-time points within a frame and blend them to eliminate the "teleporting" effect.
  • Disable blur at hard cuts: No blending for 1 frame before and after a transition cut (otherwise the cut becomes a "blur point").
  • Performance: If a single frame takes >200ms to render, optimize (lower probe resolution / reduce elements). Before full render, estimate time as "number of frames × per-frame cost" and report it.

3.6 Asset Discipline

  • All assets local: assets/ directory. Any external links must be downloaded. An external 404 = render failure; a changed external asset = a changed film.
  • File names: Lowercase English with hyphens (e.g., logo-main.png). Spaces/Chinese characters are an escaping nightmare in ffmpeg.
  • Large files: Pre-compress video assets to render resolution. Don't put 4K source footage into a 1080p timeline.

3.7 Multi-Resolution Adaptation: Single Source, Multiple Outputs

  1. Landscape master first: Start with a 1920x1080 landscape version. The portrait version re-layouts the storyboard—it's not a simple crop.
  2. Why not crop: Cropping cuts subtitles and visual subjects. Portrait's information density is completely different from landscape; the storyboard must be rewritten.
  3. Reuse strategy: Reuse seek(t) logic, adjust layout parameters per aspect ratio. In film.json, create a separate entry for each aspect ratio, and the audit script checks each one.

4. Anti-Patterns

  • ❌ Dragging on the timeline and exporting—changing one word means redoing everything; loses all AI collaboration advantages
  • ❌ All animations linear—the source of "PPT-slide feel"; easing functions are free
  • ❌ Skipping probes and going straight to full render—rework is billed by the minute
  • ❌ Visual state depends on previous frame—fixing one frame requires re-rendering the entire film; destroys determinism
  • ❌ Using external assets—"It works on my machine" is the most expensive five words in motion design

5. Frequently Asked Questions

Q: Must I use a headless browser? Can I use canvas screen recording? A: That's fine, but ensure a constant frame rate. The headless browser's value is "frame-by-frame, reproducible"; screen recording is fast. Use screen recording for probes, use frame-by-frame for full render.

Q: What about 3D elements? A: Write WebGL into the same seek(t) system—time is still the only input. Don't introduce a second timeline just for 3D.

Q: Rendering too slow? A: Three quick fixes: lower probe resolution (540p is enough for composition checks), reduce sub-frame samples, or pre-render static backgrounds as a single image. Always report estimated cost before starting.

Q: Font rendering differs across machines? A: Put font files in assets/ and reference them locally. Never rely on system fonts. Even a slight weight difference changes the slogan's personality.

Q: I want to add random particle effects in seek(t)? A: Random = not deterministic. Use seeded random with a seed written into film.json. Same input, same frame—ironclad rule.

Q: Color difference between probe static frames and final output? A: Probes and full render use the same rendering code and the same color configuration. Probes are just lower resolution + fewer frames—don't use a different pipeline.

Q: seek(t) is too verbose to write? A: Extract common functions: a scene scheduler, an easing library, and a transition library—each in its own file. By the third scene, writing a new scene becomes filling in a template.

6. Self-Check and Feedback

Render plan self-check:

  1. Are the four elements of film.json complete and consistent with brief?
  2. Does seek(t) depend only on t? Are easing functions explicit?
  3. Does probe/ have 3–5 keyframes and have they been confirmed by the user?
  4. Are all assets localized and file names compliant?
  5. Has render time been estimated?

Standard smoke test: Run the audit script against fixtures/film-good and confirm 28 rules pass with zero blockers; break one rule (e.g., canvas size) and confirm the corresponding rule is caught.

Feedback channel: Submit to https://github.com/lhg-plugs/lhg-motion-video/issues with title [QC] <one-sentence issue>, and body containing "Input → Wrong output → Expected output".

Produced by: Liu Hongguang

This skill is produced by the real-person IP "Liu Hongguang" (Hefei, Anhui) and belongs to lhg-skills.

  • GitHub homepage: https://github.com/lhg-skills — All skills open-sourced here, welcome to star
  • WeChat Video Channel: Search "刘洪光实名上网"
  • WeChat: lhgsmsw

Individual skills in this repo

This repo contains 3 individual skills — each has its own dedicated page.

Related Skills