@@ -33,9 +33,9 @@ def is_codec_config_supported(width: int,
3333 """Check if a specific width/height/pixel format combination is supported by codec."""
3434 try :
3535 cc = av .codec .CodecContext .create (codec_name , "w" )
36- cc .width = width
37- cc .height = height
38- cc .pix_fmt = pix_fmt
36+ cc .width = width # type: ignore[attr-defined]
37+ cc .height = height # type: ignore[attr-defined]
38+ cc .pix_fmt = pix_fmt # type: ignore[attr-defined]
3939 cc .time_base = Fraction (1 , 30 )
4040 cc .open (strict = True )
4141 # Note: CodecContext doesn't have a close() method in newer PyAV versions
@@ -92,7 +92,7 @@ def is_raw_data_codec(codec_name: str) -> bool:
9292 return codec_name .startswith ("rawvideo" )
9393
9494 # Image codec configurations (use actual codec for container)
95- IMAGE_CODEC_CONFIGS = {
95+ IMAGE_CODEC_CONFIGS : Dict [ str , Dict [ str , Any ]] = {
9696 "libx264" : {
9797 "container_codec" : "libx264" , # Use actual codec for container
9898 "pixel_format" : "yuv420p" ,
@@ -126,7 +126,7 @@ def is_raw_data_codec(codec_name: str) -> bool:
126126 }
127127
128128 # Raw data codec configurations (always use rawvideo container)
129- RAW_DATA_CODEC_CONFIGS = {
129+ RAW_DATA_CODEC_CONFIGS : Dict [ str , Dict [ str , Any ]] = {
130130 "rawvideo" : {
131131 "container_codec" : "rawvideo" , # Always rawvideo for container
132132 "internal_codec" : "pickle_raw" , # Default internal implementation
@@ -279,15 +279,16 @@ def get_codec_for_feature(self,
279279 is_rgb_image = (data_shape is not None and len (data_shape ) == 3
280280 and data_shape [2 ] == 3 )
281281
282- if is_rgb_image :
282+ if is_rgb_image and data_shape is not None :
283283 # This is RGB image data - can use video codecs
284284 height , width = data_shape [0 ], data_shape [1 ]
285285
286286 # Check if a specific video codec was provided
287287 if self .video_codec and self .video_codec != "auto" :
288- if self .is_image_codec (
289- self .video_codec ) and self .is_valid_image_shape (
290- data_shape , self .video_codec ):
288+ if (self .is_image_codec (self .video_codec )
289+ and data_shape is not None
290+ and self .is_valid_image_shape (data_shape ,
291+ self .video_codec )):
291292 logger .debug (
292293 f"Using specified video codec { self .video_codec } for RGB shape { data_shape } "
293294 )
@@ -299,7 +300,8 @@ def get_codec_for_feature(self,
299300
300301 # Check if user specified a general codec other than auto
301302 if self .codec != "auto" and self .is_image_codec (self .codec ):
302- if self .is_valid_image_shape (data_shape , self .codec ):
303+ if data_shape is not None and self .is_valid_image_shape (
304+ data_shape , self .codec ):
303305 logger .debug (
304306 f"Using user-specified image codec { self .codec } for RGB shape { data_shape } "
305307 )
@@ -318,7 +320,8 @@ def get_codec_for_feature(self,
318320 ]
319321
320322 for codec in codec_preferences :
321- if self .is_valid_image_shape (data_shape , codec ):
323+ if data_shape is not None and self .is_valid_image_shape (
324+ data_shape , codec ):
322325 logger .debug (
323326 f"Selected image codec { codec } for RGB shape { data_shape } "
324327 )
@@ -377,16 +380,19 @@ def _can_codec_handle_feature(self, codec: str,
377380 def get_container_codec (self , codec : str ) -> str :
378381 """Get the container codec name for a given codec."""
379382 if codec in self .IMAGE_CODEC_CONFIGS :
380- return self .IMAGE_CODEC_CONFIGS [codec ]["container_codec" ]
383+ return cast (str ,
384+ self .IMAGE_CODEC_CONFIGS [codec ]["container_codec" ])
381385 elif codec in self .RAW_DATA_CODEC_CONFIGS :
382- return self .RAW_DATA_CODEC_CONFIGS [codec ]["container_codec" ]
386+ return cast (str ,
387+ self .RAW_DATA_CODEC_CONFIGS [codec ]["container_codec" ])
383388 else :
384389 raise ValueError (f"Unknown codec { codec } " )
385390
386391 def get_internal_codec (self , codec : str ) -> Optional [str ]:
387392 """Get the internal codec implementation name for raw data codecs."""
388393 if codec in self .RAW_DATA_CODEC_CONFIGS :
389- return self .RAW_DATA_CODEC_CONFIGS [codec ]["internal_codec" ]
394+ return cast (str ,
395+ self .RAW_DATA_CODEC_CONFIGS [codec ]["internal_codec" ])
390396 elif codec in self .IMAGE_CODEC_CONFIGS :
391397 # Image codecs don't have internal codecs
392398 return None
@@ -402,15 +408,18 @@ def get_raw_codec_name(self, codec: str) -> str:
402408 # Fallback for backward compatibility
403409 legacy_configs = self .CODEC_CONFIGS
404410 if codec in legacy_configs :
405- return legacy_configs [codec ].get ("raw_codec" , "pickle_raw" )
411+ return cast (str , legacy_configs [codec ].get ("raw_codec" ,
412+ "pickle_raw" ))
406413
407414 return "pickle_raw"
408415
409416 def get_pixel_format (self , codec : str ,
410417 feature_type : FeatureType ) -> Optional [str ]:
411418 """Get appropriate pixel format for codec and feature type."""
412419 if codec in self .IMAGE_CODEC_CONFIGS :
413- base_format = self .IMAGE_CODEC_CONFIGS [codec ].get ("pixel_format" )
420+ base_format = cast (
421+ Optional [str ],
422+ self .IMAGE_CODEC_CONFIGS [codec ].get ("pixel_format" ))
414423
415424 # For FFV1, use RGB24 to avoid YUV conversion issues
416425 if codec == "ffv1" :
@@ -434,14 +443,15 @@ def get_codec_options(self, codec: str) -> Dict[str, Any]:
434443
435444 if codec in self .IMAGE_CODEC_CONFIGS :
436445 # Video/image codec - only use video-specific options
437- default_options = self .IMAGE_CODEC_CONFIGS [codec ].get (
438- "options" , {} ).copy ()
446+ options_dict = self .IMAGE_CODEC_CONFIGS [codec ].get ("options" , {})
447+ default_options = cast ( Dict [ str , Any ], options_dict ).copy ()
439448 # Only merge video-specific custom options
440449 default_options .update (self .video_custom_options )
441450 elif codec in self .RAW_DATA_CODEC_CONFIGS :
442451 # Raw data codec - only use raw-specific options
443- default_options = (self .RAW_DATA_CODEC_CONFIGS [codec ].get (
444- "options" , {}).copy ())
452+ options_dict = self .RAW_DATA_CODEC_CONFIGS [codec ].get (
453+ "options" , {})
454+ default_options = cast (Dict [str , Any ], options_dict ).copy ()
445455 # Only merge raw-specific custom options
446456 default_options .update (self .raw_custom_options )
447457
@@ -451,7 +461,7 @@ def get_codec_options(self, codec: str) -> Dict[str, Any]:
451461 def for_transcoding_to_internal_codec (
452462 cls ,
453463 internal_codec : str ,
454- codec_options : Optional [Dict [str , Any ]] = None ) -> "CodecConfig" :
464+ codec_options : Optional [Dict [str , Any ]] = None ) -> Any :
455465 """Create a CodecConfig specifically for transcoding to a particular internal codec.
456466
457467 This is used during transcoding operations where we need to convert between
0 commit comments