ComfyUI Node

Video for LivePortrait

Turn any video into the clean 512x512 driving clip LivePortrait actually wants

By Isi-dev·Created 2 years ago·Updated 10 months ago· 33
Video for LivePortrait
  • video
  • video
  • video2
handle_rotfalse
set_face_boxfalse
box_size256

LivePortrait is picky about its driving video. It wants a tight, stable, centered face crop - feed it raw footage of someone and the animation quality tanks. "Video for LivePortrait" is the fix: feed it any video of a person, at any resolution, and it spits out a clean 512×512 clip of their face, stabilized and centered, ready to drive the animation. If you've been hand-cropping driving clips in a video editor, this node just deleted that job.

How it works

It runs MediaPipe Face Mesh on every frame. First it scales the video so its shortest side is 1024 (better landmark stability), then finds the eyes and mouth, and computes the vector from eye-center to mouth. On the first frame it locks in a reference: a rotation angle and a crop size - roughly half the mouth-to-forehead distance, which lands you on a head-and-shoulders shot. Subsequent frames get rotated back to match the reference if you turn on handle_rot, cropped around the eye center, and resized to 512×512.

The detection backend is worth knowing about: it's MediaPipe, Google's Apache 2.0 face-landmark library - the same swap Kijai made in LivePortrait in 2024 because InsightFace's pretrained models are non-commercial. This node touches no InsightFace, so there's no license landmine downstream and none of InsightFace's infamous install pain. If a frame has no face, you get a blank black 512×512 frame and a console message.

Inputs that matter

  • video (required): the IMAGE batch of your footage.
  • handle_rot: rotate frames to match the reference face angle. Default off; turn it on for tilted or rotating heads.
  • set_face_box: use a fixed box_size for the crop instead of auto-sizing to each face. Flip it on when the automatic crop jumps around between frames.
  • box_size: 128–4096, default 256. Only used when set_face_box is on - a larger box keeps more of the head and shoulders.

Outputs are video and video2, and here's the quirk: they're identical. The node returns the same tensor twice. Wire either into your LivePortrait driving-video input; the duplicate is a convenience, not a feature.

Install

Same pack as everything else. ComfyUI Manager, search ComfyUI-Animation_Nodes_and_Workflows, or:

cd ComfyUI/custom_nodes
git clone https://github.com/Isi-dev/ComfyUI_Animation_Nodes_and_Workflows
cd ComfyUI-Animation_Nodes_and_Workflows
pip install -r requirements.txt

The key dependency here is mediapipe (alongside torch, torchaudio, numpy, opencv-python). If the node complains it can't import mediapipe, that's the first thing to fix. A ready-made workflow ships in the pack's animationWorkflows folder as generate_512x512_video_for_LivePortrait.json, so you don't have to wire the graph from memory. Isi-dev is known in this niche - they also maintain ComfyUI-UniAnimate-W and Wan 2.1 Colab notebooks, so the driving-video workflow style should feel familiar if you've used those.

Common issues

  • Black frames flash in the output. The face left frame, or turned too far for detection. Keep the person's face in shot for the whole clip.
  • The node returns nothing / downstream errors. MediaPipe failed to import; the code prints a message and returns None rather than raising. Reinstall mediapipe and restart.
  • The crop jumps around between frames. That's the auto-sized box adapting to each frame. Set set_face_box on and give it a fixed box_size.
  • Head rotation looks wrong. Leave handle_rot off if the person keeps their head mostly still - it can overcorrect and wobble.
Categoryimage

Inputs (4)

NameTypeDefaultDescription
videoIMAGE
handle_rotBOOLEANfalse
set_face_boxBOOLEANfalse
box_sizeINT256128–4096

Outputs (2)

NameTypeDescription
videoIMAGE
video2IMAGE