mirror of
https://github.com/facefusion/facefusion.git
synced 2026-07-28 04:50:58 +02:00
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>
This commit is contained in:
co-authored by
Claude Opus 4.8
parent
1b151c5c3e
commit
76c1f79f29
+27
-1
@@ -6,7 +6,7 @@ import pytest
|
||||
import facefusion.ffmpeg
|
||||
from facefusion import ffmpeg, ffmpeg_builder, 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.ffmpeg import concat_video, extract_frames, fix_audio_encoder, fix_video_encoder, merge_video, read_audio_buffer, replace_audio, restore_audio
|
||||
from facefusion.ffprobe import extract_video_metadata
|
||||
from facefusion.filesystem import copy_file
|
||||
from facefusion.temp_helper import clear_temp_directory, create_temp_directory, get_temp_file_path, resolve_temp_frame_set
|
||||
@@ -236,3 +236,29 @@ def test_replace_audio() -> None:
|
||||
clear_temp_directory(target_path)
|
||||
|
||||
state_manager.init_item('output_audio_encoder', 'aac')
|
||||
|
||||
|
||||
def test_fix_audio_encoder() -> None:
|
||||
assert fix_audio_encoder('avi', 'libopus') == 'aac'
|
||||
assert fix_audio_encoder('m4v', 'libopus') == 'aac'
|
||||
assert fix_audio_encoder('mpeg', 'libopus') == 'aac'
|
||||
assert fix_audio_encoder('wmv', 'libopus') == 'aac'
|
||||
assert fix_audio_encoder('mov', 'flac') == 'aac'
|
||||
assert fix_audio_encoder('mov', 'libopus') == 'aac'
|
||||
assert fix_audio_encoder('mxf', 'libopus') == 'pcm_s16le'
|
||||
assert fix_audio_encoder('webm', 'aac') == 'libopus'
|
||||
assert fix_audio_encoder('mp4', 'aac') == 'aac'
|
||||
assert fix_audio_encoder('avi', 'aac') == 'aac'
|
||||
|
||||
|
||||
def test_fix_video_encoder() -> None:
|
||||
assert fix_video_encoder('m4v', 'libx265') == 'libx264'
|
||||
assert fix_video_encoder('mpeg', 'libx265') == 'libx264'
|
||||
assert fix_video_encoder('mxf', 'libx265') == 'libx264'
|
||||
assert fix_video_encoder('wmv', 'libx265') == 'libx264'
|
||||
assert fix_video_encoder('mkv', 'rawvideo') == 'libx264'
|
||||
assert fix_video_encoder('mp4', 'rawvideo') == 'libx264'
|
||||
assert fix_video_encoder('mov', 'libvpx-vp9') == 'libx264'
|
||||
assert fix_video_encoder('webm', 'libx264') == 'libvpx-vp9'
|
||||
assert fix_video_encoder('mp4', 'libx265') == 'libx265'
|
||||
assert fix_video_encoder('avi', 'rawvideo') == 'rawvideo'
|
||||
|
||||
@@ -1,7 +1,7 @@
|
||||
from shutil import which
|
||||
|
||||
from facefusion import ffmpeg_builder
|
||||
from facefusion.ffmpeg_builder import chain, concat, convert_color_space, keep_video_alpha, restrict_color_transfer, 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
|
||||
from facefusion.ffmpeg_builder import chain, concat, convert_color_space, keep_video_alpha, restrict_color_transfer, run, select_frame_range, set_audio_quality, set_audio_sample_size, set_faststart, set_filter_thread_count, set_global_thread_count, set_input_seek, set_output_format, set_stream_mode, set_video_encoder, set_video_fps, set_video_quality, set_video_tag
|
||||
|
||||
|
||||
def test_run() -> None:
|
||||
@@ -41,6 +41,19 @@ def test_set_stream_mode() -> None:
|
||||
assert set_stream_mode('v4l2') == [ '-f', 'v4l2' ]
|
||||
|
||||
|
||||
#todo: needs review - [testing] question if the assertions are good
|
||||
#todo: run mutation testing, strip down to the minimum, test with real data
|
||||
def test_set_input_seek() -> None:
|
||||
assert set_input_seek(0.0) == [ '-ss', '0.0' ]
|
||||
assert set_input_seek(4.2) == [ '-ss', '4.2' ]
|
||||
|
||||
|
||||
#todo: needs review - [testing] question if the assertions are good
|
||||
#todo: run mutation testing, strip down to the minimum, test with real data
|
||||
def test_set_output_format() -> None:
|
||||
assert set_output_format('rawvideo') == [ '-f', 'rawvideo' ]
|
||||
|
||||
|
||||
def test_select_frame_range() -> None:
|
||||
assert select_frame_range(0, None, 30) == [ '-vf', 'trim=start_frame=0,fps=30' ]
|
||||
assert select_frame_range(None, 100, 30) == [ '-vf', 'trim=end_frame=100,fps=30' ]
|
||||
@@ -83,6 +96,16 @@ def test_set_audio_quality() -> None:
|
||||
assert set_audio_quality('flac', 100) == []
|
||||
|
||||
|
||||
def test_set_global_thread_count() -> None:
|
||||
assert set_global_thread_count(8) == [ '-threads', '8' ]
|
||||
assert set_global_thread_count(16) == [ '-threads', '16' ]
|
||||
|
||||
|
||||
def test_set_filter_thread_count() -> None:
|
||||
assert set_filter_thread_count(8) == [ '-filter_threads', '8' ]
|
||||
assert set_filter_thread_count(16) == [ '-filter_threads', '16' ]
|
||||
|
||||
|
||||
def test_set_faststart() -> None:
|
||||
assert set_faststart('m4v') == [ '-movflags', '+faststart' ]
|
||||
assert set_faststart('mov') == [ '-movflags', '+faststart' ]
|
||||
|
||||
@@ -0,0 +1,192 @@
|
||||
import tempfile
|
||||
|
||||
import numpy
|
||||
import pytest
|
||||
|
||||
from facefusion import ffmpeg, ffmpeg_builder, process_manager, state_manager
|
||||
from facefusion.download import conditional_download
|
||||
from facefusion.ffprobe import extract_video_metadata
|
||||
from facefusion.temp_helper import create_temp_directory, get_temp_file_path
|
||||
from facefusion.video_manager import clear_video_pool, close_video_writer, conditional_set_video_reader_position, get_reader, get_writer, read_video_reader_frame, read_video_reader_window, refresh_video_reader, write_video_writer_frame
|
||||
from .helper import get_test_example_file, get_test_examples_directory
|
||||
|
||||
|
||||
@pytest.fixture(scope = 'module', autouse = True)
|
||||
def before_all() -> None:
|
||||
process_manager.start()
|
||||
conditional_download(get_test_examples_directory(),
|
||||
[
|
||||
'https://github.com/facefusion/facefusion-assets/releases/download/examples-3.0.0/target-240p.mp4'
|
||||
])
|
||||
|
||||
for video_fps in [ 25, 30 ]:
|
||||
ffmpeg.run_ffmpeg(
|
||||
ffmpeg_builder.chain(
|
||||
ffmpeg_builder.set_input(get_test_example_file('target-240p.mp4')),
|
||||
ffmpeg_builder.set_video_fps(video_fps),
|
||||
ffmpeg_builder.set_output(get_test_example_file('target-240p-' + str(video_fps) + 'fps.mp4'))
|
||||
)
|
||||
)
|
||||
|
||||
state_manager.init_item('temp_path', tempfile.gettempdir())
|
||||
state_manager.init_item('temp_frame_format', 'png')
|
||||
state_manager.init_item('output_video_encoder', 'libx264')
|
||||
state_manager.init_item('output_video_quality', 80)
|
||||
state_manager.init_item('output_video_preset', 'veryfast')
|
||||
state_manager.init_item('temp_pixel_format', 'bgr24')
|
||||
|
||||
|
||||
@pytest.fixture(scope = 'function', autouse = True)
|
||||
def before_each() -> None:
|
||||
clear_video_pool()
|
||||
|
||||
|
||||
#todo: needs review - [testing] question if the assertions are good
|
||||
#todo: run mutation testing, strip down to the minimum, test with real data
|
||||
def test_get_reader() -> None:
|
||||
video_reader = get_reader(get_test_example_file('target-240p-25fps.mp4'))
|
||||
video_metadata = video_reader.get('metadata')
|
||||
|
||||
assert video_metadata.get('resolution') == (426, 226)
|
||||
assert video_metadata.get('fps') == 25.0
|
||||
assert video_metadata.get('frame_total') == 270
|
||||
assert video_reader.get('position') == 0
|
||||
assert get_reader(get_test_example_file('target-240p-25fps.mp4')) is video_reader
|
||||
|
||||
|
||||
#todo: needs review - [testing] question if the assertions are good
|
||||
#todo: run mutation testing, strip down to the minimum, test with real data
|
||||
def test_conditional_set_video_reader_position() -> None:
|
||||
video_reader = get_reader(get_test_example_file('target-240p-25fps.mp4'))
|
||||
|
||||
conditional_set_video_reader_position(video_reader, 50)
|
||||
|
||||
assert video_reader.get('position') == 50
|
||||
|
||||
conditional_set_video_reader_position(video_reader, 10)
|
||||
|
||||
assert video_reader.get('position') == 10
|
||||
|
||||
conditional_set_video_reader_position(video_reader, 200)
|
||||
|
||||
assert video_reader.get('position') == 200
|
||||
|
||||
|
||||
#todo: needs review - [testing] question if the assertions are good
|
||||
#todo: run mutation testing, strip down to the minimum, test with real data
|
||||
def test_refresh_video_reader() -> None:
|
||||
video_reader = get_reader(get_test_example_file('target-240p-25fps.mp4'))
|
||||
sequential_frames = {}
|
||||
|
||||
for frame_number in range(30):
|
||||
sequential_frames[frame_number] = read_video_reader_frame(video_reader)
|
||||
|
||||
for frame_number in [ 5, 17, 29 ]:
|
||||
refresh_video_reader(video_reader, frame_number)
|
||||
vision_frame = read_video_reader_frame(video_reader)
|
||||
|
||||
assert numpy.array_equal(vision_frame, sequential_frames.get(frame_number)) is True
|
||||
|
||||
|
||||
#todo: needs review - [testing] question if the assertions are good
|
||||
#todo: run mutation testing, strip down to the minimum, test with real data
|
||||
def test_read_video_reader_frame() -> None:
|
||||
video_reader = get_reader(get_test_example_file('target-240p-25fps.mp4'))
|
||||
vision_frame = read_video_reader_frame(video_reader)
|
||||
|
||||
assert vision_frame.shape == (226, 426, 3)
|
||||
assert video_reader.get('position') == 1
|
||||
|
||||
conditional_set_video_reader_position(video_reader, 269)
|
||||
vision_frame = read_video_reader_frame(video_reader)
|
||||
|
||||
assert vision_frame.shape == (226, 426, 3)
|
||||
assert read_video_reader_frame(video_reader) is None
|
||||
|
||||
|
||||
#todo: needs review - [testing] question if the assertions are good
|
||||
#todo: run mutation testing, strip down to the minimum, test with real data
|
||||
def test_read_video_reader_window() -> None:
|
||||
video_reader = get_reader(get_test_example_file('target-240p-25fps.mp4'))
|
||||
frame_set = read_video_reader_window(video_reader, 0, 4)
|
||||
|
||||
assert sorted(frame_set) == [ 0, 1, 2, 3, 4 ]
|
||||
|
||||
frame_set = read_video_reader_window(video_reader, 100, 104)
|
||||
|
||||
assert sorted(frame_set) == [ 100, 101, 102, 103, 104 ]
|
||||
|
||||
frame_set = read_video_reader_window(video_reader, 268, 275)
|
||||
|
||||
assert sorted(frame_set) == [ 268, 269 ]
|
||||
|
||||
|
||||
#todo: needs review - [testing] question if the assertions are good
|
||||
#todo: run mutation testing, strip down to the minimum, test with real data
|
||||
def test_evict_video_reader_buffer() -> None:
|
||||
video_reader = get_reader(get_test_example_file('target-240p-25fps.mp4'))
|
||||
read_video_reader_window(video_reader, 0, 4)
|
||||
frame_set = read_video_reader_window(video_reader, 21, 25)
|
||||
|
||||
assert min(frame_set) == 5
|
||||
assert max(frame_set) == 25
|
||||
|
||||
|
||||
#todo: needs review - [testing] question if the assertions are good
|
||||
#todo: run mutation testing, strip down to the minimum, test with real data
|
||||
def test_get_writer() -> None:
|
||||
target_path = get_test_example_file('target-240p-25fps.mp4')
|
||||
video_metadata = extract_video_metadata(target_path)
|
||||
create_temp_directory(target_path)
|
||||
video_writer = get_writer(target_path, video_metadata, 25.0, (426, 226), (426, 226), 25.0)
|
||||
|
||||
assert get_writer(target_path, video_metadata, 25.0, (426, 226), (426, 226), 25.0) is video_writer
|
||||
|
||||
|
||||
#todo: needs review - [testing] question if the assertions are good
|
||||
#todo: run mutation testing, strip down to the minimum, test with real data
|
||||
def test_write_video_writer_frame() -> None:
|
||||
target_path = get_test_example_file('target-240p-25fps.mp4')
|
||||
create_temp_directory(target_path)
|
||||
video_reader = get_reader(target_path)
|
||||
video_writer = get_writer(target_path, video_reader.get('metadata'), 25.0, (426, 226), (426, 226), 25.0)
|
||||
|
||||
for frame_number in range(25):
|
||||
vision_frame = read_video_reader_frame(video_reader)
|
||||
write_video_writer_frame(video_writer, vision_frame)
|
||||
|
||||
assert close_video_writer(video_writer) is True
|
||||
|
||||
video_metadata = extract_video_metadata(get_temp_file_path(target_path))
|
||||
|
||||
assert video_metadata.get('duration') == 1.0
|
||||
assert video_metadata.get('frame_total') == 25
|
||||
assert video_metadata.get('fps') == 25.0
|
||||
assert video_metadata.get('resolution') == (426, 226)
|
||||
assert video_metadata.get('color_transfer') == 'bt709'
|
||||
|
||||
|
||||
#todo: needs review - [testing] question if the assertions are good
|
||||
#todo: run mutation testing, strip down to the minimum, test with real data
|
||||
def test_close_video_writer() -> None:
|
||||
target_path = get_test_example_file('target-240p-30fps.mp4')
|
||||
create_temp_directory(target_path)
|
||||
video_reader = get_reader(target_path)
|
||||
video_writer = get_writer(target_path, video_reader.get('metadata'), 30.0, (426, 226), (426, 226), 30.0)
|
||||
vision_frame = read_video_reader_frame(video_reader)
|
||||
write_video_writer_frame(video_writer, vision_frame)
|
||||
|
||||
assert close_video_writer(video_writer) is True
|
||||
|
||||
|
||||
#todo: needs review - [testing] question if the assertions are good
|
||||
#todo: run mutation testing, strip down to the minimum, test with real data
|
||||
def test_clear_video_pool() -> None:
|
||||
target_path = get_test_example_file('target-240p-25fps.mp4')
|
||||
create_temp_directory(target_path)
|
||||
video_reader = get_reader(target_path)
|
||||
video_writer = get_writer(target_path, video_reader.get('metadata'), 25.0, (426, 226), (426, 226), 25.0)
|
||||
clear_video_pool()
|
||||
|
||||
assert video_reader.get('process').returncode == -9
|
||||
assert video_writer.get('process').returncode == -9
|
||||
Reference in New Issue
Block a user