---
name: ai-music-video-production
description: Plan, verify, and assemble a beat-locked AI music video from a locked audio mix and separated stems. Covers three-clock timing, character reference locks, positive-only video prompting, framing-locked still repairs, vocal-stem lip-sync alignment, caption onset audits, and FFmpeg/ffprobe delivery QC. Use when producing or auditing a multi-shot AI music video or short musical film. Do not use for single standalone clips without a locked song track or for impersonating non-consenting private individuals.
license: MIT
compatibility: Works in any Agent Skills harness (Claude Code, Codex, Grok Build / Cursor, Hermes, or local agents). Local assembly and QC require Python 3.10+, ffmpeg >= 6, and ffprobe on PATH. Media generation works with any image/video provider (e.g. Pixio) or local model pipeline.
metadata:
  version: "1.0.0"
  author: "Dylan J. Harris"
  source-article: "https://www.dylanjharris.com/writing/how-i-make-ai-films"
  tested: "2026-12-05"
---

# AI Music Video Production & Delivery QC

## Goal

Produce a repeatable, code-assembled music video where character identity, visual transitions, lip-sync, and captions lock cleanly to one chosen recording without wasting credits on avoidable re-generations.

## Use when / Do not use when

- **Use when:** You have a finalized song audio file (plus vocal and drum stems when available) and need to storyboard, generate shots, align lip-sync, assemble in code, and verify the final export.
- **Do not use when:** You are still choosing between unfinished song drafts, making an unrelated one-off image, or attempting to strip watermarks, bypass provider safety policies, or generate deceptive real-person likenesses.

## Inputs

Ask the user for any missing item before generating or rendering:

1. Locked master audio file and isolated vocal / drum stems (if available).
2. Exact lyrics with intended section breaks (Intro, Verse, Chorus, Bridge, Outro).
3. Cast list with approved base portraits and written fixed traits (hair, wardrobe, accessories).
4. Target resolution, frame rate (e.g. 24 fps or 30 fps), and aspect ratios (e.g. 16:9 master, 9:16 vertical).
5. Budget cap and preferred media generation route (subscription pool, pay-per-job provider such as Pixio, or local open-weight models).

## Preconditions

- `ffmpeg` and `ffprobe` available on `PATH` for audio slicing, frame extraction, assembly, and QC.
- Python 3.10+ (with OpenCV/Pillow if running local composites or contact sheets).
- Provider API credentials supplied via environment variables only (never written into shot tables, prompts, or committed files).

## First-principles invariants

1. **One source audio clock rules everything.** Never trust a single global BPM number across an entire track; anchor cuts to actual song timestamps and check phrasing by ear.
2. **Keep three clocks strictly separate in code:**
   - `song_time`: position inside the chosen audio master.
   - `clip_time`: position inside a single generated video file (`source_trim_start + playback_speed * elapsed_shot_time`).
   - `film_time`: position in the final rendered video (`song_time + opening_length`).
3. **Convert absolute timestamps to integer frames before subtracting.** Rounding individual shot durations independently accumulates visible drift across 80–120 shots.
4. **Verify available clip duration before rendering:** `(source_duration - source_trim_start) / playback_speed >= requested_shot_duration`.
5. **Never edit a video take to fix a bad still.** Approve character identity, props, and framing at full resolution on the still before running motion.
6. **Chain transitions from actual retained frames.** Extract the exact last retained frame of the accepted outgoing clip and pair it with the exact first frame of the incoming shot.

## Procedure

### 1. Lock the song, stems, and visual rule
- Lock one master mix and separate lead vocals and drums.
- Define one physical visual rule or recurring set of spaces anchored to the song's narrative instead of disconnected clip montages.
- Draft a versioned JSON shot table (`song_start`, `song_end`, `section`, `cast`, `framing`, `source_clip`, `trim_start`, `speed`, `caption_zone`).

### 2. Lock character identity before motion
- Assign each reference image a single explicit role: face/identity, wardrobe/room, or style.
- Frame facial performance shots thigh-up or closer; wide full-body shots shrink faces below model detail thresholds.
- If one character drifts in an approved multi-person still, crop a tight framing-locked tile around only that subject, repair the tile once, and feather-paste only the masked subject back onto the master plate.

### 3. Prompt motion in positive physical terms
- Write video prompts describing visible physical action, gaze direction, and posture.
- Avoid negative phrasing (e.g. "never look down", "do not turn away"); video models often fixate on the forbidden action.
- Test included subscription-pool or local open-weight routes on one representative shot before spending metered credits on paid routes.

### 4. Align vocal lip-sync and captions
- Slice each singing window directly from the isolated vocal stem (adding brief muted lead-in where needed).
- Pair the vocal slice with an emotionally matched base still.
- Cross-correlate the returned lip-sync take's audio track against the sliced vocal window to compute the best-fit sample offset, then round to the nearest frame.
- Treat ASR/Whisper word timestamps as a draft. Audit word-0 onsets against vocal-stem bandpass energy to catch early pulls into breaths, ad-libs, or reverb tails.
- Export burned-in kinetic captions and `.srt` subtitles from the same audited word-timing file.

### 5. Assemble deterministically with bounded memory
- Inspect clip durations with `ffprobe` ahead of render rather than decoding every source clip up front.
- Bound active video decoders with a small LRU cache (e.g. 6 open clips) so 100+ shot renders stay within desktop RAM limits.
- Lock approved shots; re-review fixes inside short context reels (5 seconds before and after the changed cut) before running a full master render.

### 6. Run automated delivery QC
Run every check below on the final export before upload:

```bash
# 1. Full stream decode check (fails on corrupt packets)
ffmpeg -v error -i master.mp4 -f null -

# 2. Exact duration, resolution, fps, and codecs
ffprobe -v error -show_entries format=duration:stream=codec_name,width,height,r_frame_rate -of default=noprint_wrappers=1 master.mp4

# 3. Integrated loudness and true peak (EBU R128)
ffmpeg -i master.mp4 -af ebur128=peak=true -f null -

# 4. Unwanted black frames and frozen video segments
ffmpeg -i master.mp4 -vf "blackdetect=d=0.1:pix_th=0.1,freezedetect=n=-60dB:d=0.5" -f null -
```

## Human gates

Stop and ask the user for explicit approval before:

- Submitting paid media generations that exceed the stated budget cap.
- Depicting any real person's likeness (require explicit consent or clear satirical public-figure disclosure rules).
- Uploading, publishing, or overwriting public video files or descriptions.

## Verification

- [ ] `ffmpeg -v error -i master.mp4 -f null -` exits 0 with empty stderr.
- [ ] Exported runtime matches `song_duration + opening_length + outro_length` within 1 frame.
- [ ] No unexpected blackdetect or freezedetect hits inside active scenes.
- [ ] Mouth filmstrips and full-speed playback confirm lip closure alignment on every chorus (including repeated choruses).
- [ ] Every face, caption, and final second inspected at full playback speed.

## Failure modes

| Symptom | Likely cause | Fix |
|---|---|---|
| Lip-sync looks late or frozen | Trim/speed math error or clip shorter than shot window | Check `available_output_duration` and audio cross-correlation offset before regenerating |
| Subject performs forbidden action | Negated words inside the motion prompt | Rewrite strictly as positive physical posture and gaze |
| Neighboring cast faces warp during an edit | Whole-frame image regeneration | Repair only a tight framing-locked tile and feather-paste the masked subject |
| Lyrics flash up to 1s before vocal enters | Whisper segment-onset pull into breath or reverb | Audit word-0 onset against vocal-stem energy valleys |
| Renderer crashes near the end of a long cut | Unbounded clip decoding in memory | Pre-probe with `ffprobe` and decode through a bounded LRU clip cache |

## Output contract

Return:
1. Updated shot-table manifest (`shots.json`) and render script changes.
2. Summary of shots generated, repaired, or locked (with any failed takes logged).
3. Full `ffprobe`/`ffmpeg` QC report (runtime, resolution, loudness, black/freeze counts).
4. List of items still requiring human watch-through before upload.

## Provenance

- Source guide: [How I make AI music videos](https://www.dylanjharris.com/writing/how-i-make-ai-films) (tested Dec 5, 2026).
- Provider-agnostic workflow; Pixio, Suno, Python, OpenCV, and FFmpeg are named as tested examples, not required vendors.
