From b20d7975814a640ee1c34b8cc6f353be190221b1 Mon Sep 17 00:00:00 2001 From: Jason Kneen Date: Wed, 14 Aug 2024 00:53:52 +0100 Subject: [PATCH] Revert model and Fixes --- README.md | 2 +- modules/core.py | 4 ++-- modules/globals.py | 1 + modules/processors/frame/face_swapper.py | 4 ++-- modules/utilities.py | 19 +++++++++++++++++-- 5 files changed, 23 insertions(+), 7 deletions(-) diff --git a/README.md b/README.md index 04fb584..75b1e43 100644 --- a/README.md +++ b/README.md @@ -87,7 +87,7 @@ pip install onnxruntime-silicon==1.13.1 2. Usage in case the provider is available: ``` -python run.py --execution-provider metal +python run.py --execution-provider coreml ``` diff --git a/modules/core.py b/modules/core.py index 83eb751..e317550 100644 --- a/modules/core.py +++ b/modules/core.py @@ -75,13 +75,13 @@ def parse_args() -> None: program.add_argument('--keep-audio', help='keep original audio', dest='keep_audio', action='store_true', default=True) program.add_argument('--keep-frames', help='keep temporary frames', dest='keep_frames', action='store_true', default=True) program.add_argument('--many-faces', help='process every face', dest='many_faces', action='store_true', default=False) - program.add_argument('--video-encoder', help='adjust output video encoder', dest='video_encoder', default='libx265', choices=['libx264', 'libx265', 'libvpx-vp9']) + program.add_argument('--video-encoder', help='adjust output video encoder', dest='video_encoder', default='libvpx-vp9', choices=['libx264', 'libx265', 'libvpx-vp9']) program.add_argument('--video-quality', help='adjust output video quality', dest='video_quality', type=int, default=1, choices=range(52), metavar='[0-51]') program.add_argument('--max-memory', help='maximum amount of RAM in GB', dest='max_memory', type=int, default=suggest_max_memory()) program.add_argument('--execution-provider', help='execution provider', dest='execution_provider', default=['coreml'], choices=suggest_execution_providers(), nargs='+') program.add_argument('--execution-threads', help='number of execution threads', dest='execution_threads', type=int, default=suggest_execution_threads()) program.add_argument('--video-processor', help='video processor to use', dest='video_processor', default='cv2', choices=['cv2', 'ffmpeg']) - program.add_argument('--model', help='model to use for face swapping', dest='model', default='inswapper_128v2.fp16.onnx') + program.add_argument('--model', help='model to use for face swapping', dest='model', default='inswapper_128.onnx') program.add_argument('-v', '--version', action='version', version=f'{modules.metadata.name} {modules.metadata.version}') args = program.parse_args() diff --git a/modules/globals.py b/modules/globals.py index c392a80..c5c4faf 100644 --- a/modules/globals.py +++ b/modules/globals.py @@ -24,6 +24,7 @@ execution_providers: List[str] = [] execution_threads = None headless = None log_level = 'error' +model = None fp_ui: Dict[str, bool] = {} nsfw = None camera_input_combobox = None diff --git a/modules/processors/frame/face_swapper.py b/modules/processors/frame/face_swapper.py index f833093..8bdd169 100644 --- a/modules/processors/frame/face_swapper.py +++ b/modules/processors/frame/face_swapper.py @@ -18,7 +18,7 @@ NAME = 'DLC.FACE-SWAPPER' def pre_check() -> bool: download_directory_path = resolve_relative_path('../models') - conditional_download(download_directory_path, ['https://huggingface.co/hacksider/deep-live-cam/blob/main/inswapper_128.onnx']) + conditional_download(download_directory_path, ['https://huggingface.co/hacksider/deep-live-cam/blob/main/' + modules.globals.model]) return True @@ -40,7 +40,7 @@ def get_face_swapper() -> Any: with THREAD_LOCK: if FACE_SWAPPER is None: - model_path = resolve_relative_path('../models/inswapper_128.onnx') + model_path = resolve_relative_path('../models/' + modules.globals.model) FACE_SWAPPER = insightface.model_zoo.get_model(model_path, providers=modules.globals.execution_providers) return FACE_SWAPPER diff --git a/modules/utilities.py b/modules/utilities.py index e3f5930..ea0bc8f 100644 --- a/modules/utilities.py +++ b/modules/utilities.py @@ -27,8 +27,8 @@ def run_ffmpeg(args: List[str]) -> bool: try: subprocess.check_output(commands, stderr=subprocess.STDOUT) return True - except Exception: - pass + except subprocess.CalledProcessError as e: + print(f"FFmpeg error: {e.output.decode().strip()}") # Capture and print the error message return False @@ -60,6 +60,21 @@ def extract_frames(target_path: str) -> None: cap.release() +def extract_frames_ffmpeg(target_path: str) -> None: + temp_directory_path = get_temp_directory_path(target_path) + os.makedirs(temp_directory_path, exist_ok=True) # Ensure output directory exists + try: + ( + ffmpeg + .input(target_path) + .output(os.path.join(temp_directory_path, '%04d.png'), start_number=0) + .overwrite_output() + .run(capture_stdout=True, capture_stderr=True) + ) + except Exception as e: + print(f"Error running FFmpeg: {str(e)}") + + def create_video(target_path: str, fps: float = 30.0) -> None: temp_output_path = get_temp_output_path(target_path) temp_directory_path = get_temp_directory_path(target_path)