Ë
    Aô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)Úfrom_avrational)ÚStream)Ú
VideoFrame)Úint32_t)Úmemcpyc                   óV  — 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ej                  fd	„«       Zej                  dej                  fd
„«       Zd„ Zdd„Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zed„ «       Zy)ÚVideoStreamc                 ó¼  — | j                  «       s'd| j                  j                  › dt        | «      d›d�S | 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.z (container closed) at 0xÚxú>z<av.VideoStream #z video/<nocodec> at 0xú z, z at 0x)
Ú_is_openÚ	__class__Ú__name__ÚidÚcodec_contextÚindexÚnameÚformatÚwidthÚheight©Úselfs    ú`/var/www/html/academy/tools/voices/clone/fw-venv/lib/python3.12/site-packages/av/video/stream.pyÚ__repr__zVideoStream.__repr__   sÕ   € Ø�}‰}Œà�t—~‘~×.Ñ.Ð/Ð/HÌÈDËÐRSÈÐTUÐVðð ×ÑÐ%Ø& 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Útyper   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                  t        j                  «       | 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`.
        )	Ú_assert_has_codec_contextÚlibÚAVERROR_ENCODER_NOT_FOUNDr   ÚencodeÚ_streamÚptrr   Ústream_index)r   r'   ÚpacketsÚpackets       r   r,   zVideoStream.encode'   s_   € ð 	×&Ñ&¤s×'DÑ'DÔEØ×$Ñ$×+Ñ+¨EÓ2ˆàò 	5ˆFØ!ˆFŒNØ&*§h¡h§n¡nˆF�J‰JÕ#ð	5ð ˆr   r1   c                 óX   — | j                  «        | 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)   r   Údecode)r   r1   s     r   r3   zVideoStream.decode8   s'   € ð 	×&Ñ&Ô(Ø×!Ñ!×(Ñ(¨Ó0Ð0r   Úreturnc                 óø   — t        j                  | «       | j                  �/| j                  j                  j                  | j                  _        | j                  �| j                  r| j                  «        y y y ©N)r   Ú_finalize_for_outputr   r.   r    Úavg_frame_rateÚ_has_display_matrixÚ_apply_display_matrixr   s    r   r7   z VideoStream._finalize_for_outputD   se   € ä×#Ñ# DÔ)Ø×ÑÐ)Ø&*×&8Ñ&8×&<Ñ&<×&FÑ&FˆD�H‰HÔ#ð ×ÑÐ)¨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   r*   Ú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   r:   z!VideoStream._apply_display_matrixN   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.
        NFr<   z+display matrix must have exactly 9 elementsT)r9   ÚintÚlenÚ
ValueErrorÚrangerH   )r   ÚmatrixÚvÚvalsÚis        r   Úset_display_matrixzVideoStream.set_display_matrix]   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)r*   Úav_display_rotation_setrH   ÚfloatÚav_display_matrix_flipÚboolr9   )r   ÚdegreesÚhflipÚvflips       r   Úset_display_rotationz VideoStream.set_display_rotationp   sH   € ô 	×#Ñ# D×$8Ñ$8¼5À»>¸/ÔJÜ×"Ñ" 4×#7Ñ#7¼¸e»ÄdÈ5ÃkÔRØ#'ˆÕ r   c                 ó`   — | j                  «        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: AVRational
        )Ú_assert_openr   r.   r8   r   s    r   Úaverage_ratezVideoStream.average_rate~   s%   € ð 	×ÑÔÜ˜tŸx™x×6Ñ6Ó7Ð7r   c                 ó`   — | j                  «        t        | 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: AVRational
        )r_   r   r.   Úr_frame_rater   s    r   Ú	base_ratezVideoStream.base_rate‹   s%   € ð 	×ÑÔÜ˜tŸx™x×4Ñ4Ó5Ð5r   c                 ó²   — | j                  «        t        j                  t        j                  | j
                  t        j                  «      }t        |«      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: AVRational
        )r_   r*   Úav_guess_frame_rater=   rE   r.   r   )r   Úvals     r   Úguessed_ratezVideoStream.guessed_rate™   s@   € ð 	×ÑÔÜ!×5Ñ5Ü�K‰K˜Ÿ™¤6§;¡;ó
ˆô ˜sÓ#Ð#r   c                 ó¾   — | j                  «        t        j                  | j                  j                  | j                  t
        j                  «      }t        |«      S )zõ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: AVRational
        )r_   r*   Úav_guess_sample_aspect_ratioÚ	containerr.   r=   rE   r   )r   Úsars     r   Úsample_aspect_ratiozVideoStream.sample_aspect_ratio¨   sF   € ð 	×ÑÔÜ!×>Ñ>Ø�N‰N×Ñ §¡¬&¯+©+ó
ˆô ˜sÓ#Ð#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        |«      S )z­The guessed display aspect ratio (DAR) of this stream.

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

        :type: AVRational
        i   )r=   Údeclarer*   Ú
AVRationalÚ	av_reducer@   ÚnumÚdenr   r   rl   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×!=Ñ!=Ñ=Øô	
ô ˜sÓ#Ð#r   r6   )FF)r   Ú
__module__Ú__qualname__r   r&   r=   Úccallr   r,   r   r3   ÚcfuncÚvoidr7   r:   rT   r]   Úpropertyr`   rc   rg   rl   rt   © r   r   r   r      s  „ ò
ò	1ð ‡\�\ñ˜J¨Ñ-ò ó ðð  ‡\�\ñ	1˜V d™]ò 	1ó ð	1ð ‡\�\ð) f§k¡kò )ó ð)ð ‡\�\ð1 v§{¡{ò 1ó ð1ò(ó&(ð ñ
8ó ð
8ð ñ6ó ð6ð ñ$ó ð$ð ñ$ó ð$ð ñ$ó ñ$r   r   )r=   Úcython.cimportsr   r*   Úcython.cimports.av.packetr   Úcython.cimports.av.rationalr   Úcython.cimports.av.streamr   Úcython.cimports.av.video.framer   Úcython.cimports.libc.stdintr   Úcython.cimports.libc.stringr	   ÚfinalÚcclassr   r{   r   r   ú<module>r…      sK   ðÛ Ý (Ý ,Ý 7Ý ,Ý 5Ý /Ý .ð ‡�Ø‡�ô{$�&ó {$ó ó ñ{$r   