diff --git a/video2x/upscaler.py b/video2x/upscaler.py index bd10208..e1ef777 100755 --- a/video2x/upscaler.py +++ b/video2x/upscaler.py @@ -74,7 +74,7 @@ class Upscaler(multiprocessing.Process): time.sleep(0.1) continue - difference_ratio = -1 + difference_ratio = 0 if image0 is not None: difference = ImageChops.difference(image0, image1) difference_stat = ImageStat.Stat(difference) @@ -85,9 +85,22 @@ class Upscaler(multiprocessing.Process): ) # if the difference is lower than threshold - # process the interpolation + # skip this frame if difference_ratio < difference_threshold: + # make sure the previous frame has been processed + if frame_index > 0: + while self.processed_frames[frame_index - 1] is None: + time.sleep(0.1) + + # make the current image the same as the previous result + self.processed_frames[frame_index] = self.processed_frames[ + frame_index - 1 + ] + + # if the difference is greater than threshold + # process this frame + else: width, height = image1.size # calculate required minimum scale ratio @@ -149,20 +162,6 @@ class Upscaler(multiprocessing.Process): image1 = image1.resize((output_width, output_height), Image.LANCZOS) self.processed_frames[frame_index] = image1 - # if the difference is greater than threshold - # there's a change in camera angle, ignore - else: - - # make sure the previous frame has been processed - if frame_index > 0: - while self.processed_frames[frame_index - 1] is None: - time.sleep(0.1) - - # make the current image the same as the previous result - self.processed_frames[frame_index] = self.processed_frames[ - frame_index - 1 - ] - # send exceptions into the client connection pipe except (SystemExit, KeyboardInterrupt): break diff --git a/video2x/video2x.py b/video2x/video2x.py index f52cbf8..e8fa6da 100755 --- a/video2x/video2x.py +++ b/video2x/video2x.py @@ -378,7 +378,7 @@ def parse_arguments() -> argparse.Namespace: "-t", "--threshold", type=float, - help="if the % difference between two adjacent frames exceeds this value, two images are deemed the same; 0 is off", + help="skip if the % difference between two adjacent frames is below this value; set to 0 to process all frames", default=0, ) @@ -400,7 +400,7 @@ def parse_arguments() -> argparse.Namespace: "-t", "--threshold", type=float, - help="if the % difference between two adjacent frames exceeds this value, no interpolation will be performed; 0 is off", + help="skip if the % difference between two adjacent frames exceeds this value; set to 100 to interpolate all frames", default=10, )