From 37a71f661ce654da340665e1791956dd58f737e6 Mon Sep 17 00:00:00 2001 From: Jose Manuel Date: Fri, 2 Jun 2023 20:40:02 +0200 Subject: [PATCH] Use flags as global --- roop/core.py | 8 ++++---- roop/utils.py | 17 +++++++++-------- 2 files changed, 13 insertions(+), 12 deletions(-) diff --git a/roop/core.py b/roop/core.py index 8b53fef..2629c37 100644 --- a/roop/core.py +++ b/roop/core.py @@ -217,12 +217,12 @@ def start(): fps, exact_fps = detect_fps(target_path) if not args['keep_fps'] and fps > 30: this_path = output_dir + "/" + video_name + ".mp4" - set_fps(target_path, this_path, 30, roop.globals.use_gpu) + set_fps(target_path, this_path, 30) target_path, exact_fps = this_path, 30 else: shutil.copy(target_path, output_dir) status("extracting frames...") - extract_frames(target_path, output_dir, roop.globals.use_gpu) + extract_frames(target_path, output_dir) args['frame_paths'] = tuple(sorted( glob.glob(output_dir + "/*.png"), key=lambda x: int(x.split(sep)[-1].replace(".png", "")) @@ -230,9 +230,9 @@ def start(): status("swapping in progress...") start_processing() status("creating video...") - create_video(video_name, exact_fps, output_dir, roop.globals.use_gpu) + create_video(video_name, exact_fps, output_dir) status("adding audio...") - add_audio(output_dir, target_path, video_name_full, args['keep_frames'], args['output_file'], roop.globals.use_gpu) + add_audio(output_dir, target_path, video_name_full, args['keep_frames'], args['output_file']) save_path = args['output_file'] if args['output_file'] else output_dir + "/" + video_name + ".mp4" print("\n\nVideo saved as:", save_path, "\n\n") status("swap successful!") diff --git a/roop/utils.py b/roop/utils.py index 69c0aad..479ddb8 100644 --- a/roop/utils.py +++ b/roop/utils.py @@ -1,5 +1,6 @@ import os import shutil +import roop.globals sep = "/" if os.name == "nt": @@ -29,29 +30,29 @@ def detect_fps(input_path): return 30, 30 -def set_fps(input_path, output_path, fps, use_gpu): +def set_fps(input_path, output_path, fps): input_path, output_path = path(input_path), path(output_path) - hwaccel_option = '-hwaccel cuda' if use_gpu else '' + hwaccel_option = '-hwaccel cuda' if roop.globals.use_gpu else '' os.system(f'ffmpeg {hwaccel_option} -i "{input_path}" -filter:v fps=fps={fps} "{output_path}" -loglevel error') -def create_video(video_name, fps, output_dir, use_gpu): +def create_video(video_name, fps, output_dir): output_dir = path(output_dir) - hwaccel_option = '-hwaccel cuda' if use_gpu else '' + hwaccel_option = '-hwaccel cuda' if roop.globals.use_gpu else '' os.system(f'ffmpeg {hwaccel_option} -framerate "{fps}" -i "{output_dir}{sep}%04d.png" -c:v libx264 -crf 7 -pix_fmt yuv420p -y "{output_dir}{sep}output.mp4" -loglevel error') -def extract_frames(input_path, output_dir, use_gpu): +def extract_frames(input_path, output_dir): input_path, output_dir = path(input_path), path(output_dir) - hwaccel_option = '-hwaccel cuda' if use_gpu else '' + hwaccel_option = '-hwaccel cuda' if roop.globals.use_gpu else '' os.system(f'ffmpeg {hwaccel_option} -i "{input_path}" "{output_dir}{sep}%04d.png" -loglevel error') -def add_audio(output_dir, target_path, video, keep_frames, output_file, use_gpu): +def add_audio(output_dir, target_path, video, keep_frames, output_file): video_name = os.path.splitext(video)[0] save_to = output_file if output_file else output_dir + "/swapped-" + video_name + ".mp4" save_to_ff, output_dir_ff = path(save_to), path(output_dir) - hwaccel_option = '-hwaccel cuda' if use_gpu else '' + hwaccel_option = '-hwaccel cuda' if roop.globals.use_gpu else '' os.system(f'ffmpeg {hwaccel_option} -i "{output_dir_ff}{sep}output.mp4" -i "{output_dir_ff}{sep}{video}" -c:v copy -map 0:v:0 -map 1:a:0 -y "{save_to_ff}" -loglevel error') if not os.path.isfile(save_to): shutil.move(output_dir + "/output.mp4", save_to)