File size: 2,569 Bytes
fcac53f |
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 |
import os
import subprocess
from pathlib import Path
def find_venv_python(start_path: Path) -> str:
for parent in [start_path] + list(start_path.parents):
venv_python = parent / ".venv" / "Scripts" / "python.exe"
if venv_python.exists():
print(f"✅ Tìm thấy môi trường ảo tại: {venv_python}")
return str(venv_python)
raise FileNotFoundError("Không tìm thấy môi trường ảo '.venv'.")
# Thiết lập đường dẫn
base_path = Path(r"D:\CODE\wav_to_lip_api\Wav2Lip-HD")
python_exe = find_venv_python(base_path)
input_video = base_path / "input_videos" / "noi _chuyen_new.mp4"
input_audio = base_path / "input_audios" / "demo_002.mp3"
output_wav2lip = base_path / "output_videos_wav2lip" / "demo_003.mp4"
frames_wav2lip = base_path / "frames_wav2lip" / "demo_003"
frames_hd = base_path / "frames_hd" / "demo_003"
output_hd_video = base_path / "output_videos_hd" / "demo_003.mkv"
# Bước 1: Wav2Lip
print("🔁 Đang chạy Wav2Lip...")
subprocess.run([
python_exe, base_path / "inference.py",
"--checkpoint_path", base_path / "checkpoints" / "wav2lip_gan.pth",
"--segmentation_path", base_path / "checkpoints" / "face_segmentation.pth",
"--sr_path", base_path / "checkpoints" / "esrgan_yunying.pth",
"--face", input_video,
"--audio", input_audio,
"--save_frames",
"--gt_path", base_path / "data" / "gt",
"--pred_path", base_path / "data" / "lq",
"--no_sr",
"--outfile", output_wav2lip
])
# # Bước 2: Video2frames
# print("🔁 Đang trích xuất frames từ video...")
# subprocess.run([
# python_exe, base_path / "video2frames.py",
# "--input_video", output_wav2lip,
# "--frames_path", frames_wav2lip
# ])
# # Bước 3: Real-ESRGAN
# print("🔁 Đang nâng cấp ảnh với Real-ESRGAN...")
# subprocess.run([
# python_exe, base_path / "Real-ESRGAN" / "inference_realesrgan.py",
# "-n", "RealESRGAN_x4plus",
# "-i", frames_wav2lip,
# "--output", frames_hd,
# "--outscale", "3.5",
# "--face_enhance"
# ])
# # Bước 4: FFmpeg
# print("🔁 Đang tạo video HD bằng FFmpeg...")
# frame_pattern = str(frames_hd / "frame_%05d_out.jpg")
# subprocess.run([
# "ffmpeg",
# "-r", "20",
# "-i", frame_pattern,
# "-i", str(input_audio),
# "-vcodec", "libx264",
# "-crf", "25",
# "-preset", "veryslow",
# "-acodec", "copy",
# str(output_hd_video)
# ])
print("✅ Hoàn tất toàn bộ quá trình!")
|