From 29d65d8e794d3403e1af60a32de92f6644d527a0 Mon Sep 17 00:00:00 2001 From: Jose Manuel Date: Fri, 2 Jun 2023 21:12:25 +0200 Subject: [PATCH] Centraliza ffmpeg run command --- roop/globals.py | 2 +- roop/utils.py | 14 +++++++------- 2 files changed, 8 insertions(+), 8 deletions(-) diff --git a/roop/globals.py b/roop/globals.py index 9972193..d0f621a 100644 --- a/roop/globals.py +++ b/roop/globals.py @@ -2,7 +2,7 @@ import onnxruntime use_gpu = False all_faces = False -debug = False +log_level = 'quiet' providers = onnxruntime.get_available_providers() if 'TensorrtExecutionProvider' in providers: diff --git a/roop/utils.py b/roop/utils.py index 0aed392..a92f7fc 100644 --- a/roop/utils.py +++ b/roop/utils.py @@ -29,28 +29,28 @@ def detect_fps(input_path): pass return 30, 30 -def get_ffmpeg_cmd(): +def run_ffmpeg(args): hwaccel_option = '-hwaccel cuda' if roop.globals.use_gpu else '' - log_level = '-loglevel error' if roop.globals.debug else '-loglevel quiet' + log_level = '-loglevel {roop.globals.log_level}' - return f'ffmpeg {hwaccel_option} {log_level}' + os.system(f'ffmpeg {hwaccel_option} {log_level} {args}') def set_fps(input_path, output_path, fps): basic_command = get_ffmpeg_cmd() input_path, output_path = path(input_path), path(output_path) - os.system(f'{basic_command} -i "{input_path}" -filter:v fps=fps={fps} "{output_path}"') + run_ffmpeg(f'-i "{input_path}" -filter:v fps=fps={fps} "{output_path}"') def create_video(video_name, fps, output_dir): basic_command = get_ffmpeg_cmd() output_dir = path(output_dir) - os.system(f'{basic_command} -framerate "{fps}" -i "{output_dir}{sep}%04d.png" -c:v libx264 -crf 7 -pix_fmt yuv420p -y "{output_dir}{sep}output.mp4"') + run_ffmpeg(f'-framerate "{fps}" -i "{output_dir}{sep}%04d.png" -c:v libx264 -crf 7 -pix_fmt yuv420p -y "{output_dir}{sep}output.mp4"') def extract_frames(input_path, output_dir): basic_command = get_ffmpeg_cmd() input_path, output_dir = path(input_path), path(output_dir) - os.system(f'{basic_command} -i "{input_path}" "{output_dir}{sep}%04d.png"') + run_ffmpeg(f'-i "{input_path}" "{output_dir}{sep}%04d.png"') def add_audio(output_dir, target_path, video, keep_frames, output_file): @@ -58,7 +58,7 @@ 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) - os.system(f'{basic_command} -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}"') + run_ffmpeg(f'-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}"') if not os.path.isfile(save_to): shutil.move(output_dir + "/output.mp4", save_to) if not keep_frames: