朋友有个口播视频合成的需求,这段时间做了些调研,核心是两个能力:音色克隆和对口型视频合成。

上一篇我们已经讲了音色克隆,今天我们来看一下对口型视频合成的实现。

部署验证

本次所有测试全部在AutoDL平台进行。

测试机器规格如下:

GPU RTX 4090(24GB) * 1
CPU 16 vCPU Intel(R) Xeon(R) Platinum 8352V CPU @ 2.10GHz
内存 120GB
硬盘 系统盘:30 GB
    数据盘:免费:50GB SSD  付费:0GB

省钱提示:

AutoDL有开机和无卡开机两种模式,无卡开机每小时0.1元,在环境部署阶段使用无卡开机模式,部署完成后再切换到正常开机模式测试。

Wav2Lip

基于2020年的A Lip Sync Expert Is All You Need for Speech to Lip Generation In the Wild论文实现,最经典的对口型方案,项目资料多、社区使用经验丰富。

项目地址: https://github.com/Rudrabha/Wav2Lip

https://github.com/anothermartz/Easy-Wav2Lip

本次使用Easy-Wav2Lip进行部署验证。

部署测试

  1. 创建虚拟环境
conda create -n wav2lip python=3.10 -y
conda activate wav2lip
  1. 克隆代码
git clone https://github.com/anothermartz/Easy-Wav2Lip.git
cd Easy-Wav2Lip
  1. 安装依赖
pip install -r requirements.txt
  1. 下载模型
python install.py
  1. 合成测试
python inference.py \
    --checkpoint_path checkpoints/Wav2Lip_GAN.pth \
    --face input.mp4 \
    --audio input.wav \
    --outfile output.mp4 \
    --out_height 1608

默认合成的视频分辨率较低,可以通过 --out_height 指定输出视频高度,例如设置为原视频高度,以尽量保持输出分辨率。

实际耗时如下:

# --quality Fast
real    0m23.950s
user    1m13.251s
sys     1m1.965s

# --quality Enhanced
real    13m55.324s
user    196m45.613s
sys     6m58.818s

Video-ReTalking

基于2022年的Audio-based Lip Synchronization for Talking Head Video Editing In the Wild论文实现,由西安电子科技大学、腾讯 AI Lab、清华大学等机构提出的口型同步与表情编辑方案。

项目地址:

https://github.com/opentalker/video-retalking

部署测试

  1. 准备系统依赖
sudo apt update
sudo apt install -y git wget curl build-essential cmake ffmpeg
nvidia-smi
conda --version
  1. 克隆项目
cd ~
git clone https://github.com/OpenTalker/video-retalking.git --recursive
cd video-retalking
  1. 创建环境并安装依赖
conda create -n video_retalking python=3.8 -y
conda activate video_retalking

pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 \
    --index-url https://download.pytorch.org/whl/cu118

pip install -r requirements.txt
  1. 下载权重
cd ~/video-retalking
mkdir -p checkpoints
cd checkpoints

BASE=https://github.com/vinthony/video_retalking/releases/download/v0.0.1

for f in \
  30_net_gen.pth \
  BFM.zip \
  DNet.pt \
  ENet.pth \
  expression.mat \
  face3d.pth \
  GFPGANv1.3.pth \
  GPEN-BFR-512.pth \
  LNet.pth \
  ParseNet-latest.pth \
  RetinaFace-R50.pth \
  shape_predictor_68_face_landmarks.dat
do
  wget -c "$BASE/$f"
done

unzip -o BFM.zip -d BFM
rm BFM.zip

权重总大小约 4GB。缺任何一个文件,都可能在加载 checkpoint 阶段报错。

  1. 合成测试
python3 inference.py \
  --face input.mp4 \
  --audio input.wav \
  --outfile ./result.mp4

实际耗时如下:

real    6m13.248s
user    11m8.239s
sys     1m17.590s

MuseTalk

基于2024年的Real-Time High Quality Lip Synchronization with Latent Space Inpainting论文实现,由腾讯音乐天琴实验室开源的实时高质量唇形同步模型。

它走潜在空间 inpainting 路线,v1.5 相比早期版本提升了清晰度和唇语同步效果。

项目地址:

https://github.com/TMElyralab/MuseTalk

部署测试

  1. 安装系统依赖
nvidia-smi
conda --version
sudo apt update
sudo apt install -y git ffmpeg build-essential
  1. 创建环境
conda create -n musetalk python=3.10 -y
conda activate musetalk

pip install torch==2.0.1 torchvision==0.15.2 torchaudio==2.0.2 \
    --index-url https://download.pytorch.org/whl/cu118
  1. 克隆项目并安装依赖
git clone https://github.com/TMElyralab/MuseTalk.git
cd MuseTalk

pip install -r requirements.txt
pip install --no-cache-dir -U openmim
mim install mmengine
mim install "mmcv==2.0.1"
mim install "mmdet==3.1.0"
mim install "mmpose==1.1.0"
pip install munkres json_tricks xtcocotools
  1. 配置 FFmpeg
export FFMPEG_PATH=$(which ffmpeg)
echo 'export FFMPEG_PATH=$(which ffmpeg)' >> ~/.bashrc
source ~/.bashrc
  1. 下载模型
export HF_ENDPOINT=https://hf-mirror.com # 国内网络可以先设置 HuggingFace 镜像
cd ~/MuseTalk

hf download TMElyralab/MuseTalk --local-dir models/
hf download stabilityai/sd-vae-ft-mse --local-dir models/sd-vae-ft-mse/
hf download openai/whisper-tiny --local-dir models/whisper/
hf download yzd-v/DWPose --include "dw-ll_ucoco_384.pth" --local-dir models/dwpose/
hf download ByteDance/LatentSync --include "latentsync_syncnet.pt" --local-dir models/syncnet/
hf download afrizalha/musetalk-models \
    --include "face-parse-bisent/79999_iter.pth" \
    --local-dir models/

wget https://download.pytorch.org/models/resnet18-5c106cde.pth \
    -O models/face-parse-bisent/resnet18-5c106cde.pth

模型目录大致应包含:

models/
├── musetalk/
├── musetalkV15/
├── syncnet/
├── dwpose/
├── face-parse-bisent/
├── sd-vae-ft-mse/
└── whisper/
  1. 合成测试
python -m scripts.inference \
    --inference_config configs/inference/my_task.yaml \
    --result_dir results/my_output \
    --unet_model_path models/musetalkV15/unet.pth \
    --unet_config models/musetalkV15/musetalk.json \
    --version v15 \
    --use_float16

输出文件会保存在 results/my_output/目录下。

实际耗时如下:

real    2m54.050s
user    8m12.693s
sys     0m59.808s

方案对比总结

方案部署难度推理速度画面质量适合场景
Wav2Lip / Easy-Wav2Lip中等Fast 模式最快,Enhanced 模式最慢一般,嘴部和脸部容易模糊快速验证、低成本批量测试
Video-ReTalking较高中等偏慢较好,带人脸增强流程高质量离线视频合成
MuseTalk较高较快本次测试最好数字人、实时或准实时口型驱动

从本次测试结果看,如果只是快速验证流程,Wav2Lip / Easy-Wav2Lip 成本最低;如果更重视最终观感,可以考虑 Video-ReTalking;如果希望在速度和效果之间取得更好的平衡,MuseTalk 是目前更推荐的方案。

效果对比

Wav2Lip

Video-ReTalking

MuseTalk

基于本次测试素材来看,MuseTalk 的画面质量最优,Video-ReTalking次之,Wav2Lip最差,抖动最明显。

从合成速度来看,从快到慢依次为:Wav2Lip Fast、MuseTalk、Video-ReTalking、Wav2Lip Enhanced。

结论

整体来看,MuseTalk 在本次测试中速度和效果都比较均衡,是三个方案里我目前最推荐继续深入尝试的方案。