Skip to content

Commit b90927b

Browse files
committed
Add test for FFmpeg logs
1 parent 079de41 commit b90927b

File tree

1 file changed

+32
-1
lines changed

1 file changed

+32
-1
lines changed

test/test_encoders.py

Lines changed: 32 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1,4 +1,5 @@
11
import json
2+
import os
23
import re
34
import subprocess
45
from pathlib import Path
@@ -18,6 +19,15 @@
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+
2131
def 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

Comments
 (0)