I am trying to do some video editing and this for loop takes a folder filled with .jpg files, rearranges the pixels on the first 60 frames, and puts the scrambled frames back into the original frame folder. When I run this loop the 60 frames are scrambled appropriately and put back into the original folder but the loop never stops. I have tried a bunch of different solutions but nothing is working.
Here is the code:
root = (os.getcwd()+'/Video_images/'+ vid_path[8:21])
frames = os.listdir(root)
frames_ordered = natsorted(frames) #Folder that contains all of the frames as .jpg
for frame_index in frames_ordered:
current_frame_path = os.path.join(root, frame_index)
current_frame = Image.open(current_frame_path)
#Changing current frame into an array
channel_count = len(current_frame.getbands())
current_frame_array = np.reshape(current_frame, (current_frame.height, current_frame.width, channel_count))
current_frame.close()
#Adjusting current frame
##Shuffling the current frame by pixel rows
channels = [current_frame_array[:,:,x] for x in range(channel_count)]
row_perm_index = np.random.permutation(current_frame.height)
shuffled_rows = np.dstack([x[row_perm_index, :] for x in channels]).astype(np.uint8)
##Shuffling the columns of the current frame suffled rows
shuffled_row_channel = [shuffled_rows[:,:,x] for x in range(channel_count)]
col_perm = np.random.permutation(current_frame.width)
shuffled_cols = np.dstack([x[:, col_perm] for x in shuffled_row_channel]).astype(np.uint8)
shuffled_current_frame = Image.fromarray(shuffled_cols)
shuffled_current_frame.save(current_frame_path[:-4]+'_scrambled.jpg')
shuffled_current_frame.close()
if(frame_index == frames_ordered[59]):
break