LivePortrait User Manual

This document provides detailed usage instructions for LivePortrait, including basic inference, Gradio interface, animal mode, video editing, and other features.

Basic Inference

Image Driving

The most basic usage involves using a static image as the source and a driving video as the animation reference:

python inference.py

By default, the script uses example images from the assets/examples/source directory and example driving videos from the assets/examples/driving directory. Upon successful execution, results are saved in the animations directory with the naming convention "source_file--driving_file_concat.mp4".

The output video contains three parts: the driving video, the source image/video, and the generated animation result, spliced together in sequence.

Custom Inputs

You can specify your own source and driving files using command line parameters:

# Source file is an image
python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d0.mp4

# Source file is a video
python inference.py -s assets/examples/source/s13.mp4 -d assets/examples/driving/d0.mp4

The -s parameter specifies the source image or video path, while the -d parameter specifies the driving video path.

Viewing More Options

View all available command line parameters:

python inference.py -h

Parameters include output path, image size, animation speed, splicing method, and other detailed configurations.

Using the Gradio Web Interface

For users unfamiliar with command-line interfaces, LivePortrait offers a graphical interface based on Gradio.

Launching Human Mode Interface

python app.py

After launching, open your browser to the displayed URL (typically http://localhost:7860). In the interface, upload a source image or video, then select a driving video and click the generate button to obtain the animation result.

You can specify the port using the --server_port parameter, generate a public link using --share, and specify the server address using --server_name.

Launching Animal Mode Interface

On Linux systems with NVIDIA GPUs, you can launch the animal mode interface:

python app_animals.py

Driving Video Specifications

For optimal results, driving videos should meet the following requirements:

Aspect Ratio: It is recommended to crop to 1:1 square (such as 512x512 or 256x256 pixels). You can also enable automatic cropping (--flag_crop_driving_video).

Content Requirements: The driving video should focus on the head area, similar to example videos. Shoulder movements should be minimized.

First Frame Requirement: The first frame of the driving video should be a frontal face with a neutral expression. This is crucial for ensuring accurate animation effects.

Automatic Cropping

If your driving video does not meet the above requirements, you can use automatic cropping:

python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d13.mp4 --flag_crop_driving_video

If automatic cropping results are unsatisfactory, you can adjust the --scale_crop_driving_video and --vy_ratio_crop_driving_video parameters to fine-tune scaling and offset.

Using Motion Templates

To accelerate inference and protect privacy, LivePortrait supports using pre-generated motion template files (.pkl format). These template files record motion information from driving videos and can be reused without processing the original video each time.

Usage

# Portrait animation
python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d5.pkl

# Portrait video editing
python inference.py -s assets/examples/source/s13.mp4 -d assets/examples/driving/d5.pkl

Template files not only accelerate inference but also protect privacy—using templates eliminates the need to upload original driving videos.

Portrait Video Editing (Video-to-Video)

LivePortrait supports editing and modifying expressions and head movements of subjects in existing videos.

Basic Usage

# Source is image, driving is video
python inference.py -s assets/examples/source/s9.jpg -d assets/examples/driving/d0.mp4

Adjusting Animation Parameters

Expression Intensity: Adjust the strength of expression changes using the --driving_multiplier parameter. Values greater than 1 enhance expression changes, while values less than 1 reduce them.

Splicing Control: Use the --flag_stitching parameter to control whether stitching is enabled. Disabling stitching may alter how facial regions are presented.

Inference Acceleration

Torch Compile Acceleration

LivePortrait supports using PyTorch's torch.compile feature to accelerate inference. The first inference triggers an optimization process (approximately one minute), after which inference speed improves by 20-30%. Acceleration effects may vary depending on CUDA version.

python app.py --flag_do_torch_compile

Note: torch.compile is not supported on Windows and macOS.

Speed Testing

The project provides an inference speed testing script:

python speed.py

The test results display processing time for each module, helping you understand performance bottlenecks.

Animal Mode

Animal mode supports animating portraits of pets such as cats and dogs.

Usage Conditions

Animal mode has been tested only in the following environments: Linux system with NVIDIA GPU, Windows system with NVIDIA GPU.

Installation Requirements

Before using animal mode, install the X-Pose dependency as described in the installation guide and download animal model weights.

Running Animal Mode Inference

python inference_animals.py -s assets/examples/source/s39.jpg -d assets/examples/driving/wink.pkl --driving_multiplier 1.75 --no_flag_stitching

Animal Mode Interface

python app_animals.py

Regional Control

LivePortrait supports animation control for specific regions of images, enabling more refined effect adjustments.

Enabling Regional Control

In the Gradio interface, you can find regional control options to select which facial regions to animate (such as eyes, mouth, head pose, etc.).

Portrait Editing

In the Gradio interface, users can precisely edit various attributes of the source portrait, including expression, eye gaze direction, head angle, and more.

Privacy Protection

LivePortrait provides multiple privacy protection features:

Motion Templates: Use .pkl template files instead of original driving videos to avoid uploading sensitive content

Auto-cropping: Automatically crop driving videos to focus on the head, reducing background information

Video Protection: Template creation feature converts videos to motion templates before use

Output Format

The default output format is MP4 video file containing three parts: driving video, source content, and generated result. Use the --no_flag_concat parameter to output only the generated animation portion.

Community Tool Integration

LivePortrait is integrated by multiple community projects:

ComfyUI: Multiple ComfyUI nodes support LivePortrait with real-time preview features

Stable Diffusion WebUI: The sd-webui-live-portrait extension integrates LivePortrait into SD WebUI

FaceFusion: Version 3.0 integrates LivePortrait as an expression restorer and face editor processor

HuggingFace Spaces: Experience LivePortrait online without local installation

Best Practices

For optimal animation effects, follow these best practices:

Select high-quality source images: Clear frontal portraits yield the best results

Use professional driving videos: Videos with frontal, natural expressions drive better effects

Control driving video length: Excessively long driving videos increase processing time and may cause effect degradation

Set parameters reasonably: Adjust expression intensity and other parameters based on actual results

Maintain consistent lighting: Try to keep lighting conditions consistent between source images and driving videos