| 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'.")
|
|
|
|
|
| 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"
|
|
|
|
|
| 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
|
| ])
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
|
| print("✅ Hoàn tất toàn bộ quá trình!")
|
|
|