11import json
2+ import os
23import re
34import subprocess
45from pathlib import Path
1819)
1920
2021
22+ @pytest .fixture
23+ def with_ffmpeg_debug_logs ():
24+ # Fixture that sets the ffmpeg logs to DEBUG mode
25+ previous_log_level = os .environ .get ("TORCHCODEC_FFMPEG_LOG_LEVEL" , "QUIET" )
26+ os .environ ["TORCHCODEC_FFMPEG_LOG_LEVEL" ] = "DEBUG"
27+ yield
28+ os .environ ["TORCHCODEC_FFMPEG_LOG_LEVEL" ] = previous_log_level
29+
30+
2131def validate_frames_properties (* , actual : Path , expected : Path ):
2232
2333 frames_actual , frames_expected = (
@@ -190,7 +200,17 @@ def test_round_trip(self, method, format, tmp_path):
190200 @pytest .mark .parametrize ("num_channels" , (None , 1 , 2 ))
191201 @pytest .mark .parametrize ("format" , ("mp3" , "wav" , "flac" ))
192202 @pytest .mark .parametrize ("method" , ("to_file" , "to_tensor" ))
193- def test_against_cli (self , asset , bit_rate , num_channels , format , method , tmp_path ):
203+ def test_against_cli (
204+ self ,
205+ asset ,
206+ bit_rate ,
207+ num_channels ,
208+ format ,
209+ method ,
210+ tmp_path ,
211+ capfd ,
212+ with_ffmpeg_debug_logs ,
213+ ):
194214 # Encodes samples with our encoder and with the FFmpeg CLI, and checks
195215 # that both decoded outputs are equal
196216
@@ -210,13 +230,24 @@ def test_against_cli(self, asset, bit_rate, num_channels, format, method, tmp_pa
210230 )
211231
212232 encoder = AudioEncoder (self .decode (asset ).data , sample_rate = asset .sample_rate )
233+
213234 params = dict (bit_rate = bit_rate , num_channels = num_channels )
214235 if method == "to_file" :
215236 encoded_by_us = tmp_path / f"output.{ format } "
216237 encoder .to_file (dest = str (encoded_by_us ), ** params )
217238 else :
218239 encoded_by_us = encoder .to_tensor (format = format , ** params )
219240
241+ captured = capfd .readouterr ()
242+ if format == "wav" :
243+ assert "Timestamps are unset in a packet" not in captured .err
244+ if format == "mp3" :
245+ assert "Queue input is backward in time" not in captured .err
246+ if format in ("flac" , "wav" ):
247+ assert "Encoder did not produce proper pts" not in captured .err
248+ if format in ("flac" , "mp3" ):
249+ assert "Application provided invalid" not in captured .err
250+
220251 if format == "wav" :
221252 rtol , atol = 0 , 1e-4
222253 elif format == "mp3" and asset is SINE_MONO_S32 and num_channels == 2 :
0 commit comments