Files
facefusion/facefusion/workflows/core.py
T
b60ea40d26 3.8.0 (#1212)
* mark as next

* unify the dependency checks in pre_check and add ffprobe (#1181)

* drop keep_temp and the common options component (#1180)

Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

* introduce ffprobe and ffprobe_builder (#1182)

* introduce ffprobe and ffprobe_builder

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* introduce ffprobe and ffprobe_builder

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

* probe video metadata via ffprobe in vision (#1184)

* probe video metadata via ffprobe in vision

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* probe video metadata via ffprobe in vision

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

* adopt the workflow task vocabulary from next major (#1185)

Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

* introduce workflow-mode and workflow-strategy like next major (#1187)

Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

* restrict hdr color transfer and tag the merge output as bt709 (#1188)

* restrict hdr color transfer and tag the merge output as bt709

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* restrict hdr color transfer and tag the merge output as bt709

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* full video migration

* compose the hdr fixture via the builder chain

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* compose the test fixtures via the builder and run_ffmpeg

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

* compose every test fixture via the builder and run_ffmpeg (#1189)

* compose every test fixture via the builder and run_ffmpeg

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* use loops in tests for ffmpeg stuff

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

* New Video Manager (#1191)

* tiny adjustment for tests

* address the review on the video manager

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* introduce the stream strategy for the video workflow (#1192)

* introduce the stream strategy for the video workflow

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* address the review on the stream strategy

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

* annotate the changes for review

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* annotate the new tests for review

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* match the temp pixel format help to the locale style

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* question the set_input_seek naming

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* question the reader and writer keys

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* drop the review annotations from the encoder mapping tests

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* drop the review annotations from the thread count tests

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* drop the review annotations from the ui files

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* capture the open review questions as annotations

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

* drop the settled annotations from the types

Co-Authored-By: Claude Opus 4.8 <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01Tbcd6VWCiU4BQP1gywPr2a

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>

* switch to ffmpeg.style for audio.py

* remove todos that were never needed

* fix for ffmpeg7

* Add frame_store module (#1194)

* add frame_store module

* rename and change tests

* rename and update tests

* route window read through frame_store (#1196)

* route window read through frame_store

* update proper id

* restore todos

* restore todos

* go v4 style for workflow (#1197)

* go v4 style for workflow

* remove some todos

* route chunk read through frame_store (#1198)

* vision integration

* Deleted read_video_chunk + read_static_video_chunk

* margin decouple (#1199)

* fix windows CI fail (#1200)

* Cleanup Part1 (#1201)

* remove some todos, improve video manager, simplify ffmpeg commands and more

* do more

* remove thread count for filters

* Cleanup Part 2 (#1202)

* tons of renaming

* tons of renaming

* multi reader approach

* bring tests to an okay-ish state

* bring drain back

* improve read_video_frame speed

* rename method

* move variables

* seek video reader only when trim frame start is larger 0

* make stream the default

* Cleanup/part 3 (#1203)

* remove todo

* sort out workflow, to match upcoming v4

* remove look ahead

* remove core namespace again

* Revamp execution provider overrides/adjustments (#1206)

* Split provider hooks into override/adjust with cached CoreML base

Replace the single resolve_inference_providers processor hook with two:
override_inference_providers (full replacement) and adjust_inference_providers
(merge options onto the base providers built by create_inference_providers).
This lets CoreML processors inherit ModelCacheDirectory + SpecializationStrategy
from the base while layering ModelFormat/MLComputeUnits on top.

Co-Authored-By: Claude Opus 4.8 (1M context) <noreply@anthropic.com>
Claude-Session: https://claude.ai/code/session_01HTQCZiYjJyUX11bDpbRSiB

* fix caching for execution provider by having override and adjust ways

* fix caching for execution provider by having override and adjust ways

* fix lint

* use proper pytest fixtures

---------

Co-authored-by: Claude Opus 4.8 (1M context) <noreply@anthropic.com>

* fix update preview bug (#1205)

* fix update preview bug

* fix update preview bug

* remove guard

* add is_vision_frame

* Restrict the preview frame slider and the reader seek to the last frame index (#1207)

* fix index bug

* fix rounding bug

* avoid tobytes copy (#1208)

* beautify tests

* hide ffmpeg warnings

* simplify process_stream_frame

* Use is vision frame everywhere (#1210)

* use is_vision_frame everywhere

* fix hash

* fix lint

* fix hash creation in face store

* that model does not exist

* update workflow ffmpeg

* guard workflow (#1211)

* bump version and dependencies

* Update preview

* switch workflow strategy to disk|memory

* update preview

* update preview

* fix wording

* last minute change workflow position

* adjust wording

---------

Co-authored-by: Claude Opus 4.8 <noreply@anthropic.com>
Co-authored-by: Harisreedhar <46858047+harisreedhar@users.noreply.github.com>
Co-authored-by: harisreedhar <h4harisreedhar.s.s@gmail.com>
2026-07-30 22:25:09 +02:00

92 lines
4.3 KiB
Python

from typing import List
import numpy
from facefusion import logger, process_manager, state_manager, translator
from facefusion.audio import create_empty_audio_frame, get_audio_frame, get_voice_frame
from facefusion.common_helper import get_first
from facefusion.filesystem import filter_audio_paths
from facefusion.processors.core import get_processors_modules
from facefusion.temp_helper import clear_temp_directory, create_temp_directory
from facefusion.types import AudioFrame, ErrorCode, VisionFrame
from facefusion.vision import conditional_merge_vision_mask, extract_vision_mask, read_static_image, read_static_images, read_static_video_frame, restrict_trim_frame, restrict_video_fps, select_video_frames
def is_process_stopping() -> bool:
if process_manager.is_stopping():
process_manager.end()
logger.info(translator.get('processing_stopped'), __name__)
return process_manager.is_pending()
def setup() -> ErrorCode:
if create_temp_directory(state_manager.get_item('target_path')):
logger.debug(translator.get('creating_temp'), __name__)
return 0
def clear() -> ErrorCode:
if clear_temp_directory(state_manager.get_item('target_path')):
logger.debug(translator.get('clearing_temp'), __name__)
return 0
def conditional_get_reference_vision_frame() -> VisionFrame:
if state_manager.get_item('workflow_mode') == 'image-to-video':
return read_static_video_frame(state_manager.get_item('target_path'), state_manager.get_item('reference_frame_number'))
return read_static_image(state_manager.get_item('target_path'))
def conditional_get_source_audio_frame(frame_number : int) -> AudioFrame:
if state_manager.get_item('workflow_mode') == 'image-to-video':
trim_frame_start, _ = restrict_trim_frame(state_manager.get_item('target_path'), state_manager.get_item('trim_frame_start'), state_manager.get_item('trim_frame_end'))
temp_video_fps = restrict_video_fps(state_manager.get_item('target_path'), state_manager.get_item('output_video_fps'))
source_audio_path = get_first(filter_audio_paths(state_manager.get_item('source_paths')))
source_audio_frame = get_audio_frame(source_audio_path, temp_video_fps, frame_number - trim_frame_start)
if numpy.any(source_audio_frame):
return source_audio_frame
return create_empty_audio_frame()
def conditional_get_source_voice_frame(frame_number : int) -> AudioFrame:
if state_manager.get_item('workflow_mode') == 'image-to-video':
trim_frame_start, _ = restrict_trim_frame(state_manager.get_item('target_path'), state_manager.get_item('trim_frame_start'), state_manager.get_item('trim_frame_end'))
temp_video_fps = restrict_video_fps(state_manager.get_item('target_path'), state_manager.get_item('output_video_fps'))
source_audio_path = get_first(filter_audio_paths(state_manager.get_item('source_paths')))
source_voice_frame = get_voice_frame(source_audio_path, temp_video_fps, frame_number - trim_frame_start)
if numpy.any(source_voice_frame):
return source_voice_frame
return create_empty_audio_frame()
def conditional_get_target_vision_frames(frame_number : int) -> List[VisionFrame]:
if state_manager.get_item('workflow_mode') == 'image-to-video':
return select_video_frames(state_manager.get_item('target_path'), frame_number, state_manager.get_item('target_frame_amount'))
return [ read_static_image(state_manager.get_item('target_path')) ]
def process_temp_frame(target_vision_frames : List[VisionFrame], temp_vision_frame : VisionFrame, frame_number : int) -> VisionFrame:
reference_vision_frame = conditional_get_reference_vision_frame()
source_vision_frames = read_static_images(state_manager.get_item('source_paths'))
source_audio_frame = conditional_get_source_audio_frame(frame_number)
source_voice_frame = conditional_get_source_voice_frame(frame_number)
temp_vision_mask = extract_vision_mask(temp_vision_frame)
for processor_module in get_processors_modules(state_manager.get_item('processors')):
temp_vision_frame, temp_vision_mask = processor_module.process_frame(
{
'reference_vision_frame': reference_vision_frame,
'source_vision_frames': source_vision_frames,
'source_audio_frame': source_audio_frame,
'source_voice_frame': source_voice_frame,
'target_vision_frames': target_vision_frames,
'temp_vision_frame': temp_vision_frame[:, :, :3],
'temp_vision_mask': temp_vision_mask
})
return conditional_merge_vision_mask(temp_vision_frame, temp_vision_mask)