
* Cosmetic changes * Cosmetic changes * Run single warm up for the benchmark suite * Use latest version of Gradio * More testing * Introduce basic installer * Fix typo * Move more to installer file * Fix the installer with the uninstall all trick * Adjust wording * Fix coreml in installer * Allow Pyhton 3.9 * Add VENV to installer * Just some cosmetics * Just some cosmetics * Dedicated headless mode, Refine API of UI layouts * Use --headless for pytest * Fix testing for Windows * Normalize output path that lacks extension * Fix CI for Windows * Fix CI for Windows * UI to change output path * Add conda support for the installer * Improve installer quite a bit * Drop conda support * Install community wheels for coreml silicon * Improve output video component * Fix silicon wheel downloading * Remove venv from installer as we cannot activate via subprocess * Use join to create wheel name * Refine the output path normalization * Refine the output path normalization * Introduce ProcessMode and rename some methods * Introduce ProcessMode and rename some methods * Basic webcam integration and open_ffmpeg() * Basic webcam integration part2 * Benchmark resolutions now selectable * Rename benchmark resolution back to benchmark runs * Fix repeating output path in UI * Keep output_path untouched if not resolvable * Add more cases to normalize output path * None for those tests that don't take source path into account * Finish basic webcam integration, UI layout now with custom run() * Fix CI and hide link in webcam UI * Cosmetics on webcam UI * Move get_device to utilities * Fix CI * Introduce output-image-quality, Show and hide UI according to target media type * Benchmark with partial result updates * fix: trim frame sliders not appearing after draggin video * fix: output and temp frame setting inputs not appearing * Fix: set increased update delay to 250ms to let Gradio update conditional inputs properly * Reverted .gitignore * Adjust timings * Remove timeout hacks and get fully event driven * Update dependencies * Update dependencies * Revert NSFW library, Conditional unset trim args * Face selector works better on preview slider release * Add limit resources to UI * Introduce vision.py for all CV2 operations, Rename some methods * Add restoring audio failed * Decouple updates for preview image and preview frame slider, Move reduce_preview_frame to vision * Refactor detect_fps based on JSON output * Only webcam when open * More conditions to vision.py * Add udp and v4l2 streaming to webcam UI * Detect v4l2 device to be used * Refactor code a bit * Use static max memory for UI * Fix CI * Looks stable to me * Update preview * Update preview --------- Co-authored-by: Sumit <vizsumit@gmail.com>
155 lines
5.9 KiB
Python
155 lines
5.9 KiB
Python
import glob
|
|
import platform
|
|
import subprocess
|
|
import pytest
|
|
|
|
import facefusion.globals
|
|
from facefusion.utilities import conditional_download, detect_fps, extract_frames, create_temp, get_temp_directory_path, clear_temp, normalize_output_path, is_file, is_directory, is_image, is_video, encode_execution_providers, decode_execution_providers
|
|
|
|
|
|
@pytest.fixture(scope = 'module', autouse = True)
|
|
def before_all() -> None:
|
|
facefusion.globals.temp_frame_quality = 100
|
|
facefusion.globals.trim_frame_start = None
|
|
facefusion.globals.trim_frame_end = None
|
|
facefusion.globals.temp_frame_format = 'png'
|
|
conditional_download('.assets/examples',
|
|
[
|
|
'https://github.com/facefusion/facefusion-assets/releases/download/examples/source.jpg',
|
|
'https://github.com/facefusion/facefusion-assets/releases/download/examples/target-240p.mp4'
|
|
])
|
|
subprocess.run([ 'ffmpeg', '-i', '.assets/examples/target-240p.mp4', '-vf', 'fps=25', '.assets/examples/target-240p-25fps.mp4' ])
|
|
subprocess.run([ 'ffmpeg', '-i', '.assets/examples/target-240p.mp4', '-vf', 'fps=30', '.assets/examples/target-240p-30fps.mp4' ])
|
|
subprocess.run([ 'ffmpeg', '-i', '.assets/examples/target-240p.mp4', '-vf', 'fps=60', '.assets/examples/target-240p-60fps.mp4' ])
|
|
|
|
|
|
@pytest.fixture(scope = 'function', autouse = True)
|
|
def before_each() -> None:
|
|
facefusion.globals.trim_frame_start = None
|
|
facefusion.globals.trim_frame_end = None
|
|
facefusion.globals.temp_frame_quality = 90
|
|
facefusion.globals.temp_frame_format = 'jpg'
|
|
|
|
|
|
def test_detect_fps() -> None:
|
|
assert detect_fps('.assets/examples/target-240p-25fps.mp4') == 25.0
|
|
assert detect_fps('.assets/examples/target-240p-30fps.mp4') == 30.0
|
|
assert detect_fps('.assets/examples/target-240p-60fps.mp4') == 60.0
|
|
|
|
|
|
def test_extract_frames() -> None:
|
|
target_paths =\
|
|
[
|
|
'.assets/examples/target-240p-25fps.mp4',
|
|
'.assets/examples/target-240p-30fps.mp4',
|
|
'.assets/examples/target-240p-60fps.mp4'
|
|
]
|
|
for target_path in target_paths:
|
|
temp_directory_path = get_temp_directory_path(target_path)
|
|
create_temp(target_path)
|
|
|
|
assert extract_frames(target_path, 30.0) is True
|
|
assert len(glob.glob1(temp_directory_path, '*.jpg')) == 324
|
|
|
|
clear_temp(target_path)
|
|
|
|
|
|
def test_extract_frames_with_trim_start() -> None:
|
|
facefusion.globals.trim_frame_start = 224
|
|
data_provider =\
|
|
[
|
|
('.assets/examples/target-240p-25fps.mp4', 55),
|
|
('.assets/examples/target-240p-30fps.mp4', 100),
|
|
('.assets/examples/target-240p-60fps.mp4', 212)
|
|
]
|
|
for target_path, frame_total in data_provider:
|
|
temp_directory_path = get_temp_directory_path(target_path)
|
|
create_temp(target_path)
|
|
|
|
assert extract_frames(target_path, 30.0) is True
|
|
assert len(glob.glob1(temp_directory_path, '*.jpg')) == frame_total
|
|
|
|
clear_temp(target_path)
|
|
|
|
|
|
def test_extract_frames_with_trim_start_and_trim_end() -> None:
|
|
facefusion.globals.trim_frame_start = 124
|
|
facefusion.globals.trim_frame_end = 224
|
|
data_provider =\
|
|
[
|
|
('.assets/examples/target-240p-25fps.mp4', 120),
|
|
('.assets/examples/target-240p-30fps.mp4', 100),
|
|
('.assets/examples/target-240p-60fps.mp4', 50)
|
|
]
|
|
for target_path, frame_total in data_provider:
|
|
temp_directory_path = get_temp_directory_path(target_path)
|
|
create_temp(target_path)
|
|
|
|
assert extract_frames(target_path, 30.0) is True
|
|
assert len(glob.glob1(temp_directory_path, '*.jpg')) == frame_total
|
|
|
|
clear_temp(target_path)
|
|
|
|
|
|
def test_extract_frames_with_trim_end() -> None:
|
|
facefusion.globals.trim_frame_end = 100
|
|
data_provider =\
|
|
[
|
|
('.assets/examples/target-240p-25fps.mp4', 120),
|
|
('.assets/examples/target-240p-30fps.mp4', 100),
|
|
('.assets/examples/target-240p-60fps.mp4', 50)
|
|
]
|
|
for target_path, frame_total in data_provider:
|
|
temp_directory_path = get_temp_directory_path(target_path)
|
|
create_temp(target_path)
|
|
|
|
assert extract_frames(target_path, 30.0) is True
|
|
assert len(glob.glob1(temp_directory_path, '*.jpg')) == frame_total
|
|
|
|
clear_temp(target_path)
|
|
|
|
|
|
def test_normalize_output_path() -> None:
|
|
if platform.system().lower() != 'windows':
|
|
assert normalize_output_path('.assets/examples/source.jpg', None, '.assets/examples/target-240p.mp4') == '.assets/examples/target-240p.mp4'
|
|
assert normalize_output_path(None, '.assets/examples/target-240p.mp4', '.assets/examples/target-240p.mp4') == '.assets/examples/target-240p.mp4'
|
|
assert normalize_output_path('.assets/examples/source.jpg', '.assets/examples/target-240p.mp4', '.assets/examples') == '.assets/examples/source-target-240p.mp4'
|
|
assert normalize_output_path(None, '.assets/examples/target-240p.mp4', '.assets/examples/output.mp4') == '.assets/examples/output.mp4'
|
|
assert normalize_output_path(None, '.assets/examples/target-240p.mp4', '.assets/output.mov') == '.assets/output.mp4'
|
|
assert normalize_output_path(None, '.assets/examples/target-240p.mp4', '.assets/examples/invalid') is None
|
|
assert normalize_output_path(None, '.assets/examples/target-240p.mp4', '.assets/invalid/output.mp4') is None
|
|
assert normalize_output_path(None, '.assets/examples/target-240p.mp4', 'invalid') is None
|
|
assert normalize_output_path('.assets/examples/source.jpg', '.assets/examples/target-240p.mp4', None) is None
|
|
|
|
|
|
def test_is_file() -> None:
|
|
assert is_file('.assets/examples/source.jpg') is True
|
|
assert is_file('.assets/examples') is False
|
|
assert is_file('invalid') is False
|
|
|
|
|
|
def test_is_directory() -> None:
|
|
assert is_directory('.assets/examples') is True
|
|
assert is_directory('.assets/examples/source.jpg') is False
|
|
assert is_directory('invalid') is False
|
|
|
|
|
|
def test_is_image() -> None:
|
|
assert is_image('.assets/examples/source.jpg') is True
|
|
assert is_image('.assets/examples/target-240p.mp4') is False
|
|
assert is_image('invalid') is False
|
|
|
|
|
|
def test_is_video() -> None:
|
|
assert is_video('.assets/examples/target-240p.mp4') is True
|
|
assert is_video('.assets/examples/source.jpg') is False
|
|
assert is_video('invalid') is False
|
|
|
|
|
|
def test_encode_execution_providers() -> None:
|
|
assert encode_execution_providers([ 'CPUExecutionProvider' ]) == [ 'cpu' ]
|
|
|
|
|
|
def test_decode_execution_providers() -> None:
|
|
assert decode_execution_providers([ 'cpu' ]) == [ 'CPUExecutionProvider' ]
|