Media lipsync

From damionrashford/media-os · View interactive version

Media lipsync is an AI agent skill from the GitHub repository damionrashford/media-os. Open-source AI lip-sync and talking-head animation with STRICTLY permissive-license models: LivePortrait (MIT, Kuaishou 2024, drives FACIAL motion — head pose, expression, lip-region — of a single still image from a driving audio OR a driving video of a real face), LatentSync (Apache 2.0, ByteDance

How to use this skill

Skill file

Media Lipsync (open-source talking-head + lip-sync)

Context: $ARGUMENTS

Quick start

When to use

Which model does what (read this first)

| Model | License | What it does | Inputs | Output |

|--------------|-----------|-------------------------------------------------------------------|----------------------------------|--------|

| LivePortrait | MIT | Portrait animation: head pose + expression + mouth, from 1 image | 1 still image + (audio OR video) | talking-head video |

| LatentSync | Apache 2.0 | Pure lip-region diffusion on an existing video | 1 video + 1 audio | same video, new lips |

Rule of thumb:

Step 1 — Install

Neither model is on PyPI as a drop-in wheel; both are installed by cloning the

reference repo and running their own inference.py. This skill drives those

scripts via subprocess.

uv run .claude/skills/media-lipsync/scripts/lipsync.py install liveportrait
# prints:
#   git clone https://github.com/KwaiVGI/LivePortrait ~/LivePortrait
#   cd ~/LivePortrait && pip install -r requirements.txt
#   (follow README.md section "Download pretrained weights")

uv run .claude/skills/media-lipsync/scripts/lipsync.py install latentsync
# prints:
#   git clone https://github.com/bytedance/LatentSync ~/LatentSync
#   cd ~/LatentSync && pip install -r requirements.txt
#   huggingface-cli download ByteDance/LatentSync --local-dir checkpoints

Check what's present:

uv run .claude/skills/media-lipsync/scripts/lipsync.py check

Set LIVEPORTRAIT_ROOT / LATENTSYNC_ROOT env vars if you installed outside

~/LivePortrait / ~/LatentSync. The script finds them automatically if they

are in the standard location.

Step 2 — Prep inputs

All models want a clean face in frame. Preprocess for best results:

ffmpeg -i driver_raw.wav -ar 16000 -ac 1 -c:a pcm_s16le driver.wav
ffmpeg -i source_raw.mp4 -vf "scale=-2:512" -r 25 source.mp4   # LatentSync prefers 25 fps

Step 3 — LivePortrait: animate a still

From audio

uv run .../lipsync.py animate \
    --model liveportrait \
    --source face.jpg \
    --driving speech.wav \
    --out talking.mp4 \
    --fps 25

LivePortrait's audio-driven mode uses an inferred pose/expression sequence from the

audio. Movement is subtle — plausible talking-head, not a wild performance.

From a driving video (expression retargeting)

uv run .../lipsync.py animate \
    --model liveportrait \
    --source face.jpg \
    --driving actor.mp4 \
    --out retargeted.mp4

The output preserves the SOURCE's identity, with the DRIVING video's head pose +

expression. Ethical note: do not use for impersonation without consent.

Step 4 — LatentSync: re-sync an existing video

uv run .../lipsync.py sync \
    --model latentsync \
    --video original.mp4 \
    --audio new_voice.wav \
    --out resynced.mp4 \
    --steps 25 --guidance 1.5

LatentSync runs 25-step latent diffusion per lip region. On an H100 it's ~10 seconds

of processing per 1 second of video; on a 4090 ~30 seconds per second. CPU-only is

not practical.

Step 5 — Dubbing workflow

Combine with media-tts-ai for voice and media-whisper for alignment if needed.

# 1. Generate dubbed audio (media-tts-ai)
uv run .claude/skills/media-tts-ai/scripts/tts.py ...  --out dubbed_es.wav

# 2. Re-sync lips
uv run .../lipsync.py dub \
    --video source_en.mp4 \
    --new-audio dubbed_es.wav \
    --model latentsync \
    --out final_es.mp4

dub is a thin wrapper around sync with defaults tuned for speech dubbing

(guidance 1.5, 25 steps, strong lip-region weighting).

Step 6 — Post

Gotchas

Examples

Example 1: Still photo to talking head (audio-driven)

uv run .../lipsync.py animate \
    --model liveportrait \
    --source ceo_headshot.jpg \
    --driving announcement.wav \
    --out ceo_speaking.mp4 --fps 25

Example 2: Expression retarget a still from an actor's performance

uv run .../lipsync.py animate \
    --model liveportrait \
    --source painting_portrait.jpg \
    --driving actor_read.mp4 \
    --out painting_acting.mp4

Example 3: Dub an English clip into Spanish with clean lips

# (1) generate Spanish voice via media-tts-ai -> dubbed_es.wav
# (2) re-sync lips:
uv run .../lipsync.py dub \
    --video interview_en.mp4 \
    --new-audio dubbed_es.wav \
    --out interview_es.mp4

Example 4: Check env before running

uv run .../lipsync.py check
# reports: cuda ok, LivePortrait repo at ~/LivePortrait, LatentSync at ~/LatentSync

Example 5: Dry-run to see the exact inference.py command

uv run .../lipsync.py animate --model liveportrait \
    --source face.jpg --driving speech.wav --out out.mp4 \
    --dry-run --verbose
# prints the exact `python inference.py ...` command without running it.

Troubleshooting

Error: `LivePortrait repo not found`

Cause: repo isn't at ~/LivePortrait and LIVEPORTRAIT_ROOT isn't set.

Solution: git clone https://github.com/KwaiVGI/LivePortrait ~/LivePortrait, OR export LIVEPORTRAIT_ROOT=/path/to/LivePortrait.

Error: `No module named 'torch'` inside inference.py

Cause: the LivePortrait / LatentSync venv doesn't have the deps installed.

Solution: cd ~/LivePortrait && pip install -r requirements.txt. The driver does not auto-install.

Output has eyes closed / blinking forever

Cause: LivePortrait reference frame had closed eyes.

Solution: pick a source image with eyes open, neutral expression. Do NOT laugh / grimace.

LatentSync output is blurry around the mouth

Cause: source video resolution too low, or heavy JPEG compression on the video.

Solution: source at >=512 px short edge, re-encode lossless first (ffmpeg -c:v libx264 -crf 12). Consider upscaling source with media-upscale before LatentSync.

Lip sync drifts after 20 seconds

Cause: audio and video clocks drift (VFR source, or audio sample rate mismatch).

Solution: force CFR + 16 kHz audio upfront. ffmpeg -r 25 -i in.mp4 -c:v libx264 -c:a copy fixed.mp4 && ffmpeg -i new.aif -ar 16000 -ac 1 -c:a pcm_s16le new.wav.

CUDA out of memory on a long video (LatentSync)

Cause: model holds whole video in VRAM.

Solution: split the video into 30-s chunks (ffmpeg-cut-concat segment mode), run LatentSync per chunk, concat the outputs. No built-in chunker in the driver.

"module xformers has no attribute ..." on Apple Silicon (LatentSync)

Cause: xformers / flash-attn have no MPS path.

Solution: run LatentSync on a CUDA machine. On Apple Silicon, only LivePortrait works (audio-driven mode is usable; video-driven mode runs but slow).

Use this skill with your AI agent: Open on Skill Issue to copy, download, or add to your library. Works with Claude, ChatGPT, Gemini, Cursor, Windsurf and more.