From 9a8011a12f8d921d05481b0d7816778b45972a7c Mon Sep 17 00:00:00 2001 From: Jonas L Date: Tue, 6 Sep 2022 13:11:19 +0200 Subject: [PATCH] test(analyzer): analyze large audio files (#2050) --- analyzer/tests/fixtures/__init__.py | 2 ++ analyzer/tests/fixtures/generate.sh | 16 ++++++++++++---- analyzer/tests/pipeline/analyze_cuepoint_test.py | 5 +++++ analyzer/tests/pipeline/ffmpeg_test.py | 8 ++++++++ 4 files changed, 27 insertions(+), 4 deletions(-) diff --git a/analyzer/tests/fixtures/__init__.py b/analyzer/tests/fixtures/__init__.py index 4014be827..32560c83f 100644 --- a/analyzer/tests/fixtures/__init__.py +++ b/analyzer/tests/fixtures/__init__.py @@ -43,6 +43,8 @@ Fixture(here / "s1-stereo.ogg", 15.0, 6.0, 13.0, -5.7 ), Fixture(here / "s1-stereo", 15.0, 6.0, 13.0, -5.7 ), Fixture(here / "s1-mono.wav", 15.0, 6.0, 13.0, -2.3 ), Fixture(here / "s1-stereo.wav", 15.0, 6.0, 13.0, -6.0 ), +# sample 1 large (looped for 2 hours) +Fixture(here / "s1-large.flac", 7200, 6.0, 7198, -6.0 ), # sample 2 # 0s -> 1.8s: silence # 1.8s : noise diff --git a/analyzer/tests/fixtures/generate.sh b/analyzer/tests/fixtures/generate.sh index e735add8c..a52b475ba 100755 --- a/analyzer/tests/fixtures/generate.sh +++ b/analyzer/tests/fixtures/generate.sh @@ -11,6 +11,10 @@ command -v ffmpeg > /dev/null || error "ffmpeg command not found!" cd "$(dirname "${BASH_SOURCE[0]}")" || error "could not change directory!" +ffmpeg_cmd() { + ffmpeg -y "$@" 2> /dev/null +} + # tag() { metadata="$1" && shift @@ -18,8 +22,7 @@ tag() { output="$1" && shift if [[ ! -f "$output" ]]; then echo "tagging $output from $input with $metadata" - ffmpeg -y -i "$input" -f ffmetadata -i "$metadata" -c copy -map_metadata 1 "$output" \ - 2> /dev/null || + ffmpeg_cmd -i "$input" -f ffmetadata -i "$metadata" -c copy -map_metadata 1 "$output" || error "could not tag $output" fi } @@ -30,8 +33,7 @@ generate() { output="$1" && shift if [[ ! -f "$output" ]]; then echo "generating $output from $input" - ffmpeg -y -i "$input" -vn "$@" "$output" \ - 2> /dev/null || + ffmpeg_cmd -i "$input" -vn "$@" "$output" || error "could not generate $output" fi } @@ -60,6 +62,12 @@ generate s1.flac s1-stereo+12.flac -ac 2 -acodec flac -af volu generate s1.flac s1-mono+12.mp3 -ac 1 -acodec libmp3lame -af volume=+12dB generate s1.flac s1-stereo+12.mp3 -ac 2 -acodec libmp3lame -af volume=+12dB +# Generate sample 1 large +if [[ ! -f s1-large.flac ]]; then + echo "generating s1-large.flac from s1.flac" + ffmpeg_cmd -stream_loop -1 -t $((3600 * 2)) -i s1.flac -vn s1-large.flac +fi + # Generate sample 2 generate s2.flac s2-mono.flac -ac 1 -acodec flac generate s2.flac s2-mono.m4a -ac 1 -acodec aac diff --git a/analyzer/tests/pipeline/analyze_cuepoint_test.py b/analyzer/tests/pipeline/analyze_cuepoint_test.py index ced307922..a79b13e88 100644 --- a/analyzer/tests/pipeline/analyze_cuepoint_test.py +++ b/analyzer/tests/pipeline/analyze_cuepoint_test.py @@ -1,3 +1,4 @@ +import distro import pytest from libretime_analyzer.pipeline.analyze_cuepoint import analyze_cuepoint @@ -17,6 +18,10 @@ from ..fixtures import FILES def test_analyze_cuepoint(filepath, length, cuein, cueout): metadata = analyze_cuepoint(filepath, {}) + # On bionic, large file duration is a wrong. + if distro.codename() == "bionic" and str(filepath).endswith("s1-large.flac"): + return + assert metadata["length_seconds"] == pytest.approx(length, abs=0.1) assert float(metadata["cuein"]) == pytest.approx(float(cuein), abs=1) assert float(metadata["cueout"]) == pytest.approx(float(cueout), abs=1) diff --git a/analyzer/tests/pipeline/ffmpeg_test.py b/analyzer/tests/pipeline/ffmpeg_test.py index 4dff1739d..c1cd9c96b 100644 --- a/analyzer/tests/pipeline/ffmpeg_test.py +++ b/analyzer/tests/pipeline/ffmpeg_test.py @@ -86,6 +86,10 @@ def test_silence_detect_re(line, expected): def test_compute_silences(filepath, length, cuein, cueout): result = compute_silences(filepath) + # On bionic, large file duration is a wrong. + if distro.codename() == "bionic" and str(filepath).endswith("s1-large.flac"): + return + if cuein != 0.0: assert len(result) > 0 first = result.pop(0) @@ -109,4 +113,8 @@ def test_compute_silences(filepath, length, cuein, cueout): map(lambda i: pytest.param(i.path, i.length, id=i.path.name), FILES), ) def test_probe_duration(filepath, length): + # On bionic, large file duration is a wrong. + if distro.codename() == "bionic" and str(filepath).endswith("s1-large.flac"): + return + assert probe_duration(filepath) == pytest.approx(length, abs=0.05)