ó
    pyüi™  ã                   óÊ  • S SK r S SKrS SKrS SKJr  S SKJr  S SKJr  S SK	r
S SKJrJr  S SKJr  SSKJr  SS	KJr  SS
KJr  SSKJrJrJrJr  SSKJrJr  SSKJrJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'J(r(J)r)  SSK*J+r+  SSK,J-r-  SSK.J/r/J0r0J1r1J2r2J3r3J4r4J5r5J6r6J7r7  \%" 5       (       a  S SK8r8\'" 5       (       a  S SK9J:s  J;s  J<r=  \" 5       (       a  SSKJ>r>  \(R~                  " \@5      rASrB\#" S\B5      \-" SS9 " S S\5      5       5       rC\$" \CRˆ                  5      \ClD        \CRˆ                  RŠ                  b5  \CRˆ                  RŠ                  R�                  SSSS9\CRˆ                  lE        gg)é    N)ÚCallable)Úpartial)ÚAny)Úcreate_repoÚis_offline_mode)Úvalidate_typed_dicté   )Úcustom_object_save)ÚTorchvisionBackend)ÚBatchFeature)ÚChannelDimensionÚSizeDictÚis_vision_availableÚvalidate_kwargs)ÚUnpackÚVideosKwargs)ÚIMAGE_PROCESSOR_NAMEÚPROCESSOR_NAMEÚVIDEO_PROCESSOR_NAMEÚ
TensorTypeÚadd_start_docstringsÚ	copy_funcÚis_torch_availableÚis_torchcodec_availableÚis_torchvision_v2_availableÚloggingÚsafe_load_json_file)Úcached_file)Úrequires)	Ú
VideoInputÚVideoMetadataÚgroup_videos_by_shapeÚinfer_channel_dimension_formatÚis_valid_videoÚ
load_videoÚmake_batched_metadataÚmake_batched_videosÚreorder_videos)ÚPILImageResamplingaÊ  
    Args:
        do_resize (`bool`, *optional*, defaults to `self.do_resize`):
            Whether to resize the video's (height, width) dimensions to the specified `size`. Can be overridden by the
            `do_resize` parameter in the `preprocess` method.
        size (`dict`, *optional*, defaults to `self.size`):
            Size of the output video after resizing. Can be overridden by the `size` parameter in the `preprocess`
            method.
        size_divisor (`int`, *optional*, defaults to `self.size_divisor`):
            The size by which to make sure both the height and width can be divided.
        default_to_square (`bool`, *optional*, defaults to `self.default_to_square`):
            Whether to default to a square video when resizing, if size is an int.
        resample (`PILImageResampling`, *optional*, defaults to `self.resample`):
            Resampling filter to use if resizing the video. Only has an effect if `do_resize` is set to `True`. Can be
            overridden by the `resample` parameter in the `preprocess` method.
        do_center_crop (`bool`, *optional*, defaults to `self.do_center_crop`):
            Whether to center crop the video to the specified `crop_size`. Can be overridden by `do_center_crop` in the
            `preprocess` method.
        crop_size (`dict[str, int]` *optional*, defaults to `self.crop_size`):
            Size of the output video after applying `center_crop`. Can be overridden by `crop_size` in the `preprocess`
            method.
        do_rescale (`bool`, *optional*, defaults to `self.do_rescale`):
            Whether to rescale the video by the specified scale `rescale_factor`. Can be overridden by the
            `do_rescale` parameter in the `preprocess` method.
        rescale_factor (`int` or `float`, *optional*, defaults to `self.rescale_factor`):
            Scale factor to use if rescaling the video. Only has an effect if `do_rescale` is set to `True`. Can be
            overridden by the `rescale_factor` parameter in the `preprocess` method.
        do_normalize (`bool`, *optional*, defaults to `self.do_normalize`):
            Whether to normalize the video. Can be overridden by the `do_normalize` parameter in the `preprocess`
            method. Can be overridden by the `do_normalize` parameter in the `preprocess` method.
        image_mean (`float` or `list[float]`, *optional*, defaults to `self.image_mean`):
            Mean to use if normalizing the video. This is a float or list of floats the length of the number of
            channels in the video. Can be overridden by the `image_mean` parameter in the `preprocess` method. Can be
            overridden by the `image_mean` parameter in the `preprocess` method.
        image_std (`float` or `list[float]`, *optional*, defaults to `self.image_std`):
            Standard deviation to use if normalizing the video. This is a float or list of floats the length of the
            number of channels in the video. Can be overridden by the `image_std` parameter in the `preprocess` method.
            Can be overridden by the `image_std` parameter in the `preprocess` method.
        do_convert_rgb (`bool`, *optional*, defaults to `self.image_std`):
            Whether to convert the video to RGB.
        video_metadata (`VideoMetadata`, *optional*):
            Metadata of the video containing information about total duration, fps and total number of frames.
        do_sample_frames (`int`, *optional*, defaults to `self.do_sample_frames`):
            Whether to sample frames from the video before processing or to process the whole video.
        num_frames (`int`, *optional*, defaults to `self.num_frames`):
            Maximum number of frames to sample when `do_sample_frames=True`.
        fps (`int` or `float`, *optional*, defaults to `self.fps`):
            Target frames to sample per second when `do_sample_frames=True`.
        return_tensors (`str` or `TensorType`, *optional*):
            Returns stacked tensors if set to `pt, otherwise returns a list of tensors.
        data_format (`ChannelDimension` or `str`, *optional*, defaults to `ChannelDimension.FIRST`):
            The channel dimension format for the output video. Can be one of:
            - `"channels_first"` or `ChannelDimension.FIRST`: video in (num_channels, height, width) format.
            - `"channels_last"` or `ChannelDimension.LAST`: video in (height, width, num_channels) format.
            - Unset: Use the channel dimension format of the input video.
        input_data_format (`ChannelDimension` or `str`, *optional*):
            The channel dimension format for the input video. If unset, the channel dimension format is inferred
            from the input video. Can be one of:
            - `"channels_first"` or `ChannelDimension.FIRST`: video in (num_channels, height, width) format.
            - `"channels_last"` or `ChannelDimension.LAST`: video in (height, width, num_channels) format.
            - `"none"` or `ChannelDimension.NONE`: video in (height, width) format.
        device (`torch.device`, *optional*):
            The device to process the videos on. If unset, the device is inferred from the input videos.
        return_metadata (`bool`, *optional*):
            Whether to return video metadata or not.
        z!Constructs a base VideoProcessor.)ÚvisionÚtorchvision)Úbackendsc                   óþ  ^ • \ rS rSrSrSrSrSrSrSr	Sr
SrSrSrSrSrSrSrSrSrSrSrSr\rS/rS\\   SS4U 4S	 jjrS\4S
 jrSSS\4S jr  SAS\ S\!S-  S\!\"-  S-  4S jjr#  SAS\S\ \$-  S\%S-  S\&S-  S\'S   4
S jjr(  SAS\S\)\*-  S-  S\)S-  S\'S   4S jjr+\," \-5      S\S\\   S\4S j5       r. SBS\'S   S\%S\%S\/SSS \%S!\/S"\%S#\"S$\%S%\"\'\"   -  S-  S&\"\'\"   -  S-  S'\)\0-  S-  S\4S( jjr1\2     SCS)\)\3Rh                  -  S*\)\3Rh                  -  S-  S+\%S,\%S-\)\%-  S-  S.\)4S/ jj5       r5SDS0\)\3Rh                  -  S1\%4S2 jjr6\2S)\)\3Rh                  -  S\7\$\)\84   \$\)\84   4   4S3 j5       r9\2S4\$\)\84   4S5 j5       r:S\$\)\84   4U 4S6 jjr;S\)4S7 jr<S8\)\3Rh                  -  4S9 jr=S: r>\2S;\)\3Rh                  -  4S< j5       r?\2SES= j5       r@SBS>\)\'\)   -  \'\'\)      -  4S? jjrAS@rBU =rC$ )FÚBaseVideoProcessoré‘   NTgp?FÚpixel_values_videosÚkwargsÚreturnc                 ó&   >• [         TU ]  " S0 UD6  g )N© )ÚsuperÚ__init__)Úselfr1   Ú	__class__s     €Ú`/home/mande/repo/quber/.venv/lib/python3.13/site-packages/transformers/video_processing_utils.pyr6   ÚBaseVideoProcessor.__init__®   s   ø€ Ü‰ÒÑ"˜6Ó"ó    c                 ó(   • U R                   " U40 UD6$ ©N)Ú
preprocess)r7   Úvideosr1   s      r9   Ú__call__ÚBaseVideoProcessor.__call__±   s   € Ø�Š˜vÑ0¨Ñ0Ð0r;   Úvideoztorch.Tensorc                 ó$  • [         R                  " U5      nUR                  S   S:X  d#  USSSS2SS24   S:  R                  5       (       d  U$ USSSS2SS24   S-  nSUSSSS2SS24   -
  S-  USSSS2SS24   USSS2SS2SS24   -  -   nU$ )z—
Converts a video to RGB format.

Args:
    video (`"torch.Tensor"`):
        The video to convert.

Returns:
    `torch.Tensor`: The converted video.
éýÿÿÿé   .Néÿ   g     ào@r	   )ÚtvFÚgrayscale_to_rgbÚshapeÚany)r7   rB   Úalphas      r9   Úconvert_to_rgbÚ!BaseVideoProcessor.convert_to_rgb´   s²   € ô ×$Ò$ UÓ+ˆØ�;‰;�r‰?˜aÓ¨¨c°1²aº¨lÑ(;¸cÑ(A×'FÑ'F×'HÑ'HØˆLð �c˜1ša¢�lÑ# eÑ+ˆØ�U˜3 ¢aª˜?Ñ+Ñ+¨sÑ2°U¸3ÀÂaÊ¸?Ñ5KÈeÐTWÐY[ÐZ[ÐY[Ò]^Ò`aÐTaÑNbÑ5bÑbˆØˆr;   ÚmetadataÚ
num_framesÚfpsc                 óÌ  • Ub  Ub  [        S5      eUb  UOU R                  nUb  UOU R                  nUR                  nUc8  Ub5  Ub  UR                  c  [        S5      e[	        XQR                  -  U-  5      nX%:”  a  [        SU SU S35      eUb*  [
        R                  " SXUU-  5      R	                  5       nU$ [
        R                  " SU5      R	                  5       nU$ )aµ  
Default sampling function which uniformly samples the desired number of frames between 0 and total number of frames.
If `fps` is passed along with metadata, `fps` frames per second are sampled uniformty. Arguments `num_frames`
and `fps` are mutually exclusive.

Args:
    metadata (`VideoMetadata`):
        Metadata of the video containing information about total duration, fps and total number of frames.
    num_frames (`int`, *optional*):
        Maximum number of frames to sample. Defaults to `self.num_frames`.
    fps (`int` or `float`, *optional*):
        Target frames to sample per second. Defaults to `self.fps`.

Returns:
    np.ndarray:
        Indices to sample video frames.
zc`num_frames`, `fps`, and `sample_indices_fn` are mutually exclusive arguments, please use only one!zÈAsked to sample `fps` frames per second but no video metadata was provided which is required when sampling with `fps`. Please pass in `VideoMetadata` object or use a fixed `num_frames` per input videoz(Video can't be sampled. The `num_frames=z` exceeds `total_num_frames=z`. r   )Ú
ValueErrorrO   rP   Útotal_num_framesÚintÚtorchÚarange)r7   rN   rO   rP   r1   rS   Úindicess          r9   Úsample_framesÚ BaseVideoProcessor.sample_framesÍ   s
  € ð0 ‰?˜zÑ5ÜØuóð ð $.Ñ#9‘Z¸t¿¹ˆ
Ø‘_‰c¨$¯(©(ˆØ#×4Ñ4Ðð Ñ #¡/ØÑ 8§<¡<Ñ#7Ü ðhóð ô Ð-·±Ñ<¸sÑBÓCˆJàÓ(ÜØ:¸:¸,ÐFbÐcsÐbtÐtwÐxóð ð Ñ!Ü—l’l 1Ð&6È:Ñ8UÓV×ZÑZÓ\ˆGð ˆô —l’l 1Ð&6Ó7×;Ñ;Ó=ˆGØˆr;   r?   Úvideo_metadataÚdo_sample_framesÚsample_indices_fnc                 óf  • [        U5      n[        XS9n[        US   5      (       aV  U(       aO  / n/ n[        X5       H5  u  pxU" US9n	X˜l        UR                  Xy   5        UR                  U5        M7     UnUnX4$ [        US   5      (       d”  [        US   [        5      (       ak  U R                  U5       V
Vs/ s H7  n
[        R                  " U
 Vs/ s H  o°R                  U5      PM     snSS9PM9     nn
nU(       a  [        S5      e X4$ U R                  XS9u  pX4$ s  snf s  snn
f )z2
Decode input videos and sample frames if needed.
)rZ   r   )rN   )ÚdimzUSampling frames from a list of images is not supported! Set `do_sample_frames=False`.©r\   )r'   r&   r$   ÚzipÚframes_indicesÚappendÚ
isinstanceÚlistÚfetch_imagesrU   ÚstackÚprocess_imagerR   Úfetch_videos)r7   r?   rZ   r[   r\   Úsampled_videosÚsampled_metadatarB   rN   rW   ÚimagesÚimages               r9   Ú_decode_and_sample_videosÚ,BaseVideoProcessor._decode_and_sample_videos  sQ  € ô % VÓ,ˆÜ.¨vÑUˆô ˜& ™)×$Ñ$Ö)9ØˆNØ!ÐÜ#& vÖ#>‘�Ù+°XÑ>�Ø*1Ô'Ø×%Ñ% e¡nÔ5Ø ×'Ñ'¨Ö1ñ	 $?ð
 $ˆFØ-ˆNð Ð%Ð%ô    q¡	×*Ñ*Ü˜& ™)¤T×*Ñ*ð #'×"3Ñ"3°FÔ";ôâ";˜ô —K’KÉÓ OÊ¸u×!3Ñ!3°EÖ!:ÉÑ OÐUVÔWÙ";ð ñ ö $Ü$Øoóð ð $ð Ð%Ð%ð *.×):Ñ):¸6Ð):Ð)gÑ&�àÐ%Ð%ùò !Pùós   Â=D-ÃD(Ã1
D-Ä(D-Úinput_data_formatÚdevicec                 ót  • / nU H¯  n[        U[        R                  5      (       a$  [        R                  " U5      R                  5       nUc  [        U5      nU[        R                  :X  a"  UR                  SSSS5      R                  5       nUb  UR                  U5      nUR                  U5        M±     U$ )z*
Prepare the input videos for processing.
r   rE   r	   é   )rc   ÚnpÚndarrayrU   Ú
from_numpyÚ
contiguousr#   r   ÚLASTÚpermuteÚtorb   )r7   r?   ro   rp   Úprocessed_videosrB   s         r9   Ú_prepare_input_videosÚ(BaseVideoProcessor._prepare_input_videos*  s§   € ð ÐÛˆEä˜%¤§¡×,Ñ,ä×(Ò(¨Ó/×:Ñ:Ó<�ð !Ñ(Ü$BÀ5Ó$IÐ!à Ô$4×$9Ñ$9Ó9ØŸ™ a¨¨A¨qÓ1×<Ñ<Ó>�àÑ!ØŸ™ Ó(�à×#Ñ# EÖ*ñ! ð"  Ðr;   c           	      ó
  • [        UR                  5       [        U R                  R                  R                  5       5      S/-   S9  [        U R                  U5        U R                  R                   H  nUR                  U[        XS 5      5        M!     UR                  S5      nUR                  S5      nUR                  S5      nUR                  S5      nU(       a  [        U R                  40 UD6OS nU R                  UUUUS9u  pU R                  XUS9nU R                  " S0 UD6nU R                  " S0 UD6  UR                  S	5        UR                  S
5      n	U R                  " SSU0UD6n
U	(       a  XzS'   U
$ )NÚreturn_tensors)Úcaptured_kwargsÚvalid_processor_keysro   r[   rp   rZ   )rZ   r[   r\   )r?   ro   rp   Údata_formatÚreturn_metadatar?   r4   )r   Úkeysrd   Úvalid_kwargsÚ__annotations__r   Ú
setdefaultÚgetattrÚpopr   rX   rm   r{   Ú_standardize_kwargsÚ_validate_preprocess_kwargsÚ_preprocess)r7   r?   r1   Ú
kwarg_namero   r[   rp   rZ   r\   r‚   Úpreprocessed_videoss              r9   r>   ÚBaseVideoProcessor.preprocessG  s  € ô 	Ø"ŸK™K›MÜ!% d×&7Ñ&7×&GÑ&G×&LÑ&LÓ&NÓ!OÐScÐRdÑ!dò	
ô 	˜D×-Ñ-¨vÔ6ð ×+Ñ+×;Ô;ˆJØ×Ñ˜j¬'°$ÀDÓ*IÖJñ <ð #ŸJ™JÐ':Ó;ÐØ!Ÿ:™:Ð&8Ó9ÐØ—‘˜HÓ%ˆØŸ™Ð$4Ó5ˆæEUœG D×$6Ñ$6ÑA¸&ÒAÐ[_ÐØ!%×!?Ñ!?ØØ)Ø-Ø/ð	 "@ð "
Ñˆð ×+Ñ+°6ÐgmÐ+Ðnˆà×)Ò)Ñ3¨FÑ3ˆØ×(Ò(Ñ2¨6Ò2ð 	�
‰
�=Ô!Ø Ÿ*™*Ð%6Ó7ˆà"×.Ò.ÑG°fÐGÀÑGÐÞØ4BÐ 0Ñ1Ø"Ð"r;   Údo_convert_rgbÚ	do_resizeÚsizeÚresamplez7PILImageResampling | tvF.InterpolationMode | int | NoneÚdo_center_cropÚ	crop_sizeÚ
do_rescaleÚrescale_factorÚdo_normalizeÚ
image_meanÚ	image_stdr~   c           	      ó¾  • [        U5      u  nn0 nUR                  5        H:  u  nnU(       a  U R                  U5      nU(       a  U R                  UXES9nUUU'   M<     [	        UU5      n[        U5      u  nn0 nUR                  5        H8  u  nnU(       a  U R                  UU5      nU R                  UX‰X«U5      nUUU'   M:     [	        UU5      n[        SU0US9$ )N)r‘   r’   r0   )ÚdataÚtensor_type)r"   ÚitemsrL   Úresizer(   Úcenter_cropÚrescale_and_normalizer   )r7   r?   r�   r�   r‘   r’   r“   r”   r•   r–   r—   r˜   r™   r~   r1   Úgrouped_videosÚgrouped_videos_indexÚresized_videos_groupedrI   Ústacked_videosÚresized_videosÚprocessed_videos_groupedrz   s                          r9   r‹   ÚBaseVideoProcessor._preprocessv  s	  € ô$ 0EÀVÓ/LÑ,ˆÐ,Ø!#ÐØ%3×%9Ñ%9Ö%;Ñ!ˆE�>ÞØ!%×!4Ñ!4°^Ó!D�ÞØ!%§¡¨^À$ Ð!Z�Ø,:Ð" 5Ó)ñ &<ô (Ð(>Ð@TÓUˆô 0EÀ^Ó/TÑ,ˆÐ,Ø#%Ð Ø%3×%9Ñ%9Ö%;Ñ!ˆE�>ÞØ!%×!1Ñ!1°.À)Ó!L�à!×7Ñ7Ø 
¸LÐV_óˆNð /=Ð$ UÓ+ñ &<ô *Ð*BÐDXÓYÐäÐ"7Ð9IÐ!JÐXfÑgÐgr;   Úpretrained_model_name_or_pathÚ	cache_dirÚforce_downloadÚlocal_files_onlyÚtokenÚrevisionc                 ó€   • X'S'   X7S'   XGS'   XgS'   Ub  XWS'   U R                   " U40 UD6u  p‡U R                  " U40 UD6$ )aC  
Instantiate a type of [`~video_processing_utils.VideoProcessorBase`] from an video processor.

Args:
    pretrained_model_name_or_path (`str` or `os.PathLike`):
        This can be either:

        - a string, the *model id* of a pretrained video hosted inside a model repo on
          huggingface.co.
        - a path to a *directory* containing a video processor file saved using the
          [`~video_processing_utils.VideoProcessorBase.save_pretrained`] method, e.g.,
          `./my_model_directory/`.
        - a path to a saved video processor JSON *file*, e.g.,
          `./my_model_directory/video_preprocessor_config.json`.
    cache_dir (`str` or `os.PathLike`, *optional*):
        Path to a directory in which a downloaded pretrained model video processor should be cached if the
        standard cache should not be used.
    force_download (`bool`, *optional*, defaults to `False`):
        Whether or not to force to (re-)download the video processor files and override the cached versions if
        they exist.
    proxies (`dict[str, str]`, *optional*):
        A dictionary of proxy servers to use by protocol or endpoint, e.g., `{'http': 'foo.bar:3128',
        'http://hostname': 'foo.bar:4012'}.` The proxies are used on each request.
    token (`str` or `bool`, *optional*):
        The token to use as HTTP bearer authorization for remote files. If `True`, or not specified, will use
        the token generated when running `hf auth login` (stored in `~/.huggingface`).
    revision (`str`, *optional*, defaults to `"main"`):
        The specific model version to use. It can be a branch name, a tag name, or a commit id, since we use a
        git-based system for storing models and other artifacts on huggingface.co, so `revision` can be any
        identifier allowed by git.


        <Tip>

        To test a pull request you made on the Hub, you can pass `revision="refs/pr/<pr_number>"`.

        </Tip>

    return_unused_kwargs (`bool`, *optional*, defaults to `False`):
        If `False`, then this function returns just the final video processor object. If `True`, then this
        functions returns a `Tuple(video_processor, unused_kwargs)` where *unused_kwargs* is a dictionary
        consisting of the key/value pairs whose keys are not video processor attributes: i.e., the part of
        `kwargs` which has not been used to update `video_processor` and is otherwise ignored.
    subfolder (`str`, *optional*, defaults to `""`):
        In case the relevant files are located inside a subfolder of the model repo on huggingface.co, you can
        specify the folder name here.
    kwargs (`dict[str, Any]`, *optional*):
        The values in kwargs of any keys which are video processor attributes will be used to override the
        loaded values. Behavior concerning key/value pairs whose keys are *not* video processor attributes is
        controlled by the `return_unused_kwargs` keyword parameter.

Returns:
    A video processor of type [`~video_processing_utils.ImagVideoProcessorBase`].

Examples:

```python
# We can't instantiate directly the base class *VideoProcessorBase* so let's show the examples on a
# derived class: *LlavaOnevisionVideoProcessor*
video_processor = LlavaOnevisionVideoProcessor.from_pretrained(
    "llava-hf/llava-onevision-qwen2-0.5b-ov-hf"
)  # Download video_processing_config from huggingface.co and cache.
video_processor = LlavaOnevisionVideoProcessor.from_pretrained(
    "./test/saved_model/"
)  # E.g. video processor (or model) was saved using *save_pretrained('./test/saved_model/')*
video_processor = LlavaOnevisionVideoProcessor.from_pretrained("./test/saved_model/video_preprocessor_config.json")
video_processor = LlavaOnevisionVideoProcessor.from_pretrained(
    "llava-hf/llava-onevision-qwen2-0.5b-ov-hf", do_normalize=False, foo=False
)
assert video_processor.do_normalize is False
video_processor, unused_kwargs = LlavaOnevisionVideoProcessor.from_pretrained(
    "llava-hf/llava-onevision-qwen2-0.5b-ov-hf", do_normalize=False, foo=False, return_unused_kwargs=True
)
assert video_processor.do_normalize is False
assert unused_kwargs == {"foo": False}
```r©   rª   r«   r­   r¬   )Úget_video_processor_dictÚ	from_dict)	Úclsr¨   r©   rª   r«   r¬   r­   r1   Úvideo_processor_dicts	            r9   Úfrom_pretrainedÚ"BaseVideoProcessor.from_pretrained£  sd   € ðn (ˆ{ÑØ#1ÐÑ Ø%5Ð!Ñ"Ø%ˆzÑàÑØ#�7‰Oà'*×'CÒ'CÐDaÑ'lÐekÑ'lÑ$Ðà�}Š}Ð1Ñ<°VÑ<Ð<r;   Úsave_directoryÚpush_to_hubc           	      ó®  • [         R                  R                  U5      (       a  [        SU S35      e[         R                  " USS9  U(       aw  UR                  SS5      nUR                  SUR                  [         R                  R                  5      S   5      n[        U4S	S0UD6R                  nU R                  U5      nU R                  b
  [        XU S
9  [         R                  R                  U[        5      nU R                  U5        [         R#                  SU 35        U(       a"  U R%                  UWWWUR'                  S5      S9  U/$ )a  
Save an video processor object to the directory `save_directory`, so that it can be re-loaded using the
[`~video_processing_utils.VideoProcessorBase.from_pretrained`] class method.

Args:
    save_directory (`str` or `os.PathLike`):
        Directory where the video processor JSON file will be saved (will be created if it does not exist).
    push_to_hub (`bool`, *optional*, defaults to `False`):
        Whether or not to push your model to the Hugging Face model hub after saving it. You can specify the
        repository you want to push to with `repo_id` (will default to the name of `save_directory` in your
        namespace).
    kwargs (`dict[str, Any]`, *optional*):
        Additional key word arguments passed along to the [`~utils.PushToHubMixin.push_to_hub`] method.
zProvided path (z#) should be a directory, not a fileT)Úexist_okÚcommit_messageNÚrepo_idéÿÿÿÿr¸   )ÚconfigzVideo processor saved in r¬   )r¹   r¬   )ÚosÚpathÚisfileÚAssertionErrorÚmakedirsrˆ   ÚsplitÚsepr   rº   Ú_get_files_timestampsÚ_auto_classr
   Újoinr   Úto_json_fileÚloggerÚinfoÚ_upload_modified_filesÚget)r7   rµ   r¶   r1   r¹   rº   Úfiles_timestampsÚoutput_video_processor_files           r9   Úsave_pretrainedÚ"BaseVideoProcessor.save_pretrained  s0  € ô �7‰7�>‰>˜.×)Ñ)Ü  ?°>Ð2BÐBeÐ!fÓgÐgä
�Š�N¨TÒ2æØ#ŸZ™ZÐ(8¸$Ó?ˆNØ—j‘j ¨N×,@Ñ,@ÄÇÁÇÁÓ,MÈbÑ,QÓRˆGÜ! 'ÑC°DÐC¸FÑC×KÑKˆGØ#×9Ñ9¸.ÓIÐð ×ÑÑ'Ü˜t¸DÒAô ')§g¡g§l¡l°>ÔCWÓ&XÐ#à×ÑÐ5Ô6Ü�‰Ð/Ð0KÐ/LÐMÔNæØ×'Ñ'ØØØ Ø-Ø—j‘j Ó)ð (ñ ð ,Ð,Ð,r;   c                 óŽ  • UR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  SS5      nUR                  S	S
5      n	UR                  SS5      n
UR                  SS5      nSUS.nU
b  X¬S'   [        5       (       a  U(       d  [        R                  S5        Sn[	        U5      n[
        R                  R                  U5      n[
        R                  R                  U5      (       a  UnSnSnO^[        n [        U[        UUUUUUUU	SS9nU[        4 Vs/ s H  n[        UUUUUUUUUU	SS9=n  c  M  UPM!     nnU(       a  US   OSnSnUb  [        U5      nSU;   a  US   nUb  Uc  [        U5      nUc  [        SU SU SW S35      eU(       a  [        R                  SU 35        UU4$ [        R                  SW SU 35        UU4$ s  snf ! [         a    e [         a    [        SU SU SU S35      ef = f)a¶  
From a `pretrained_model_name_or_path`, resolve to a dictionary of parameters, to be used for instantiating a
video processor of type [`~video_processing_utils.VideoProcessorBase`] using `from_dict`.

Parameters:
    pretrained_model_name_or_path (`str` or `os.PathLike`):
        The identifier of the pre-trained checkpoint from which we want the dictionary of parameters.
    subfolder (`str`, *optional*, defaults to `""`):
        In case the relevant files are located inside a subfolder of the model repo on huggingface.co, you can
        specify the folder name here.

Returns:
    `tuple[Dict, Dict]`: The dictionary(ies) that will be used to instantiate the video processor object.
r©   Nrª   FÚproxiesr¬   r«   r­   Ú	subfolderÚ Ú_from_pipelineÚ
_from_autoúvideo processor)Ú	file_typeÚfrom_auto_classÚusing_pipelinez+Offline mode: forcing local_files_only=TrueT)
Úfilenamer©   rª   rÑ   r«   r¬   Ú
user_agentr­   rÒ   Ú%_raise_exceptions_for_missing_entriesr   z Can't load video processor for 'zœ'. If you were trying to load it from 'https://huggingface.co/models', make sure you don't have a local directory with the same name. Otherwise, make sure 'z2' is the correct path to a directory containing a z fileÚvideo_processorzloading configuration file z from cache at )rˆ   r   rÈ   rÉ   Ústrr½   r¾   Úisdirr¿   r   r   r   r   ÚOSErrorÚ	Exceptionr   )r±   r¨   r1   r©   rª   rÑ   r¬   r«   r­   rÒ   Úfrom_pipelinerØ   rÛ   Úis_localÚresolved_video_processor_fileÚresolved_processor_fileÚvideo_processor_filerÚ   Úresolved_fileÚresolved_video_processor_filesr²   Úprocessor_dicts                         r9   r¯   Ú+BaseVideoProcessor.get_video_processor_dict6  s÷  € ð$ —J‘J˜{¨DÓ1ˆ	ØŸ™Ð$4°eÓ<ˆØ—*‘*˜Y¨Ó-ˆØ—
‘
˜7 DÓ)ˆØ!Ÿ:™:Ð&8¸%Ó@ÐØ—:‘:˜j¨$Ó/ˆØ—J‘J˜{¨BÓ/ˆ	àŸ
™
Ð#3°TÓ:ˆØ Ÿ*™* \°5Ó9ˆà#4ÈÑYˆ
ØÑ$Ø+8Ð'Ñ(ä×ÑÖ%5Ü�K‰KÐEÔFØ#Ðä(+Ð,IÓ(JÐ%Ü—7‘7—=‘=Ð!>Ó?ˆÜ�7‰7�>‰>Ð7×8Ñ8Ø,IÐ)Ø&*Ð#Ø‰Hä#7Ð ð2ô +6Ø1Ü+Ø'Ø#1Ø#Ø%5ØØ)Ø%Ø'Ø:?ñ+Ð'ð &:Ô;OÑ$Pó2â$P˜ä)4Ø9Ø%-Ø&/Ø+9Ø$+Ø-=Ø"'Ø'1Ø%-Ø&/ØBGñ*ð ˜ð  ð ÷ "Ù$Pð /ð 2ö* :XÐ2°1Ò5Ð]að .ð&  $ÐØ"Ñ.Ü0Ð1HÓIˆNØ  NÓ2Ø'5Ð6GÑ'HÐ$à(Ñ4Ð9MÑ9UÜ#6Ð7TÓ#UÐ àÑ'ÜØ2Ð3PÐ2Qð R5à5RÐ4Sð T+Ø+?Ð*@ÀðGóð ö Ü�K‰KÐ5Ð6SÐ5TÐUÔVð $ VÐ+Ð+ô	 �K‰KØ-Ð.BÐ-CÀ?ÐSpÐRqÐrôð $ VÐ+Ð+ùò2øô. ó ð Üó äØ6Ð7TÐ6Uð V9à9VÐ8Wð X/Ø/CÐ.DÀEðKóð ðús$   Ä8!H ÅHÅ9HÅ?H ÈH È*Ir²   c           	      ó¬  • UR                  5       nUR                  SS5      nUR                  UR                  5        VVs0 s H"  u  pEX@R                  R
                  ;   d  M   XE_M$     snn5        U " S0 UD6n/ n[        [        UR                  5       5      5       H]  n[        Xh5      (       d  M  X€R                  R
                  ;  d  M0  [        XhUR                  US5      5        UR                  U5        M_     U(       a&  [        R                  SU R                   SU S35        [        R                  SU 35        U(       a  Xb4$ U$ s  snnf )	a‡  
Instantiates a type of [`~video_processing_utils.VideoProcessorBase`] from a Python dictionary of parameters.

Args:
    video_processor_dict (`dict[str, Any]`):
        Dictionary that will be used to instantiate the video processor object. Such a dictionary can be
        retrieved from a pretrained checkpoint by leveraging the
        [`~video_processing_utils.VideoProcessorBase.to_dict`] method.
    kwargs (`dict[str, Any]`):
        Additional parameters from which to initialize the video processor object.

Returns:
    [`~video_processing_utils.VideoProcessorBase`]: The video processor object instantiated from those
    parameters.
Úreturn_unused_kwargsFNzImage processor z	: kwargs zÍ were applied for backward compatibility. To avoid this warning, add them to valid_kwargs: create a custom TypedDict extending ImagesKwargs with these keys and set it as the `valid_kwargs` class attribute.zVideo processor r4   )Úcopyrˆ   Úupdater�   r„   r…   Úreversedrd   rƒ   ÚhasattrÚsetattrrb   rÈ   Úwarning_onceÚ__name__rÉ   )	r±   r²   r1   rì   ÚkÚvrÝ   Ú
extra_keysÚkeys	            r9   r°   ÚBaseVideoProcessor.from_dict´  s-  € ð"  4×8Ñ8Ó:ÐØ%Ÿz™zÐ*@À%ÓHÐØ×#Ñ#°f·l±l´nÔ$n²n©d¨aÈ×M]ÑM]×MmÑMmÑHm£T Q¢T±nÒ$nÔoÙÑ5Ð 4Ñ5ˆð ˆ
ÜœD §¡£Ó/Ö0ˆCÜ�×,Ó,°×<LÑ<L×<\Ñ<\Õ1\Ü˜¨f¯j©j¸¸dÓ.CÔDØ×!Ñ! #Ö&ñ 1ö Ü×ÑØ" 3§<¡< .°	¸*¸ð Fað bôô 	�‰Ð& Ð&7Ð8Ô9ÞØ"Ð*Ð*à"Ð"ùó) %os   ÁE
Á$E
c                 óz   >• [         TU ]  5       nUR                  SS5        U R                  R                  US'   U$ )zŸ
Serializes this instance to a Python dictionary.

Returns:
    `dict[str, Any]`: Dictionary of all the attributes that make up this video processor instance.
Úimage_processor_typeNÚvideo_processor_type)r5   Úto_dictrˆ   r8   ró   )r7   Úfiltered_dictr8   s     €r9   rü   ÚBaseVideoProcessor.to_dictÝ  s=   ø€ ô ™™Ó)ˆØ×ÑÐ0°$Ô7Ø04·±×0GÑ0GˆÐ,Ñ-àÐr;   c                 óì   • U R                  5       nUR                  5        H8  u  p#[        U[        R                  5      (       d  M&  UR                  5       X'   M:     [        R                  " USSS9S-   $ )z£
Serializes this instance to a JSON string.

Returns:
    `str`: String containing all the attributes that make up this feature_extractor instance in JSON format.
rr   T)ÚindentÚ	sort_keysÚ
)rü   r�   rc   rs   rt   ÚtolistÚjsonÚdumps)r7   Ú
dictionaryr÷   Úvalues       r9   Úto_json_stringÚ!BaseVideoProcessor.to_json_stringê  s\   € ð —\‘\“^ˆ
à$×*Ñ*Ö,‰JˆCÜ˜%¤§¡×,Ó,Ø"'§,¡,£.�
“ñ -ô �zŠz˜*¨Q¸$Ñ?À$ÑFÐFr;   Újson_file_pathc                 óŒ   • [        USSS9 nUR                  U R                  5       5        SSS5        g! , (       d  f       g= f)z¹
Save this instance to a JSON file.

Args:
    json_file_path (`str` or `os.PathLike`):
        Path to the JSON file in which this image_processor instance's parameters will be saved.
Úwúutf-8©ÚencodingN)ÚopenÚwriter  )r7   r
  Úwriters      r9   rÇ   ÚBaseVideoProcessor.to_json_fileù  s3   € ô �. #°Ò8¸FØ�L‰L˜×,Ñ,Ó.Ô/÷ 9×8Ö8ús	   Œ 5µ
Ac                 óT   • U R                   R                   SU R                  5        3$ )NÚ )r8   ró   r  )r7   s    r9   Ú__repr__ÚBaseVideoProcessor.__repr__  s(   € Ø—.‘.×)Ñ)Ð*¨!¨D×,?Ñ,?Ó,AÐ+BÐCÐCr;   Ú	json_filec                 ó¨   • [        USSS9 nUR                  5       nSSS5        [        R                  " W5      nU " S0 UD6$ ! , (       d  f       N,= f)a„  
Instantiates a video processor of type [`~video_processing_utils.VideoProcessorBase`] from the path to a JSON
file of parameters.

Args:
    json_file (`str` or `os.PathLike`):
        Path to the JSON file containing the parameters.

Returns:
    A video processor of type [`~video_processing_utils.VideoProcessorBase`]: The video_processor object
    instantiated from that JSON file.
Úrr  r  Nr4   )r  Úreadr  Úloads)r±   r  ÚreaderÚtextr²   s        r9   Úfrom_json_fileÚ!BaseVideoProcessor.from_json_file  sI   € ô �)˜S¨7Ò3°vØ—;‘;“=ˆD÷ 4ä#Ÿzšz¨$Ó/ÐÙÑ*Ð)Ñ*Ð*÷ 4Õ3ús   ŒAÁ
Ac                 ó    • [        U[        5      (       d  UR                  nSSKJs  Jn  [        X!5      (       d  [        U S35      eXl        g)aÁ  
Register this class with a given auto class. This should only be used for custom video processors as the ones
in the library are already mapped with `AutoVideoProcessor `.

<Tip warning={true}>

This API is experimental and may have some slight breaking changes in the next releases.

</Tip>

Args:
    auto_class (`str` or `type`, *optional*, defaults to `"AutoVideoProcessor "`):
        The auto class to register this new video processor with.
r   Nz is not a valid auto class.)	rc   rÞ   ró   Útransformers.models.autoÚmodelsÚautorð   rR   rÅ   )r±   Ú
auto_classÚauto_modules      r9   Úregister_for_auto_classÚ*BaseVideoProcessor.register_for_auto_class  sE   € ô  ˜*¤c×*Ñ*Ø#×,Ñ,ˆJç6Ð6ä�{×/Ñ/Ü 
˜|Ð+FÐGÓHÐHà$�r;   Úvideo_url_or_urlsc                 óø   • Sn[        5       (       d  [        R                  " S5        Sn[        U[        5      (       a.  [	        [        U Vs/ s H  o@R                  XBS9PM     sn6 5      $ [        XUS9$ s  snf )zÈ
Convert a single or a list of urls into the corresponding `np.array` objects.

If a single url is passed, the return value will be a single object. If a list is passed a list of objects is
returned.
Ú
torchcodeczÇ`torchcodec` is not installed and cannot be used to decode the video by default. Falling back to `torchvision`. Note that `torchvision` decoding is deprecated and will be removed in future versions. r+   r_   )Úbackendr\   )r   ÚwarningsÚwarnrc   rd   r`   rh   r%   )r7   r)  r\   r,  Úxs        r9   rh   ÚBaseVideoProcessor.fetch_videos4  s}   € ð ˆÜ&×(Ñ(Ü�MŠMðIôð $ˆGäÐ'¬×.Ñ.ÜœÑarÓsÒarÐ\]×/Ñ/°Ð/ÓWÑarÑsÐtÓuÐuäÐ/ÐTeÑfÐfùò ts   ÁA7r4   )NNr=   )NFFNÚmain)F)ÚAutoVideoProcessor)Dró   Ú
__module__Ú__qualname__Ú__firstlineno__rÅ   r’   r˜   r™   r‘   Úsize_divisorÚdefault_to_squarer”   r�   r“   r•   r–   r—   r�   r[   rP   rO   rZ   r‚   r   r„   Úmodel_input_namesr   r6   r   r@   r    rL   r!   rT   ÚfloatrX   ÚdictÚboolr   rd   rm   rÞ   r   r{   r   ÚBASE_VIDEO_PROCESSOR_DOCSTRINGr>   r   r   r‹   Úclassmethodr½   ÚPathLiker³   rÎ   Útupler   r¯   r°   rü   r  rÇ   r  r  r'  rh   Ú__static_attributes__Ú__classcell__)r8   s   @r9   r.   r.   ‘   s?  ø† ð €Kà€HØ€JØ€IØ€DØ€LØÐØ€IØ€IØ€NØ€JØ€NØ€LØ€NØÐØ
€CØ€JØ€NØ€OØ€LØ.Ð/Ðð# ¨Ñ!5ð #¸$÷ #ð1¨Lô 1ðàðð 
ôð8 "&Ø"&ñ	3àð3ð ˜$‘Jð3ð �5‰[˜4Ñõ	3ðr )-Ø-1ñ&&àð&&ð &¨Ñ,ð&&ð  ™+ð	&&ð
 $ d™?ð&&ð 
ˆnÑ	õ&&ðV <@Ø!ñ	 àð ð Ð!1Ñ1°DÑ8ð ð �d‘
ð	 ð
 
ˆnÑ	õ ñ: Ø&óð*#àð*#ð ˜Ñ&ð*#ð 
ó	*#óð*#ðt 37ñ+hà�^Ñ$ð+hð ð+hð ð	+hð
 ð+hð Lð+hð ð+hð ð+hð ð+hð ð+hð ð+hð ˜D ™KÑ'¨$Ñ.ð+hð ˜4 ™;Ñ&¨Ñ-ð+hð ˜jÑ(¨4Ñ/ð+hð  
õ!+hðZ ð /3Ø$Ø!&Ø#'Øñ`=à'*¨R¯[©[Ñ'8ð`=ð ˜Ÿ™Ñ$ tÑ+ð`=ð ð	`=ð
 ð`=ð �T‰z˜DÑ ð`=ð ô`=ó ð`=ñD.-¨c°B·K±KÑ.?ð .-Èdõ .-ð` ð{,Ø,/°"·+±+Ñ,=ð{,à	ˆt�C˜�H‰~˜t C¨ H™~Ð-Ñ	.ó{,ó ð{,ðz ð&#¨T°#°s°(©^ó &#ó ð&#ðP˜˜c 3˜h™÷ ðG ô Gð	0¨3°·±Ñ+<ô 	0òDð ð+ s¨R¯[©[Ñ'8ó +ó ð+ð$ ó%ó ð%ñ2g¨c°D¸±I©oÀÀTÈ#ÁYÁÑ.O÷ gó gr;   r.   rÖ   r2  zvideo processor file)ÚobjectÚobject_classÚobject_files)Gr  r½   r-  Úcollections.abcr   Ú	functoolsr   Útypingr   Únumpyrs   Úhuggingface_hubr   r   Úhuggingface_hub.dataclassesr   Údynamic_module_utilsr
   Úimage_processing_backendsr   Úimage_processing_utilsr   Úimage_utilsr   r   r   r   Úprocessing_utilsr   r   Úutilsr   r   r   r   r   r   r   r   r   r   r   Ú	utils.hubr   Úutils.import_utilsr   Úvideo_utilsr    r!   r"   r#   r$   r%   r&   r'   r(   rU   Ú$torchvision.transforms.v2.functionalÚ
transformsÚv2Ú
functionalrG   r)   Ú
get_loggerró   rÈ   r<  r.   r¶   Ú__doc__Úformatr4   r;   r9   Ú<module>r[     sK  ðó Û 	Û Ý $Ý Ý ã ß 8Ý ;å 4Ý 9Ý 0÷ó ÷ 3÷÷ ÷ ñ õ #Ý (÷
÷ 
õ 
ñ ×ÑÛá× Ñ ß6Ó6á×ÑÝ/ð 
×	Ò	˜HÓ	%€ðA"Ð ñH Ø'Ø"óñ 
Ð,Ñ-ôp
gÐ+ó p
gó .ó	ð
p
gñf "+Ð+=×+IÑ+IÓ!JÐ Ô Ø×!Ñ!×)Ñ)Ñ5Ø-?×-KÑ-K×-SÑ-S×-ZÑ-ZØ Ð/CÐRhð .[ð .Ð×"Ñ"Õ*ð 6r;   