
    Hui                     t    d dl Z d dlmZ d dlmZ d dlmZmZ d dl	m
Z
 e j                   G d de             Zy)    N)libav)Packet)avrational_to_fractionto_avrational)
VideoFramec                       e Zd Zd Zd Zej                  ddedz  fd       Zej                  dde	dz  fd       Z
ed        Zed	        Zed
        Zed        Zed        Zy)VideoStreamc                     d| j                    d| j                   d| j                  r| j                  j                  nd  d| j                  j                   d| j                  j
                   dt        |       ddS )Nz<av.VideoStream # z, xz at 0x>)indexnameformatcodec_contextwidthheightidselfs    A/opt/pipecat/venv/lib/python3.12/site-packages/av/video/stream.py__repr__zVideoStream.__repr__
   sq    

|1TYYKr#';;t{{D94;M;M;S;S:TTU!!(()4|1>	
    c                     |dv r%t        dt        |       j                   d| d      t        | j                  |      S )N)	frameraterate'z' object has no attribute ')AttributeErrortype__name__getattrr   )r   r   s     r   __getattr__zVideoStream.__getattr__   sK    (( DJ''((CD6K  t))400r   Nframec                     | j                   j                  |      }|D ].  }| |_        | j                  j                  |j                  _        0 |S )z
        Encode an :class:`.VideoFrame` and return a list of :class:`.Packet`.

        :rtype: list[Packet]

        .. seealso:: This is mostly a passthrough to :meth:`.CodecContext.encode`.
        )r   encode_streamptrr   stream_index)r   r#   packetspackets       r   r%   zVideoStream.encode   sK     $$++E2 	5F!FN&*hhnnFJJ#	5 r   r*   c                 8    | j                   j                  |      S )z
        Decode a :class:`.Packet` and return a list of :class:`.VideoFrame`.

        :rtype: list[VideoFrame]

        .. seealso:: This is a passthrough to :meth:`.CodecContext.decode`.
        )r   decode)r   r*   s     r   r,   zVideoStream.decode*   s     !!((00r   c                 f    t        t        j                  | j                  j                              S )z
        The average frame rate of this video stream.

        This is calculated when the file is opened by looking at the first
        few frames and averaging their rate.

        :type: fractions.Fraction | None
        )r   cythonaddressr'   avg_frame_rater   s    r   average_ratezVideoStream.average_rate5   s"     &fnnTXX5L5L&MNNr   c                 f    t        t        j                  | j                  j                              S )a  
        The base frame rate of this stream.

        This is calculated as the lowest framerate at which the timestamps of
        frames can be represented accurately. See :ffmpeg:`AVStream.r_frame_rate`
        for more.

        :type: fractions.Fraction | None
        )r   r.   r/   r'   r_frame_rater   s    r   	base_ratezVideoStream.base_rateA   s"     &fnnTXX5J5J&KLLr   c                     t        j                  t        j                  | j                  t        j                        }t        t        j                  |            S )zThe guessed frame rate of this stream.

        This is a wrapper around :ffmpeg:`av_guess_frame_rate`, and uses multiple
        heuristics to decide what is "the" frame rate.

        :type: fractions.Fraction | None
        )libav_guess_frame_rater.   NULLr'   r   r/   )r   vals     r   guessed_ratezVideoStream.guessed_rateN   s=     "55KK6;;
 &fnnS&9::r   c                     t        j                  | j                  j                  | j                  t        j
                        }t        t	        j                  |            S )a  The guessed sample aspect ratio (SAR) of this stream.

        This is a wrapper around :ffmpeg:`av_guess_sample_aspect_ratio`, and uses multiple
        heuristics to decide what is "the" sample aspect ratio.

        :type: fractions.Fraction | None
        )r6   av_guess_sample_aspect_ratio	containerr'   r.   r8   r   r/   )r   sars     r   sample_aspect_ratiozVideoStream.sample_aspect_ratio\   sC     ">>NN&++
 &fnnS&9::r   c                    t        j                  t        j                        }t        j                  t        j
                  |j                        t        j
                  |j                        | j                  j                  | j                  j                  z  | j                  j                  | j                  j                  z  d       t        t        j
                  |            S )zThe guessed display aspect ratio (DAR) of this stream.

        This is calculated from :meth:`.VideoStream.guessed_sample_aspect_ratio`.

        :type: fractions.Fraction | None
        i   )r.   declarer6   
AVRational	av_reducer/   numdenr   r   r?   r   r   )r   dars     r   display_aspect_ratioz VideoStream.display_aspect_ratioj   s     nnS^^,NN377#NN377#KK 8 8 < <<KK!9!9!=!==	
 &fnnS&9::r   )N)r    
__module____qualname__r   r"   r.   ccallr   r%   r   r,   propertyr1   r4   r:   r?   rG    r   r   r	   r	      s    
1 \\J-    \\1Vd] 1 1 	O 	O 
M 
M ; ; ; ; ; ;r   r	   )r.   cython.cimportsr   r6   cython.cimports.av.packetr   cython.cimports.av.utilsr   r   cython.cimports.av.video.framer   cclassStreamr	   rL   r   r   <module>rS      s6     ( , J 5 r;& r; r;r   