ó
    ‡Ž¡js…  ã                   ó¶  • 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  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*J+r+  SSK,J-r-  SSK.J/r/J0r0J1r1J2r2J3r3J4r4J5r5J6r6J7r7J8r8J9r9  \$" 5       (       a  S SK:r:\&" 5       (       a  S SK;J<s  J=s  J>r?  \" 5       (       a  SSKJ@r@  \'R‚                  " \B5      rC\-" SS9 " S S\5      5       rD\#" \DRŠ                  5      \DlE        \DRŠ                  RŒ                  b5  \DRŠ                  RŒ                  R�                  SSSS9\DRŠ                  lF        gg)é    N)ÚCallable)Úpartial)ÚAny)Ú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Úauto_docstringÚ	copy_funcÚis_torch_availableÚis_torchcodec_availableÚis_torchvision_v2_availableÚloggingÚsafe_load_json_file)Úcached_fileÚhf_api)Úrequires)Ú TORCHVISION_VIDEO_DECODING_ERRORÚ
VideoInputÚVideoMetadataÚgroup_videos_by_shapeÚinfer_channel_dimension_formatÚ'is_torchvision_video_decoding_availableÚis_valid_videoÚ
load_videoÚmake_batched_metadataÚmake_batched_videosÚreorder_videos)ÚPILImageResampling)Ú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+\,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'\)\/-  S-  S\4S( jjr0\1     SCS)\)\2Rf                  -  S*\)\2Rf                  -  S-  S+\%S,\%S-\)\%-  S-  S.\)4S/ jj5       r4SDS0\)\2Rf                  -  S1\%4S2 jjr5\1S)\)\2Rf                  -  S\6\$\)\74   \$\)\74   4   4S3 j5       r8\1S4\$\)\74   4S5 j5       r9S\$\)\74   4U 4S6 jjr:S\)4S7 jr;S8\)\2Rf                  -  4S9 jr<S: r=\1S;\)\2Rf                  -  4S< j5       r>\1SES= j5       r?SBS>\)\'\)   -  \'\'\)      -  4S? jjr@S@rAU =rB$ )FÚBaseVideoProcessoréO   NTgp?FÚpixel_values_videosÚkwargsÚreturnc                 ó&   >• [         TU ]  " S0 UD6  g )N© )ÚsuperÚ__init__)Úselfr3   Ú	__class__s     €Ú±C:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\transformers/video_processing_utils.pyr8   ÚBaseVideoProcessor.__init__h   s   ø€ Ü‰ÒÑ"˜6Ó"ó    c                 ó(   • U R                   " U40 UD6$ ©N)Ú
preprocess)r9   Úvideosr3   s      r;   Ú__call__ÚBaseVideoProcessor.__call__k   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SSS2SS2SS24   $ 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)r9   rD   Úalphas      r;   Úconvert_to_rgbÚ!BaseVideoProcessor.convert_to_rgbn   sÄ   € ô ×$Ò$ UÓ+ˆØ�;‰;�r‰?˜aÓ¨¨c°1²aº¨lÑ(;¸cÑ(A×'FÑ'F×'HÑ'HØ˜˜b˜q˜b¢!¢Q˜Ñ'Ð'ð �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 uniformly. 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   )Ú
ValueErrorrQ   rR   Útotal_num_framesÚintÚtorchÚarange)r9   rP   rQ   rR   r3   rU   Úindicess          r;   Ú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=   rA   Ú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.
)r\   r   )rP   )Ú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_imagesrW   ÚstackÚprocess_imagerT   Úfetch_videos)r9   rA   r\   r]   r^   Úsampled_videosÚsampled_metadatarD   rP   rY   ÚimagesÚimages               r;   Ú_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   rG   r   é   )re   ÚnpÚndarrayrW   Ú
from_numpyÚ
contiguousr$   r   ÚLASTÚpermuteÚtord   )r9   rA   rq   rr   Úprocessed_videosrD   s         r;   Ú_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_keysrq   r]   rr   r\   )r\   r]   r^   )rA   rq   rr   Údata_formatÚreturn_metadatarA   r6   )r   Úkeysrf   Úvalid_kwargsÚ__annotations__r   Ú
setdefaultÚgetattrÚpopr   rZ   ro   r}   Ú_standardize_kwargsÚ_validate_preprocess_kwargsÚ_preprocess)r9   rA   r3   Ú
kwarg_namerq   r]   rr   r\   r^   r„   Úpreprocessed_videoss              r;   r@   ÚBaseVideoProcessor.preprocess  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”   r2   )ÚdataÚtensor_type)r#   ÚitemsrN   Úresizer*   Úcenter_cropÚrescale_and_normalizer   )r9   rA   r‘   r’   r“   r”   r•   r–   r—   r˜   r™   rš   r›   r€   r3   Úgrouped_videosÚgrouped_videos_indexÚresized_videos_groupedrK   Ústacked_videosÚresized_videosÚprocessed_videos_groupedr|   s                          r;   r�   ÚBaseVideoProcessor._preprocess.  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¯   r3   Úvideo_processor_dicts	            r;   Ú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(       a†  UR                  SS5      nUR                  SUR                  [         R                  R                  5      S   5      n[        5       R                  " 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   Úcreate_repor¼   Ú_get_files_timestampsÚ_auto_classr	   Újoinr   Úto_json_fileÚloggerÚinfoÚ_upload_modified_filesÚget)r9   r·   r¸   r3   r»   r¼   Úfiles_timestampsÚoutput_video_processor_files           r;   Úsave_pretrainedÚ"BaseVideoProcessor.save_pretrained¾  s8  € ô �7‰7�>‰>˜.×)Ñ)Ü  ?°>Ð2BÐBeÐ!fÓgÐgä
�Š�N¨TÒ2æØ#ŸZ™ZÐ(8¸$Ó?ˆNØ—j‘j ¨N×,@Ñ,@ÄÇÁÇÁÓ,MÈbÑ,QÓRˆGÜ“h×*Ò*¨7ÑL¸TÐLÀVÑL×TÑTˆ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ª   r3   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                         r;   r±   Ú+BaseVideoProcessor.get_video_processor_dictî  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 r6   )ÚcopyrŠ   ÚupdaterŸ   r†   r‡   Úreversedrf   r…   ÚhasattrÚsetattrrd   rË   Úwarning_onceÚ__name__rÌ   )	r³   r´   r3   rï   ÚkÚvrà   Ú
extra_keysÚkeys	            r;   r²   ÚBaseVideoProcessor.from_dictl  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)r7   Úto_dictrŠ   r:   rö   )r9   Úfiltered_dictr:   s     €r;   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.
rt   T)ÚindentÚ	sort_keysÚ
)rÿ   rŸ   re   ru   rv   ÚtolistÚjsonÚdumps)r9   Ú
dictionaryrú   Úvalues       r;   Ú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  )r9   r  Úwriters      r;   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Ú )r:   rö   r  )r9   s    r;   Ú__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  Nr6   )r  Úreadr  Úloads)r³   r  ÚreaderÚtextr´   s        r;   Ú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.)	re   rá   rö   Útransformers.models.autoÚmodelsÚautoró   rT   rÈ   )r³   Ú
auto_classÚauto_modules      r;   Ú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       (       d9  [        5       (       d  [        S[         35      e[        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.
Ú
torchcodeczQ`torchcodec` is not installed and cannot be used to decode the video by default. zÇ`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-   ra   )Úbackendr^   )r   r%   ÚImportErrorr    ÚwarningsÚwarnre   rf   rb   rj   r'   )r9   r,  r^   r/  Úxs        r;   rj   ÚBaseVideoProcessor.fetch_videosì  s£   € ð ˆÜ&×(Ñ(ä:×<Ñ<Ü!ØgÜ7Ð8ð:óð ô �MŠMðIôð $ˆGäÐ'¬×.Ñ.ÜœÑarÓsÒarÐ\]×/Ñ/°Ð/ÓWÑarÑsÐtÓuÐuäÐ/ÐTeÑfÐfùò ts   Á.Br6   )NNr?   )NFFNÚmain)F)ÚAutoVideoProcessor)Crö   Ú
__module__Ú__qualname__Ú__firstlineno__rÈ   r”   rš   r›   r“   Úsize_divisorÚdefault_to_squarer–   r’   r•   r—   r˜   r™   r‘   r]   rR   rQ   r\   r„   r   r†   Úmodel_input_namesr   r8   r   rB   r!   rN   r"   rV   ÚfloatrZ   ÚdictÚboolr   rf   ro   rá   r   r}   r   r@   r   r   r�   Úclassmethodr¿   ÚPathLikerµ   rÑ   Útupler   r±   r²   rÿ   r  rÊ   r  r"  r*  rj   Ú__static_attributes__Ú__classcell__)r:   s   @r;   r0   r0   O   s5  ø† à€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=   r0   rÙ   r6  zvideo processor file)ÚobjectÚobject_classÚobject_files)Hr  r¿   r1  Úcollections.abcr   Ú	functoolsr   Útypingr   Únumpyru   Úhuggingface_hubr   Ú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   r   Úutils.import_utilsr   Úvideo_utilsr    r!   r"   r#   r$   r%   r&   r'   r(   r)   r*   rW   Ú$torchvision.transforms.v2.functionalÚ
transformsÚv2Ú
functionalrI   r+   Ú
get_loggerrö   rË   r0   r¸   Ú__doc__Úformatr6   r=   r;   Ú<module>r^     s1  ðó Û 	Û Ý $Ý Ý ã Ý +Ý ;å 4Ý 9Ý 0÷ó ÷ 3÷÷ ÷ ñ ÷ +Ý (÷÷ ÷ ñ ñ ×ÑÛá× Ñ ß6Ó6á×ÑÝ/ð 
×	Ò	˜HÓ	%€ñ 
Ð,Ñ-ôt
gÐ+ó t
gó .ðt
gñn "+Ð+=×+IÑ+IÓ!JÐ Ô Ø×!Ñ!×)Ñ)Ñ5Ø-?×-KÑ-K×-SÑ-S×-ZÑ-ZØ Ð/CÐRhð .[ð .Ð×"Ñ"Õ*ð 6r=   