|
24 | 24 | in_fbcode, |
25 | 25 | NASA_AUDIO, |
26 | 26 | NASA_AUDIO_MP3, |
| 27 | + NASA_AUDIO_MP3_44100, |
27 | 28 | NASA_VIDEO, |
28 | 29 | SINE_MONO_S16, |
29 | 30 | SINE_MONO_S32, |
@@ -1165,6 +1166,35 @@ def test_sample_rate_conversion_stereo(self): |
1165 | 1166 | decoder = AudioDecoder(asset.path, sample_rate=44_100) |
1166 | 1167 | decoder.get_samples_played_in_range(start_seconds=0) |
1167 | 1168 |
|
| 1169 | + def test_downsample_empty_frame(self): |
| 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. |
| 1175 | + # |
| 1176 | + # NASA_AUDIO_MP3_44100's first frame has only 47 samples which triggers |
| 1177 | + # the test scenario: |
| 1178 | + # ``` |
| 1179 | + # » 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 |
| 1180 | + # "nb_samples": 47, |
| 1181 | + # "nb_samples": 1152, |
| 1182 | + # "nb_samples": 1152, |
| 1183 | + # ``` |
| 1184 | + asset = NASA_AUDIO_MP3_44100 |
| 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 | + ) |
| 1197 | + |
1168 | 1198 | def test_s16_ffmpeg4_bug(self): |
1169 | 1199 | # s16 fails on FFmpeg4 but can be decoded on other versions. |
1170 | 1200 | # Debugging logs show that we're hitting: |
|
0 commit comments