From 0c34dd846c9a7d1490fcc3df02d578cb5ba2c09d Mon Sep 17 00:00:00 2001 From: henryruhs Date: Tue, 22 Aug 2023 10:44:55 +0200 Subject: [PATCH] Simplify code and reduce to 25fps by default --- facefusion/core.py | 22 ++++++---------------- facefusion/utilities.py | 4 ++-- tests/test_utilities.py | 8 ++++---- 3 files changed, 12 insertions(+), 22 deletions(-) diff --git a/facefusion/core.py b/facefusion/core.py index 24dcce75..15691f9a 100755 --- a/facefusion/core.py +++ b/facefusion/core.py @@ -150,16 +150,12 @@ def process_image() -> None: def process_video() -> None: if predict_video(facefusion.globals.target_path): return + fps = detect_fps(facefusion.globals.target_path) if facefusion.globals.keep_fps else 25.0 update_status(wording.get('creating_temp')) create_temp(facefusion.globals.target_path) # extract frames - if facefusion.globals.keep_fps: - fps = detect_fps(facefusion.globals.target_path) - update_status(wording.get('extracting_frames_fps').format(fps = fps)) - extract_frames(facefusion.globals.target_path, fps) - else: - update_status(wording.get('extracting_frames_fps').format(fps = 30)) - extract_frames(facefusion.globals.target_path) + update_status(wording.get('extracting_frames_fps').format(fps = fps)) + extract_frames(facefusion.globals.target_path, fps) # process frame temp_frame_paths = get_temp_frame_paths(facefusion.globals.target_path) if temp_frame_paths: @@ -171,15 +167,9 @@ def process_video() -> None: update_status(wording.get('temp_frames_not_found')) return # create video - if facefusion.globals.keep_fps: - fps = detect_fps(facefusion.globals.target_path) - update_status(wording.get('creating_video_fps').format(fps = fps)) - if not create_video(facefusion.globals.target_path, fps): - update_status(wording.get('creating_video_failed')) - else: - update_status(wording.get('creating_video_fps').format(fps = 30)) - if not create_video(facefusion.globals.target_path): - update_status(wording.get('creating_video_failed')) + update_status(wording.get('creating_video_fps').format(fps = fps)) + if not create_video(facefusion.globals.target_path, fps): + update_status(wording.get('creating_video_failed')) # handle audio if facefusion.globals.skip_audio: move_temp(facefusion.globals.target_path, facefusion.globals.output_path) diff --git a/facefusion/utilities.py b/facefusion/utilities.py index 300b76a6..97d55481 100644 --- a/facefusion/utilities.py +++ b/facefusion/utilities.py @@ -44,7 +44,7 @@ def detect_fps(target_path : str) -> Optional[float]: return None -def extract_frames(target_path : str, fps : float = 30) -> bool: +def extract_frames(target_path : str, fps : float) -> bool: temp_directory_path = get_temp_directory_path(target_path) temp_frame_quality = round(31 - (facefusion.globals.temp_frame_quality * 0.31)) trim_frame_start = facefusion.globals.trim_frame_start @@ -62,7 +62,7 @@ def extract_frames(target_path : str, fps : float = 30) -> bool: return run_ffmpeg(commands) -def create_video(target_path : str, fps : float = 30) -> bool: +def create_video(target_path : str, fps : float) -> bool: temp_output_path = get_temp_output_path(target_path) temp_directory_path = get_temp_directory_path(target_path) output_video_quality = round(51 - (facefusion.globals.output_video_quality * 0.5)) diff --git a/tests/test_utilities.py b/tests/test_utilities.py index 8f1e3b21..4dcb8e25 100644 --- a/tests/test_utilities.py +++ b/tests/test_utilities.py @@ -46,7 +46,7 @@ def test_extract_frames() -> None: temp_directory_path = get_temp_directory_path(target_path) create_temp(target_path) - assert extract_frames(target_path, 30) is True + assert extract_frames(target_path, 30.0) is True assert len(glob.glob1(temp_directory_path, '*.jpg')) == 324 clear_temp(target_path) @@ -64,7 +64,7 @@ def test_extract_frames_with_trim_start() -> None: temp_directory_path = get_temp_directory_path(target_path) create_temp(target_path) - assert extract_frames(target_path, 30) is True + assert extract_frames(target_path, 30.0) is True assert len(glob.glob1(temp_directory_path, '*.jpg')) == frame_total clear_temp(target_path) @@ -83,7 +83,7 @@ def test_extract_frames_with_trim_start_and_trim_end() -> None: temp_directory_path = get_temp_directory_path(target_path) create_temp(target_path) - assert extract_frames(target_path, 30) is True + assert extract_frames(target_path, 30.0) is True assert len(glob.glob1(temp_directory_path, '*.jpg')) == frame_total clear_temp(target_path) @@ -101,7 +101,7 @@ def test_extract_frames_with_trim_end() -> None: temp_directory_path = get_temp_directory_path(target_path) create_temp(target_path) - assert extract_frames(target_path, 30) is True + assert extract_frames(target_path, 30.0) is True assert len(glob.glob1(temp_directory_path, '*.jpg')) == frame_total clear_temp(target_path)