diff --git a/video2x/decoder.py b/video2x/decoder.py index 1941548..ef8d7ce 100755 --- a/video2x/decoder.py +++ b/video2x/decoder.py @@ -104,16 +104,13 @@ class VideoDecoder(threading.Thread): "RGB", (self.input_width, self.input_height), buffer ) - # if this is the first frame - # there wouldn't be a "previous image" - if previous_image is not None: - self.processing_queue.put( - ( - frame_index, - (previous_image, image), - self.processing_settings, - ) + self.processing_queue.put( + ( + frame_index, + (previous_image, image), + self.processing_settings, ) + ) previous_image = image frame_index += 1 diff --git a/video2x/interpolator.py b/video2x/interpolator.py index 41232b3..035a8fb 100755 --- a/video2x/interpolator.py +++ b/video2x/interpolator.py @@ -56,6 +56,11 @@ class Interpolator(multiprocessing.Process): time.sleep(0.1) continue + # if image0 is None, image1 is the first frame + # skip this round + if image0 is None: + continue + difference = ImageChops.difference(image0, image1) difference_stat = ImageStat.Stat(difference) difference_ratio = ( diff --git a/video2x/upscaler.py b/video2x/upscaler.py index ab78646..bd10208 100755 --- a/video2x/upscaler.py +++ b/video2x/upscaler.py @@ -74,11 +74,15 @@ class Upscaler(multiprocessing.Process): time.sleep(0.1) continue - difference = ImageChops.difference(image0, image1) - difference_stat = ImageStat.Stat(difference) - difference_ratio = ( - sum(difference_stat.mean) / (len(difference_stat.mean) * 255) * 100 - ) + difference_ratio = -1 + if image0 is not None: + difference = ImageChops.difference(image0, image1) + difference_stat = ImageStat.Stat(difference) + difference_ratio = ( + sum(difference_stat.mean) + / (len(difference_stat.mean) * 255) + * 100 + ) # if the difference is lower than threshold # process the interpolation @@ -150,8 +154,9 @@ class Upscaler(multiprocessing.Process): else: # make sure the previous frame has been processed - while self.processed_frames[frame_index - 1] is None: - time.sleep(0.1) + 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[ diff --git a/video2x/video2x.py b/video2x/video2x.py index af2bfa1..f52cbf8 100755 --- a/video2x/video2x.py +++ b/video2x/video2x.py @@ -378,8 +378,8 @@ 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", - default=0.1, + help="if the % difference between two adjacent frames exceeds this value, two images are deemed the same; 0 is off", + default=0, ) # interpolator arguments @@ -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", + help="if the % difference between two adjacent frames exceeds this value, no interpolation will be performed; 0 is off", default=10, )