|
|
@@ -1,6 +1,7 @@ |
|
|
|
"""test_feature_extractors.py - test pipeline feature extractors""" |
|
|
|
import unittest |
|
|
|
import os |
|
|
|
import random |
|
|
|
import pytest |
|
|
|
import pipeline.feature_extractors as extractors |
|
|
|
|
|
|
@@ -162,6 +163,30 @@ class TestLoudAudioFeatureExtractor(unittest.TestCase): |
|
|
|
""" |
|
|
|
return [(0.0, 0.0), (1.0, 1.0), (2.0, 2.0), (3.0, 3.0), (4.0, 4.0)] |
|
|
|
|
|
|
|
def _mock_get_loudnessess(self, *args, length=100, min_loudness=-101, max_loudness=100, |
|
|
|
seed=42, **kwargs) -> list: |
|
|
|
"""Mock _get_loudnesses() |
|
|
|
|
|
|
|
Parameters: |
|
|
|
- length : int >=0, number of loudness instances to generate |
|
|
|
- min_loudness : int, minimum loudness value (special value: -101 for "-inf") |
|
|
|
- max_loudness : int, maximum loudness value |
|
|
|
|
|
|
|
Note that int min/max loudness are divided by float 100 |
|
|
|
to get the actual loudness value between -1.0 and 1.0 |
|
|
|
|
|
|
|
Return a list of 2-tuple floats (timecode, loudness) representing loud audio instances |
|
|
|
""" |
|
|
|
loudnesses = [] |
|
|
|
random.seed(seed) |
|
|
|
for i in range(length): |
|
|
|
loudness = random.randint(min_loudness, max_loudness) / 100 |
|
|
|
if min_loudness == -101: |
|
|
|
loudness = "-inf" if loudness == -1.01 else f"{loudness}" |
|
|
|
loudnesses.append((float(f"{i}.0"), float(loudness))) |
|
|
|
|
|
|
|
return loudnesses |
|
|
|
|
|
|
|
def test_init(self): |
|
|
|
video_source = TestSourceMedia().one_colour_silent_audio() |
|
|
|
test_extractor = extractors.LoudAudioFeatureExtractor(input_files=video_source) |
|
|
@@ -191,6 +216,16 @@ class TestLoudAudioFeatureExtractor(unittest.TestCase): |
|
|
|
test_extractor.teardown() |
|
|
|
self.assertEqual(len(test_extractor.features), 5) |
|
|
|
|
|
|
|
def test_extract_mocked_get_loudnesses(self): |
|
|
|
"""Test extract with mocked loudness detection""" |
|
|
|
video_source = TestSourceMedia().one_colour_silent_audio() |
|
|
|
test_extractor = extractors.LoudAudioFeatureExtractor(input_files=video_source) |
|
|
|
test_extractor._get_loudnesses = self._mock_get_loudnessess |
|
|
|
test_extractor.setup() |
|
|
|
test_extractor.run() |
|
|
|
test_extractor.teardown() |
|
|
|
self.assertEqual(len(test_extractor.features), 100) |
|
|
|
|
|
|
|
# TODO: add sample video with loud audio to test _loudnessdetect() |
|
|
|
|
|
|
|
class TestVideoActivityFeatureExtractor(unittest.TestCase): |
|
|
|