Skip to content
This repository was archived by the owner on Dec 14, 2023. It is now read-only.

Commit daddaf1

Browse files
Merge pull request #49 from JCBrouwer/bugfix/robust-video-folder
Make VideoFolder dataset more robust
2 parents 07eb5bb + 644b37a commit daddaf1

File tree

1 file changed

+5
-2
lines changed

1 file changed

+5
-2
lines changed

utils/dataset.py

Lines changed: 5 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -502,12 +502,15 @@ def get_frame_buckets(self, vr):
502502

503503
def get_frame_batch(self, vr, resize=None):
504504
native_fps = vr.get_avg_fps()
505-
every_nth_frame = round(native_fps / self.fps)
505+
every_nth_frame = max(1, round(native_fps / self.fps))
506506

507507
effective_length = len(vr) // every_nth_frame
508508

509509
if effective_length < self.n_sample_frames:
510-
return self.__getitem__(random.randint(1, len(self.video_files) - 1))
510+
raise ValueError(
511+
f"Video is too short to sample {self.n_sample_frames} frames at {self.fps} fps. "
512+
f"Native video framerate is {native_fps} with length {len(vr)} frames."
513+
)
511514

512515
effective_idx = random.randint(1, effective_length - self.n_sample_frames)
513516

0 commit comments

Comments
 (0)