Generate analyzer fixtures using ffmpeg
This commit is contained in:
parent
eb3ac44fa5
commit
8ac5c1ba03
|
@ -15,6 +15,7 @@ apt-get install -y gstreamer1.0-plugins-base \
|
|||
liquidsoap-plugin-vorbis \
|
||||
python3-gst-1.0 \
|
||||
silan \
|
||||
ffmpeg \
|
||||
gcc \
|
||||
gir1.2-gtk-3.0 \
|
||||
python3-setuptools \
|
||||
|
|
|
@ -10,7 +10,10 @@ lint:
|
|||
pylint ${MODULE_APP}
|
||||
pylint ${MODULE_TESTS}
|
||||
|
||||
test:
|
||||
fixtures:
|
||||
bash tests/fixtures/generate.sh
|
||||
|
||||
test: fixtures
|
||||
pytest -n ${CPU_CORES} --color=yes -v --cov=${MODULE_APP} ${MODULE_TESTS}
|
||||
|
||||
all: lint test
|
||||
|
|
|
@ -0,0 +1 @@
|
|||
s*-*
|
|
@ -0,0 +1,270 @@
|
|||
from collections import namedtuple
|
||||
from datetime import timedelta
|
||||
from pathlib import Path
|
||||
|
||||
from pytest import approx
|
||||
|
||||
here = Path(__file__).parent
|
||||
fixtures_path = here
|
||||
|
||||
FILE_INVALID_DRM = here / "invalid.wma"
|
||||
FILE_INVALID_TXT = here / "invalid.txt"
|
||||
|
||||
Fixture = namedtuple(
|
||||
"Fixture",
|
||||
["path", "length", "cuein", "cueout", "replaygain"],
|
||||
)
|
||||
|
||||
# length,cuein,cueout
|
||||
s1 = [10.0, 2.3, 10.0]
|
||||
s2 = [3.9, 0.0, 3.9]
|
||||
|
||||
FILES = [
|
||||
# Sample 1 MP3
|
||||
Fixture(here / "s1-jointstereo.mp3", *s1, -1.6),
|
||||
Fixture(here / "s1-mono.mp3", *s1, -0.7),
|
||||
Fixture(here / "s1-stereo.mp3", *s1, -1.6),
|
||||
# Sample 1 FLAC
|
||||
Fixture(here / "s1-mono.flac", *s1, -1.6),
|
||||
Fixture(here / "s1-stereo.flac", *s1, -2.3),
|
||||
# Sample 1 AAC
|
||||
Fixture(here / "s1-mono.m4a", *s1, -4.5),
|
||||
Fixture(here / "s1-stereo.m4a", *s1, -2.3),
|
||||
# Sample 1 Vorbis
|
||||
Fixture(here / "s1-mono.ogg", *s1, -4.3),
|
||||
Fixture(here / "s1-stereo.ogg", *s1, -2.3),
|
||||
# Sample 2 MP3
|
||||
Fixture(here / "s2-jointstereo.mp3", *s2, 6.1),
|
||||
Fixture(here / "s2-mono.mp3", *s2, 6.1),
|
||||
Fixture(here / "s2-stereo.mp3", *s2, 6.1),
|
||||
# Sample 2 FLAC
|
||||
Fixture(here / "s2-mono.flac", *s2, 5.2),
|
||||
Fixture(here / "s2-stereo.flac", *s2, 5.2),
|
||||
# Sample 2 AAC
|
||||
Fixture(here / "s2-mono.m4a", *s2, 2.6),
|
||||
Fixture(here / "s2-stereo.m4a", *s2, 6.1),
|
||||
# Sample 2 Vorbis
|
||||
Fixture(here / "s2-mono.ogg", *s2, 2.3),
|
||||
Fixture(here / "s2-stereo.ogg", *s2, 5.2),
|
||||
]
|
||||
|
||||
FixtureMeta = namedtuple(
|
||||
"FixtureMeta",
|
||||
["path", "metadata"],
|
||||
)
|
||||
|
||||
meta = {
|
||||
"cuein": 0.0,
|
||||
"sample_rate": 48000,
|
||||
"length": str(timedelta(seconds=10)),
|
||||
"length_seconds": approx(10.0, abs=0.1),
|
||||
"ftype": "audioclip",
|
||||
"hidden": False,
|
||||
# Tags
|
||||
"album_title": "Test Album",
|
||||
"artist_name": "Test Artist",
|
||||
"track_title": "Test Title",
|
||||
"track_number": "1",
|
||||
"track_total": "10",
|
||||
"year": "1999",
|
||||
"genre": "Test Genre",
|
||||
"comment": "Test Comment",
|
||||
}
|
||||
|
||||
FILES_TAGGED = [
|
||||
FixtureMeta(
|
||||
here / "s1-jointstereo-tagged.mp3",
|
||||
{
|
||||
**meta,
|
||||
"bit_rate": approx(128000, abs=1e2),
|
||||
"channels": 2,
|
||||
"filesize": approx(161094, abs=1e2),
|
||||
"mime": "audio/mp3",
|
||||
},
|
||||
),
|
||||
FixtureMeta(
|
||||
here / "s1-mono-tagged.mp3",
|
||||
{
|
||||
**meta,
|
||||
"bit_rate": approx(64000, abs=1e2),
|
||||
"channels": 1,
|
||||
"filesize": approx(80646, abs=1e2),
|
||||
"mime": "audio/mp3",
|
||||
},
|
||||
),
|
||||
FixtureMeta(
|
||||
here / "s1-stereo-tagged.mp3",
|
||||
{
|
||||
**meta,
|
||||
"bit_rate": approx(128000, abs=1e2),
|
||||
"channels": 2,
|
||||
"filesize": approx(161094, abs=1e2),
|
||||
"mime": "audio/mp3",
|
||||
},
|
||||
),
|
||||
FixtureMeta(
|
||||
here / "s1-mono-tagged.flac",
|
||||
{
|
||||
**meta,
|
||||
"bit_rate": approx(454468, abs=1e2),
|
||||
"channels": 1,
|
||||
"filesize": approx(576516, abs=1e2),
|
||||
"mime": "audio/flac",
|
||||
},
|
||||
),
|
||||
FixtureMeta(
|
||||
here / "s1-stereo-tagged.flac",
|
||||
{
|
||||
**meta,
|
||||
"bit_rate": approx(687113, abs=1e2),
|
||||
"channels": 2,
|
||||
"filesize": approx(867323, abs=1e2),
|
||||
"mime": "audio/flac",
|
||||
},
|
||||
),
|
||||
FixtureMeta(
|
||||
here / "s1-mono-tagged.m4a",
|
||||
{
|
||||
**meta,
|
||||
"bit_rate": approx(65000, abs=5e4),
|
||||
"channels": 2, # Weird
|
||||
"filesize": approx(80000, abs=1e5),
|
||||
"mime": "audio/mp4",
|
||||
},
|
||||
),
|
||||
FixtureMeta(
|
||||
here / "s1-stereo-tagged.m4a",
|
||||
{
|
||||
**meta,
|
||||
"bit_rate": approx(128000, abs=1e5),
|
||||
"channels": 2,
|
||||
"filesize": approx(150000, abs=1e5),
|
||||
"mime": "audio/mp4",
|
||||
},
|
||||
),
|
||||
FixtureMeta(
|
||||
here / "s1-mono-tagged.ogg",
|
||||
{
|
||||
**meta,
|
||||
"bit_rate": approx(80000, abs=1e2),
|
||||
"channels": 1,
|
||||
"filesize": approx(81340, abs=1e2),
|
||||
"mime": "audio/vorbis",
|
||||
},
|
||||
),
|
||||
FixtureMeta(
|
||||
here / "s1-stereo-tagged.ogg",
|
||||
{
|
||||
**meta,
|
||||
"bit_rate": approx(112000, abs=1e2),
|
||||
"channels": 2,
|
||||
"filesize": approx(104036, abs=1e2),
|
||||
"mime": "audio/vorbis",
|
||||
},
|
||||
),
|
||||
]
|
||||
|
||||
meta = {
|
||||
**meta,
|
||||
"album_title": "Ä ä Ü ü ß",
|
||||
"artist_name": "てすと",
|
||||
"track_title": "アイウエオカキクケコサシスセソタチツテ",
|
||||
"track_number": "1",
|
||||
"track_total": "10",
|
||||
"year": "1999",
|
||||
"genre": "Я Б Г Д Ж Й",
|
||||
"comment": "Ł Ą Ż Ę Ć Ń Ś Ź",
|
||||
}
|
||||
|
||||
FILES_TAGGED += [
|
||||
FixtureMeta(
|
||||
here / "s1-jointstereo-tagged-utf8.mp3",
|
||||
{
|
||||
**meta,
|
||||
"bit_rate": approx(128000, abs=1e2),
|
||||
"channels": 2,
|
||||
"filesize": approx(161161, abs=1e2),
|
||||
"mime": "audio/mp3",
|
||||
},
|
||||
),
|
||||
FixtureMeta(
|
||||
here / "s1-mono-tagged-utf8.mp3",
|
||||
{
|
||||
**meta,
|
||||
"bit_rate": approx(64000, abs=1e2),
|
||||
"channels": 1,
|
||||
"filesize": approx(80713, abs=1e2),
|
||||
"mime": "audio/mp3",
|
||||
},
|
||||
),
|
||||
FixtureMeta(
|
||||
here / "s1-stereo-tagged-utf8.mp3",
|
||||
{
|
||||
**meta,
|
||||
"bit_rate": approx(128000, abs=1e2),
|
||||
"channels": 2,
|
||||
"filesize": approx(161161, abs=1e2),
|
||||
"mime": "audio/mp3",
|
||||
},
|
||||
),
|
||||
FixtureMeta(
|
||||
here / "s1-mono-tagged-utf8.flac",
|
||||
{
|
||||
**meta,
|
||||
"bit_rate": approx(454468, abs=1e2),
|
||||
"channels": 1,
|
||||
"filesize": approx(576583, abs=1e2),
|
||||
"mime": "audio/flac",
|
||||
},
|
||||
),
|
||||
FixtureMeta(
|
||||
here / "s1-stereo-tagged-utf8.flac",
|
||||
{
|
||||
**meta,
|
||||
"bit_rate": approx(687113, abs=1e2),
|
||||
"channels": 2,
|
||||
"filesize": approx(867390, abs=1e2),
|
||||
"mime": "audio/flac",
|
||||
},
|
||||
),
|
||||
FixtureMeta(
|
||||
here / "s1-mono-tagged-utf8.m4a",
|
||||
{
|
||||
**meta,
|
||||
"bit_rate": approx(65000, abs=5e4),
|
||||
"channels": 2, # Weird
|
||||
"filesize": approx(80000, abs=1e5),
|
||||
"mime": "audio/mp4",
|
||||
},
|
||||
),
|
||||
FixtureMeta(
|
||||
here / "s1-stereo-tagged-utf8.m4a",
|
||||
{
|
||||
**meta,
|
||||
"bit_rate": approx(128000, abs=1e5),
|
||||
"channels": 2,
|
||||
"filesize": approx(150000, abs=1e5),
|
||||
"mime": "audio/mp4",
|
||||
},
|
||||
),
|
||||
FixtureMeta(
|
||||
here / "s1-mono-tagged-utf8.ogg",
|
||||
{
|
||||
**meta,
|
||||
"bit_rate": approx(80000, abs=1e2),
|
||||
"channels": 1,
|
||||
"filesize": approx(81408, abs=1e2),
|
||||
"mime": "audio/vorbis",
|
||||
},
|
||||
),
|
||||
FixtureMeta(
|
||||
here / "s1-stereo-tagged-utf8.ogg",
|
||||
{
|
||||
**meta,
|
||||
"bit_rate": approx(112000, abs=1e2),
|
||||
"channels": 2,
|
||||
"filesize": approx(104104, abs=1e2),
|
||||
"mime": "audio/vorbis",
|
||||
},
|
||||
),
|
||||
]
|
|
@ -0,0 +1,81 @@
|
|||
#!/usr/bin/env bash
|
||||
|
||||
set -u
|
||||
|
||||
error() {
|
||||
echo >&2 "error: $*"
|
||||
exit 1
|
||||
}
|
||||
|
||||
command -v ffmpeg > /dev/null || error "ffmpeg command not found!"
|
||||
|
||||
cd "$(dirname "${BASH_SOURCE[0]}")" || error "could not change directory!"
|
||||
|
||||
# <metadata> <input> <output>
|
||||
tag() {
|
||||
metadata="$1" && shift
|
||||
input="$1" && shift
|
||||
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 ||
|
||||
error "could not tag $output"
|
||||
fi
|
||||
}
|
||||
|
||||
# <input> <output> <flags...>
|
||||
generate() {
|
||||
input="$1" && shift
|
||||
output="$1" && shift
|
||||
if [[ ! -f "$output" ]]; then
|
||||
echo "generating $output from $input"
|
||||
ffmpeg -y -i "$input" -vn "$@" "$output" \
|
||||
2> /dev/null ||
|
||||
error "could not generate $output"
|
||||
fi
|
||||
}
|
||||
|
||||
# Generated sample 1
|
||||
generate s1.flac s1-mono.flac -ac 1 -acodec flac
|
||||
generate s1.flac s1-mono.m4a -ac 1 -acodec aac
|
||||
generate s1.flac s1-mono.mp3 -ac 1 -acodec libmp3lame
|
||||
generate s1.flac s1-mono.ogg -ac 1 -acodec libvorbis
|
||||
generate s1.flac s1-stereo.flac -ac 2 -acodec flac
|
||||
generate s1.flac s1-stereo.m4a -ac 2 -acodec aac
|
||||
generate s1.flac s1-stereo.mp3 -ac 2 -acodec libmp3lame
|
||||
generate s1.flac s1-stereo.ogg -ac 2 -acodec libvorbis
|
||||
generate s1.flac s1-jointstereo.mp3 -ac 2 -acodec libmp3lame -joint_stereo 1
|
||||
|
||||
# Generated sample 2
|
||||
generate s2.flac s2-mono.flac -ac 1 -acodec flac
|
||||
generate s2.flac s2-mono.m4a -ac 1 -acodec aac
|
||||
generate s2.flac s2-mono.mp3 -ac 1 -acodec libmp3lame
|
||||
generate s2.flac s2-mono.ogg -ac 1 -acodec libvorbis
|
||||
generate s2.flac s2-stereo.flac -ac 2 -acodec flac
|
||||
generate s2.flac s2-stereo.m4a -ac 2 -acodec aac
|
||||
generate s2.flac s2-stereo.mp3 -ac 2 -acodec libmp3lame
|
||||
generate s2.flac s2-stereo.ogg -ac 2 -acodec libvorbis
|
||||
generate s2.flac s2-jointstereo.mp3 -ac 2 -acodec libmp3lame -joint_stereo 1
|
||||
|
||||
# Tag sample 1
|
||||
tag metadata.txt s1-mono.flac s1-mono-tagged.flac
|
||||
tag metadata.txt s1-mono.m4a s1-mono-tagged.m4a
|
||||
tag metadata.txt s1-mono.mp3 s1-mono-tagged.mp3
|
||||
tag metadata.txt s1-mono.ogg s1-mono-tagged.ogg
|
||||
tag metadata.txt s1-stereo.flac s1-stereo-tagged.flac
|
||||
tag metadata.txt s1-stereo.m4a s1-stereo-tagged.m4a
|
||||
tag metadata.txt s1-stereo.mp3 s1-stereo-tagged.mp3
|
||||
tag metadata.txt s1-stereo.ogg s1-stereo-tagged.ogg
|
||||
tag metadata.txt s1-jointstereo.mp3 s1-jointstereo-tagged.mp3
|
||||
|
||||
# Tag utf8 sample 1
|
||||
tag metadata-utf8.txt s1-mono.flac s1-mono-tagged-utf8.flac
|
||||
tag metadata-utf8.txt s1-mono.m4a s1-mono-tagged-utf8.m4a
|
||||
tag metadata-utf8.txt s1-mono.mp3 s1-mono-tagged-utf8.mp3
|
||||
tag metadata-utf8.txt s1-mono.ogg s1-mono-tagged-utf8.ogg
|
||||
tag metadata-utf8.txt s1-stereo.flac s1-stereo-tagged-utf8.flac
|
||||
tag metadata-utf8.txt s1-stereo.m4a s1-stereo-tagged-utf8.m4a
|
||||
tag metadata-utf8.txt s1-stereo.mp3 s1-stereo-tagged-utf8.mp3
|
||||
tag metadata-utf8.txt s1-stereo.ogg s1-stereo-tagged-utf8.ogg
|
||||
tag metadata-utf8.txt s1-jointstereo.mp3 s1-jointstereo-tagged-utf8.mp3
|
|
@ -0,0 +1,8 @@
|
|||
;FFMETADATA1
|
||||
album=Ä ä Ü ü ß
|
||||
artist=てすと
|
||||
title=アイウエオカキクケコサシスセソタチツテ
|
||||
track=1/10
|
||||
date=1999
|
||||
genre=Я Б Г Д Ж Й
|
||||
comment=Ł Ą Ż Ę Ć Ń Ś Ź
|
|
@ -0,0 +1,8 @@
|
|||
;FFMETADATA1
|
||||
album=Test Album
|
||||
artist=Test Artist
|
||||
title=Test Title
|
||||
track=1/10
|
||||
date=1999
|
||||
genre=Test Genre
|
||||
comment=Test Comment
|
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Binary file not shown.
Loading…
Reference in New Issue