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

Signed-off-by: Isotr0py <2037008807@qq.com>
This commit is contained in:
Isotr0py
2025-05-07 15:36:06 +00:00
committed by GitHub
parent 1a6af1453d
commit be8ff88e66
2 changed files with 21 additions and 2 deletions
+4 -2
View File
@@ -81,7 +81,8 @@ class OpenCVVideoBackend(VideoLoader):
total_frames_num = int(cap.get(cv2.CAP_PROP_FRAME_COUNT))
full_read = num_frames == -1 or total_frames_num < num_frames
if full_read:
frame_idx = list(range(0, total_frames_num))
num_frames = total_frames_num
frame_idx = list(range(0, num_frames))
else:
uniform_sampled_frames = np.linspace(0,
total_frames_num - 1,
@@ -104,7 +105,8 @@ class OpenCVVideoBackend(VideoLoader):
frames[i] = cv2.cvtColor(frame, cv2.COLOR_BGR2RGB)
i += 1
# we expect all frames loaded
assert i == num_frames
assert i == num_frames, (f"Expected reading {num_frames} frames, "
f"but only loaded {i} frames from video.")
return frames