
    +h                     b    S SK r S SKJrJrJr  S SKrS SKrS SKrSSK	J
r
JrJr   " S S\
5      rg)    N)ListOptionalUnion   )VaeImageProcessoris_valid_imageis_valid_image_imagelistc                       \ rS rSrSrSS\\   S\\   S\R                  4S jjr	 SS\R                  S	\
S\\R                  \R                  \\R                   R                      4   4S
 jj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  o@R!                  XBUS9PM     snSS9nUR#                  SS	S
SS5      nU$ s  snf )aR  
Preprocesses input video(s).

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.
r      zPassing `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)axiszPassing `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   imgs        S/home/james-whalen/.local/lib/python3.13/site-packages/diffusers/video_processor.pypreprocess_videoVideoProcessor.preprocess_video   s   2 eT""z%(BJJ'G'GERSHMM]^L^MMn
 NN5q1EeT""z%(ELL'I'IeTUhmm_`N`MMp
 IIe!,E
 ebjj%,,788UZZ1_KEt$$a)A)AE]^cEdEdGEt$$)A%()K)KEw  Y^_Y^RU__Su_MY^_efg aAq!, `s   G<r(   output_typec                 \   UR                   S   n/ n[        U5       H;  nX   R                  SSSS5      nU R                  Xb5      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$ )	z
Converts a video tensor to a list of frames for export.

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-   
batch_sizeoutputs	batch_idx	batch_vidbatch_outputs           r*   postprocess_video VideoProcessor.postprocess_videoY   s     [[^
z*I(00Aq!<I++ICLNN<( +
 $hhw'G  D kk'*G  %},efgg     )NN)r   )__name__
__module____qualname____firstlineno____doc__r   intr    r!   r+   strr   r   r   r   PILImager:   __static_attributes__r=   r<   r*   r   r      s|    ";hsm ;8TW= ;didpdp ;| 7;\\03	rzz5<<ciioo)>>	? r<   r   )r   typingr   r   r   numpyr   rE   r    image_processorr   r   r	   r   r=   r<   r*   <module>rK      s.     ( (  
  X XX& Xr<   