Skip to content

Commit 6df7fc8

Browse files
Dan-Floresaboood40091NicolasHug
authored
[release 0.9.1] Update version and cherrypick windows fix (#1116)
Co-authored-by: AboodXD <[email protected]> Co-authored-by: Nicolas Hug <[email protected]>
1 parent 2b603c2 commit 6df7fc8

File tree

2 files changed

+23
-4
lines changed

2 files changed

+23
-4
lines changed

src/torchcodec/_core/ops.py

Lines changed: 22 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -6,7 +6,12 @@
66

77
import io
88
import json
9+
import os
10+
import shutil
11+
import sys
912
import warnings
13+
from contextlib import nullcontext
14+
from pathlib import Path
1015
from types import ModuleType
1116
from typing import List, Optional, Tuple, Union
1217

@@ -22,7 +27,7 @@
2227
_pybind_ops: Optional[ModuleType] = None
2328

2429

25-
def load_torchcodec_shared_libraries():
30+
def load_torchcodec_shared_libraries() -> tuple[int, str]:
2631
# Successively try to load the shared libraries for each version of FFmpeg
2732
# that we support. We always start with the highest version, working our way
2833
# down to the lowest version. Once we can load ALL shared libraries for a
@@ -70,7 +75,8 @@ def load_torchcodec_shared_libraries():
7075
raise RuntimeError(
7176
f"""Could not load libtorchcodec. Likely causes:
7277
1. FFmpeg is not properly installed in your environment. We support
73-
versions 4, 5, 6, 7, and 8.
78+
versions 4, 5, 6, 7, and 8. On Windows, ensure you've installed
79+
the "full-shared" version which ships DLLs.
7480
2. The PyTorch version ({torch.__version__}) is not compatible with
7581
this version of TorchCodec. Refer to the version compatibility
7682
table:
@@ -82,7 +88,20 @@ def load_torchcodec_shared_libraries():
8288
)
8389

8490

85-
ffmpeg_major_version, core_library_path = load_torchcodec_shared_libraries()
91+
expose_ffmpeg_dlls = nullcontext
92+
if sys.platform == "win32" and hasattr(os, "add_dll_directory"):
93+
# On windows we try to locate the FFmpeg DLLs and temporarily add them to
94+
# the DLL search path. This seems to be needed on some users machine, but
95+
# not on our CI. We don't know why.
96+
if ffmpeg_path := shutil.which("ffmpeg"):
97+
98+
def expose_ffmpeg_dlls(): # noqa: F811
99+
ffmpeg_dir = Path(ffmpeg_path).parent
100+
return os.add_dll_directory(str(ffmpeg_dir)) # that's the actual CM
101+
102+
103+
with expose_ffmpeg_dlls():
104+
ffmpeg_major_version, core_library_path = load_torchcodec_shared_libraries()
86105

87106

88107
# Note: We use disallow_in_graph because PyTorch does constant propagation of

version.txt

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

0 commit comments

Comments
 (0)