
    VjiU                         d dl Z d dl mZ d dlmZmZmZ d dlmZ d Ze G d de                      Z	e G d d	e                      Z
e G d
 de                      ZdS )    N)	dataclass)IterableIteratorUnion)Tensorc                     | j         j        dz   }d}t          j        |           D ]5}|j        }t          | |          }|dk    r	d}|j        }|| | d| dz  }6|S )Nz:
z  datazdata (shape)z: 
)	__class____name__dataclassesfieldsnamegetattrshape)selfsspacesfield
field_name	field_vals         K/root/voice-cloning/.venv/lib/python3.11/site-packages/torchcodec/_frame.py_frame_reprr      s     	%'AF#D)) 4 4Z
D*--	'J!I	3
33i3333H    c                   l    e Zd ZU dZeed<   	 eed<   	 eed<   	 d Zdee	eef                  fdZ
d Zd	S )
Framez.A single video frame with associated metadata.r	   pts_secondsduration_secondsc                     | j         j        dk    st          d| j         j                  t	          | j                  | _        t	          | j                  | _        d S )N   z2data must be 3-dimensional, got self.data.shape = )r	   ndim
ValueErrorr   floatr   r   r   s    r   __post_init__zFrame.__post_init__)   sZ     y~""T	TTUUU !122 %d&; < <r   returnc              #   f   K   t          j        |           D ]}t          | |j                  V  d S Nr   r   r   r   r   r   s     r   __iter__zFrame.__iter__1   E       '-- 	, 	,E$
++++++	, 	,r   c                      t          |           S r(   r   r$   s    r   __repr__zFrame.__repr__5       4   r   N)r   
__module____qualname____doc__r   __annotations__r#   r%   r   r   r+   r/    r   r   r   r      s         88
LLL3;8= = =,(5#78 , , , ,! ! ! ! !r   r   c                   j    e Zd ZU dZeed<   	 eed<   	 eed<   	 d Zded          fdZddZ	d	 Z
d
 ZdS )
FrameBatcha  Multiple video frames with associated metadata.

    The ``data`` tensor is typically 4D for sequences of frames (NHWC or NCHW),
    or 5D for sequences of clips, as returned by the :ref:`samplers
    <sphx_glr_generated_examples_decoding_sampling.py>`. When ``data`` is 4D (resp.  5D)
    the ``pts_seconds`` and ``duration_seconds`` tensors are 1D (resp. 2D).

    .. note::
        The ``pts_seconds`` and ``duration_seconds`` Tensors are always returned
        on CPU, even if ``data`` is on GPU.
    r	   r   r   c                 @   | j         j        dk     rt          d| j         j                  | j         j        d d         }|| j        j        cxk    r| j        j        k    s<n t          d| j         j        d|d| j        j        d| j        j        d	          d S )	Nr    z;data must be at least 3-dimensional, got self.data.shape = zjTried to create a FrameBatch but the leading dimensions of the inputs do not match. Got self.data.shape = zS so we expected the shape of pts_seconds and duration_seconds to be leading_dims = z#, but got self.pts_seconds.shape = z# and self.duration_seconds.shape = .)r	   r!   r"   r   r   r   )r   leading_dimss     r   r%   zFrameBatch.__post_init__N   s     9>APDIOPP   yss+ 0 6UUUU$:O:UUUUUUyU U*6U U #)U U 483H3NU U U   VUr   r&   c              #      K   t          | j        | j        | j                  D ]\  }}}t	          |||          V  d S N)r	   r   r   )zipr	   r   r   r7   )r   r	   r   r   s       r   r+   zFrameBatch.__iter___   sq      36It')>4
 4
 	 	/D+/ '!1      	 	r   c                 h    t          | j        |         | j        |         | j        |                   S r=   )r7   r	   r   r   )r   keys     r   __getitem__zFrameBatch.__getitem__i   s8    3(-!237
 
 
 	
r   c                 *    t          | j                  S r(   )lenr	   r$   s    r   __len__zFrameBatch.__len__p   s    49~~r   c                      t          |           S r(   r.   r$   s    r   r/   zFrameBatch.__repr__s   r0   r   N)r&   r7   )r   r1   r2   r3   r   r4   r%   r   r+   rA   rD   r/   r5   r   r   r7   r7   9   s         
 
 LLL6PM  "(<0    
 
 
 
  ! ! ! ! !r   r7   c                   x    e Zd ZU dZeed<   	 eed<   	 eed<   	 eed<   	 d Zde	e
eef                  fdZd	 Zd
S )AudioSamplesz'Audio samples with associated metadata.r	   r   r   sample_ratec                     | j         j        dk    st          d| j         j                  t	          | j                  | _        t          | j                  | _        d S )N   z2data must be 2-dimensional, got self.data.shape = )r	   r!   r"   r   r#   r   intrH   r$   s    r   r%   zAudioSamples.__post_init__   sZ     y~""T	TTUUU !122t/00r   r&   c              #   f   K   t          j        |           D ]}t          | |j                  V  d S r(   r)   r*   s     r   r+   zAudioSamples.__iter__   r,   r   c                      t          |           S r(   r.   r$   s    r   r/   zAudioSamples.__repr__   r0   r   N)r   r1   r2   r3   r   r4   r#   rK   r%   r   r   r+   r/   r5   r   r   rG   rG   w   s         11
LLLk:201 1 1,(5#78 , , , ,! ! ! ! !r   rG   )r   r   typingr   r   r   torchr   r   r   r7   rG   r5   r   r   <module>rP      s       ! ! ! ! ! ! , , , , , , , , , ,          ! ! ! ! !H ! ! !4 :! :! :! :! :! :! :! :!z ! ! ! ! !8 ! ! ! ! !r   