Skip to content

Commit e039053

Browse files
committed
Remove outdated workarounds in recent ffmpeg on Windows
1 parent 9196d42 commit e039053

File tree

2 files changed

+26
-7
lines changed

2 files changed

+26
-7
lines changed

test/test_encoders.py

Lines changed: 17 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,24 @@
1616
from .utils import (
1717
assert_tensor_close_on_at_least,
1818
get_ffmpeg_major_version,
19+
get_ffmpeg_minor_version,
1920
in_fbcode,
2021
IS_WINDOWS,
2122
NASA_AUDIO_MP3,
2223
SINE_MONO_S32,
2324
TestContainerFile,
2425
)
2526

27+
IS_WINDOWS_WITH_FFMPEG_LE_70 = (
28+
IS_WINDOWS
29+
or (
30+
get_ffmpeg_major_version() < 7
31+
or (
32+
get_ffmpeg_major_version() == 7 and get_ffmpeg_minor_version() == 0
33+
)
34+
)
35+
)
36+
2637

2738
@pytest.fixture
2839
def with_ffmpeg_debug_logs():
@@ -155,7 +166,7 @@ def test_bad_input_parametrized(self, method, tmp_path):
155166
avcodec_open2_failed_msg = "avcodec_open2 failed: Invalid argument"
156167
with pytest.raises(
157168
RuntimeError,
158-
match=avcodec_open2_failed_msg if IS_WINDOWS else "invalid sample rate=10",
169+
match=avcodec_open2_failed_msg if IS_WINDOWS_WITH_FFMPEG_LE_70 else "invalid sample rate=10",
159170
):
160171
getattr(decoder, method)(**valid_params)
161172

@@ -164,14 +175,14 @@ def test_bad_input_parametrized(self, method, tmp_path):
164175
)
165176
with pytest.raises(
166177
RuntimeError,
167-
match=avcodec_open2_failed_msg if IS_WINDOWS else "invalid sample rate=10",
178+
match=avcodec_open2_failed_msg if IS_WINDOWS_WITH_FFMPEG_LE_70 else "invalid sample rate=10",
168179
):
169180
getattr(decoder, method)(sample_rate=10, **valid_params)
170181
with pytest.raises(
171182
RuntimeError,
172183
match=(
173184
avcodec_open2_failed_msg
174-
if IS_WINDOWS
185+
if IS_WINDOWS_WITH_FFMPEG_LE_70
175186
else "invalid sample rate=99999999"
176187
),
177188
):
@@ -192,7 +203,7 @@ def test_bad_input_parametrized(self, method, tmp_path):
192203
for num_channels in (0, 3):
193204
match = (
194205
avcodec_open2_failed_msg
195-
if IS_WINDOWS
206+
if IS_WINDOWS_WITH_FFMPEG_LE_70
196207
else re.escape(
197208
f"Desired number of channels ({num_channels}) is not supported"
198209
)
@@ -316,7 +327,7 @@ def test_against_cli(
316327
else:
317328
rtol, atol = None, None
318329

319-
if IS_WINDOWS and format == "mp3":
330+
if IS_WINDOWS_WITH_FFMPEG_LE_70 and format == "mp3":
320331
# We're getting a "Could not open input file" on Windows mp3 files when decoding.
321332
# TODO: https://github.com/pytorch/torchcodec/issues/837
322333
return
@@ -370,7 +381,7 @@ def test_against_to_file(
370381
else:
371382
raise ValueError(f"Unknown method: {method}")
372383

373-
if not (IS_WINDOWS and format == "mp3"):
384+
if not (IS_WINDOWS_WITH_FFMPEG_LE_70 and format == "mp3"):
374385
# We're getting a "Could not open input file" on Windows mp3 files when decoding.
375386
# TODO: https://github.com/pytorch/torchcodec/issues/837
376387
torch.testing.assert_close(

test/utils.py

Lines changed: 9 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,15 +76,23 @@ def make_video_decoder(*args, **kwargs) -> tuple[VideoDecoder, str]:
7676
return dec, clean_device
7777

7878

79-
def get_ffmpeg_major_version():
79+
def _get_ffmpeg_version_string():
8080
ffmpeg_version = get_ffmpeg_library_versions()["ffmpeg_version"]
8181
# When building FFmpeg from source there can be a `n` prefix in the version
8282
# string. This is quite brittle as we're using av_version_info(), which has
8383
# no stable format. See https://github.com/pytorch/torchcodec/issues/100
8484
if ffmpeg_version.startswith("n"):
8585
ffmpeg_version = ffmpeg_version.removeprefix("n")
86+
87+
return ffmpeg_version
88+
89+
def get_ffmpeg_major_version():
90+
ffmpeg_version = _get_ffmpeg_version_string()
8691
return int(ffmpeg_version.split(".")[0])
8792

93+
def get_ffmpeg_minor_version():
94+
ffmpeg_version = _get_ffmpeg_version_string()
95+
return int(ffmpeg_version.split(".")[1])
8896

8997
def cuda_version_used_for_building_torch() -> Optional[tuple[int, int]]:
9098
# Return the CUDA version that was used to build PyTorch. That's not always

0 commit comments

Comments
 (0)