@@ -44,6 +44,7 @@ def _generate_timecode_list(
4444 `frame_margin` accepts an int (frames), float (seconds), or str (e.g. ``"0.1s"``).
4545 """
4646 framerate = scene_list [0 ][0 ].framerate
47+ assert framerate is not None
4748 margin_secs = FrameTimecode (timecode = frame_margin , fps = framerate ).seconds
4849 result = []
4950 for start , end in scene_list :
@@ -71,7 +72,7 @@ def _generate_timecode_list(
7172
7273def _scale_image (
7374 image : np .ndarray ,
74- aspect_ratio : float ,
75+ aspect_ratio : float | None ,
7576 height : int | None ,
7677 width : int | None ,
7778 scale : float | None ,
@@ -90,9 +91,11 @@ def _scale_image(
9091 if height and not width :
9192 factor = height / float (image_height )
9293 width = int (factor * image_width )
93- if width and not height :
94+ elif width and not height :
9495 factor = width / float (image_width )
9596 height = int (factor * image_height )
97+ assert height is not None
98+ assert width is not None
9699 assert height > 0 and width > 0
97100 image = cv2 .resize (image , (width , height ), interpolation = interpolation .value )
98101 elif scale :
@@ -106,7 +109,7 @@ def __init__(
106109 num_images : int = 3 ,
107110 frame_margin : int | float | str = 1 ,
108111 image_extension : str = "jpg" ,
109- imwrite_param : dict [ str , int | None ] | None = None ,
112+ imwrite_param : list [ int ] | None = None ,
110113 image_name_template : str = "$VIDEO_NAME-Scene-$SCENE_NUMBER-$IMAGE_NUMBER" ,
111114 scale : float | None = None ,
112115 height : int | None = None ,
@@ -153,7 +156,7 @@ def __init__(
153156 self ._height = height
154157 self ._width = width
155158 self ._interpolation = interpolation
156- self ._imwrite_param = imwrite_param if imwrite_param else {}
159+ self ._imwrite_param : list [ int ] = imwrite_param if imwrite_param is not None else []
157160
158161 def run (
159162 self ,
@@ -337,7 +340,7 @@ def generate_timecode_list(self, scene_list: SceneList) -> list[list[FrameTimeco
337340 def resize_image (
338341 self ,
339342 image : np .ndarray ,
340- aspect_ratio : float ,
343+ aspect_ratio : float | None ,
341344 ) -> np .ndarray :
342345 return _scale_image (
343346 image , aspect_ratio , self ._height , self ._width , self ._scale , self ._interpolation
@@ -436,7 +439,7 @@ def save_images(
436439 width ,
437440 interpolation ,
438441 )
439- return extractor .run (video , scene_list , output_dir , show_progress )
442+ return extractor .run (video , scene_list , output_dir , bool ( show_progress ) )
440443
441444 # Setup flags and init progress bar if available.
442445 completed = True
@@ -467,7 +470,7 @@ def save_images(
467470 for j , image_timecode in enumerate (scene_timecodes ):
468471 video .seek (image_timecode )
469472 frame_im = video .read ()
470- if frame_im is not None and frame_im is not False :
473+ if isinstance ( frame_im , np . ndarray ) :
471474 # TODO: Add extension to template.
472475 # TODO: Allow NUM to be a valid suffix in addition to NUMBER.
473476 file_path = "{}.{}" .format (
@@ -495,9 +498,11 @@ def save_images(
495498 if height and not width :
496499 factor = height / float (frame_height )
497500 width = int (factor * frame_width )
498- if width and not height :
501+ elif width and not height :
499502 factor = width / float (frame_width )
500503 height = int (factor * frame_height )
504+ assert height is not None
505+ assert width is not None
501506 assert height > 0 and width > 0
502507 frame_im = cv2 .resize (
503508 frame_im , (width , height ), interpolation = interpolation .value
0 commit comments