Refactor/ffmpeg less stream (#1092)

* remove ffmpeg from stream to use opus and vpx, add bunch of todos

* fix testing

* improve download checkout

* fix datachannel download, fix super dirty test clients - setup logic does not belong there

* fix testing
This commit is contained in:
Henry Ruhs
2026-05-09 14:50:38 +02:00
committed by henryruhs
parent 430b16ce56
commit 76c413a2c1
25 changed files with 371 additions and 708 deletions
+19 -23
View File
@@ -12,26 +12,18 @@ from facefusion.apis import asset_store
from facefusion.apis.core import create_api
from facefusion.core import common_pre_check, processors_pre_check
from facefusion.download import conditional_download
from facefusion.libraries import datachannel as datachannel_module
from .assert_helper import get_test_example_file, get_test_examples_directory
from .stream_helper import create_sdp_offer, open_websocket_stream
@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'
])
@pytest.fixture(scope = 'module')
def test_client() -> Iterator[TestClient]:
state_manager.init_item('execution_device_ids', [ 0 ])
state_manager.init_item('execution_providers', [ 'cpu' ])
state_manager.init_item('download_providers', [ 'github', 'huggingface' ])
state_manager.init_item('temp_path', tempfile.gettempdir())
state_manager.init_item('processors', [ 'face_swapper' ])
state_manager.init_item('face_selector_mode', 'many')
state_manager.init_item('face_detector_model', 'yolo_face')
state_manager.init_item('face_detector_size', '640x640')
state_manager.init_item('face_detector_score', 0.5)
@@ -44,24 +36,29 @@ def test_client() -> Iterator[TestClient]:
state_manager.init_item('face_mask_padding', [ 0, 0, 0, 0 ])
state_manager.init_item('face_swapper_model', 'hyperswap_1a_256')
state_manager.init_item('face_swapper_pixel_boost', '256x256')
state_manager.init_item('face_swapper_weight', 0.5)
common_pre_check()
processors_pre_check()
datachannel_module.pre_check()
with TestClient(create_api()) as test_client:
yield test_client
conditional_download(get_test_examples_directory(),
[
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/source.jpg'
])
@pytest.fixture(scope = 'function', autouse = True)
def before_each() -> None:
state_manager.init_item('source_paths', None)
session_manager.SESSIONS.clear()
asset_store.clear()
# TODO: enable again
@pytest.mark.skip
@pytest.fixture(scope = 'module')
def test_client() -> Iterator[TestClient]:
with TestClient(create_api()) as test_client:
yield test_client
def test_stream_image(test_client : TestClient) -> None:
create_session_response = test_client.post('/session', json =
{
@@ -92,10 +89,9 @@ def test_stream_image(test_client : TestClient) -> None:
assert select_response.status_code == 200
with test_client.websocket_connect('/stream', subprotocols =
with test_client.websocket_connect('/stream?mode=image', subprotocols =
[
'access_token.' + access_token,
'image'
'access_token.' + access_token
]) as websocket:
websocket.send_bytes(source_content)
output_bytes = websocket.receive_bytes()
@@ -104,8 +100,6 @@ def test_stream_image(test_client : TestClient) -> None:
assert output_vision_frame.shape == (1024, 1024, 3)
# TODO: enable again
@pytest.mark.skip
def test_stream_video(test_client : TestClient) -> None:
create_session_response = test_client.post('/session', json =
{
@@ -137,9 +131,11 @@ def test_stream_video(test_client : TestClient) -> None:
ready_event = threading.Event()
stop_event = threading.Event()
#TODO: use asyncio
stream_thread = threading.Thread(target = open_websocket_stream, args = (test_client, [ 'access_token.' + access_token, 'video' ], source_content, ready_event, stop_event))
stream_thread = threading.Thread(target = open_websocket_stream, args = (test_client, [ 'access_token.' + access_token ], source_content, ready_event, stop_event))
stream_thread.start()
ready_event.wait()
ready_event.wait(timeout = 10)
assert ready_event.is_set()
sdp_offer = create_sdp_offer()
stream_response = test_client.post('/stream', content = sdp_offer, headers =
@@ -152,4 +148,4 @@ def test_stream_video(test_client : TestClient) -> None:
assert stream_response.text
stop_event.set()
stream_thread.join()
stream_thread.join(timeout = 10)