def find_duplicates(res=32):
# load in the video file
filename = 'video.mp4'
vid = imageio.get_reader(filename, 'ffmpeg')
all_frames = vid.get_length()
# we'll store the info on repeated frames here
seen_frames = {}
duplicate_frames = {}
for x in range(all_frames):
# get frame x
frame = vid.get_data(x)
if x % 1000 == 0:
print("frame count: ",x,"\t",round(x*1.0/all_frames,3)*100,'%')
# hash our frame
hashed = ahash(frame, res)
if seen_frames.get( hashed, None):
# if we've seen this frame before, add it to the list of frames
# that all have the same hashed value in duplicate_frames
duplicate_frames[hashed].append(x)
else:
# if it's the first time seeing a frame, put it in seen_frames
seen_frames[hashed] = x
duplicate_frames[hashed] = [x]
# return a list of lists of duplicate frames
return [duplicate_frames[x] for x in duplicate_frames if len(duplicate_frames[x]) > 1]
评论列表
文章目录