Skip to content

Commit b3f37c7

Browse files
committed
Add test
1 parent dc1f6d7 commit b3f37c7

File tree

2 files changed

+19
-6
lines changed

2 files changed

+19
-6
lines changed

test/decoders/test_decoders.py

Lines changed: 19 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -1167,20 +1167,33 @@ def test_sample_rate_conversion_stereo(self):
11671167
decoder.get_samples_played_in_range(start_seconds=0)
11681168

11691169
def test_downsample_empty_frame(self):
1170-
# Non-regression test for TODO.
1170+
# Non-regression test for
1171+
# https://github.com/pytorch/torchcodec/pull/586: when downsampling by
1172+
# a great factor, if an input frame has a small amount of sample, the
1173+
# resampled frame (as output by swresample) may contain zero sample. We
1174+
# make sure we handle this properly.
11711175
#
1172-
# This asset has
1176+
# NASA_AUDIO_MP3_44100's first frame has only 47 samples which triggers
1177+
# the test scenario:
11731178
# ```
11741179
# » ffprobe -v error -hide_banner -select_streams a:0 -show_frames -of json test/resources/nasa_13013.mp4.audio_44100.mp3 | grep nb_samples | head -n 3
11751180
# "nb_samples": 47,
11761181
# "nb_samples": 1152,
11771182
# "nb_samples": 1152,
11781183
# ```
11791184
asset = NASA_AUDIO_MP3_44100
1180-
# assert asset.sample_rate == 8000
1181-
# assert asset.num_channels == 2
1182-
# decoder = AudioDecoder(asset.path, sample_rate=44_100)
1183-
# decoder.get_samples_played_in_range(start_seconds=0)
1185+
assert asset.sample_rate == 44_100
1186+
decoder = AudioDecoder(asset.path, sample_rate=8_000)
1187+
frames_44100_to_8000 = decoder.get_samples_played_in_range(start_seconds=0)
1188+
1189+
# Just checking correctness now
1190+
asset = NASA_AUDIO_MP3
1191+
assert asset.sample_rate == 8_000
1192+
decoder = AudioDecoder(asset.path)
1193+
frames_8000 = decoder.get_samples_played_in_range(start_seconds=0)
1194+
torch.testing.assert_close(
1195+
frames_44100_to_8000.data, frames_8000.data, atol=0.03, rtol=0
1196+
)
11841197

11851198
def test_s16_ffmpeg4_bug(self):
11861199
# s16 fails on FFmpeg4 but can be decoded on other versions.

test/resources/nasa_13013.mp4.audio_44100.all_frames_info.json renamed to test/resources/nasa_13013.mp4.audio_44100.mp3.stream0.all_frames_info.json

File renamed without changes.

0 commit comments

Comments
 (0)