Ë
    ÛÍ:jä  ã                   ó²   — d dl Z d dlmZ d dlmZ d dlmZ d dlm	Z	 d dl
mZ d dlmZ d dlmZ e j                   e j"                   G d	„ d
e«      «       «       Zy)é    N)Úlibav)ÚPacket)ÚStream)Úavrational_to_fraction)Ú
VideoFrame)Úint32_t)Úmemcpyc                   ó"  — 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j                  d„ «       Zej                  d	„ «       Zd
„ Zdd„Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zy)ÚVideoStreamc                 óN  — | j                   €d| j                  › dt        | «      d›d�S 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 video/<nocodec> at 0xÚxú>ú z, z at 0x)Úcodec_contextÚindexÚidÚnameÚformatÚwidthÚheight©Úselfs    úd/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/av/video/stream.pyÚ__repr__zVideoStream.__repr__   sŸ   € Ø×ÑÐ%Ø& t§z¡z lÐ2HÌÈDËÐRSÈÐTUÐVÐVà §
¡
˜|¨1¨T¯Y©Y¨K°rØ#'§;¢;ˆt�{‰{×Ò°DÐ9¸¸4×;MÑ;M×;SÑ;SÐ:TÐTUØ×!Ñ!×(Ñ(Ð)¨´°4³¸¨|¸1ð>ð	
ó    c                 óâ   — |dv r%t        dt        | «      j                  › d|› d�«      ‚| j                  €%t        dt        | «      j                  › d|› d�«      ‚t	        | j                  |«      S )N)Ú	framerateÚrateú'z' object has no attribute ')ÚAttributeErrorÚtypeÚ__name__r   Úgetattr)r   r   s     r   Ú__getattr__zVideoStream.__getattr__   s„   € ØÐ(Ñ(Ü Ø”D˜“J×'Ñ'Ð(Ð(CÀDÀ6ÈÐKóð ð ×ÑÐ%Ü Ø”D˜“J×'Ñ'Ð(Ð(CÀDÀ6ÈÐ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ˆàò 	5ˆFØ!ˆFŒNØ&*§h¡h§n¡nˆF�J‰JÕ#ð	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.decode3   s   € ð ×!Ñ!×(Ñ(¨Ó0Ð0r   c                 ó‚   — t        j                  | «       | j                  �| j                  r| j	                  «        y y y ©N)r   Ú_finalize_for_outputr   Ú_has_display_matrixÚ_apply_display_matrixr   s    r   r1   z VideoStream._finalize_for_output>   s;   € ä×#Ñ# DÔ)ð ×ÑÐ)¨d×.FÒ.FØ×&Ñ&Õ(ð /GÐ)r   c                 óÌ  — dt        j                  t        «      z  }t        j                  t        j
                  | j                  j                  j                  «      t        j
                  | j                  j                  j                  «      t        j                  |d«      }|t         j                  k(  rt        d«      ‚t        |j                  | j                  |«       y )Né	   r   z+could not allocate display matrix side data)ÚcythonÚsizeofr   ÚlibÚav_packet_side_data_newÚaddressr)   ÚcodecparÚcoded_side_dataÚnb_coded_side_dataÚAV_PKT_DATA_DISPLAYMATRIXÚNULLÚMemoryErrorr	   ÚdataÚ_display_matrix)r   ÚnÚsds      r   r3   z!VideoStream._apply_display_matrixF   sœ   € àœFŸM™M¬'Ó2Ñ2ˆÜ36×3NÑ3NÜ�N‰N˜4Ÿ8™8×,Ñ,×<Ñ<Ó=Ü�N‰N˜4Ÿ8™8×,Ñ,×?Ñ?Ó@Ü×)Ñ)ØØó4
ˆð ”—‘ÒÜÐKÓLÐLäˆr�w‰w˜×,Ñ,¨aÕ0r   c                 óÖ   — |€d| _         y|D �cg c]  }t        |«      ‘Œ }}t        |«      dk7  rt        d«      ‚t	        d«      D ]  }||   | j
                  |<   Œ d| _         yc c}w )aB  Set the display matrix written to the container as coded side data.

        ``matrix`` is a sequence of 9 integers in FFmpeg's ``AV_PKT_DATA_DISPLAYMATRIX``
        layout, or ``None`` to clear. Must be called before the first frame is
        encoded. See :meth:`set_display_rotation` for a higher-level helper.
        NFr5   z+display matrix must have exactly 9 elementsT)r2   ÚintÚlenÚ
ValueErrorÚrangerB   )r   ÚmatrixÚvÚvalsÚis        r   Úset_display_matrixzVideoStream.set_display_matrixU   sv   € ð ˆ>Ø',ˆDÔ$Øà &Ö'˜1”�A•Ð'ˆÐ'Üˆt‹9˜Š>ÜÐJÓKÐKä�q“ò 	.ˆAØ&*¨1¡gˆD× Ñ  Ò#ð	.à#'ˆÕ ùò (s   �A&c                 óÌ   — t        j                  | j                  t        |«       «       t        j                  | j                  t        |«      t        |«      «       d| _        y)ah  Set the container display matrix from a rotation and optional flips.

        ``degrees`` is a counter-clockwise rotation (matching the value read back
        from :attr:`VideoFrame.rotation`); ``hflip`` / ``vflip`` mirror after it.
        Together these express all eight EXIF orientations. Must be called before
        the first frame is encoded.
        TN)r8   Úav_display_rotation_setrB   ÚfloatÚav_display_matrix_flipÚboolr2   )r   ÚdegreesÚhflipÚvflips       r   Úset_display_rotationz VideoStream.set_display_rotationh   sH   € ô 	×#Ñ# D×$8Ñ$8¼5À»>¸/ÔJÜ×"Ñ" 4×#7Ñ#7¼¸e»ÄdÈ5ÃkÔRØ#'ˆÕ r   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   r6   r:   r)   Úavg_frame_rater   s    r   Úaverage_ratezVideoStream.average_ratev   s"   € ô &¤f§n¡n°T·X±X×5LÑ5LÓ&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   r6   r:   r)   Úr_frame_rater   s    r   Ú	base_ratezVideoStream.base_rate‚   s"   € ô &¤f§n¡n°T·X±X×5JÑ5JÓ&KÓLÐLr   c                 ó¸   — t        j                  t        j                  | j                  t        j                  «      }t        t        j                  |«      «      S )zãThe 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
        )r8   Úav_guess_frame_rater6   r?   r)   r   r:   )r   Úvals     r   Úguessed_ratezVideoStream.guessed_rate�   s=   € ô "×5Ñ5Ü�K‰K˜Ÿ™¤6§;¡;ó
ˆô &¤f§n¡n°SÓ&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
        )r8   Úav_guess_sample_aspect_ratioÚ	containerr)   r6   r?   r   r:   )r   Úsars     r   Úsample_aspect_ratiozVideoStream.sample_aspect_ratio�   sC   € ô "×>Ñ>Ø�N‰N×Ñ §¡¬&¯+©+ó
ˆô &¤f§n¡n°SÓ&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 )z¼The guessed display aspect ratio (DAR) of this stream.

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

        :type: fractions.Fraction | None
        i   )r6   Údeclarer8   Ú
AVRationalÚ	av_reducer:   ÚnumÚdenr   r   rf   r   r   )r   Údars     r   Údisplay_aspect_ratioz VideoStream.display_aspect_ratio«   s—   € ô �n‰nœSŸ^™^Ó,ˆÜ�‰Ü�N‰N˜3Ÿ7™7Ó#Ü�N‰N˜3Ÿ7™7Ó#Ø�K‰K×Ñ × 8Ñ 8× <Ñ <Ñ<Ø�K‰K×Ñ ×!9Ñ!9×!=Ñ!=Ñ=Øô	
ô &¤f§n¡n°SÓ&9Ó:Ð:r   r0   )FF)r"   Ú
__module__Ú__qualname__r   r$   r6   Úccallr   r'   r   r.   Úcfuncr1   r3   rN   rW   ÚpropertyrZ   r]   ra   rf   rn   © r   r   r   r      sõ   „ ò
ò	1ð ‡\�\ñ˜J¨Ñ-ò ó ðð  ‡\�\ñ1˜V d™]ò 1ó ð1ð ‡\�\ñ)ó ð)ð ‡\�\ñ1ó ð1ò(ó&(ð ñ	Oó ð	Oð ñ
Mó ð
Mð ñ;ó ð;ð ñ;ó ð;ð ñ;ó ñ;r   r   )r6   Úcython.cimportsr   r8   Úcython.cimports.av.packetr   Úcython.cimports.av.streamr   Úcython.cimports.av.utilsr   Úcython.cimports.av.video.framer   Úcython.cimports.libc.stdintr   Úcython.cimports.libc.stringr	   ÚfinalÚcclassr   rt   r   r   ú<module>r~      sK   ðÛ Ý (Ý ,Ý ,Ý ;Ý 5Ý /Ý .ð ‡�Ø‡�ôo;�&ó o;ó ó ño;r   