Skip to content

Commit 262015b

Browse files
committed
fixed bug in video frame extraction goes into an inf. loop
1 parent 2bc240c commit 262015b

File tree

1 file changed

+3
-1
lines changed

1 file changed

+3
-1
lines changed

mmif/utils/video_document_helper.py

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -83,14 +83,16 @@ def extract_frames_as_images(video_document: Document, framenums: List[int], as_
8383
frames = []
8484
video = capture(video_document)
8585
cur_f = 0
86+
tot_fcount = video_document.get_property(FRAMECOUNT_DOCPROP_KEY)
8687
while True:
87-
if not framenums or cur_f > video_document.get_property(FRAMECOUNT_DOCPROP_KEY):
88+
if not framenums or cur_f > tot_fcount:
8889
break
8990
ret, frame = video.read()
9091
if cur_f == framenums[0]:
9192
if not ret:
9293
sec = convert(cur_f, 'f', 's', video_document.get_property(FPS_DOCPROP_KEY))
9394
warnings.warn(f'Frame #{cur_f} ({sec}s) could not be read from the video {video_document.id}.')
95+
cur_f += 1
9496
continue
9597
frames.append(Image.fromarray(frame[:, :, ::-1]) if as_PIL else frame)
9698
framenums.pop(0)

0 commit comments

Comments
 (0)