diff --git a/src/torchcodec/_core/ops.py b/src/torchcodec/_core/ops.py index 0d14e9cda..a13f3a4f3 100644 --- a/src/torchcodec/_core/ops.py +++ b/src/torchcodec/_core/ops.py @@ -88,20 +88,19 @@ def load_torchcodec_shared_libraries() -> tuple[int, str]: ) +expose_ffmpeg_dlls = nullcontext if sys.platform == "win32" and hasattr(os, "add_dll_directory"): # On windows we try to locate the FFmpeg DLLs and temporarily add them to # the DLL search path. This seems to be needed on some users machine, but # not on our CI. We don't know why. if ffmpeg_path := shutil.which("ffmpeg"): - def cm(): # noqa: F811 + def expose_ffmpeg_dlls(): # noqa: F811 ffmpeg_dir = Path(ffmpeg_path).parent return os.add_dll_directory(str(ffmpeg_dir)) # that's the actual CM -else: - cm = nullcontext -with cm(): +with expose_ffmpeg_dlls(): ffmpeg_major_version, core_library_path = load_torchcodec_shared_libraries()