* mark as next, introduce dynamic scale for face debugger

* use latest onnxruntime

* update within Gradio 5

* Remove system memory limit (#986)

* remove system memory limit from ui

* remove system memory limit from args.py

* flatten the face store

* prevent countless importlib.import_module calls

* remove --onnxruntime from install.py

* remove --onnxruntime from install.py

* resolve static inference providers to fix macos (#1127)

* resolve static inference providers to fix macos

* fix lint

* restore old behaviour

* restore old behaviour

* handle ghost and uniface as well

* adjust condition for ghost and uniface

* fix Gradio gallery styles

* remove face store (#1132)

* fix dataflow in streamer

* Face selector auto mode (#1137)

* introduce face selector auto mode

* introduce face selector auto mode

* introduce face selector auto mode

* correct way is to pass source_vision_frames

* make the world a better place

* fix dataflow in faceswapper, no read of files withing inner methods (#1148)

* fix dataflow in faceswapper, no read of files withing inner methods

* fix lint

* adjust code more

* adjust code more

* bring back the face store but for source and reference only (#1149)

* bring back the face store but for source and reference only

* fix ci

* minor improvement

* guard for tobytes()

* drop condition in select_faces()

* Replace CONFIG_PARSER global with @lru_cache (#1147)

* remove global config_parser

* fix import order

* remove lambda

* remove unused block

* optimize app context detection

* decouple common modules from core (#1152)

* decouple common modules from core

* remove that nonsense

* remove that nonsense

* minor adjustment to workflows

* Tag HEVC output as hvc1 and move moov atom to the front (#1153)

* Tag HEVC output as hvc1 and move moov atom to the front

ffmpeg defaults HEVC in MP4 to the 'hev1' sample entry and leaves the moov
atom at the tail. Apple players (QuickTime, Finder QuickLook) refuse to decode
'hev1' and stall reading a tail-placed moov on large files, so hevc_nvenc /
libx265 renders cannot be previewed on macOS.

- add ffmpeg_builder.set_video_tag(): emit `-tag:v hvc1` for every HEVC
  encoder (libx265, hevc_nvenc, hevc_amf, hevc_qsv, hevc_videotoolbox).
  Applied in merge_video where the encoder is known; `-c:v copy` in the audio
  mux / concat steps preserves the tag.
- add ffmpeg_builder.set_faststart(): emit `-movflags +faststart`, applied in
  restore_audio / replace_audio / concat_video which write the final output.

H.264 and other codecs are left untouched. Verified on a real hevc_nvenc
render: hev1 hung QuickLook (no thumbnail); after the patch the file is hvc1
with a front-placed moov and QuickLook generates a thumbnail.

* Restrict hvc1 tag and faststart to quicktime containers

Gate set_video_tag / set_faststart on the output container format
(m4v, mov, mp4) via get_file_format(), so non-quicktime muxers no longer
receive -tag:v hvc1 / -movflags +faststart. Trim test_set_video_tag to a
single positive and negative assertion.

Addresses review on #1153.

* Move hvc1 tag and faststart gates into ffmpeg_builder

Rename set_video_tag / set_faststart to conditional_* and push the
container-format gate (m4v, mov, mp4) inside the builders, keeping
ffmpeg.py free of inline conditionals. Matches the set_image_quality
pattern. Addresses review on #1153.

* post cleanup after merge

* Pack target frames (#1158)

* pack target frames

* add todos

* add todos, resolve todos

* resolve todos

* change names

* revert to single target frame for select faces

* fix lint

* return empty frame

* get() have no default

* Fix trim (#1162)

* fix trim

* fix trim

* rename ffmpeg builder method

* rename to temp_frame_set and temp_frame_pattern

---------

Co-authored-by: harisreedhar <h4harisreedhar.s.s@gmail.com>
Co-authored-by: Harisreedhar <46858047+harisreedhar@users.noreply.github.com>

* Implement face tracker (#1163)

* add face tracker

* change get_nearest_track_face -> get_nearest_track_index

* create face_creator.py and move methods around

* add type FaceTrack

* naming

* remove iou test, don't belong there

* fix spaces

* rename to interpolate_points

* rename to find_best_face_track

* just track_faces

* cleanp

* previous next naming

* remove >= and >=

* rename

* remove helper from test and use face from source.jpg

* make get_anchor_indices more readable

* track_faces() call before and is forwarded to select_faces

* change to interpolate_faces

* rename methods

* rename methods

* rename variables

* remove dtype

* move face_anlyser -> face_creator

* claenup face_creator.py

* move tests to dedicated test face detector

* move tracking inside select_faces

* simplify face_tracker (#1165)

* minor renaming

* improve face_tracker test (#1166)

* improve face_tracker test

* cleanup

* Add target frame amount (#1167)

* introduce --target-frame-amount

* add ui

* make track_faces conditional

* update choices.py

* fix []

* rename component file to frame_process.py

* fix track preview (#1168)

* introduce face origin (#1169)

* add guard to prevent failure

* show and hide voice extractor according to lip syncer

* rename average_face_coordinates to average_face_geometry

* use static faces for select_faces()

* face store with lock (#1171)

* face store with lock

* face store with lock

* remove refill color from bbox

* adjust tests and handle frame_position proper way

* enforce similar naming

* introduce face tracker score

* introduce face tracker score

* fix/audio-trim-alignment (#1173)

* fix audio offset

* fix audio offset

* remove reference_frame_number check

---------

Co-authored-by: harisreedhar <h4harisreedhar.s.s@gmail.com>

* reduce face tracker score from 0 to 0.5

* mark as 3.7.0

* make face tracker stateless

---------

Co-authored-by: Harisreedhar <46858047+harisreedhar@users.noreply.github.com>
Co-authored-by: kazuki nakai <kazuki.nakai@agiletec.net>
Co-authored-by: harisreedhar <h4harisreedhar.s.s@gmail.com>
This commit is contained in:
Henry Ruhs
2026-06-30 15:00:02 +02:00
committed by GitHub
parent 5b7d145aa7
commit a2cbfd73b1
76 changed files with 1281 additions and 586 deletions
+2 -2
View File
@@ -17,8 +17,8 @@ def before_all() -> None:
def test_get_audio_frame() -> None:
assert hasattr(get_audio_frame(get_test_example_file('source.mp3'), 25), '__array_interface__')
assert hasattr(get_audio_frame(get_test_example_file('source.wav'), 25), '__array_interface__')
assert get_audio_frame(get_test_example_file('source.mp3'), 25).shape == (80, 16)
assert get_audio_frame(get_test_example_file('source.wav'), 25).shape == (80, 16)
assert get_audio_frame('invalid', 25) is None
+7 -2
View File
@@ -1,4 +1,4 @@
from facefusion.common_helper import calculate_float_step, calculate_int_step, create_float_metavar, create_float_range, create_int_metavar, create_int_range
from facefusion.common_helper import calculate_float_step, calculate_int_step, create_float_metavar, create_float_range, create_int_metavar, create_int_range, get_middle
def test_create_int_metavar() -> None:
@@ -16,7 +16,7 @@ def test_create_int_range() -> None:
def test_create_float_range() -> None:
assert create_float_range(0.0, 1.0, 0.5) == [ 0.0, 0.5, 1.0 ]
assert create_float_range(0.0, 1.0, 0.05) == [ 0.0, 0.05, 0.10, 0.15, 0.20, 0.25, 0.30, 0.35, 0.40, 0.45, 0.50, 0.55, 0.60, 0.65, 0.70, 0.75, 0.80, 0.85, 0.90, 0.95, 1.0 ]
assert create_float_range(0.0, 0.5, 0.05) == [ 0.0, 0.05, 0.10, 0.15, 0.20, 0.25, 0.30, 0.35, 0.40, 0.45, 0.50 ]
def test_calc_int_step() -> None:
@@ -25,3 +25,8 @@ def test_calc_int_step() -> None:
def test_calc_float_step() -> None:
assert calculate_float_step([ 0.1, 0.2 ]) == 0.1
def test_get_middle() -> None:
assert get_middle([ 1, 2, 3, 4, 5 ]) == 3
assert get_middle([ 1 ]) == 1
+4 -5
View File
@@ -1,14 +1,13 @@
from configparser import ConfigParser
import pytest
from facefusion import config
from facefusion import config, state_manager
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
config.CONFIG_PARSER = ConfigParser()
config.CONFIG_PARSER.read_dict(
state_manager.init_item('config_path', 'facefusion.ini')
config_parser = config.get_static_config_parser()
config_parser.read_dict(
{
'str':
{
+105
View File
@@ -0,0 +1,105 @@
import subprocess
import numpy
import pytest
from facefusion import face_classifier, face_detector, face_landmarker, face_recognizer, state_manager
from facefusion.download import conditional_download
from facefusion.face_creator import average_face_geometry, get_many_faces, get_one_face, refill_faces
from facefusion.face_store import clear_faces
from facefusion.vision import read_static_image
from .helper import get_test_example_file, get_test_examples_directory
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
conditional_download(get_test_examples_directory(),
[
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/source.jpg'
])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('source.jpg'), '-vf', 'crop=iw*0.8:ih*0.8', get_test_example_file('source-80crop.jpg') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('source.jpg'), '-vf', 'crop=iw*0.7:ih*0.7', get_test_example_file('source-70crop.jpg') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('source.jpg'), '-vf', 'crop=iw*0.6:ih*0.6', get_test_example_file('source-60crop.jpg') ])
state_manager.init_item('execution_device_ids', [ 0 ])
state_manager.init_item('execution_providers', [ 'cpu' ])
state_manager.init_item('download_providers', [ 'github' ])
state_manager.init_item('face_detector_angles', [ 0 ])
state_manager.init_item('face_detector_model', 'many')
state_manager.init_item('face_detector_size', '640x640')
state_manager.init_item('face_detector_margin', (0, 0, 0, 0))
state_manager.init_item('face_detector_score', 0.5)
state_manager.init_item('face_landmarker_model', 'many')
state_manager.init_item('face_landmarker_score', 0.5)
face_classifier.pre_check()
face_detector.pre_check()
face_landmarker.pre_check()
face_recognizer.pre_check()
@pytest.fixture(autouse = True)
def before_each() -> None:
face_classifier.clear_inference_pool()
face_detector.clear_inference_pool()
face_landmarker.clear_inference_pool()
face_recognizer.clear_inference_pool()
clear_faces()
def test_get_one_face() -> None:
source_vision_frame = read_static_image(get_test_example_file('source.jpg'))
face = get_one_face(get_many_faces([ source_vision_frame ]))
assert face.bounding_box.size == 4
def test_get_many_faces() -> None:
source_path = get_test_example_file('source.jpg')
source_vision_frame = read_static_image(source_path)
many_faces = get_many_faces([ source_vision_frame, source_vision_frame, source_vision_frame ])
assert len(many_faces) == 3
def test_refill_faces() -> None:
source_vision_frame = read_static_image(get_test_example_file('source.jpg'))
face = get_one_face(get_many_faces([ source_vision_frame ]))
face_first = face._replace(bounding_box = numpy.array([ 0, 0, 10, 10 ]))
face_middle = face._replace(bounding_box = numpy.array([ 40, 40, 50, 50 ]))
face_last = face._replace(bounding_box = numpy.array([ 80, 80, 90, 90 ]))
fill_faces = refill_faces([ face_first, None, face_last ])
assert fill_faces[0].bounding_box.tolist() == [ 0.0, 0.0, 10.0, 10.0 ]
assert fill_faces[1].bounding_box.tolist() == [ 40.0, 40.0, 50.0, 50.0 ]
assert fill_faces[2].bounding_box.tolist() == [ 80.0, 80.0, 90.0, 90.0 ]
fill_faces = refill_faces([ face_first, None, None, None, face_last ])
assert fill_faces[0].bounding_box.tolist() == [ 0.0, 0.0, 10.0, 10.0 ]
assert fill_faces[1].bounding_box.tolist() == [ 20.0, 20.0, 30.0, 30.0 ]
assert fill_faces[2].bounding_box.tolist() == [ 40.0, 40.0, 50.0, 50.0 ]
assert fill_faces[3].bounding_box.tolist() == [ 60.0, 60.0, 70.0, 70.0 ]
assert fill_faces[4].bounding_box.tolist() == [ 80.0, 80.0, 90.0, 90.0 ]
fill_faces = refill_faces([ face_first, None, face_middle, None, face_last ])
assert fill_faces[0].bounding_box.tolist() == [ 0.0, 0.0, 10.0, 10.0 ]
assert fill_faces[1].bounding_box.tolist() == [ 20.0, 20.0, 30.0, 30.0 ]
assert fill_faces[2].bounding_box.tolist() == [ 40.0, 40.0, 50.0, 50.0 ]
assert fill_faces[3].bounding_box.tolist() == [ 60.0, 60.0, 70.0, 70.0 ]
assert fill_faces[4].bounding_box.tolist() == [ 80.0, 80.0, 90.0, 90.0 ]
def test_average_face_geometry() -> None:
source_vision_frame = read_static_image(get_test_example_file('source.jpg'))
face_previous = get_one_face(get_many_faces([ source_vision_frame ]))
face_next = get_one_face(get_many_faces([ source_vision_frame ]))
face_previous = face_previous._replace(bounding_box = numpy.array([ 0, 0, 10, 10 ]))
face_next = face_next._replace(bounding_box = numpy.array([ 80, 80, 90, 90 ]))
assert average_face_geometry([face_previous, face_next], 0.5).bounding_box.tolist() == [40.0, 40.0, 50.0, 50.0]
assert average_face_geometry([face_previous, face_next], 0.5).angle == face_next.angle
assert average_face_geometry([face_previous, face_next], 0.5).embedding is face_next.embedding
assert average_face_geometry([face_previous, face_next], 0.25).embedding is face_previous.embedding
@@ -2,10 +2,10 @@ import subprocess
import pytest
from facefusion import face_classifier, face_detector, face_landmarker, face_recognizer, state_manager
from facefusion import face_detector, state_manager
from facefusion.download import conditional_download
from facefusion.face_analyser import get_many_faces
from facefusion.face_store import clear_static_faces
from facefusion.face_detector import detect_with_retinaface, detect_with_scrfd, detect_with_yolo_face, detect_with_yunet
from facefusion.face_helper import apply_nms, get_nms_threshold
from facefusion.vision import read_static_image
from .helper import get_test_example_file, get_test_examples_directory
@@ -19,34 +19,23 @@ def before_all() -> None:
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('source.jpg'), '-vf', 'crop=iw*0.8:ih*0.8', get_test_example_file('source-80crop.jpg') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('source.jpg'), '-vf', 'crop=iw*0.7:ih*0.7', get_test_example_file('source-70crop.jpg') ])
subprocess.run([ 'ffmpeg', '-i', get_test_example_file('source.jpg'), '-vf', 'crop=iw*0.6:ih*0.6', get_test_example_file('source-60crop.jpg') ])
state_manager.init_item('execution_device_ids', [ 0 ])
state_manager.init_item('execution_providers', [ 'cpu' ])
state_manager.init_item('download_providers', [ 'github' ])
state_manager.init_item('face_detector_angles', [ 0 ])
state_manager.init_item('face_detector_model', 'many')
state_manager.init_item('face_detector_score', 0.5)
state_manager.init_item('face_landmarker_model', 'many')
state_manager.init_item('face_landmarker_score', 0.5)
face_classifier.pre_check()
face_landmarker.pre_check()
face_recognizer.pre_check()
face_detector.pre_check()
@pytest.fixture(autouse = True)
def before_each() -> None:
face_classifier.clear_inference_pool()
face_detector.clear_inference_pool()
face_landmarker.clear_inference_pool()
face_recognizer.clear_inference_pool()
clear_static_faces()
def test_get_one_face_with_retinaface() -> None:
state_manager.init_item('face_detector_model', 'retinaface')
state_manager.init_item('face_detector_size', '320x320')
state_manager.init_item('face_detector_margin', (0, 0, 0, 0))
face_detector.pre_check()
def test_detect_with_retinaface() -> None:
source_paths =\
[
get_test_example_file('source.jpg'),
@@ -57,17 +46,13 @@ def test_get_one_face_with_retinaface() -> None:
for source_path in source_paths:
source_frame = read_static_image(source_path)
many_faces = get_many_faces([ source_frame ])
bounding_boxes, face_scores, face_landmarks_5 = detect_with_retinaface(source_frame, '320x320')
keep_indices = apply_nms(bounding_boxes, face_scores, 0.5, get_nms_threshold('retinaface', [ 0 ]))
assert len(many_faces) == 1
assert len(keep_indices) == 1
def test_get_one_face_with_scrfd() -> None:
state_manager.init_item('face_detector_model', 'scrfd')
state_manager.init_item('face_detector_size', '320x320')
state_manager.init_item('face_detector_margin', (0, 0, 0, 0))
face_detector.pre_check()
def test_detect_with_scrfd() -> None:
source_paths =\
[
get_test_example_file('source.jpg'),
@@ -78,17 +63,13 @@ def test_get_one_face_with_scrfd() -> None:
for source_path in source_paths:
source_frame = read_static_image(source_path)
many_faces = get_many_faces([ source_frame ])
bounding_boxes, face_scores, face_landmarks_5 = detect_with_scrfd(source_frame, '320x320')
keep_indices = apply_nms(bounding_boxes, face_scores, 0.5, get_nms_threshold('scrfd', [ 0 ]))
assert len(many_faces) == 1
assert len(keep_indices) == 1
def test_get_one_face_with_yoloface() -> None:
state_manager.init_item('face_detector_model', 'yolo_face')
state_manager.init_item('face_detector_size', '640x640')
state_manager.init_item('face_detector_margin', (0, 0, 0, 0))
face_detector.pre_check()
def test_detect_with_yolo_face() -> None:
source_paths =\
[
get_test_example_file('source.jpg'),
@@ -99,17 +80,13 @@ def test_get_one_face_with_yoloface() -> None:
for source_path in source_paths:
source_frame = read_static_image(source_path)
many_faces = get_many_faces([ source_frame ])
bounding_boxes, face_scores, face_landmarks_5 = detect_with_yolo_face(source_frame, '640x640')
keep_indices = apply_nms(bounding_boxes, face_scores, 0.5, get_nms_threshold('yolo_face', [ 0 ]))
assert len(many_faces) == 1
assert len(keep_indices) == 1
def test_get_one_face_with_yunet() -> None:
state_manager.init_item('face_detector_model', 'yunet')
state_manager.init_item('face_detector_size', '640x640')
state_manager.init_item('face_detector_margin', (0, 0, 0, 0))
face_detector.pre_check()
def test_detect_with_yunet() -> None:
source_paths =\
[
get_test_example_file('source.jpg'),
@@ -120,14 +97,7 @@ def test_get_one_face_with_yunet() -> None:
for source_path in source_paths:
source_frame = read_static_image(source_path)
many_faces = get_many_faces([ source_frame ])
bounding_boxes, face_scores, face_landmarks_5 = detect_with_yunet(source_frame, '640x640')
keep_indices = apply_nms(bounding_boxes, face_scores, 0.5, get_nms_threshold('yunet', [ 0 ]))
assert len(many_faces) == 1
def test_get_many_faces() -> None:
source_path = get_test_example_file('source.jpg')
source_frame = read_static_image(source_path)
many_faces = get_many_faces([ source_frame, source_frame, source_frame ])
assert len(many_faces) == 3
assert len(keep_indices) == 1
+102
View File
@@ -0,0 +1,102 @@
import numpy
import pytest
from facefusion import face_classifier, face_detector, face_landmarker, face_recognizer, state_manager
from facefusion.common_helper import get_first, get_last
from facefusion.download import conditional_download
from facefusion.face_creator import get_many_faces, get_one_face
from facefusion.face_store import clear_faces
from facefusion.face_tracker import create_face_tracks, select_face_track, track_faces
from facefusion.vision import read_static_video_chunk, read_static_video_frame
from .helper import get_test_example_file, get_test_examples_directory
@pytest.fixture(scope = 'module', autouse = True)
def before_all() -> None:
conditional_download(get_test_examples_directory(),
[
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/target-240p.mp4'
])
state_manager.init_item('execution_device_ids', [ 0 ])
state_manager.init_item('execution_providers', [ 'cpu' ])
state_manager.init_item('download_providers', [ 'github' ])
state_manager.init_item('face_detector_angles', [ 0 ])
state_manager.init_item('face_detector_model', 'yolo_face')
state_manager.init_item('face_detector_size', '640x640')
state_manager.init_item('face_detector_margin', (0, 0, 0, 0))
state_manager.init_item('face_detector_score', 0.5)
state_manager.init_item('face_landmarker_model', 'many')
state_manager.init_item('face_landmarker_score', 0.5)
state_manager.init_item('face_tracker_score', 0.3)
face_classifier.pre_check()
face_detector.pre_check()
face_landmarker.pre_check()
face_recognizer.pre_check()
@pytest.fixture(autouse = True)
def before_each() -> None:
face_classifier.clear_inference_pool()
face_detector.clear_inference_pool()
face_landmarker.clear_inference_pool()
face_recognizer.clear_inference_pool()
clear_faces()
def test_track_faces() -> None:
target_path = get_test_example_file('target-240p.mp4')
video_frame_chunk = read_static_video_chunk(target_path, 0, 7)
target_vision_frames = [ video_frame_chunk.get(frame_number) for frame_number in sorted(video_frame_chunk) ]
empty_vision_frame = numpy.zeros_like(get_first(target_vision_frames))
target_vision_frames[2] = empty_vision_frame
target_vision_frames[3] = empty_vision_frame
target_vision_frames[4] = empty_vision_frame
target_vision_frames[5] = empty_vision_frame
assert len(track_faces(target_vision_frames, 0.3)) == 1
target_vision_frames = [ video_frame_chunk.get(frame_number) for frame_number in sorted(video_frame_chunk)[:5] ]
target_vision_frames[0] = empty_vision_frame
target_vision_frames[1] = empty_vision_frame
target_vision_frames[2] = empty_vision_frame
assert len(track_faces(target_vision_frames, 0.3)) == 0
def test_create_face_tracks() -> None:
target_vision_frame = read_static_video_frame(get_test_example_file('target-240p.mp4'), 0)
multi_face_vision_frame = numpy.hstack([ target_vision_frame, target_vision_frame ])
face_tracks = create_face_tracks([ target_vision_frame, target_vision_frame ], 0.3)
assert len(face_tracks) == 1
assert sorted(get_first(face_tracks)) == [ 0, 1 ]
face_tracks = create_face_tracks([ multi_face_vision_frame, multi_face_vision_frame ], 0.3)
assert len(face_tracks) == 2
assert sorted(get_first(face_tracks)) == [ 0, 1 ]
assert sorted(get_last(face_tracks)) == [ 0, 1 ]
assert len(create_face_tracks([ target_vision_frame, target_vision_frame ], 1.0)) == 2
def test_select_face_track() -> None:
target_vision_frame = read_static_video_frame(get_test_example_file('target-240p.mp4'), 0)
face = get_one_face(get_many_faces([ target_vision_frame ]))
face_overlap = face._replace(bounding_box = numpy.array([ 12, 12, 52, 52 ]))
face_distant = face._replace(bounding_box = numpy.array([ 200, 200, 240, 240 ]))
face_track_overlap =\
{
0 : face._replace(bounding_box = numpy.array([ 10, 10, 50, 50 ]))
}
face_track_distant =\
{
0 : face._replace(bounding_box = numpy.array([ 100, 100, 140, 140 ]))
}
assert select_face_track([ face_track_overlap, face_track_distant ], face_overlap, 0.3) is face_track_overlap
assert select_face_track([ face_track_overlap, face_track_distant ], face_distant, 0.3) == {}
+2 -2
View File
@@ -9,7 +9,7 @@ from facefusion import process_manager, state_manager
from facefusion.download import conditional_download
from facefusion.ffmpeg import concat_video, extract_frames, merge_video, read_audio_buffer, replace_audio, restore_audio
from facefusion.filesystem import copy_file
from facefusion.temp_helper import clear_temp_directory, create_temp_directory, get_temp_file_path, resolve_temp_frame_paths
from facefusion.temp_helper import clear_temp_directory, create_temp_directory, get_temp_file_path, resolve_temp_frame_set
from facefusion.types import EncoderSet
from .helper import get_test_example_file, get_test_examples_directory, get_test_output_file, prepare_test_output_directory
@@ -85,7 +85,7 @@ def test_extract_frames() -> None:
create_temp_directory(target_path)
assert extract_frames(target_path, (452, 240), 30.0, trim_frame_start, trim_frame_end) is True
assert len(resolve_temp_frame_paths(target_path)) == frame_total
assert len(resolve_temp_frame_set(target_path)) == frame_total
clear_temp_directory(target_path)
+19 -1
View File
@@ -1,7 +1,7 @@
from shutil import which
from facefusion import ffmpeg_builder
from facefusion.ffmpeg_builder import chain, concat, keep_video_alpha, run, select_frame_range, set_audio_quality, set_audio_sample_size, set_stream_mode, set_video_encoder, set_video_fps, set_video_quality
from facefusion.ffmpeg_builder import chain, concat, keep_video_alpha, run, select_frame_range, set_audio_quality, set_audio_sample_size, set_faststart, set_stream_mode, set_video_encoder, set_video_fps, set_video_quality, set_video_tag
def test_run() -> None:
@@ -71,6 +71,24 @@ def test_set_audio_quality() -> None:
assert set_audio_quality('flac', 100) == []
def test_set_faststart() -> None:
assert set_faststart('m4v') == [ '-movflags', '+faststart' ]
assert set_faststart('mov') == [ '-movflags', '+faststart' ]
assert set_faststart('mp4') == [ '-movflags', '+faststart' ]
assert set_faststart('mkv') == []
assert set_faststart('webm') == []
def test_set_video_tag() -> None:
assert set_video_tag('libx265', 'm4v') == [ '-tag:v', 'hvc1' ]
assert set_video_tag('hevc_nvenc', 'mov') == [ '-tag:v', 'hvc1' ]
assert set_video_tag('hevc_videotoolbox', 'mp4') == [ '-tag:v', 'hvc1' ]
assert set_video_tag('libx265', 'mkv') == []
assert set_video_tag('libx265', 'webm') == []
assert set_video_tag('libx264', 'mp4') == []
assert set_video_tag('h264_nvenc', 'mp4') == []
def test_set_video_quality() -> None:
assert set_video_quality('libx264', 0) == [ '-crf', '51' ]
assert set_video_quality('libx264', 50) == [ '-crf', '26' ]
-8
View File
@@ -1,8 +0,0 @@
from facefusion.common_helper import is_linux, is_macos
from facefusion.memory import limit_system_memory
def test_limit_system_memory() -> None:
assert limit_system_memory(4) is True
if is_linux() or is_macos():
assert limit_system_memory(1024) is False
+3 -3
View File
@@ -5,7 +5,7 @@ import pytest
from facefusion import state_manager
from facefusion.download import conditional_download
from facefusion.temp_helper import get_temp_directory_path, get_temp_file_path, get_temp_frames_pattern
from facefusion.temp_helper import get_temp_directory_path, get_temp_file_path, get_temp_frame_pattern
from .helper import get_test_example_file, get_test_examples_directory
@@ -29,6 +29,6 @@ def test_get_temp_directory_path() -> None:
assert get_temp_directory_path(get_test_example_file('target-240p.mp4')) == os.path.join(temp_directory, 'facefusion', 'target-240p')
def test_get_temp_frames_pattern() -> None:
def test_get_temp_frame_pattern() -> None:
temp_directory = tempfile.gettempdir()
assert get_temp_frames_pattern(get_test_example_file('target-240p.mp4'), '%04d') == os.path.join(temp_directory, 'facefusion', 'target-240p', '%04d.png')
assert get_temp_frame_pattern(get_test_example_file('target-240p.mp4'), '%04d') == os.path.join(temp_directory, 'facefusion', 'target-240p', '%04d.png')
+20 -2
View File
@@ -1,11 +1,12 @@
import os
import subprocess
import numpy
import pytest
from facefusion.common_helper import is_linux
from facefusion.download import conditional_download
from facefusion.vision import calculate_histogram_difference, count_trim_frame_total, count_video_frame_total, detect_image_resolution, detect_video_duration, detect_video_fps, detect_video_resolution, match_frame_color, normalize_resolution, pack_resolution, predict_video_frame_total, read_image, read_video_frame, restrict_image_resolution, restrict_trim_frame, restrict_video_fps, restrict_video_resolution, scale_resolution, unpack_resolution, write_image
from facefusion.vision import calculate_histogram_difference, count_trim_frame_total, count_video_frame_total, detect_image_resolution, detect_video_duration, detect_video_fps, detect_video_resolution, match_frame_color, normalize_resolution, pack_resolution, predict_video_frame_total, read_image, read_video_chunk, read_video_frame, restrict_image_resolution, restrict_trim_frame, restrict_video_fps, restrict_video_resolution, scale_resolution, select_video_frames, unpack_resolution, write_image
from .helper import get_test_example_file, get_test_examples_directory, get_test_output_file, prepare_test_output_directory
@@ -63,10 +64,27 @@ def test_restrict_image_resolution() -> None:
def test_read_video_frame() -> None:
assert hasattr(read_video_frame(get_test_example_file('target-240p-25fps.mp4')), '__array_interface__')
target_path = get_test_example_file('target-240p-25fps.mp4')
assert read_video_frame(target_path).shape == (226, 426, 3)
assert numpy.array_equal(read_video_frame(target_path, 49), select_video_frames(target_path, 49, 5)[5])
assert numpy.array_equal(read_video_frame(target_path, 50), select_video_frames(target_path, 50, 5)[5])
assert numpy.array_equal(read_video_frame(target_path, 51), select_video_frames(target_path, 51, 5)[5])
assert read_video_frame('invalid') is None
def test_read_video_chunk() -> None:
assert len(read_video_chunk(get_test_example_file('target-240p-25fps.mp4'), 1, 40)) == 40
assert read_video_chunk('invalid', 1, 40) == {}
def test_select_video_frames() -> None:
assert len(select_video_frames(get_test_example_file('target-240p-25fps.mp4'), 50, 5)) == 11
assert len(select_video_frames(get_test_example_file('target-240p-25fps.mp4'), 1, 5)) == 11
assert len(select_video_frames(get_test_example_file('target-240p-25fps.mp4'), 269, 5)) == 11
assert select_video_frames('invalid', 50, 5) == []
def test_count_video_frame_total() -> None:
assert count_video_frame_total(get_test_example_file('target-240p-25fps.mp4')) == 270
assert count_video_frame_total(get_test_example_file('target-240p-30fps.mp4')) == 324