diff --git a/tests/test_ffmpeg.py b/tests/test_ffmpeg.py index 8be082a0..d18ab18e 100644 --- a/tests/test_ffmpeg.py +++ b/tests/test_ffmpeg.py @@ -5,7 +5,7 @@ import pytest from facefusion import process_manager, state_manager from facefusion.download import conditional_download -from facefusion.ffmpeg import concat_video, extract_frames, read_audio_buffer, replace_audio +from facefusion.ffmpeg import concat_video, extract_frames, read_audio_buffer, restore_audio, replace_audio from facefusion.filesystem import copy_file from facefusion.temp_helper import clear_temp_directory, create_temp_directory, get_temp_directory_path, get_temp_file_path from .helper import get_test_example_file, get_test_examples_directory, get_test_output_file, prepare_test_output_directory @@ -24,6 +24,8 @@ def before_all() -> None: subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vf', 'fps=25', get_test_example_file('target-240p-25fps.mp4') ]) subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vf', 'fps=30', get_test_example_file('target-240p-30fps.mp4') ]) subprocess.run([ 'ffmpeg', '-i', get_test_example_file('target-240p.mp4'), '-vf', 'fps=60', get_test_example_file('target-240p-60fps.mp4') ]) + subprocess.run([ 'ffmpeg', '-i', get_test_example_file('source.mp3'), '-i', get_test_example_file('target-240p.mp4'), '-ar', '16000', get_test_example_file('target-240p-16khz.mp4') ]) + subprocess.run([ 'ffmpeg', '-i', get_test_example_file('source.mp3'), '-i', get_test_example_file('target-240p.mp4'), '-ar', '48000', get_test_example_file('target-240p-48khz.mp4') ]) state_manager.init_item('temp_frame_format', 'jpg') state_manager.init_item('output_audio_encoder', 'aac') @@ -55,14 +57,14 @@ def test_extract_frames() -> None: def test_extract_frames_with_trim_start() -> None: state_manager.init_item('trim_frame_start', 224) - providers =\ + target_paths =\ [ (get_test_example_file('target-240p-25fps.mp4'), 55), (get_test_example_file('target-240p-30fps.mp4'), 100), (get_test_example_file('target-240p-60fps.mp4'), 212) ] - for target_path, frame_total in providers: + for target_path, frame_total in target_paths: temp_directory_path = get_temp_directory_path(target_path) create_temp_directory(target_path) @@ -75,14 +77,14 @@ def test_extract_frames_with_trim_start() -> None: def test_extract_frames_with_trim_start_and_trim_end() -> None: state_manager.init_item('trim_frame_start', 124) state_manager.init_item('trim_frame_end', 224) - providers =\ + target_paths =\ [ (get_test_example_file('target-240p-25fps.mp4'), 120), (get_test_example_file('target-240p-30fps.mp4'), 100), (get_test_example_file('target-240p-60fps.mp4'), 50) ] - for target_path, frame_total in providers: + for target_path, frame_total in target_paths: temp_directory_path = get_temp_directory_path(target_path) create_temp_directory(target_path) @@ -94,14 +96,14 @@ def test_extract_frames_with_trim_start_and_trim_end() -> None: def test_extract_frames_with_trim_end() -> None: state_manager.init_item('trim_frame_end', 100) - providers =\ + target_paths =\ [ (get_test_example_file('target-240p-25fps.mp4'), 120), (get_test_example_file('target-240p-30fps.mp4'), 100), (get_test_example_file('target-240p-60fps.mp4'), 50) ] - for target_path, frame_total in providers: + for target_path, frame_total in target_paths: temp_directory_path = get_temp_directory_path(target_path) create_temp_directory(target_path) @@ -128,6 +130,23 @@ def test_read_audio_buffer() -> None: assert read_audio_buffer(get_test_example_file('invalid.mp3'), 1, 1) is None +def test_restore_audio() -> None: + target_paths =\ + [ + get_test_example_file('target-240p-16khz.mp4'), + get_test_example_file('target-240p-48khz.mp4') + ] + output_path = get_test_output_file('test-restore-audio.mp4') + + for target_path in target_paths: + create_temp_directory(target_path) + copy_file(target_path, get_temp_file_path(target_path)) + + assert restore_audio(target_path, output_path, 30) is True + + clear_temp_directory(target_path) + + def test_replace_audio() -> None: target_path = get_test_example_file('target-240p.mp4') output_path = get_test_output_file('test-replace-audio.mp4')