
    Z j                        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     t/root/GenerationalWealth/GenerationalWealth/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c1al(;c(A'F'F'H'HL c1al#e+U3a?++s2U3a?5KeTWY[Z[Y[]^`aTaNb5b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!zAsked 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  $.#9Zt
_c$((#44 #/8<<#7 h  -<sBCJ(::,Fbcsbttwx  !ll1&6:8UVZZ\G  ll1&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	Xl        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  oR                  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'%%en5 ''1	 $?
 $F-N %%  q	**&)T** #'"3"3F";"; KK Ou!3!3E!: OUV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%,,((/::< !($B5$I! $4$9$99aAq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    	"KKM!%d&7&7&G&G&L&L&N!OScRd!d	
 	D--v6 ++;;Jj'$D*IJ < #JJ':;!::&89H%$45EUGD$6$6A&A[_!%!?!?)-/	 "@ "
 ++6gm+n))3F3((262 	

=! **%67"..Gf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XXU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
LV_N /=$U+ &< **BDXY"79I!JXf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  pU 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#7O'*'C'CDa'lek'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_idr   )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    77>>.)) ?>2BBe!fgg
NT2#ZZ(8$?NjjN,@,@,Mb,QRG!'CDCFCKKG#99.I 'tDA ')ggll>CW&X#56/0K/LMN'' -jj) (  ,,,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  XS'   [        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   $ JJ{D1	$4e<**Y-

7D)!::&8%@::j$/JJ{B/	

#3T: **\59#4Y
$+8'(%5KKEF#(+,I(J%77==!>?77>>788,I)&*#H#7 2 +61+'#1#%5)%':?+' &:;O$P2$P)49%-&/+9$+-="''1%-&/BG*     "$P / 2* :X215]a .&  $".01HIN N2'56G'H$(49M9U#67T#U '23P2Q R55R4S T++?*@G  KK56S5TUV $V++	 KK-.B-C?SpRqr $V++2.    67T6U V99V8W X//C.DE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  XR                  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:%zz*@%H##flln$nndaM]M]MmMmHmTQTn$no5 45 
D/0C,,<L<L<\<\1\fjj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$7040G0G,-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\     \\^
$**,JC%,,"',,.
 - zz*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     .#8FLL,,./ 988s	    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     )S73v;;=D 4#zz$/*)** 43s   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}     &((MMI $G'..arsar\]///War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 #$ #1L 1 
8 "&"&	33 $J3 5[4	3r )--1&&&& &,&& +	&&
 $d?&& 
n	&&V <@!	   !11D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+`= 	`=
 `= TzD `= `= `=D.-cBKK.? .-d .-` {,,/"++,={,	tCH~tCH~-	.{, {,z &#T#s(^ &# &#Pc3h G G	03+< 	0D +sR[['8 + +$ % %2gcDIo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 /CRh .[ .""* 6r;   