Centraliza ffmpeg run command

This commit is contained in:
Jose Manuel 2023-06-02 21:12:25 +02:00
parent 74783142e6
commit 29d65d8e79
2 changed files with 8 additions and 8 deletions

View File

@ -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:

View File

@ -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: