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

Signed-off-by: Isotr0py <Isotr0py@outlook.com>

Isotr0py committed Jul 8, 2026 at 10:52 UTC 5e975eae1ac9fff65ef8067bc50769874911a137
2 files changed +21 -2
vllm/multimodal/video.py
+3 -2
@@ -15,7 +15,7 @@ import torch
15
16 from vllm import envs
17 from vllm.logger import init_logger
18 -from vllm.utils.import_utils import PlaceholderModule
18 +from vllm.utils.import_utils import PlaceholderModule, check_torchcodec_available
19 from vllm.utils.mem_constants import MiB_bytes
20 from vllm.utils.registry import ExtensionManager
21
@@ -33,7 +33,7 @@ except ImportError:
33
34 try:
35 from torchcodec.decoders import VideoDecoder
36 -except ImportError:
36 +except (ImportError, RuntimeError):
37 VideoDecoder = PlaceholderModule("torchcodec").placeholder_attr( # type: ignore[assignment]
38 "decoders.VideoDecoder"
39 )
@@ -956,6 +956,7 @@ class VideoBackend(
956 assert not frame_recovery, (
957 "frame_recovery is only available for `opencv` backend"
958 )
959 + check_torchcodec_available()
960 decoder = cls.make_torchcodec_decoder(
961 data,
962 num_ffmpeg_threads=num_ffmpeg_threads,
vllm/utils/import_utils.py
+18
@@ -552,3 +552,21 @@ def has_cutedsl() -> bool:
552 def has_humming() -> bool:
553 """Whether the optional `humming` package is available."""
554 return _has_module("humming")
555 +
556 +
557 +def check_torchcodec_available():
558 + """Whether the optional `torchcodec` package is available."""
559 + try:
560 + import torchcodec # noqa: F401
561 + except RuntimeError as e:
562 + # torchcodec will raise RuntimeError during import instead
563 + # of ImportError when system ffmpeg unavailable, with a
564 + # message that can leak sensitive system information.
565 + # Trim it down to avoid it.
566 + marker = (
567 + "The following exceptions were raised as we tried to load libtorchcodec:"
568 + )
569 + message = str(e)
570 + if marker in message:
571 + raise RuntimeError(message.split(marker, 1)[0].rstrip()) from None
572 + raise e