mirror of
https://github.com/facefusion/facefusion.git
synced 2026-07-31 14:27:24 +02:00
Compare commits
30
Commits
| Author | SHA1 | Date | |
|---|---|---|---|
|
|
1434c2c9bc | ||
|
|
a394d48f34 | ||
|
|
5e8a37110d | ||
|
|
66d4cad568 | ||
|
|
7990faa38c | ||
|
|
aba04180ed | ||
|
|
3e7645e65c | ||
|
|
0fc547a975 | ||
|
|
ec4cba0947 | ||
|
|
33ed68679d | ||
|
|
585a7d75da | ||
|
|
4a8bfec297 | ||
|
|
e25efafef0 | ||
|
|
c5f892e76c | ||
|
|
d249733feb | ||
|
|
a14d688869 | ||
|
|
8c92608569 | ||
|
|
4ee27234f8 | ||
|
|
3602f69207 | ||
|
|
be77bd6572 | ||
|
|
76c1f79f29 | ||
|
|
1b151c5c3e | ||
|
|
a515d7fc3f | ||
|
|
4d92e8b5b7 | ||
|
|
74bfb8c297 | ||
|
|
a982ed9f61 | ||
|
|
fe4aedec4d | ||
|
|
a1e9a4180b | ||
|
|
3702f2ec99 | ||
|
|
fb4c11983d |
Binary file not shown.
|
Before Width: | Height: | Size: 1.1 MiB After Width: | Height: | Size: 1.1 MiB |
@@ -43,7 +43,7 @@ jobs:
|
||||
- name: Checkout
|
||||
uses: actions/checkout@v4
|
||||
- name: Set up FFmpeg
|
||||
uses: AnimMouse/setup-ffmpeg@v1
|
||||
uses: FedericoCarboni/setup-ffmpeg@v3
|
||||
- name: Set up Python 3.12
|
||||
uses: actions/setup-python@v5
|
||||
with:
|
||||
|
||||
+4
-4
@@ -1,3 +1,7 @@
|
||||
[workflow]
|
||||
workflow_mode =
|
||||
workflow_strategy =
|
||||
|
||||
[paths]
|
||||
temp_path =
|
||||
jobs_path =
|
||||
@@ -68,10 +72,6 @@ output_video_quality =
|
||||
output_video_scale =
|
||||
output_video_fps =
|
||||
|
||||
[workflow]
|
||||
workflow_mode =
|
||||
workflow_strategy =
|
||||
|
||||
[processors]
|
||||
processors =
|
||||
age_modifier_model =
|
||||
|
||||
+2
-2
@@ -9,6 +9,8 @@ from facefusion.vision import detect_video_fps
|
||||
|
||||
def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
|
||||
apply_state_item('command', args.get('command'))
|
||||
apply_state_item('workflow_mode', args.get('workflow_mode'))
|
||||
apply_state_item('workflow_strategy', args.get('workflow_strategy'))
|
||||
apply_state_item('temp_path', args.get('temp_path'))
|
||||
apply_state_item('jobs_path', args.get('jobs_path'))
|
||||
apply_state_item('source_paths', args.get('source_paths'))
|
||||
@@ -61,8 +63,6 @@ def apply_args(args : Args, apply_state_item : ApplyStateItem) -> None:
|
||||
output_video_fps = normalize_fps(args.get('output_video_fps')) or detect_video_fps(args.get('target_path'))
|
||||
apply_state_item('output_video_fps', output_video_fps)
|
||||
|
||||
apply_state_item('workflow_mode', args.get('workflow_mode'))
|
||||
apply_state_item('workflow_strategy', args.get('workflow_strategy'))
|
||||
available_processors = [ get_file_name(file_path) for file_path in resolve_file_paths('facefusion/processors/modules') ]
|
||||
apply_state_item('processors', args.get('processors'))
|
||||
|
||||
|
||||
@@ -9,7 +9,7 @@ from facefusion.download import conditional_download_hashes, conditional_downloa
|
||||
from facefusion.filesystem import resolve_relative_path
|
||||
from facefusion.thread_helper import conditional_thread_semaphore
|
||||
from facefusion.types import Detection, DownloadScope, DownloadSet, Fps, InferencePool, ModelSet, VisionFrame
|
||||
from facefusion.vision import detect_video_fps, fit_contain_frame, is_vision_frame, read_image
|
||||
from facefusion.vision import detect_video_fps, fit_contain_frame, read_image
|
||||
|
||||
STREAM_COUNTER = 0
|
||||
|
||||
@@ -172,7 +172,7 @@ def analyse_video(video_path : str, trim_frame_start : int, trim_frame_end : int
|
||||
vision_frame = video_manager.read_video_frame(video_reader)
|
||||
|
||||
if frame_number % int(video_fps) == 0:
|
||||
if is_vision_frame(vision_frame):
|
||||
if numpy.any(vision_frame):
|
||||
total += 1
|
||||
|
||||
if analyse_frame(vision_frame):
|
||||
|
||||
+9
-12
@@ -100,7 +100,7 @@ def pre_check() -> bool:
|
||||
def common_pre_check() -> bool:
|
||||
content_analyser_content = inspect.getsource(content_analyser).encode()
|
||||
|
||||
return hash_helper.create_hash(content_analyser_content) == '3c6ce25e'
|
||||
return hash_helper.create_hash(content_analyser_content) == '0922c180'
|
||||
|
||||
|
||||
def processors_pre_check() -> bool:
|
||||
@@ -315,19 +315,16 @@ def conditional_process() -> ErrorCode:
|
||||
if state_manager.get_item('workflow_mode') == 'auto':
|
||||
state_manager.set_item('workflow_mode', detect_workflow_mode())
|
||||
|
||||
if state_manager.get_item('workflow_mode') == detect_workflow_mode():
|
||||
for processor_module in get_processors_modules(state_manager.get_item('processors')):
|
||||
if not processor_module.pre_process('output'):
|
||||
return 2
|
||||
for processor_module in get_processors_modules(state_manager.get_item('processors')):
|
||||
if not processor_module.pre_process('output'):
|
||||
return 2
|
||||
|
||||
if state_manager.get_item('workflow_mode') == 'image-to-image':
|
||||
return image_to_image.process(start_time)
|
||||
if state_manager.get_item('workflow_mode') == 'image-to-video':
|
||||
return image_to_video.process(start_time)
|
||||
if state_manager.get_item('workflow_mode') == 'image-to-image':
|
||||
return image_to_image.process(start_time)
|
||||
if state_manager.get_item('workflow_mode') == 'image-to-video':
|
||||
return image_to_video.process(start_time)
|
||||
|
||||
return 0
|
||||
|
||||
return 2
|
||||
return 0
|
||||
|
||||
|
||||
def detect_workflow_mode() -> WorkflowMode:
|
||||
|
||||
@@ -10,7 +10,6 @@ from facefusion.face_helper import apply_nms, average_points, convert_to_face_la
|
||||
from facefusion.face_landmarker import detect_face_landmark, estimate_face_landmark_68_5
|
||||
from facefusion.face_recognizer import calculate_face_embedding
|
||||
from facefusion.types import BoundingBox, Face, FaceLandmark5, FaceLandmarkSet, FaceScoreSet, Score, VisionFrame
|
||||
from facefusion.vision import is_vision_frame
|
||||
|
||||
|
||||
def create_faces(vision_frame : VisionFrame, bounding_boxes : List[BoundingBox], face_scores : List[Score], face_landmarks_5 : List[FaceLandmark5]) -> List[Face]:
|
||||
@@ -74,7 +73,7 @@ def get_many_faces(vision_frames : List[VisionFrame]) -> List[Face]:
|
||||
many_faces : List[Face] = []
|
||||
|
||||
for vision_frame in vision_frames:
|
||||
if is_vision_frame(vision_frame):
|
||||
if numpy.any(vision_frame):
|
||||
all_bounding_boxes = []
|
||||
all_face_scores = []
|
||||
all_face_landmarks_5 = []
|
||||
|
||||
@@ -1,16 +1,17 @@
|
||||
import threading
|
||||
from typing import List, Optional
|
||||
|
||||
import numpy
|
||||
|
||||
from facefusion.hash_helper import create_hash
|
||||
from facefusion.types import Face, FaceStore, VisionFrame
|
||||
from facefusion.vision import is_vision_frame
|
||||
|
||||
FACE_STORE : FaceStore = {}
|
||||
|
||||
|
||||
def get_faces(vision_frame : VisionFrame) -> Optional[List[Face]]:
|
||||
if is_vision_frame(vision_frame):
|
||||
vision_hash = create_hash(vision_frame.tobytes())
|
||||
if numpy.any(vision_frame):
|
||||
vision_hash = create_hash(vision_frame.data)
|
||||
|
||||
if FACE_STORE.get(vision_hash):
|
||||
return FACE_STORE.get(vision_hash).get('faces')
|
||||
@@ -19,8 +20,8 @@ def get_faces(vision_frame : VisionFrame) -> Optional[List[Face]]:
|
||||
|
||||
|
||||
def set_faces(vision_frame : VisionFrame, faces : List[Face]) -> None:
|
||||
if is_vision_frame(vision_frame):
|
||||
vision_hash = create_hash(vision_frame.tobytes())
|
||||
if numpy.any(vision_frame):
|
||||
vision_hash = create_hash(vision_frame.data)
|
||||
FACE_STORE.setdefault(vision_hash,
|
||||
{
|
||||
'lock': threading.Lock()
|
||||
@@ -28,8 +29,8 @@ def set_faces(vision_frame : VisionFrame, faces : List[Face]) -> None:
|
||||
|
||||
|
||||
def resolve_lock(vision_frame : VisionFrame) -> threading.Lock:
|
||||
if is_vision_frame(vision_frame):
|
||||
vision_hash = create_hash(vision_frame.tobytes())
|
||||
if numpy.any(vision_frame):
|
||||
vision_hash = create_hash(vision_frame.data)
|
||||
return FACE_STORE.setdefault(vision_hash,
|
||||
{
|
||||
'lock': threading.Lock()
|
||||
|
||||
@@ -66,7 +66,7 @@ def run_ffmpeg(commands : List[Command]) -> subprocess.Popen[bytes]:
|
||||
|
||||
def open_ffmpeg(commands : List[Command]) -> subprocess.Popen[bytes]:
|
||||
commands = ffmpeg_builder.run(commands)
|
||||
return subprocess.Popen(commands, stdin = subprocess.PIPE, stderr = subprocess.DEVNULL, stdout = subprocess.PIPE)
|
||||
return subprocess.Popen(commands, stdin = subprocess.PIPE, stdout = subprocess.PIPE, pipesize = 1024 * 1024)
|
||||
|
||||
|
||||
def create_video_reader(video_path : str, frame_number : int, video_metadata : VideoReaderMetadata) -> subprocess.Popen[bytes]:
|
||||
|
||||
@@ -28,8 +28,8 @@ if is_windows():
|
||||
ONNXRUNTIME_SET['directml'] = ('onnxruntime-directml', '1.24.4')
|
||||
ONNXRUNTIME_SET['qnn'] = ('onnxruntime-qnn', '1.24.4')
|
||||
if is_linux():
|
||||
ONNXRUNTIME_SET['migraphx'] = ('onnxruntime-migraphx', '1.26.0')
|
||||
ONNXRUNTIME_SET['rocm'] = ('onnxruntime-rocm', '1.22.2.post3')
|
||||
ONNXRUNTIME_SET['migraphx'] = ('onnxruntime-migraphx', '1.25.0')
|
||||
ONNXRUNTIME_SET['rocm'] = ('onnxruntime-rocm', '1.22.2.post1')
|
||||
|
||||
|
||||
def cli() -> None:
|
||||
|
||||
@@ -98,6 +98,8 @@ LOCALES : Locales =\
|
||||
{
|
||||
'install_dependency': 'choose the variant of {dependency} to install',
|
||||
'skip_conda': 'skip the conda environment check',
|
||||
'workflow_mode': 'choose the workflow mode',
|
||||
'workflow_strategy': 'choose the workflow strategy',
|
||||
'config_path': 'choose the config file to override defaults',
|
||||
'temp_path': 'specify the directory for the temporary resources',
|
||||
'jobs_path': 'specify the directory to store jobs',
|
||||
@@ -134,7 +136,7 @@ LOCALES : Locales =\
|
||||
'voice_extractor_model': 'choose the model responsible for extracting the voices',
|
||||
'trim_frame_start': 'specify the starting frame of the target video',
|
||||
'trim_frame_end': 'specify the ending frame of the target video',
|
||||
'temp_frame_format': 'specify the temporary frame format',
|
||||
'temp_frame_format': 'specify the temporary resources format',
|
||||
'temp_pixel_format': 'specify the temporary pixel format',
|
||||
'target_frame_amount': 'specify the amount of target frames forwarded to the processor',
|
||||
'output_image_quality': 'specify the image quality which translates to the image compression',
|
||||
@@ -147,8 +149,6 @@ LOCALES : Locales =\
|
||||
'output_video_quality': 'specify the video quality which translates to the video compression',
|
||||
'output_video_scale': 'specify the video scale based on the target video',
|
||||
'output_video_fps': 'specify the video fps based on the target video',
|
||||
'workflow_mode': 'detect or enforce the workflow mode',
|
||||
'workflow_strategy': 'process the temporary frames in memory or on disk',
|
||||
'processors': 'load a single or multiple processors (choices: {choices}, ...)',
|
||||
'background-remover-model': 'choose the model responsible for removing the background',
|
||||
'background-remover-color': 'apply red, green blue and alpha values of the background',
|
||||
@@ -204,6 +204,7 @@ LOCALES : Locales =\
|
||||
'clear_button': 'CLEAR',
|
||||
'download_providers_checkbox_group': 'DOWNLOAD PROVIDERS',
|
||||
'execution_providers_checkbox_group': 'EXECUTION PROVIDERS',
|
||||
'workflow_mode_dropdown': 'WORKFLOW MODE',
|
||||
'workflow_strategy_dropdown': 'WORKFLOW STRATEGY',
|
||||
'execution_thread_count_slider': 'EXECUTION THREAD COUNT',
|
||||
'face_detector_angles_checkbox_group': 'FACE DETECTOR ANGLES',
|
||||
|
||||
@@ -4,7 +4,7 @@ METADATA =\
|
||||
{
|
||||
'name': 'FaceFusion',
|
||||
'description': 'Industry leading face manipulation platform',
|
||||
'version': '3.8.0',
|
||||
'version': 'NEXT',
|
||||
'license': 'OpenRAIL-AS',
|
||||
'author': 'Henry Ruhs',
|
||||
'url': 'https://facefusion.io'
|
||||
|
||||
@@ -9,4 +9,4 @@ FrameEnhancerInputs = TypedDict('FrameEnhancerInputs',
|
||||
'temp_vision_mask' : Mask
|
||||
})
|
||||
|
||||
FrameEnhancerModel = Literal['clear_reality_x4', 'face_dat_x4', 'nomos8k_sc_x4', 'real_esrgan_x2', 'real_esrgan_x2_fp16', 'real_esrgan_x4', 'real_esrgan_x4_fp16', 'real_esrgan_x8', 'real_esrgan_x8_fp16', 'real_hatgan_x4', 'real_web_photo_x4', 'realistic_rescaler_x4', 'remacri_x4', 'siax_x4', 'span_kendata_x4', 'swin2_sr_x4', 'tghq_face_x8', 'ultra_sharp_x4', 'ultra_sharp_2_x4']
|
||||
FrameEnhancerModel = Literal['clear_reality_x4', 'face_dat_x4', 'lsdir_x4', 'nomos8k_sc_x4', 'real_esrgan_x2', 'real_esrgan_x2_fp16', 'real_esrgan_x4', 'real_esrgan_x4_fp16', 'real_esrgan_x8', 'real_esrgan_x8_fp16', 'real_hatgan_x4', 'real_web_photo_x4', 'realistic_rescaler_x4', 'remacri_x4', 'siax_x4', 'span_kendata_x4', 'swin2_sr_x4', 'tghq_face_x8', 'ultra_sharp_x4', 'ultra_sharp_2_x4']
|
||||
|
||||
+10
-10
@@ -21,6 +21,15 @@ def create_help_formatter_large(prog : str) -> HelpFormatter:
|
||||
return HelpFormatter(prog, max_help_position = 300)
|
||||
|
||||
|
||||
def create_workflow_program() -> ArgumentParser:
|
||||
program = ArgumentParser(add_help = False)
|
||||
group_workflow = program.add_argument_group('workflow')
|
||||
group_workflow.add_argument('--workflow-mode', help = translator.get('help.workflow_mode'), default = config.get_str_value('workflow', 'workflow_mode', 'auto'), choices = facefusion.choices.workflow_modes)
|
||||
group_workflow.add_argument('--workflow-strategy', help = translator.get('help.workflow_strategy'), default = config.get_str_value('workflow', 'workflow_strategy', 'stream'), choices = facefusion.choices.workflow_strategies)
|
||||
job_store.register_step_keys([ 'workflow_mode', 'workflow_strategy' ])
|
||||
return program
|
||||
|
||||
|
||||
def create_config_path_program() -> ArgumentParser:
|
||||
program = ArgumentParser(add_help = False)
|
||||
group_paths = program.add_argument_group('paths')
|
||||
@@ -200,15 +209,6 @@ def create_output_creation_program() -> ArgumentParser:
|
||||
return program
|
||||
|
||||
|
||||
def create_workflow_program() -> ArgumentParser:
|
||||
program = ArgumentParser(add_help = False)
|
||||
group_workflow = program.add_argument_group('workflow')
|
||||
group_workflow.add_argument('--workflow-mode', help = translator.get('help.workflow_mode'), default = config.get_str_value('workflow', 'workflow_mode', 'auto'), choices = facefusion.choices.workflow_modes)
|
||||
group_workflow.add_argument('--workflow-strategy', help = translator.get('help.workflow_strategy'), default = config.get_str_value('workflow', 'workflow_strategy', 'memory'), choices = facefusion.choices.workflow_strategies)
|
||||
job_store.register_step_keys([ 'workflow_mode', 'workflow_strategy' ])
|
||||
return program
|
||||
|
||||
|
||||
def create_processors_program() -> ArgumentParser:
|
||||
program = ArgumentParser(add_help = False)
|
||||
available_processors = [ get_file_name(file_path) for file_path in resolve_file_paths('facefusion/processors/modules') ]
|
||||
@@ -309,7 +309,7 @@ def create_step_index_program() -> ArgumentParser:
|
||||
|
||||
|
||||
def collect_step_program() -> ArgumentParser:
|
||||
return ArgumentParser(parents = [ create_face_detector_program(), create_face_landmarker_program(), create_face_selector_program(), create_face_tracker_program(), create_face_masker_program(), create_voice_extractor_program(), create_frame_extraction_program(), create_frame_distribution_program(), create_output_creation_program(), create_workflow_program(), create_processors_program() ], add_help = False)
|
||||
return ArgumentParser(parents = [ create_workflow_program(), create_face_detector_program(), create_face_landmarker_program(), create_face_selector_program(), create_face_tracker_program(), create_face_masker_program(), create_voice_extractor_program(), create_frame_extraction_program(), create_frame_distribution_program(), create_output_creation_program(), create_processors_program() ], add_help = False)
|
||||
|
||||
|
||||
def collect_job_program() -> ArgumentParser:
|
||||
|
||||
@@ -5,6 +5,7 @@ from concurrent.futures import ThreadPoolExecutor
|
||||
from typing import Deque, Iterator, List
|
||||
|
||||
import cv2
|
||||
import numpy
|
||||
from tqdm import tqdm
|
||||
|
||||
from facefusion import ffmpeg_builder, logger, state_manager, translator
|
||||
@@ -14,7 +15,7 @@ from facefusion.ffmpeg import open_ffmpeg
|
||||
from facefusion.filesystem import is_directory
|
||||
from facefusion.processors.core import get_processors_modules
|
||||
from facefusion.types import Fps, StreamMode, VisionFrame
|
||||
from facefusion.vision import extract_vision_mask, is_vision_frame, read_static_images
|
||||
from facefusion.vision import extract_vision_mask, read_static_images
|
||||
|
||||
|
||||
def multi_process_capture(camera_capture : cv2.VideoCapture, camera_fps : Fps) -> Iterator[VisionFrame]:
|
||||
@@ -30,7 +31,7 @@ def multi_process_capture(camera_capture : cv2.VideoCapture, camera_fps : Fps) -
|
||||
if analyse_stream(capture_vision_frame, camera_fps):
|
||||
camera_capture.release()
|
||||
|
||||
if is_vision_frame(capture_vision_frame):
|
||||
if numpy.any(capture_vision_frame):
|
||||
future = executor.submit(process_stream_frame, source_vision_frames, capture_vision_frame)
|
||||
futures.append(future)
|
||||
|
||||
|
||||
+5
-5
@@ -65,7 +65,7 @@ Locales : TypeAlias = Dict[Language, Dict[str, Any]]
|
||||
LocalePoolSet : TypeAlias = Dict[str, Locales]
|
||||
|
||||
WorkflowMode = Literal['auto', 'image-to-image', 'image-to-video']
|
||||
WorkflowStrategy = Literal['disk', 'memory']
|
||||
WorkflowStrategy = Literal['disk', 'stream']
|
||||
|
||||
CameraCaptureSet : TypeAlias = Dict[str, cv2.VideoCapture]
|
||||
CameraPoolSet = TypedDict('CameraPoolSet',
|
||||
@@ -322,6 +322,8 @@ JobSet : TypeAlias = Dict[str, Job]
|
||||
StateKey = Literal\
|
||||
[
|
||||
'command',
|
||||
'workflow_mode',
|
||||
'workflow_strategy',
|
||||
'config_path',
|
||||
'temp_path',
|
||||
'jobs_path',
|
||||
@@ -376,8 +378,6 @@ StateKey = Literal\
|
||||
'output_video_quality',
|
||||
'output_video_scale',
|
||||
'output_video_fps',
|
||||
'workflow_mode',
|
||||
'workflow_strategy',
|
||||
'processors',
|
||||
'open_browser',
|
||||
'ui_layouts',
|
||||
@@ -395,6 +395,8 @@ StateKey = Literal\
|
||||
State = TypedDict('State',
|
||||
{
|
||||
'command' : str,
|
||||
'workflow_mode' : WorkflowMode,
|
||||
'workflow_strategy' : WorkflowStrategy,
|
||||
'config_path' : str,
|
||||
'temp_path' : str,
|
||||
'jobs_path' : str,
|
||||
@@ -449,8 +451,6 @@ State = TypedDict('State',
|
||||
'output_video_quality' : int,
|
||||
'output_video_scale' : Scale,
|
||||
'output_video_fps' : float,
|
||||
'workflow_mode' : WorkflowMode,
|
||||
'workflow_strategy' : WorkflowStrategy,
|
||||
'processors' : List[str],
|
||||
'open_browser' : bool,
|
||||
'ui_layouts' : List[str],
|
||||
|
||||
@@ -18,7 +18,7 @@ from facefusion.types import AudioFrame, Face, Mask, VisionFrame
|
||||
from facefusion.uis import choices as uis_choices
|
||||
from facefusion.uis.core import get_ui_component, get_ui_components, register_ui_component
|
||||
from facefusion.uis.types import ComponentOptions, PreviewMode
|
||||
from facefusion.vision import detect_frame_orientation, extract_vision_mask, fit_cover_frame, is_vision_frame, merge_vision_mask, obscure_frame, read_static_image, read_static_images, read_video_frame, restrict_frame, select_video_frames, unpack_resolution
|
||||
from facefusion.vision import detect_frame_orientation, extract_vision_mask, fit_cover_frame, merge_vision_mask, obscure_frame, read_static_image, read_static_images, read_video_frame, restrict_frame, select_video_frames, unpack_resolution
|
||||
|
||||
PREVIEW_IMAGE : Optional[gradio.Image] = None
|
||||
|
||||
@@ -277,7 +277,7 @@ def create_face_by_face(reference_vision_frame : VisionFrame, source_vision_fram
|
||||
target_crop_vision_frame = extract_crop_frame(target_vision_frame, target_face)
|
||||
output_crop_vision_frame = extract_crop_frame(temp_vision_frame, target_face)
|
||||
|
||||
if is_vision_frame(target_crop_vision_frame) and is_vision_frame(output_crop_vision_frame):
|
||||
if numpy.any(target_crop_vision_frame) and numpy.any(output_crop_vision_frame):
|
||||
target_crop_dimension = min(target_crop_vision_frame.shape[:2])
|
||||
target_crop_vision_frame = fit_cover_frame(target_crop_vision_frame, (target_crop_dimension, target_crop_dimension))
|
||||
output_crop_vision_frame = fit_cover_frame(output_crop_vision_frame, (target_crop_dimension, target_crop_dimension))
|
||||
|
||||
@@ -4,14 +4,21 @@ import gradio
|
||||
|
||||
import facefusion.choices
|
||||
from facefusion import state_manager, translator
|
||||
from facefusion.types import WorkflowStrategy
|
||||
from facefusion.types import WorkflowMode, WorkflowStrategy
|
||||
|
||||
WORKFLOW_MODE_DROPDOWN : Optional[gradio.Dropdown] = None
|
||||
WORKFLOW_STRATEGY_DROPDOWN : Optional[gradio.Dropdown] = None
|
||||
|
||||
|
||||
def render() -> None:
|
||||
global WORKFLOW_MODE_DROPDOWN
|
||||
global WORKFLOW_STRATEGY_DROPDOWN
|
||||
|
||||
WORKFLOW_MODE_DROPDOWN = gradio.Dropdown(
|
||||
label = translator.get('uis.workflow_mode_dropdown'),
|
||||
choices = facefusion.choices.workflow_modes,
|
||||
value = state_manager.get_item('workflow_mode')
|
||||
)
|
||||
WORKFLOW_STRATEGY_DROPDOWN = gradio.Dropdown(
|
||||
label = translator.get('uis.workflow_strategy_dropdown'),
|
||||
choices = facefusion.choices.workflow_strategies,
|
||||
@@ -20,8 +27,13 @@ def render() -> None:
|
||||
|
||||
|
||||
def listen() -> None:
|
||||
WORKFLOW_MODE_DROPDOWN.change(update_workflow_mode, inputs = WORKFLOW_MODE_DROPDOWN)
|
||||
WORKFLOW_STRATEGY_DROPDOWN.change(update_workflow_strategy, inputs = WORKFLOW_STRATEGY_DROPDOWN)
|
||||
|
||||
|
||||
def update_workflow_mode(workflow_mode : WorkflowMode) -> None:
|
||||
state_manager.set_item('workflow_mode', workflow_mode)
|
||||
|
||||
|
||||
def update_workflow_strategy(workflow_strategy : WorkflowStrategy) -> None:
|
||||
state_manager.set_item('workflow_strategy', workflow_strategy)
|
||||
|
||||
@@ -3,7 +3,7 @@ from functools import partial
|
||||
from facefusion import process_manager, state_manager
|
||||
from facefusion.types import ErrorCode
|
||||
from facefusion.workflows.core import clear, setup
|
||||
from facefusion.workflows.to_video import analyse_video, extract_frames, finalize_video, merge_frames, process_disk_frames, process_memory_frames, restore_audio
|
||||
from facefusion.workflows.to_video import analyse_video, extract_frames, finalize_video, merge_frames, process_disk_frames, process_stream_frames, restore_audio
|
||||
|
||||
|
||||
def process(start_time : float) -> ErrorCode:
|
||||
@@ -22,8 +22,8 @@ def process(start_time : float) -> ErrorCode:
|
||||
merge_frames
|
||||
])
|
||||
|
||||
if state_manager.get_item('workflow_strategy') == 'memory':
|
||||
tasks.append(process_memory_frames)
|
||||
if state_manager.get_item('workflow_strategy') == 'stream':
|
||||
tasks.append(process_stream_frames)
|
||||
|
||||
tasks.extend(
|
||||
[
|
||||
|
||||
@@ -1,5 +1,5 @@
|
||||
from concurrent.futures import ThreadPoolExecutor
|
||||
from itertools import repeat
|
||||
from concurrent.futures import ThreadPoolExecutor, as_completed
|
||||
from typing import Tuple
|
||||
|
||||
import cv2
|
||||
import numpy
|
||||
@@ -58,8 +58,19 @@ def process_disk_frames() -> ErrorCode:
|
||||
read_static_video_frame(state_manager.get_item('target_path'), state_manager.get_item('reference_frame_number'))
|
||||
|
||||
with ThreadPoolExecutor(max_workers = state_manager.get_item('execution_thread_count')) as executor:
|
||||
for temp_vision_frame_ in executor.map(process_disk_frame, temp_frame_set.values(), temp_frame_set.keys()):
|
||||
if not is_process_stopping():
|
||||
futures = []
|
||||
|
||||
for frame_number, temp_frame_path in temp_frame_set.items():
|
||||
future = executor.submit(process_disk_frame, temp_frame_path, frame_number)
|
||||
futures.append(future)
|
||||
|
||||
for future in as_completed(futures):
|
||||
if is_process_stopping():
|
||||
for pending_future in futures:
|
||||
pending_future.cancel()
|
||||
|
||||
if not future.cancelled():
|
||||
future.result()
|
||||
progress.update()
|
||||
|
||||
for processor_module in get_processors_modules(state_manager.get_item('processors')):
|
||||
@@ -73,7 +84,7 @@ def process_disk_frames() -> ErrorCode:
|
||||
return 0
|
||||
|
||||
|
||||
def process_memory_frame(frame_number : int, temp_video_resolution : Resolution) -> VisionFrame:
|
||||
def process_stream_frame(frame_number : int, temp_video_resolution : Resolution) -> Tuple[int, VisionFrame]:
|
||||
target_vision_frames = select_video_frames(state_manager.get_item('target_path'), frame_number, state_manager.get_item('target_frame_amount'))
|
||||
target_vision_frame = get_middle(target_vision_frames)
|
||||
temp_vision_frame = target_vision_frame.copy()
|
||||
@@ -89,10 +100,10 @@ def process_memory_frame(frame_number : int, temp_video_resolution : Resolution)
|
||||
if state_manager.get_item('temp_pixel_format') == 'bgr24':
|
||||
temp_vision_frame = temp_vision_frame[:, :, :3]
|
||||
|
||||
return numpy.ascontiguousarray(temp_vision_frame)
|
||||
return frame_number, numpy.ascontiguousarray(temp_vision_frame)
|
||||
|
||||
|
||||
def process_memory_frames() -> ErrorCode:
|
||||
def process_stream_frames() -> 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'))
|
||||
output_video_resolution = scale_resolution(detect_video_resolution(state_manager.get_item('target_path')), state_manager.get_item('output_video_scale'))
|
||||
temp_video_resolution = restrict_video_resolution(state_manager.get_item('target_path'), output_video_resolution)
|
||||
@@ -108,8 +119,19 @@ def process_memory_frames() -> ErrorCode:
|
||||
read_static_video_frame(state_manager.get_item('target_path'), state_manager.get_item('reference_frame_number'))
|
||||
|
||||
with ThreadPoolExecutor(max_workers = state_manager.get_item('execution_thread_count')) as executor:
|
||||
for temp_vision_frame in executor.map(process_memory_frame, temp_frame_range, repeat(temp_video_resolution)):
|
||||
if not is_process_stopping():
|
||||
futures = []
|
||||
|
||||
for frame_number in temp_frame_range:
|
||||
future = executor.submit(process_stream_frame, frame_number, temp_video_resolution)
|
||||
futures.append(future)
|
||||
|
||||
for future in futures:
|
||||
if is_process_stopping():
|
||||
for pending_future in futures:
|
||||
pending_future.cancel()
|
||||
|
||||
if not future.cancelled():
|
||||
_, temp_vision_frame = future.result()
|
||||
video_manager.write_video_frame(video_writer, temp_vision_frame)
|
||||
progress.update()
|
||||
|
||||
|
||||
+5
-5
@@ -1,8 +1,8 @@
|
||||
gradio-rangeslider==0.0.8
|
||||
gradio==5.50.0
|
||||
numpy==2.4.6
|
||||
onnx==1.22.0
|
||||
numpy==2.2.1
|
||||
onnx==1.21.0
|
||||
onnxruntime==1.26.0
|
||||
opencv-python-headless==5.0.0.93
|
||||
tqdm==4.70.0
|
||||
scipy==1.18.0
|
||||
opencv-python==4.13.0.92
|
||||
tqdm==4.67.3
|
||||
scipy==1.17.1
|
||||
|
||||
@@ -50,35 +50,34 @@ def test_get_reader() -> None:
|
||||
assert video_metadata.get('resolution') == (426, 226)
|
||||
assert video_metadata.get('fps') == 25.0
|
||||
assert video_metadata.get('frame_total') == 270
|
||||
|
||||
assert get_reader(get_test_example_file('target-240p-25fps.mp4'), 'read_video_frame') is video_reader
|
||||
assert not get_reader(get_test_example_file('target-240p-25fps.mp4'), 'select_video_frames').get('id') == video_reader.get('id')
|
||||
|
||||
|
||||
def test_conditional_seek_video_reader() -> None:
|
||||
video_reader = get_reader(get_test_example_file('target-240p-25fps.mp4'), 'read_video_frame')
|
||||
video_frames = {}
|
||||
sequential_frames = {}
|
||||
|
||||
for frame_number in range(30):
|
||||
video_frames[frame_number] = read_video_frame(video_reader)
|
||||
sequential_frames[frame_number] = read_video_frame(video_reader)
|
||||
|
||||
for frame_number in [ 5, 17, 29 ]:
|
||||
conditional_seek_video_reader(video_reader, frame_number)
|
||||
|
||||
assert numpy.array_equal(read_video_frame(video_reader), video_frames.get(frame_number)) is True
|
||||
assert numpy.array_equal(read_video_frame(video_reader), sequential_frames.get(frame_number)) is True
|
||||
|
||||
|
||||
def test_seek_video_reader() -> None:
|
||||
video_reader = get_reader(get_test_example_file('target-240p-25fps.mp4'), 'read_video_frame')
|
||||
video_frames = {}
|
||||
sequential_frames = {}
|
||||
|
||||
for frame_number in range(30):
|
||||
video_frames[frame_number] = read_video_frame(video_reader)
|
||||
sequential_frames[frame_number] = read_video_frame(video_reader)
|
||||
|
||||
for frame_number in [ 5, 17, 29 ]:
|
||||
seek_video_reader(video_reader, frame_number)
|
||||
|
||||
assert numpy.array_equal(read_video_frame(video_reader), video_frames.get(frame_number)) is True
|
||||
assert numpy.array_equal(read_video_frame(video_reader), sequential_frames.get(frame_number)) is True
|
||||
|
||||
|
||||
def test_drain_video_reader() -> None:
|
||||
@@ -134,7 +133,6 @@ def test_collect_video_frames() -> None:
|
||||
|
||||
def test_close_video_reader() -> None:
|
||||
video_reader = get_reader(get_test_example_file('target-240p-25fps.mp4'), 'select_video_frames')
|
||||
|
||||
read_video_frames(video_reader, 0, 4)
|
||||
close_video_reader(video_reader)
|
||||
|
||||
@@ -178,7 +176,6 @@ def test_close_video_writer() -> None:
|
||||
create_temp_directory(target_path)
|
||||
video_reader = get_reader(target_path, 'read_video_frame')
|
||||
video_writer = get_writer(target_path, 30.0, (426, 226), (426, 226), 30.0)
|
||||
|
||||
write_video_frame(video_writer, read_video_frame(video_reader))
|
||||
|
||||
assert close_video_writer(video_writer) is True
|
||||
@@ -189,7 +186,6 @@ def test_clear_video_pool() -> None:
|
||||
create_temp_directory(target_path)
|
||||
video_reader = get_reader(target_path, 'select_video_frames')
|
||||
video_writer = get_writer(target_path, 25.0, (426, 226), (426, 226), 25.0)
|
||||
|
||||
read_video_frames(video_reader, 0, 4)
|
||||
write_video_frame(video_writer, read_video_frame(video_reader))
|
||||
clear_video_pool()
|
||||
|
||||
Reference in New Issue
Block a user