44 lines
1.4 KiB
Python
44 lines
1.4 KiB
Python
import torch
|
|
|
|
from media_ops import floor_h3_frame_count, trim_audio_to_frames
|
|
from nodes import MiniMaxH3TrimSourceAV
|
|
|
|
|
|
def test_floor_h3_frame_count_keeps_valid_length():
|
|
assert floor_h3_frame_count(124) == 124
|
|
|
|
|
|
def test_floor_h3_frame_count_drops_to_previous_grid_length():
|
|
assert floor_h3_frame_count(140) == 124
|
|
assert floor_h3_frame_count(141) == 141
|
|
|
|
|
|
def test_floor_h3_frame_count_rejects_too_few_frames():
|
|
try:
|
|
floor_h3_frame_count(4)
|
|
except ValueError as error:
|
|
assert "at least 5" in str(error)
|
|
else:
|
|
raise AssertionError("Expected fewer than five frames to be rejected")
|
|
|
|
|
|
def test_trim_audio_uses_h3_24_fps_duration():
|
|
waveform = torch.arange(20_000, dtype=torch.float32).reshape(1, 1, -1)
|
|
audio = {"waveform": waveform, "sample_rate": 1000}
|
|
trimmed, target = trim_audio_to_frames(audio, 124)
|
|
assert target == round(124 * 1000 / 24)
|
|
assert trimmed["waveform"].shape[-1] == target
|
|
assert audio["waveform"].shape[-1] == 20_000
|
|
|
|
|
|
def test_trim_node_keeps_frames_and_audio_synchronized():
|
|
frames = torch.zeros((140, 32, 64, 3))
|
|
audio = {"waveform": torch.zeros((1, 2, 300_000)), "sample_rate": 48_000}
|
|
trimmed_frames, trimmed_audio, length, info = MiniMaxH3TrimSourceAV().trim(
|
|
frames, audio
|
|
)
|
|
assert trimmed_frames.shape[0] == 124
|
|
assert trimmed_audio["waveform"].shape[-1] == 248_000
|
|
assert length == 124
|
|
assert "dropped 16" in info
|