Skip to content

Commit 2fbd8f8

Browse files
angelayialhridoy
authored andcommitted
[bugfix] Lazy import cv2 (vllm-project#26869)
Signed-off-by: angelayi <[email protected]>
1 parent 74bc4b2 commit 2fbd8f8

File tree

1 file changed

+4
-1
lines changed

1 file changed

+4
-1
lines changed

vllm/assets/video.py

Lines changed: 4 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -5,7 +5,6 @@
55
from functools import lru_cache
66
from typing import Any, ClassVar, Literal
77

8-
import cv2
98
import numpy as np
109
import numpy.typing as npt
1110
from huggingface_hub import hf_hub_download
@@ -43,6 +42,8 @@ def download_video_asset(filename: str) -> str:
4342

4443

4544
def video_to_ndarrays(path: str, num_frames: int = -1) -> npt.NDArray:
45+
import cv2
46+
4647
cap = cv2.VideoCapture(path)
4748
if not cap.isOpened():
4849
raise ValueError(f"Could not open video file {path}")
@@ -78,6 +79,8 @@ def video_to_pil_images_list(path: str, num_frames: int = -1) -> list[Image.Imag
7879

7980

8081
def video_get_metadata(path: str, num_frames: int = -1) -> dict[str, Any]:
82+
import cv2
83+
8184
cap = cv2.VideoCapture(path)
8285
if not cap.isOpened():
8386
raise ValueError(f"Could not open video file {path}")

0 commit comments

Comments
 (0)