diff --git a/facefusion/workflows/image_to_video.py b/facefusion/workflows/image_to_video.py index 4d532b20..2bebdd09 100644 --- a/facefusion/workflows/image_to_video.py +++ b/facefusion/workflows/image_to_video.py @@ -1,4 +1,4 @@ -from concurrent.futures import Future, ThreadPoolExecutor, as_completed +from concurrent.futures import ThreadPoolExecutor, as_completed from functools import partial from typing import List, Tuple @@ -21,45 +21,43 @@ from facefusion.workflows.core import is_process_stopping def process(start_time : float) -> ErrorCode: - trim_frame_start, trim_frame_end = restrict_trim_frame(state_manager.get_item('target_path'), state_manager.get_item('trim_frame_start'), state_manager.get_item('trim_frame_end')) + tasks =\ + [ + setup, + extract_frames, + process_disk_frames, + merge_frames, + enforce_analysis, + restore_audio, + partial(finalize_video, start_time) + ] - with ThreadPoolExecutor(max_workers = 1) as analyse_executor: - analyse_future = analyse_executor.submit(analyse_video, state_manager.get_item('target_path'), trim_frame_start, trim_frame_end) + if state_manager.get_item('workflow_mode') == 'stream': tasks =\ [ setup, - extract_frames, - process_disk_frames, - merge_frames, - partial(enforce_analysis, analyse_future), + process_stream_frames, + enforce_analysis, restore_audio, partial(finalize_video, start_time) ] + process_manager.start() - if state_manager.get_item('workflow_mode') == 'stream': - tasks =\ - [ - setup, - process_stream_frames, - partial(enforce_analysis, analyse_future), - restore_audio, - partial(finalize_video, start_time) - ] - process_manager.start() + for task in tasks: + error_code = task() #type:ignore[operator] - for task in tasks: - error_code = task() #type:ignore[operator] + if error_code > 0: + process_manager.end() + return error_code - if error_code > 0: - process_manager.end() - return error_code - - process_manager.end() + process_manager.end() return 0 -def enforce_analysis(analyse_future : Future[bool]) -> ErrorCode: - if analyse_future.result(): +def enforce_analysis() -> ErrorCode: + trim_frame_start, trim_frame_end = restrict_trim_frame(state_manager.get_item('target_path'), state_manager.get_item('trim_frame_start'), state_manager.get_item('trim_frame_end')) + + if analyse_video(state_manager.get_item('target_path'), trim_frame_start, trim_frame_end): clear_temp_directory(state_manager.get_item('target_path')) return 3 return 0