ó
    oM‡j¡   ã                   ó`   • S SK r S SKrS SKrS SKrS SKJs  Jr  SSK	J
r
JrJr   " S S\
5      rg)é    Né   )ÚVaeImageProcessorÚis_valid_imageÚis_valid_image_imagelistc                   ó^  • \ rS rSrSrSS\S-  S\S-  S\R                  4S jjr SS\R                  S	\	S\
R                  \R                  -  \\R                  R                     -  4S
 jjr\S\S\S\S\\\4   4S j5       r\S\R                  S\S\S\R                  4S j5       rSrg)ÚVideoProcessoré   zSimple video processor.NÚheightÚwidthÚreturnc                 ó  • [        U[        5      (       ae  [        US   [        R                  5      (       aC  US   R                  S:X  a0  [
        R                  " S[        5        [        R                  " USS9n[        U[        5      (       ae  [        US   [        R                  5      (       aC  US   R                  S:X  a0  [
        R                  " S[        5        [        R                  " USS9n[        U[        R                  [        R                  45      (       a  UR                  S:X  a  [        U5      nOr[        U[        5      (       a  [        US   5      (       d  [        U5      (       a  U/nO6[        U[        5      (       a  [        US   5      (       a  UnO[        S5      e[        R                  " U Vs/ s H  oPR                   " U4X#S.UD6PM     snSS9nUR#                  SS	S
SS5      nU$ s  snf )a9  
Preprocesses input video(s). Keyword arguments will be forwarded to `VaeImageProcessor.preprocess`.

Args:
    video (`list[PIL.Image]`, `list[list[PIL.Image]]`, `torch.Tensor`, `np.array`, `list[torch.Tensor]`, `list[np.array]`):
        The input video. It can be one of the following:
        * list of the PIL images.
        * list of list of PIL images.
        * 4D Torch tensors (expected shape for each tensor `(num_frames, num_channels, height, width)`).
        * 4D NumPy arrays (expected shape for each array `(num_frames, height, width, num_channels)`).
        * list of 4D Torch tensors (expected shape for each tensor `(num_frames, num_channels, height,
          width)`).
        * list of 4D NumPy arrays (expected shape for each array `(num_frames, height, width, num_channels)`).
        * 5D NumPy arrays: expected shape for each array `(batch_size, num_frames, height, width,
          num_channels)`.
        * 5D Torch tensors: expected shape for each array `(batch_size, num_frames, num_channels, height,
          width)`.
    height (`int`, *optional*, defaults to `None`):
        The height in preprocessed frames of the video. If `None`, will use the `get_default_height_width()` to
        get default height.
    width (`int`, *optional*`, defaults to `None`):
        The width in preprocessed frames of the video. If `None`, will use get_default_height_width()` to get
        the default width.

Returns:
    `torch.Tensor` of shape `(batch_size, num_channels, num_frames, height, width)`:
        A 5D tensor holding the batched channels-first video(s).
r   é   z”Passing `video` as a list of 5d np.ndarray is deprecated.Please concatenate the list along the batch dimension and pass it as a single 5d np.ndarray)Úaxisz˜Passing `video` as a list of 5d torch.Tensor is deprecated.Please concatenate the list along the batch dimension and pass it as a single 5d torch.TensorzeInput is in incorrect format. Currently, we only support numpy.ndarray, torch.Tensor, PIL.Image.Image)r
   r   )Údimé   r   é   é   )Ú
isinstanceÚlistÚnpÚndarrayÚndimÚwarningsÚwarnÚFutureWarningÚconcatenateÚtorchÚTensorÚcatr   r   Ú
ValueErrorÚstackÚ
preprocessÚpermute)ÚselfÚvideor
   r   ÚkwargsÚimgs         Ú§C:\Users\johnn\AppData\Local\Packages\PythonSoftwareFoundation.Python.3.13_qbz5n2kfra8p0\LocalCache\local-packages\Python313\site-packages\diffusers/video_processor.pyÚpreprocess_videoÚVideoProcessor.preprocess_video   sŸ  € ô: �eœT×"Ñ"¤z°%¸±(¼B¿J¹J×'GÑ'GÈEÐRSÉHÏMÉMÐ]^ÓL^Ü�MŠMðnäôô
 —N’N 5¨qÑ1ˆEÜ�eœT×"Ñ"¤z°%¸±(¼E¿L¹L×'IÑ'IÈeÐTUÉhÏmÉmÐ_`ÓN`Ü�MŠMðpäôô
 —I’I˜e¨!Ñ,ˆEô
 �eœbŸj™j¬%¯,©,Ð7×8Ñ8¸U¿Z¹ZÈ1»_Ü˜“K‰EÜ˜œt×$Ñ$¬¸¸a¹×)AÑ)AÔE]Ð^c×EdÑEdØ�G‰EÜ˜œt×$Ñ$Ô)AÀ%ÈÁ(×)KÑ)KØ‰EäØwóð ô —’ÑchÓiÒchÐ\_Ÿ_š_¨SÐW¸ÑWÐPVÔWÑchÑiÐopÑqˆð —‘˜a  A q¨!Ó,ˆàˆùò js   ÇHr%   Úoutput_typec                 ó`  • UR                   S   n/ n[        U5       H=  nX   R                  SSSS5      nU R                  " Xr40 UD6nUR	                  U5        M?     US:X  a  [
        R                  " U5      nU$ US:X  a  [        R                  " U5      nU$ US:X  d  [        U S35      eU$ )	a  
Converts a video tensor to a list of frames for export. Keyword arguments will be forwarded to
`VaeImageProcessor.postprocess`.

Args:
    video (`torch.Tensor`): The video as a tensor.
    output_type (`str`, defaults to `"np"`): Output type of the postprocessed `video` tensor.
r   r   r   r   r   ÚptÚpilz9 does not exist. Please choose one of ['np', 'pt', 'pil'])	ÚshapeÚranger#   ÚpostprocessÚappendr   r!   r   r    )	r$   r%   r+   r&   Ú
batch_sizeÚoutputsÚ	batch_idxÚ	batch_vidÚbatch_outputs	            r(   Úpostprocess_videoÚ VideoProcessor.postprocess_video]   s¿   € ð —[‘[ ‘^ˆ
ØˆÜ˜zÖ*ˆIØÑ(×0Ñ0°°A°q¸!Ó<ˆIØ×+Ò+¨IÑMÀfÑMˆLØ�N‰N˜<Ö(ñ +ð
 ˜$ÓÜ—h’h˜wÓ'ˆGð ˆð ˜DÓ Ü—k’k 'Ó*ˆGð ˆð  Ó%Ü ˜}Ð,eÐfÓgÐgàˆó    Úratiosc                 ó–   ^• [        X-  5      m[        UR                  5       U4S jS9nX#   n[        US   5      [        US   5      4$ )aN  
Returns the binned height and width based on the aspect ratio.

Args:
    height (`int`): The height of the image.
    width (`int`): The width of the image.
    ratios (`dict`): A dictionary where keys are aspect ratios and values are tuples of (height, width).

Returns:
    `tuple[int, int]`: The closest binned height and width.
c                 ó2   >• [        [        U 5      T-
  5      $ )N)ÚabsÚfloat)ÚratioÚars    €r(   Ú<lambda>Ú:VideoProcessor.classify_height_width_bin.<locals>.<lambda>†   s   ø€ ¼SÄÀuÃÐPRÑARÔ=Sr:   )Úkeyr   r   )r?   ÚminÚkeysÚint)r
   r   r;   Úclosest_ratioÚ
default_hwrA   s        @r(   Úclassify_height_width_binÚ(VideoProcessor.classify_height_width_binx   sI   ø€ ô �6‘>Ó"ˆÜ˜FŸK™K›MÔ/SÑTˆØÑ*ˆ
Ü�:˜a‘=Ó!¤3 z°!¡}Ó#5Ð5Ð5r:   ÚsamplesÚ	new_widthÚ
new_heightc                 óà  • U R                   S   U R                   S   pCX2:w  d  XA:w  aÆ  [        X#-  X-  5      n[        XE-  5      n[        X5-  5      nU R                   u  p‰p«nU R                  SSSSS5      R	                  XŠ-  X›U5      n [
        R                  " XU4SSS9n Xa-
  S-  nXÑ-   nXr-
  S-  nXò-   nU S	S	2S	S	2UU2XÞ24   n U R	                  XŠX’U5      R                  SSSSS5      n U $ )
aä  
Resizes and crops a tensor of videos to the specified dimensions.

Args:
    samples (`torch.Tensor`):
        A tensor of shape (N, C, T, H, W) where N is the batch size, C is the number of channels, T is the
        number of frames, H is the height, and W is the width.
    new_width (`int`): The desired width of the output videos.
    new_height (`int`): The desired height of the output videos.

Returns:
    `torch.Tensor`: A tensor containing the resized and cropped videos.
r   r   r   r   r   ÚbilinearF)ÚsizeÚmodeÚalign_cornersN)r/   ÚmaxrG   r#   ÚreshapeÚFÚinterpolate)rL   rM   rN   Úorig_heightÚ
orig_widthr@   Úresized_widthÚresized_heightÚnÚcÚtÚhÚwÚstart_xÚend_xÚstart_yÚend_ys                    r(   Úresize_and_crop_tensorÚ%VideoProcessor.resize_and_crop_tensorŠ   s   € ð #*§-¡-°Ñ"2°G·M±MÀ!Ñ4D�Zð Ó$¨
Ó(?Ü˜
Ñ0°)Ñ2HÓIˆEÜ 
Ñ 2Ó3ˆMÜ  Ñ!4Ó5ˆNð $ŸM™M‰MˆA�!˜Ø—o‘o a¨¨A¨q°!Ó4×<Ñ<¸Q¹UÀAÈ!ÓLˆGô —m’mØ¨}Ð=ÀJÐ^cñˆGð
 %Ñ0°QÑ6ˆGØÑ'ˆEØ%Ñ2°qÑ8ˆGØÑ(ˆEØša¢ G¨E M°7°=Ð@ÑAˆGð —o‘o a¨A¸9ÓE×MÑMÈaÐQRÐTUÐWXÐZ[Ó\ˆGàˆr:   © )NN)r   )Ú__name__Ú
__module__Ú__qualname__Ú__firstlineno__Ú__doc__rG   r   r   r)   Ústrr   r   r   ÚPILÚImager8   ÚstaticmethodÚdictÚtuplerJ   re   Ú__static_attributes__rg   r:   r(   r   r      së   † Ù"ñ?¨c°D©jð ?ÈÈdÉ
ð ?Ðhm×htÑhtõ ?ðD 7;ñØ—\‘\ðØ03ðà	�‰�e—l‘lÑ	" T¨#¯)©)¯/©/Ñ%:Ñ	:õð6 ð6¨#ð 6°cð 6À4ð 6ÈEÐRUÐWZÐRZÉOó 6ó ð6ð" ð)¨¯©ð )Àð )ÐRUð )ÐZ_×ZfÑZfó )ó ó)r:   r   )r   Únumpyr   rn   r   Útorch.nn.functionalÚnnÚ
functionalrV   Úimage_processorr   r   r   r   rg   r:   r(   Ú<module>ry      s.   ðó ã Û 
Û ß Ð ç XÑ Xô[Ð&õ [r:   