This repository was archived by the owner on Dec 14, 2023. It is now read-only.
File tree Expand file tree Collapse file tree 1 file changed +8
-10
lines changed Expand file tree Collapse file tree 1 file changed +8
-10
lines changed Original file line number Diff line number Diff line change @@ -505,20 +505,18 @@ def get_frame_buckets(self, vr):
505505 return resize
506506
507507 def get_frame_batch (self , vr , resize = None ):
508+ n_sample_frames = self .n_sample_frames
508509 native_fps = vr .get_avg_fps ()
510+
509511 every_nth_frame = max (1 , round (native_fps / self .fps ))
510-
512+ every_nth_frame = min (len (vr ), every_nth_frame )
513+
511514 effective_length = len (vr ) // every_nth_frame
515+ if effective_length < n_sample_frames :
516+ n_sample_frames = effective_length
512517
513- if effective_length < self .n_sample_frames :
514- raise ValueError (
515- f"Video is too short to sample { self .n_sample_frames } frames at { self .fps } fps. "
516- f"Native video framerate is { native_fps } with length { len (vr )} frames."
517- )
518-
519- effective_idx = random .randint (1 , effective_length - self .n_sample_frames )
520-
521- idxs = every_nth_frame * np .arange (effective_idx , effective_idx + self .n_sample_frames )
518+ effective_idx = random .randint (0 , (effective_length - n_sample_frames ))
519+ idxs = every_nth_frame * np .arange (effective_idx , effective_idx + n_sample_frames )
522520
523521 video = vr .get_batch (idxs )
524522 video = rearrange (video , "f h w c -> f c h w" )
You can’t perform that action at this time.
0 commit comments