Colab AI Video & Pet Lip-Sync Production
Overview
This skill packages a proven two-stage pipeline for producing natural, syllable-synced AI short videos (especially non-human pets/reptiles/animals singing to music) with minimal Google Colab CCU burn:
- Local 0-CCU Driven Preview: Crop a crisp close-up, extract a clean audio envelope and reference timing, stabilize a single sharp mouth bank (no spring head-jerk), apply a physical vertical eyelid-close wipe for emotional climaxes, and verify 100% syllable-level lip-sync locally at 30fps.
- Colab GPU Low-Denoise V2V Polish: Polish the verified preview with
Wan2.1-T2V-1.3B-Diffusers(WanVideoToVideoPipeline,strength=0.28) on an L4/A100 GPU (~3 min, ~6 GB VRAM) to fuse eyelids/jaw seams naturally, optionally add a sub-pixelINTER_LANCZOS4emotional dolly zoom, burn seamless-crf 15Noto Sans CJK subtitles, and verify with dynamic playback plus a 4fps audit sheet before stopping the VM.
For detailed troubleshooting of every pitfall (macOS OpenSSL 4 WebSocket drops,
MCP 3-minute timeouts, A100 40GB OOM, flash_attn SDPA patch, GPU 503
fallbacks, tongue-smudge artifacts, etc.), read
references/pitfalls_and_tuning.md.
Dependencies
colabskill (required): All Google Colab VM lifecycle actions (colab_status,colab_new,colab_exec,colab_files,colab_stop) MUST use the installedcolabMCP tools and surface the side panel link[Colab](sidecar://colab-status/colab_panel/).image-generatorsubagent (recommended): Used in Stage 2 to generate a pixel-aligned closed-eyes (or custom emotional expression) edit of the subject's close-up photo.- Local tools:
ffmpeg,ffprobe, anduvonPATH.
Core Workflow
Stage 1: Assets, Audio & Reference Analysis (0 CCU)
- Framing check: Ensure the subject's face fills at least ~50–65% of the
frame width (9:16 vertical, e.g.
480×832or448×768). If the raw photo is wide, crop tightly around the face and front paws while preserving the original background. - Extract & analyze audio (use
uv runon scripts/video_toolkit.py):- Run
analyze-audioto produce a 30fps syllable-energy JSON and locate exact phrase boundaries & pauses. - If a reference performance video exists, run
analyze-refto generate a contact sheet and identify emotional eye-closure windows and subtitle beats.
- Run
- Prepare seamless SRT: Draft subtitles aligned to the vocal boundaries
and run
validate-srtto guarantee validHH:MM:SS,mmmtimestamps with zero flicker gaps.
Stage 2: Local 0-CCU Synced Preview (Iterate Until Rhythm Is 100%)
- Obtain a sharp mouth-opening bank:
- Either run a short single-clip S2V pass (e.g.,
Wan2.2-S2V-14Bwith--infer_frames 48,--t5_cpu, SDPA patch, and decoupledAUDIO_CFG=7.5— see pitfalls_and_tuning.md) to harvest 8–10 consecutive sharp jaw-opening frames, or reuse an existing clean bank. - Rule: Use one razor-sharp stabilized bank rather than mixing in a softer secondary bank (blurry pink mouth edges cause V2V models to hallucinate protruding tongues).
- Either run a short single-clip S2V pass (e.g.,
- Generate pixel-aligned closed-eye expression:
- Delegate to
image-generatorwith strict instructions to keep framing, lighting, pose, and background identical while editing only the eyelids tightly shut. - Visually inspect with
read_fileand verify eye alignment on a grid.
- Delegate to
- Render 30fps local preview:
- Run
build-previewto lock the upper head (zero sideways spring jerk), drive the jaw with a smooth 70ms RMS + gentle syllable-dip envelope, and apply a top-to-bottom vertical eyelid wipe (never a flat alpha crossfade) on emotional climax windows. - Watch the preview via
read_fileand iterate locally (0 CCU, ~20–60s per tweak) until the user confirms mouth speed, eye timing, and framing.
- Run
Stage 3: Colab GPU Low-Denoise V2V Polish & Post-Processing
- Check
colab_statusfirst and pick an eligible GPU (L424GB is fast and cheap forWan2.1-T2V-1.3B-Diffusers, ~3 min / ~6 GB VRAM;A100also works).- If Colab GPU provisioning returns
503 Service Unavailable, do NOT hang in a loop: inform the user, offer a fast CPU subtitle pass if desired, or schedule a retry later.
- If Colab GPU provisioning returns
- Always run heavy Colab jobs in the background:
- Launch downloads and diffusion runs via
subprocess.Popenlogging to a file (MCP calls have a 3-minute hard timeout). Never runcolab_execandcolab_filesconcurrently on the same session.
- Launch downloads and diffusion runs via
- Run scripts/colab_v2v_polish.py on the
Colab GPU:
- Recommended golden parameters:
--model-id Wan-AI/Wan2.1-T2V-1.3B-Diffusers,--strength 0.28(0.25–0.30preserves razor-sharp jaw edges while fusing eyelids and adding natural skin/breathing cohesion),--steps 32,--guidance 5.0. - Always include
sticking out tongue, protruding tongue, pink smudge, blurry mouthin the negative prompt. - Optionally enable
--dolly-zoomfor a smooth sub-pixelINTER_LANCZOS4climax push-in (1.00x → 1.11x, zero background rotation) and pass--subtitlesto burnNoto Sans CJK TCat-crf 15.
- Recommended golden parameters:
Stage 4: Mandatory Visual Audit & Safe Shutdown
- Never rely on 1fps thumbnails alone: Download the rendered
.mp4locally, watch the actual video with audio viaread_file, AND runaudit-videoto inspect a 4fps contact sheet across the entire duration. - CCU-safe shutdown protocol:
- Unless the user explicitly asked for immediate auto-shutdown, keep the
GPU session alive while the user inspects the final video (avoiding
re-downloading weights if a tweak is needed), clearly stating the live
status and
[Colab](sidecar://colab-status/colab_panel/)link. - The moment the user approves (or says stop), call
colab_stopand verifycolab_statusreportsassignments: 0andrate: 0.0.
- Unless the user explicitly asked for immediate auto-shutdown, keep the
GPU session alive while the user inspects the final video (avoiding
re-downloading weights if a tweak is needed), clearly stating the live
status and
Utility Scripts
All local tools live in scripts/video_toolkit.py
and use only Python stdlib + ffmpeg/ffprobe (run via uv run):
TOOL=~/.gemini/config/skills/colab-ai-video-production/scripts/video_toolkit.py
# 1. Analyze vocal audio into a 30fps syllable-openness JSON
uv run "$TOOL" analyze-audio \
--audio assets/audio/chorus.wav \
--fps 30 \
--output work/audio_envelope.json
# 2. Extract a contact sheet from a reference performance video
uv run "$TOOL" analyze-ref \
--video assets/audio/reference.mp4 \
--fps 2 \
--tile 5x4 \
--output work/ref_contact.jpg
# 3. Validate (and optionally auto-close flicker gaps in) an SRT subtitle file
uv run "$TOOL" validate-srt \
--srt assets/audio/lyrics.srt \
--fix-gaps \
--output work/srt_report.json
# 4. Build a 0-CCU 30fps stabilized preview with vertical eyelid close
uv run "$TOOL" build-preview \
--mouth-video outputs/s2v_source.mp4 \
--mouth-frames 56:66 \
--eyes-closed assets/photos/eyes_closed.jpg \
--audio assets/audio/chorus.wav \
--climax-windows "1.92-5.34,7.42-9.18" \
--output outputs/preview_synced.mp4
# 5. Audit any rendered video with a 4fps contact sheet + ffprobe JSON
uv run "$TOOL" audit-video \
--video outputs/final_subtitled.mp4 \
--fps 4 \
--output work/audit_4fps.jpg
For the Colab GPU polishing stage, upload
scripts/colab_v2v_polish.py and run inside the
Colab VM (background Popen):
python3 colab_v2v_polish.py \
--input preview_synced.mp4 \
--audio chorus.wav \
--subtitles lyrics.srt \
--model-id /content/Wan2.1-T2V-1.3B-Diffusers \
--strength 0.28 --steps 32 --guidance 5.0 \
--dolly-zoom \
--output-clean outputs/final_master.mp4 \
--output-sub outputs/final_master_subtitled.mp4
Common Mistakes
- Trusting pure Audio-to-Video (
Wan2.2-S2V) on reptiles/non-humans: Human-trained audio cross-attention misses syllable articulation on non-human mouths and resets to a closed mouth at 48-frame chunk boundaries. Always drive lip-sync explicitly locally first, then polish with low-denoise V2V. - Scrubbing a full-frame mouth ramp without stabilizing the head: If the source ramp drifts sideways as the mouth opens, scrubbing it back and forth creates an obvious spring/boomerang head-jerk. Lock the upper head and blend only the aligned jaw region.
- Using high V2V strength (
>= 0.35) or blurry secondary mouth frames: Causes diffusion models to turn soft pink mouth rims into protruding tongues or smeared scales. Keep V2Vstrengtharound0.25–0.30on a single sharp mouth bank. - Burning subtitles with default
libx264CRF (23): Destroys fine fur/scale texture and drops bitrate below 600 kbps. Always pass-crf 15and installfonts-noto-cjkon Colab Linux.