diff --git a/gnes/preprocessor/video/ffmpeg.py b/gnes/preprocessor/video/ffmpeg.py index 80a1ab5a..48f5d958 100644 --- a/gnes/preprocessor/video/ffmpeg.py +++ b/gnes/preprocessor/video/ffmpeg.py @@ -89,18 +89,27 @@ def pic_weight(images: List['np.ndarray']) -> List[float]: def duplicate_rm_hash(self, images: List['np.ndarray']) -> List['np.ndarray']: - hash_list = [phash_descriptor(_) for _ in images] + hash_list = [] + for _ in images: + try: + hash_list.append(phash_descriptor(_)) + except Exception: + hash_list.append(False) + self.logger.info('Broken image: ignored !') ret = [] for i, h in enumerate(hash_list): flag = 1 if len(ret) >= 1: # only keep images with high phash diff # comparing only last kept 9 pics - for j in range(1, min(len(ret) + 1, 9)): - dist = abs(ret[-j][1] - h) - if dist < self.phash_thresh: - flag = 0 - break + if h: + for j in range(1, min(len(ret) + 1, 9)): + dist = abs(ret[-j][1] - h) + if dist < self.phash_thresh: + flag = 0 + break + else: + flag = 0 if flag: ret.append((i, h))