Skip to content

Commit d272e4d

Browse files
traversaroNicolasHug
authored andcommitted
Enable tests with ffmpeg8 on Windows (meta-pytorch#973)
1 parent f39ebfd commit d272e4d

File tree

3 files changed

+38
-10
lines changed

3 files changed

+38
-10
lines changed

.github/workflows/windows_wheel.yaml

Lines changed: 6 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -71,8 +71,7 @@ jobs:
7171
# TODO: FFmpeg 5 on Windows segfaults in avcodec_open2() when passing
7272
# bad parameters.
7373
# See https://github.com/pytorch/torchcodec/pull/806
74-
# TODO: Support FFmpeg 8 on Windows
75-
ffmpeg-version-for-tests: ['4.4.2', '5.1.2', '6.1.1', '7.0.1']
74+
ffmpeg-version-for-tests: ['4.4.2', '5.1.2', '6.1.1', '7.0.1', '8.0']
7675
needs: build
7776
steps:
7877
- uses: actions/download-artifact@v4
@@ -83,7 +82,11 @@ jobs:
8382
uses: conda-incubator/setup-miniconda@v2
8483
with:
8584
auto-update-conda: true
86-
miniconda-version: "latest"
85+
# Using miniforge instead of miniconda ensures that the default
86+
# conda channel is conda-forge instead of main/default. This ensures
87+
# ABI consistency between dependencies:
88+
# https://conda-forge.org/docs/user/transitioning_from_defaults/
89+
miniforge-version: latest
8790
activate-environment: test
8891
python-version: ${{ matrix.python-version }}
8992
- name: Update pip

test/test_encoders.py

Lines changed: 20 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -16,13 +16,19 @@
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 = IS_WINDOWS and (
28+
get_ffmpeg_major_version() < 7
29+
or (get_ffmpeg_major_version() == 7 and get_ffmpeg_minor_version() == 0)
30+
)
31+
2632

2733
@pytest.fixture
2834
def with_ffmpeg_debug_logs():
@@ -155,7 +161,11 @@ def test_bad_input_parametrized(self, method, tmp_path):
155161
avcodec_open2_failed_msg = "avcodec_open2 failed: Invalid argument"
156162
with pytest.raises(
157163
RuntimeError,
158-
match=avcodec_open2_failed_msg if IS_WINDOWS else "invalid sample rate=10",
164+
match=(
165+
avcodec_open2_failed_msg
166+
if IS_WINDOWS_WITH_FFMPEG_LE_70
167+
else "invalid sample rate=10"
168+
),
159169
):
160170
getattr(decoder, method)(**valid_params)
161171

@@ -164,14 +174,18 @@ def test_bad_input_parametrized(self, method, tmp_path):
164174
)
165175
with pytest.raises(
166176
RuntimeError,
167-
match=avcodec_open2_failed_msg if IS_WINDOWS else "invalid sample rate=10",
177+
match=(
178+
avcodec_open2_failed_msg
179+
if IS_WINDOWS_WITH_FFMPEG_LE_70
180+
else "invalid sample rate=10"
181+
),
168182
):
169183
getattr(decoder, method)(sample_rate=10, **valid_params)
170184
with pytest.raises(
171185
RuntimeError,
172186
match=(
173187
avcodec_open2_failed_msg
174-
if IS_WINDOWS
188+
if IS_WINDOWS_WITH_FFMPEG_LE_70
175189
else "invalid sample rate=99999999"
176190
),
177191
):
@@ -192,7 +206,7 @@ def test_bad_input_parametrized(self, method, tmp_path):
192206
for num_channels in (0, 3):
193207
match = (
194208
avcodec_open2_failed_msg
195-
if IS_WINDOWS
209+
if IS_WINDOWS_WITH_FFMPEG_LE_70
196210
else re.escape(
197211
f"Desired number of channels ({num_channels}) is not supported"
198212
)
@@ -316,7 +330,7 @@ def test_against_cli(
316330
else:
317331
rtol, atol = None, None
318332

319-
if IS_WINDOWS and format == "mp3":
333+
if IS_WINDOWS_WITH_FFMPEG_LE_70 and format == "mp3":
320334
# We're getting a "Could not open input file" on Windows mp3 files when decoding.
321335
# TODO: https://github.com/pytorch/torchcodec/issues/837
322336
return
@@ -370,7 +384,7 @@ def test_against_to_file(
370384
else:
371385
raise ValueError(f"Unknown method: {method}")
372386

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

test/utils.py

Lines changed: 12 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -76,16 +76,27 @@ 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+
90+
def get_ffmpeg_major_version():
91+
ffmpeg_version = _get_ffmpeg_version_string()
8692
return int(ffmpeg_version.split(".")[0])
8793

8894

95+
def get_ffmpeg_minor_version():
96+
ffmpeg_version = _get_ffmpeg_version_string()
97+
return int(ffmpeg_version.split(".")[1])
98+
99+
89100
def cuda_version_used_for_building_torch() -> Optional[tuple[int, int]]:
90101
# Return the CUDA version that was used to build PyTorch. That's not always
91102
# the same as the CUDA version that is currently installed on the running

0 commit comments

Comments
 (0)