[Bugfix] Avoid blocking model launching when no system ffmpeg available for TorchCodec (#47888)

Signed-off-by: Isotr0py <Isotr0py@outlook.com>
This commit is contained in:
Isotr0py
2026-07-08 10:52:25 +08:00
committed by GitHub
parent f7fc0ca993
commit 5e975eae1a
2 changed files with 21 additions and 2 deletions
+18
View File
@@ -552,3 +552,21 @@ def has_cutedsl() -> bool:
def has_humming() -> bool:
"""Whether the optional `humming` package is available."""
return _has_module("humming")
def check_torchcodec_available():
"""Whether the optional `torchcodec` package is available."""
try:
import torchcodec # noqa: F401
except RuntimeError as e:
# torchcodec will raise RuntimeError during import instead
# of ImportError when system ffmpeg unavailable, with a
# message that can leak sensitive system information.
# Trim it down to avoid it.
marker = (
"The following exceptions were raised as we tried to load libtorchcodec:"
)
message = str(e)
if marker in message:
raise RuntimeError(message.split(marker, 1)[0].rstrip()) from None
raise e