Skip to content

Commit d6cceee

Browse files
committed
fix issue 302, where method extract_frames_as_images destory input frame list
1 parent 2e17432 commit d6cceee

File tree

1 file changed

+4
-3
lines changed

1 file changed

+4
-3
lines changed

mmif/utils/video_document_helper.py

Lines changed: 4 additions & 3 deletions
Original file line numberDiff line numberDiff line change
@@ -84,18 +84,19 @@ def extract_frames_as_images(video_document: Document, framenums: List[int], as_
8484
video = capture(video_document)
8585
cur_f = 0
8686
tot_fcount = video_document.get_property(FRAMECOUNT_DOCPROP_KEY)
87+
framenums_copy = framenums.copy()
8788
while True:
88-
if not framenums or cur_f > tot_fcount:
89+
if not framenums_copy or cur_f > tot_fcount:
8990
break
9091
ret, frame = video.read()
91-
if cur_f == framenums[0]:
92+
if cur_f == framenums_copy[0]:
9293
if not ret:
9394
sec = convert(cur_f, 'f', 's', video_document.get_property(FPS_DOCPROP_KEY))
9495
warnings.warn(f'Frame #{cur_f} ({sec}s) could not be read from the video {video_document.id}.')
9596
cur_f += 1
9697
continue
9798
frames.append(Image.fromarray(frame[:, :, ::-1]) if as_PIL else frame)
98-
framenums.pop(0)
99+
framenums_copy.pop(0)
99100
cur_f += 1
100101
return frames
101102

0 commit comments

Comments
 (0)