@tduncan / Nvidia-Optimization-Stack-VLLM Mirror · read-only / commits / be8ff88e66
Fork 0

A high-throughput and memory-efficient inference and serving engine for LLMs

Mirrored from https://github.com/tduncan-lum/Nvidia-Optimization-Stack---VLLM.git

Synced Nov 15, 11:00 UTC

[Bugfix] Fix Video IO error for short video (#17791)

Signed-off-by: Isotr0py <2037008807@qq.com>

Isotr0py committed May 7, 2025 at 23:36 UTC be8ff88e661d72b67f8410354b6a33ad78d2c81c
2 files changed +21 -2
tests/multimodal/test_utils.py
+17
@@ -26,6 +26,11 @@ TEST_IMAGE_URLS = [
26 "https://upload.wikimedia.org/wikipedia/commons/0/0b/RGBA_comp.png",
27 ]
28
29 +TEST_VIDEO_URLS = [
30 + "https://www.bogotobogo.com/python/OpenCV_Python/images/mean_shift_tracking/slow_traffic_small.mp4",
31 + "https://filesamples.com/samples/video/avi/sample_640x360.avi",
32 +]
33 +
34
35 @pytest.fixture(scope="module")
36 def url_images() -> dict[str, Image.Image]:
@@ -134,6 +139,18 @@ async def test_fetch_image_local_files(image_url: str):
139 f"file://{temp_dir}/../{os.path.basename(image_url)}")
140
141
142 +@pytest.mark.asyncio
143 +@pytest.mark.parametrize("video_url", TEST_VIDEO_URLS)
144 +@pytest.mark.parametrize("num_frames", [-1, 32, 1800])
145 +async def test_fetch_video_http(video_url: str, num_frames: int):
146 + connector = MediaConnector()
147 +
148 + video_sync = connector.fetch_video(video_url, num_frames=num_frames)
149 + video_async = await connector.fetch_video_async(video_url,
150 + num_frames=num_frames)
151 + assert np.array_equal(video_sync, video_async)
152 +
153 +
154 # Used for the next two tests related to `merge_and_sort_multimodal_metadata`.
155 class TestCase(NamedTuple):
156 mm_positions: "MultiModalPlaceholderDict"
vllm/multimodal/video.py
+4 -2
@@ -81,7 +81,8 @@ class OpenCVVideoBackend(VideoLoader):
81 total_frames_num = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
82 full_read = num_frames == -1 or total_frames_num < num_frames
83 if full_read:
84 - frame_idx = list(range(0, total_frames_num))
84 + num_frames = total_frames_num
85 + frame_idx = list(range(0, num_frames))
86 else:
87 uniform_sampled_frames = np.linspace(0,
88 total_frames_num - 1,
@@ -104,7 +105,8 @@ class OpenCVVideoBackend(VideoLoader):
105 frames[i] = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
106 i += 1
107 # we expect all frames loaded
107 - assert i == num_frames
108 + assert i == num_frames, (f"Expected reading {num_frames} frames, "
109 + f"but only loaded {i} frames from video.")
110 return frames
111
112