Simplify code and reduce to 25fps by default

This commit is contained in:
henryruhs 2023-08-22 10:44:55 +02:00
parent 09c2fb2f46
commit 0c34dd846c
3 changed files with 12 additions and 22 deletions

View File

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

View File

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

View File

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