o
    ]i                     @   sV   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 deZdS )    N)libav)Packet)avrational_to_fractionto_avrational)
VideoFramec                   @   s   e Zd Zdd Zdd ZejddedB fddZejdd	e	dB fd
dZ
edd Zedd Zedd Zedd Zedd ZdS )VideoStreamc                 C   sJ   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self r   C/home/ubuntu/.local/lib/python3.10/site-packages/av/video/stream.py__repr__
   s   zVideoStream.__repr__c                 C   s0   |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   r   r   r   __getattr__   s
   zVideoStream.__getattr__Nframec                 C   s,   | j |}|D ]}| |_| jj|j_q|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packetr   r   r   r       s
   
zVideoStream.encoder%   c                 C   s   | 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%   r   r   r   r&   *   s   	zVideoStream.decodec                 C      t t| 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   r   r   r   average_rate5   s   
zVideoStream.average_ratec                 C   r'   )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   r   r   r   	base_rateA   s   zVideoStream.base_ratec                 C   s"   t tj| jtj}tt|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   valr   r   r   guessed_rateN   s   	zVideoStream.guessed_ratec                 C   s$   t | jj| jtj}tt|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
        )r.   av_guess_sample_aspect_ratio	containerr"   r(   r0   r   r)   )r   sarr   r   r   sample_aspect_ratio\   s   	zVideoStream.sample_aspect_ratioc                 C   sT   t tj}tt |jt |j| jj	| j
j | jj| j
j d tt |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(   declarer.   
AVRational	av_reducer)   numdenr   r   r6   r   r   )r   darr   r   r   display_aspect_ratioj   s   

z VideoStream.display_aspect_ratio)N)r   
__module____qualname__r   r   r(   ccallr   r    r   r&   propertyr+   r-   r2   r6   r=   r   r   r   r   r      s"    




r   )r(   cython.cimportsr   r.   cython.cimports.av.packetr   cython.cimports.av.utilsr   r   cython.cimports.av.video.framer   cclassStreamr   r   r   r   r   <module>   s    