soft-matter/pims

Partial video frame reading becomes progressively slower

KangByungwoo opened this issue · 0 comments

Hi,

If I run the below code:

v = pims.Video(avi_filename) # v.shape = (n_frames, H, W, 3)

pre_frames = 100
post_frames = 200

v2 = np.zeros((len(frame_idxs), pre_frames + post_frames, H, W))

for iter, frame_idx in enumerate(frame_idxs):
start_time = time.time()

start_frame = frame_idx - pre_frames 
end_frame = frame_idx + post_frames 

if start_frame >= 0 and end_frame <= num_frames:
    v2[trial_idx] = np.array(v[start_frame:end_frame])[...,0] # [...,0] b/c video is greyscale so last dim is redundant.


print('iter: {} ({:.2f})'.format(iter, time.time() - start_time))

The time for each for-loop iteration becomes progressively longer even though the number of frames read is fixed. For e.g,

iter: 0 (0.92)
iter: 1 (1.37)
iter: 2 (1.48)
iter: 3 (1.60)
iter: 4 (1.82)
iter: 5 (1.95)
iter: 6 (2.27)
iter: 7 (2.47)
iter: 8 (2.55)
iter: 9 (2.74)
...

Why is this so? Is there a workaround for this? Thank you!