Skip to content

Commit bf6a743

Browse files
committed
Merge branch 'main' of github.com:pytorch/torchcodec into fallback-better
2 parents 4178e23 + 3827dfe commit bf6a743

File tree

8 files changed

+127
-77
lines changed

8 files changed

+127
-77
lines changed

.github/workflows/linux_wheel.yaml

Lines changed: 6 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -71,10 +71,14 @@ jobs:
7171
name: meta-pytorch_torchcodec__${{ matrix.python-version }}_cpu_x86_64
7272
path: pytorch/torchcodec/dist/
7373
- name: Setup conda env
74-
uses: conda-incubator/setup-miniconda@v2
74+
uses: conda-incubator/setup-miniconda@v3
7575
with:
7676
auto-update-conda: true
77-
miniconda-version: "latest"
77+
# Using miniforge instead of miniconda ensures that the default
78+
# conda channel is conda-forge instead of main/default. This ensures
79+
# ABI consistency between dependencies:
80+
# https://conda-forge.org/docs/user/transitioning_from_defaults/
81+
miniforge-version: latest
7882
activate-environment: test
7983
python-version: ${{ matrix.python-version }}
8084
- name: Update pip

README.md

Lines changed: 5 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -107,8 +107,8 @@ ffmpeg -f lavfi -i \
107107
`torch` and `torchcodec`.
108108

109109
2. Install FFmpeg, if it's not already installed. Linux distributions usually
110-
come with FFmpeg pre-installed. TorchCodec supports all major FFmpeg versions
111-
in [4, 7].
110+
come with FFmpeg pre-installed. TorchCodec supports major FFmpeg versions
111+
in [4, 7] on all platforms, and FFmpeg version 8 is supported on Mac and Linux.
112112

113113
If FFmpeg is not already installed, or you need a more recent version, an
114114
easy way to install it is to use `conda`:
@@ -131,6 +131,7 @@ The following table indicates the compatibility between versions of
131131
| `torchcodec` | `torch` | Python |
132132
| ------------------ | ------------------ | ------------------- |
133133
| `main` / `nightly` | `main` / `nightly` | `>=3.10`, `<=3.13` |
134+
| `0.8` | `2.9` | `>=3.10`, `<=3.13` |
134135
| `0.7` | `2.8` | `>=3.9`, `<=3.13` |
135136
| `0.6` | `2.8` | `>=3.9`, `<=3.13` |
136137
| `0.5` | `2.7` | `>=3.9`, `<=3.13` |
@@ -147,7 +148,8 @@ format you want. Refer to Nvidia's GPU support matrix for more details
147148
[here](https://developer.nvidia.com/video-encode-and-decode-gpu-support-matrix-new).
148149

149150
1. Install FFmpeg with NVDEC support.
150-
TorchCodec with CUDA should work with FFmpeg versions in [4, 7].
151+
TorchCodec with CUDA should work with FFmpeg versions in [4, 7] on all platforms,
152+
and FFmpeg version 8 is supported on Linux.
151153

152154
If FFmpeg is not already installed, or you need a more recent version, an
153155
easy way to install it is to use `conda`:

src/torchcodec/_core/ops.py

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -69,7 +69,7 @@ def load_torchcodec_shared_libraries():
6969
raise RuntimeError(
7070
f"""Could not load libtorchcodec. Likely causes:
7171
1. FFmpeg is not properly installed in your environment. We support
72-
versions 4, 5, 6 and 7.
72+
versions 4, 5, 6, and 7 on all platforms, and 8 on Mac and Linux.
7373
2. The PyTorch version ({torch.__version__}) is not compatible with
7474
this version of TorchCodec. Refer to the version compatibility
7575
table:

src/torchcodec/decoders/_video_decoder.py

Lines changed: 0 additions & 7 deletions
Original file line numberDiff line numberDiff line change
@@ -148,13 +148,6 @@ def __init__(
148148

149149
device_variant = _get_cuda_backend()
150150

151-
# Legacy support for device="cuda:0:beta" syntax
152-
# TODONVDEC P2: remove support for this everywhere. This will require
153-
# updating our tests.
154-
if device == "cuda:0:beta":
155-
device = "cuda:0"
156-
device_variant = "beta"
157-
158151
core.add_video_stream(
159152
self._decoder,
160153
stream_index=stream_index,

test/test_decoders.py

Lines changed: 68 additions & 57 deletions
Large diffs are not rendered by default.

test/test_ops.py

Lines changed: 13 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -1384,7 +1384,9 @@ def decode(self, file_path) -> torch.Tensor:
13841384
frames, *_ = get_frames_in_range(decoder, start=0, stop=60)
13851385
return frames
13861386

1387-
@pytest.mark.parametrize("format", ("mov", "mp4", "mkv", "webm"))
1387+
@pytest.mark.parametrize(
1388+
"format", ("mov", "mp4", "mkv", pytest.param("webm", marks=pytest.mark.slow))
1389+
)
13881390
def test_video_encoder_round_trip(self, tmp_path, format):
13891391
# Test that decode(encode(decode(asset))) == decode(asset)
13901392
ffmpeg_version = get_ffmpeg_major_version()
@@ -1424,7 +1426,16 @@ def test_video_encoder_round_trip(self, tmp_path, format):
14241426

14251427
@pytest.mark.skipif(in_fbcode(), reason="ffmpeg CLI not available")
14261428
@pytest.mark.parametrize(
1427-
"format", ("mov", "mp4", "avi", "mkv", "webm", "flv", "gif")
1429+
"format",
1430+
(
1431+
"mov",
1432+
"mp4",
1433+
"avi",
1434+
"mkv",
1435+
"flv",
1436+
"gif",
1437+
pytest.param("webm", marks=pytest.mark.slow),
1438+
),
14281439
)
14291440
def test_video_encoder_against_ffmpeg_cli(self, tmp_path, format):
14301441
ffmpeg_version = get_ffmpeg_major_version()

test/utils.py

Lines changed: 33 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -14,6 +14,7 @@
1414
import torch
1515

1616
from torchcodec._core import get_ffmpeg_library_versions
17+
from torchcodec.decoders import set_cuda_backend, VideoDecoder
1718
from torchcodec.decoders._video_decoder import _read_custom_frame_mappings
1819

1920
IS_WINDOWS = sys.platform in ("win32", "cygwin")
@@ -26,27 +27,55 @@ def needs_cuda(test_item):
2627
return pytest.mark.needs_cuda(test_item)
2728

2829

30+
# This is a special device string that we use to test the "beta" CUDA backend.
31+
# It only exists here, in this test utils file. Public and core APIs have no
32+
# idea that this is how we're tesing them. That is, that's not a supported
33+
# `device` parameter for the VideoDecoder or for the _core APIs.
34+
# Tests using all_supported_devices() will get this device string, and the test
35+
# need to clean it up by calling either make_video_decoder for VideoDecoder, or
36+
# unsplit_device_str for core APIs.
37+
_CUDA_BETA_DEVICE_STR = "cuda:beta"
38+
39+
2940
def all_supported_devices():
3041
return (
3142
"cpu",
3243
pytest.param("cuda", marks=pytest.mark.needs_cuda),
33-
pytest.param("cuda:0:beta", marks=pytest.mark.needs_cuda),
44+
pytest.param(_CUDA_BETA_DEVICE_STR, marks=pytest.mark.needs_cuda),
3445
)
3546

3647

3748
def unsplit_device_str(device_str: str) -> str:
3849
# helper meant to be used as
3950
# device, device_variant = unsplit_device_str(device)
40-
# when `device` comes from all_supported_devices() and may be "cuda:0:beta".
51+
# when `device` comes from all_supported_devices() and may be _CUDA_BETA_DEVICE_STR.
4152
# It is used:
42-
# - before calling `.to(device)` where device can't be "cuda:0:beta"
53+
# - before calling `.to(device)` where device can't be _CUDA_BETA_DEVICE_STR.
4354
# - before calling add_video_stream(device=device, device_variant=device_variant)
44-
if device_str == "cuda:0:beta":
55+
if device_str == _CUDA_BETA_DEVICE_STR:
4556
return "cuda", "beta"
4657
else:
4758
return device_str, "ffmpeg"
4859

4960

61+
def make_video_decoder(*args, **kwargs) -> tuple[VideoDecoder, str]:
62+
# Helper to create a VideoDecoder with the right cuda backend if needed.
63+
# kwargs is expected to have a "device" key which comes from
64+
# all_supported_devices(), and can be _CUDA_BETA_DEVICE_STR.
65+
device = kwargs.pop("device", "cpu")
66+
if device == _CUDA_BETA_DEVICE_STR:
67+
clean_device, backend = "cuda", "beta"
68+
else:
69+
clean_device, backend = device, "ffmpeg"
70+
71+
# set_cuda_backend is a no-op if the device is "cpu", so we can use it
72+
# unconditionally.
73+
with set_cuda_backend(backend):
74+
dec = VideoDecoder(*args, **kwargs, device=clean_device)
75+
76+
return dec, clean_device
77+
78+
5079
def get_ffmpeg_major_version():
5180
ffmpeg_version = get_ffmpeg_library_versions()["ffmpeg_version"]
5281
# When building FFmpeg from source there can be a `n` prefix in the version

version.txt

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -1 +1 @@
1-
0.7.0a0
1+
0.9.0a0

0 commit comments

Comments
 (0)