@@ -1682,26 +1682,25 @@ def test_downsample_empty_frame(self):
1682
1682
frames_44100_to_8000 .data , frames_8000 .data , atol = 0.03 , rtol = 0
1683
1683
)
1684
1684
1685
- def test_s16_ffmpeg4_bug (self ):
1686
- # s16 fails on FFmpeg4 but can be decoded on other versions.
1687
- # Debugging logs show that we're hitting:
1688
- # [SWR @ 0x560a7abdaf80] Input channel count and layout are unset
1689
- # which seems to point to:
1690
- # https://github.com/FFmpeg/FFmpeg/blob/40a6963fbd0c47be358a3760480180b7b532e1e9/libswresample/swresample.c#L293-L305
1691
- # ¯\_(ツ)_/¯
1685
+ def test_decode_s16_ffmpeg4 (self ):
1686
+ # Non-regression test for https://github.com/pytorch/torchcodec/issues/843
1687
+ # Ensures that decoding s16 on FFmpeg4 handles
1688
+ # unset input channel count and layout
1692
1689
1693
1690
asset = SINE_MONO_S16
1694
1691
decoder = AudioDecoder (asset .path )
1695
1692
assert decoder .metadata .sample_rate == asset .sample_rate
1696
1693
assert decoder .metadata .sample_format == asset .sample_format
1697
1694
1698
- cm = (
1699
- pytest .raises (RuntimeError , match = "The frame has 0 channels, expected 1." )
1700
- if get_ffmpeg_major_version () == 4
1701
- else contextlib .nullcontext ()
1695
+ test_samples = decoder .get_samples_played_in_range ()
1696
+ assert test_samples .data .shape [0 ] == decoder .metadata .num_channels
1697
+ assert test_samples .sample_rate == decoder .metadata .sample_rate
1698
+ reference_frames = asset .get_frame_data_by_range (
1699
+ start = 0 , stop = 1 , stream_index = 0
1700
+ )
1701
+ torch .testing .assert_close (
1702
+ test_samples .data [0 ], reference_frames , atol = 0 , rtol = 0
1702
1703
)
1703
- with cm :
1704
- decoder .get_samples_played_in_range ()
1705
1704
1706
1705
@pytest .mark .parametrize ("asset" , (NASA_AUDIO , NASA_AUDIO_MP3 ))
1707
1706
@pytest .mark .parametrize ("sample_rate" , (None , 8000 , 16_000 , 44_1000 ))
0 commit comments