kadian: autonomous beat-sync video production
You cannot hear the music and you cannot see which frame changes without measuring. Every timing decision guessed from a nominal BPM number ("120 BPM", "beat 3") drifts. kadian gives you the full autonomous loop — listen, conform music, scan source clips, pre-check plan, assemble or code-render, audit with numbers and diagnostic frames, and fix until clean — so the user receives a finished beat-synced video without having to act as a manual editor.
Setup
kadian --version || pip install git+https://github.com/A1mL3ssNoob/kadian.git # or: pip install .
ffmpeg -version # must be on PATH
If installed as a Claude Code plugin, the package ships with it: pip install "${CLAUDE_PLUGIN_ROOT}".
Output is English or Chinese (--lang en|zh, or KADIAN_LANG). Every command accepts --json PATH (or - for stdout).
The autonomous loop
1. Listen once (brief)
Start with a single compact musical map before designing anything:
kadian brief music.wav --fps 30 --json brief.json
This reports tempo (to 0.001 BPM), stability, warnings (tempo_moves, low_bar_line_confidence, maybe_half_tempo), bar-by-bar sections, drops, breaks / pre-drop cutouts, and tier-1 structural anchors. Need the full beat grid or every attack? Run kadian beats music.wav --fps 30 --json beats.json or kadian hits music.wav --tier 2 --fps 30 --json hits.json (pass --stems DIR if you separated stems with kadian stems).
2. Conform music to target duration (conform)
AI-generated music almost never matches your target video length. Never hand-write ffmpeg acrossfade chains (they eat fade duration and shift every downstream beat). Cut strictly by whole bars with pre-downbeat equal-power crossfades and automatic grid re-verification:
kadian conform music.wav --duration 20 --out soundtrack.wav # auto-pick whole bars keeping intro & drop
kadian conform music.wav --bars "1-4,7-12" --out soundtrack.wav # or explicit bar ranges
Always confirm post-splice check: ... -> grid OK, then measure soundtrack.wav for all downstream planning.
3. Scan source clips if editing footage / AI-generated clips (clip)
Before cutting live footage or AI-generated video clips (Veo, Kling, Seedance, etc.), scan each clip:
kadian clip clip1.mp4 --fps 30 --json clip1.json
Use active bounds to skip dead static/black head frames, avoid crossing internal_cuts (common hidden cuts inside AI clips), and pick action_peaks (align_source_t) when you want an in-clip movement (jump, turn, punch) to land directly on a beat.
4. Draft and pre-check the plan BEFORE rendering (plan)
Build plan.json exclusively from real measured hits (never BPM arithmetic). You can draft a cue skeleton first and edit it to fit your script:
kadian plan soundtrack.wav --fps 30 --pace medium --out plan.json # or --clips 10
Then validate plan.json in 0.5 seconds before spending minutes rendering:
kadian plan soundtrack.wav --check plan.json --fps 30 --strict
# Or auto-snap minor timing slips onto real hits:
kadian plan soundtrack.wav --check plan.json --fps 30 --snap plan.json
Only start rendering once plan --check --strict passes (or every remaining warning is intentional). Full format: plan-format.md.
5. Build the video
- Footage / AI clips / image montage: write a
shots.jsonshotlist and letkadian assembleproduce a frame-accurate CFR MP4 + exact matchingplan.jsonin one shot (see code-video.md):kadian assemble shots.json --music soundtrack.wav --fps 30 --out out.mp4 --plan-out plan.json - Motion graphics / UI / lyric video (Remotion, HTML, scripts): load
beats.json/plan.jsondirectly into code, round once (Math.round(seconds * fps)), and put the biggest visual change on the beat frame (ease out after it). See code-video.md.
6. Audit the render and self-repair until clean (check --strict --sheets)
Always verify the rendered file with its own muxed sound:
kadian check out.mp4 --plan plan.json --music soundtrack.wav --strict --sheets diag --json check.json
- Every problem in
check.jsoncarries a machine-actionablefix(action,target_frame,delta_frames,target_t). --strictexits1on any defect: A/V sync offset (>= 35 ms), cut off by >= 1 frame, ease-in animation peaking early, off-beat moment, heavy moment on a light hit, missed drop/section start, unplanned off-beat jump, too-short crowded cuts (< 250 ms), hierarchy inversion (drop weaker than ordinary cuts), or monotonous mechanical beat-pulsing.- Inspect the diagnostic PNG strips in
diag/with your vision tool (gold border = target beat frameB, red border = actual peak frameP) to catch visual defects numbers cannot see (overlapping transition flicker, unreadable text, awkward framing). - Fix all issues, re-render, and re-run
kadian check --strictuntil it passes cleanly.
7. Deliver
Deliver out.mp4 directly to the user.
- If the user wants a quick 10-second ear-check without launching a server, generate a lossless-video click-track copy:
kadian preview out.mp4 --out preview_clicks.mp4. - Only build an interactive beat map (
kadian map ...+kadian serve) if the user explicitly asks to inspect tracks, solo stems, or place frame marks in a browser.
Rules that make an edit feel on the beat
Details and evidence: rules.md.
- Change ON the beat frame, ease out AFTER it. An element that eases in and stops on the beat peaks 5–15 frames early and feels late and soft. Cut, appear, flash, or pass edge-on exactly on frame
f; settle afterward. - Real events carry the beat, not decoration. Use scene cuts, camera whips, reveals, lighting shifts, or words appearing — never repetitive card-bouncing or screen pulsing on every beat (
checkflags this asmonotonous). - One continuous motion per transition. Flip a single card edge-on on the beat rather than snapping two overlapping hinges.
- Respect the musical hierarchy. Save your largest visual jump (scene change, drop reveal, title hit) for tier-1 structural hits (drops, section starts). Use breaks / pre-drop cutouts as deliberate visual breathing room so the drop hits harder (
checkflags weak drops asflat_hierarchy). - Stay readable. Give text or UI at least half a beat (usually 1–2 beats); avoid rapid cuts under 250 ms unless they are deliberate
kind="tick"flurries (checkflags this ascrowded). - Cut on real attacks, not empty grid lines. Follow kicks (
low) and snares (mid) for primary cuts; reserve hi-hats (high, tier 3) for rapid flurries. - Sound slightly after picture is okay; sound ahead of picture is not. Detection thresholds are ~45 ms sound-early vs ~125 ms sound-late (ITU-R BT.1359).
checkenforces <= 35 ms both per-moment and for overall muxed A/V sync (av_offset).
Limits
- Steady tracks use one straight grid; live/drifting tempo is tracked beat by beat and flagged (
tempo_moves). Free-time rubato remains approximate. - Double/half tempo ambiguities are flagged (
maybe_half_tempo); override with--bpm. - Mix band labels (
low/mid/high) are approximate when instruments overlap; pass--stems DIR(afterkadian stems) for exact kick / snare / hat / bass / vocals roles.