Ë
    ÛÍ:jT.  ã                   óà  — d dl Z d dlmc 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mZ d dlmZmZmZ d d	lmZmZ d d
lmZ d dlmZ e j:                   e j<                  d¬«      de j>                  ej@                     de j>                  e jB                  ejD                        dejD                  fd„«       «       Z#e jH                  e jJ                   G d„ de«      «       «       Z&y)é    N)ÚCodecContext)ÚHWAccel)Ú	err_check)ÚFrame)ÚPacket)Úavrational_to_fractionÚto_avrational)ÚVideoFormatÚget_pix_fmtÚget_video_format)Ú
VideoFrameÚalloc_video_frame)ÚVideoReformatter)Úint64_tF)ÚcheckÚctxÚpix_fmtsÚreturnc                 ó  — t        j                  t         j                  t           | j                  «      }d}||   dk7  r%||   |j
                  k(  r||   S |dz  }||   dk7  rŒ%|j                  r| j                  S t        j                  S )Nr   éÿÿÿÿé   )
ÚcythonÚcastÚpointerÚAVCodecPrivateDataÚopaqueÚhardware_pix_fmtÚallow_software_fallbackÚ
sw_pix_fmtÚlibÚAV_PIX_FMT_NONE)r   r   Úprivate_dataÚis       új/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/av/video/codeccontext.pyÚ_get_hw_formatr%      s�   € ô 8>·{±{Ü�‰Ô)Ñ*¨C¯J©Jó8€Lð €AØ
�1‰+˜Ò
Ø�A‰;˜,×7Ñ7Ò7Ø˜A‘;ÐØ	ˆQ‰ˆð �1‰+˜Ó
ð
 '×>Ò>ˆ�‰ðÜDG×DWÑDWðó    c                   ó¬  — e Zd Zej                  dej
                  ej                     dej
                  ej                  ej                        de
dz  fd„«       Zej                  dedz  defd„«       Zej                  defd	„«       Zej                  d
edefd„«       Zej                  d
efd„«       Zed„ «       Zej*                  defd„«       Zed„ «       Zej*                  dej0                  fd„«       Zed„ «       Zej*                  dej0                  fd„«       Zed„ «       Zej*                  dej6                  fd„«       Zed„ «       Zej*                  d„ «       Zed„ «       Zej*                  d„ «       Zed„ «       Zej*                  d„ «       Zed„ «       Zej*                  dej6                  fd„«       Zed „ «       Z e j*                  d!„ «       Z ed"„ «       Z!ed#„ «       Z"ed$„ «       Z#e#j*                  dej6                  fd%„«       Z#ed&„ «       Z$ed'„ «       Z%ed(„ «       Z&e&j*                  d)„ «       Z&ed*„ «       Z'e'j*                  d+„ «       Z'ed,„ «       Z(e(j*                  d-„ «       Z(ed.„ «       Z)e)j*                  d/„ «       Z)ed0„ «       Z*e*j*                  d1„ «       Z*ed2„ «       Z+e+j*                  d3„ «       Z+ed4„ «       Z,e,j*                  d5„ «       Z,y)6ÚVideoCodecContextÚptrÚcodecÚhwaccelNc                 óÎ  — t        j                  | |||«       |��4	 |j                  | j                  «      | _        t        j                  | j                  j                  «      | j                  _        | j                  j                  j                  j                  | j                  _
        t        | j                  _        | j                  j                  j                  j                  | j                  _        | j                  j                   | j                  _        t#        j$                  | j                  «      | j                  _        y y # t(        $ r
 d | _        Y y w xY w©N)r   Ú_initÚcreater*   Úhwaccel_ctxr    Úav_buffer_refr)   Úhw_device_ctxÚconfigÚpix_fmtr%   Ú
get_formatÚ_private_datar   r+   r   r   Úaddressr   ÚNotImplementedError)Úselfr)   r*   r+   s       r$   r.   zVideoCodecContext._init+   s  € ô 	×Ñ˜4  e¨WÔ5àÑð(Ø#*§>¡>°$·*±*Ó#=�Ô Ü),×):Ñ):¸4×;KÑ;K×;OÑ;OÓ)P�—‘Ô&Ø#'×#3Ñ#3×#:Ñ#:×#>Ñ#>×#FÑ#F�—‘Ô Ü&4�—‘Ô#à×$Ñ$×+Ñ+×/Ñ/×7Ñ7ð ×"Ñ"Ô3ð —L‘L×8Ñ8ð ×"Ñ"Ô:ô #)§.¡.°×1CÑ1CÓ"D�—‘•ð øô 'ò 	(ð $(�Ö ð	(ús   �D2E ÅE$Å#E$Úinputr   c                 ó†  — |�|sd gS |}|j                   j                  | j                  k7  sF|j                  | j                  j                  k7  s#|j                  | j                  j                  k7  r�| j
                  st        «       | _        | j
                  j                  || j                  j                  | j                  j                  | j                   | j                  j                  ¬«      }|j                  j                  t        j                  k(  r%| j                  j                  |j                  _	        |gS )N)Úthreads)Úformatr4   Úwidthr)   ÚheightÚreformatterr   ÚreformatÚthread_countÚptsr    ÚAV_NOPTS_VALUEÚ	frame_num)r9   r:   Úvframes      r$   Ú_prepare_frames_for_encodez,VideoCodecContext._prepare_frames_for_encodeL   sã   € àˆ=¡Ø�6ˆMà"ˆà�M‰M×!Ñ! T§\¡\Ò1Ø�|‰|˜tŸx™xŸ~™~Ò-Ø�}‰} §¡§¡Ò/à×#Ò#Ü#3Ó#5�Ô à×%Ñ%×.Ñ.ØØ—‘—‘Ø—‘—‘Ø—‘ØŸ™×-Ñ-ð /ó ˆFð �:‰:�>‰>œS×/Ñ/Ò/Ø!ŸX™X×/Ñ/ˆF�J‰JŒNàˆxˆr&   c                 ó   — t        «       S r-   )r   ©r9   s    r$   Ú_alloc_next_framez#VideoCodecContext._alloc_next_frameg   s   € ä Ó"Ð"r&   ÚframeÚpacketc                 óV   — t        j                  | ||«       |}|j                  «        y r-   )r   Ú_setup_decoded_frameÚ_init_user_attributes)r9   rK   rL   rF   s       r$   rN   z&VideoCodecContext._setup_decoded_framek   s%   € ä×)Ñ)¨$°°vÔ>Ø"ˆØ×$Ñ$Õ&r&   c                 óè  — | j                   €|S |j                  j                  | j                   j                  j                  j                  k7  r|S | j                   j
                  r5| j                   j                  t        j                  t        |«      _
        |S | j                  «       }t        t        j                  |j                  |j                  d«      «       |j                  |_        |S ©Nr   )r0   r)   r=   r3   r4   Úis_hw_ownedÚ	device_idr   r   r   Ú
_device_idrJ   r   r    Úav_hwframe_transfer_datarC   )r9   rK   Úframe_sws      r$   Ú_transfer_hwframez#VideoCodecContext._transfer_hwframeq   s´   € à×ÑÐ#ØˆLØ�9‰9×Ñ˜t×/Ñ/×6Ñ6×:Ñ:×BÑBÒBð ˆLà×Ñ×'Ò'Ø8<×8HÑ8H×8RÑ8RŒF�K‰Kœ
 EÓ*Ô5ØˆLà×0Ñ0Ó2ˆÜ”#×.Ñ.¨x¯|©|¸U¿Y¹YÈÓJÔKà—y‘yˆŒØˆr&   c                 óØ   — t        t        j                  t        j                  | j
                  j                  «      | j
                  j                  | j
                  j                  «      S r-   )	r   r   r   r    ÚAVPixelFormatr)   r4   r>   r?   rI   s    r$   r=   zVideoCodecContext.format„   sC   € äÜ�K‰Kœ×)Ñ)¨4¯8©8×+;Ñ+;Ó<Ø�H‰H�N‰NØ�H‰H�O‰Oó
ð 	
r&   r=   c                 ó¦   — |j                   | j                  _         |j                  | j                  _        |j                  | j                  _        y r-   )r4   r)   r>   r?   )r9   r=   s     r$   r=   zVideoCodecContext.formatŒ   s0   € à!Ÿ>™>ˆ�‰ÔØŸ™ˆ�‰ŒØ Ÿ-™-ˆ�‰�r&   c                 óh   — | j                   t        j                  u ry| j                   j                  S rQ   )r)   r   ÚNULLr>   rI   s    r$   r>   zVideoCodecContext.width’   s#   € à�8‰8”v—{‘{Ñ"ØØ�x‰x�~‰~Ðr&   Úvaluec                 ó&   — || j                   _        y r-   )r)   r>   ©r9   r]   s     r$   r>   zVideoCodecContext.width˜   s   € àˆ�‰�r&   c                 óh   — | j                   t        j                  u ry| j                   j                  S rQ   )r)   r   r\   r?   rI   s    r$   r?   zVideoCodecContext.heightœ   s#   € à�8‰8”v—{‘{Ñ"ØØ�x‰x�‰Ðr&   c                 ó&   — || j                   _        y r-   )r)   r?   r_   s     r$   r?   zVideoCodecContext.height¢   s   € àˆ�‰�r&   c                 ó.   — | j                   j                  S )zÜ
        The number of bits per sample in the codedwords. It's mandatory for this to be set for some formats to decode properly.

        Wraps :ffmpeg:`AVCodecContext.bits_per_coded_sample`.

        :type: int
        )r)   Úbits_per_coded_samplerI   s    r$   rc   z'VideoCodecContext.bits_per_coded_sample¦   s   € ð �x‰x×-Ñ-Ð-r&   c                 óT   — | j                   rt        d«      ‚|| j                  _        y )NzNot supported for encoders)Ú
is_encoderÚ
ValueErrorr)   rc   r_   s     r$   rc   z'VideoCodecContext.bits_per_coded_sample±   s!   € à�?Š?ÜÐ9Ó:Ð:à).ˆ�‰Õ&r&   c                 óà   — t        j                  t        j                  t         j                  | j
                  j                  «      «      }t        j                  t        |j                  «      S )zE
        The pixel format's name.

        :type: str | None
        )	r    Úav_pix_fmt_desc_getr   r   rY   r)   r4   ÚstrÚname)r9   Údescs     r$   r4   zVideoCodecContext.pix_fmt¸   sI   € ô ×#Ñ#¤F§K¡K´×0AÑ0AÀ4Ç8Á8×CSÑCSÓ$TÓUð 	ô �{‰{œ3 §	¡	Ó*Ð*r&   c                 ó8   — t        |«      | j                  _        y r-   )r   r)   r4   r_   s     r$   r4   zVideoCodecContext.pix_fmtÄ   s   € ä& uÓ-ˆ�‰Õr&   c                 óf   — t        t        j                  | j                  j                  «      «      S )zZ
        The frame rate, in frames per second.

        :type: fractions.Fraction
        )r   r   r7   r)   Ú	frameraterI   s    r$   rn   zVideoCodecContext.framerateÈ   s"   € ô &¤f§n¡n°T·X±X×5GÑ5GÓ&HÓIÐIr&   c                 ój   — t        |t        j                  | j                  j                  «      «       y r-   )r	   r   r7   r)   rn   r_   s     r$   rn   zVideoCodecContext.framerateÑ   s   € ä�eœVŸ^™^¨D¯H©H×,>Ñ,>Ó?Õ@r&   c                 ó   — | j                   S )z#Another name for :attr:`framerate`.©rn   rI   s    r$   ÚratezVideoCodecContext.rateÕ   s   € ð �~‰~Ðr&   c                 ó   — || _         y r-   rq   r_   s     r$   rr   zVideoCodecContext.rateÚ   s	   € àˆ�r&   c                 ó\   — | j                   rt        d«      ‚| j                  j                  S )zj
        Sets the number of frames between keyframes. Used only for encoding.

        :type: int
        ú%Cannot access 'gop_size' as a decoder©Ú
is_decoderÚRuntimeErrorr)   Úgop_sizerI   s    r$   ry   zVideoCodecContext.gop_sizeÞ   s'   € ð �?Š?ÜÐFÓGÐGØ�x‰x× Ñ Ð r&   c                 óT   — | j                   rt        d«      ‚|| j                  _        y )Nru   rv   r_   s     r$   ry   zVideoCodecContext.gop_sizeé   s!   € à�?Š?ÜÐFÓGÐGØ!ˆ�‰Õr&   c                 óf   — t        t        j                  | j                  j                  «      «      S r-   )r   r   r7   r)   Úsample_aspect_ratiorI   s    r$   r|   z%VideoCodecContext.sample_aspect_ratioï   s    € ä%¤f§n¡n°T·X±X×5QÑ5QÓ&RÓSÐSr&   c                 ój   — t        |t        j                  | j                  j                  «      «       y r-   )r	   r   r7   r)   r|   r_   s     r$   r|   z%VideoCodecContext.sample_aspect_ratioó   s   € ä�eœVŸ^™^¨D¯H©H×,HÑ,HÓIÕJr&   c                 ó¸  — t        j                  t        j                  j                  «      t        j                  |j
                  «      | j                  j                  | j                  j                  j                  z  | j                  j                  | j                  j                  j
                  z  d«       t        t        j                  |«      «      S )Ni   )r    Ú	av_reducer   r7   ÚnumÚdenr)   r>   r|   r?   r   )r9   Údars     r$   Údisplay_aspect_ratioz&VideoCodecContext.display_aspect_ratio÷   s‰   € ô 	�‰Ü�N‰N˜3Ÿ7™7Ó#Ü�N‰N˜3Ÿ7™7Ó#Ø�H‰H�N‰N˜TŸX™X×9Ñ9×=Ñ=Ñ=Ø�H‰H�O‰O˜dŸh™h×:Ñ:×>Ñ>Ñ>Øô	
ô &¤f§n¡n°SÓ&9Ó:Ð:r&   c                 ó@   — t        | j                  j                  «      S )z
        :type: bool
        )Úboolr)   Úhas_b_framesrI   s    r$   r†   zVideoCodecContext.has_b_frames  s   € ô
 �D—H‘H×)Ñ)Ó*Ð*r&   c                 ó.   — | j                   j                  S )a  Raw ``has_b_frames`` value from FFmpeg (int, not bool).

        After :meth:`flush_buffers`, FFmpeg may reset the internal reorder
        heuristic. Set this to the known reorder depth *after* seeking to
        avoid dropped hierarchical B-frames.
        ©r)   r†   rI   s    r$   Úreorder_depthzVideoCodecContext.reorder_depth  s   € ð �x‰x×$Ñ$Ð$r&   c                 ó&   — || j                   _        y r-   rˆ   r_   s     r$   r‰   zVideoCodecContext.reorder_depth  ó   € à %ˆ�‰Õr&   c                 ó.   — | j                   j                  S ©z
        :type: int
        )r)   Úcoded_widthrI   s    r$   rŽ   zVideoCodecContext.coded_width  s   € ð
 �x‰x×#Ñ#Ð#r&   c                 ó.   — | j                   j                  S r�   )r)   Úcoded_heightrI   s    r$   r�   zVideoCodecContext.coded_height   s   € ð
 �x‰x×$Ñ$Ð$r&   c                 ó.   — | j                   j                  S )z�
        Describes the signal range of the colorspace.

        Wraps :ffmpeg:`AVFrame.color_range`.

        :type: int
        ©r)   Úcolor_rangerI   s    r$   r“   zVideoCodecContext.color_range'  s   € ð �x‰x×#Ñ#Ð#r&   c                 ó&   — || j                   _        y r-   r’   r_   s     r$   r“   zVideoCodecContext.color_range2  s   € à$ˆ�‰Õr&   c                 ó.   — | j                   j                  S )z‡
        Describes the RGB/XYZ matrix of the colorspace.

        Wraps :ffmpeg:`AVFrame.color_primaries`.

        :type: int
        ©r)   Úcolor_primariesrI   s    r$   r—   z!VideoCodecContext.color_primaries6  s   € ð �x‰x×'Ñ'Ð'r&   c                 ó&   — || j                   _        y r-   r–   r_   s     r$   r—   z!VideoCodecContext.color_primariesA  s   € à#(ˆ�‰Õ r&   c                 ó.   — | j                   j                  S )z±
        Describes the linearization function (a.k.a. transformation characteristics) of the colorspace.

        Wraps :ffmpeg:`AVFrame.color_trc`.

        :type: int
        ©r)   Ú	color_trcrI   s    r$   r›   zVideoCodecContext.color_trcE  s   € ð �x‰x×!Ñ!Ð!r&   c                 ó&   — || j                   _        y r-   rš   r_   s     r$   r›   zVideoCodecContext.color_trcP  s   € à"ˆ�‰Õr&   c                 ó.   — | j                   j                  S )z‘
        Describes the YUV/RGB transformation matrix of the colorspace.

        Wraps :ffmpeg:`AVFrame.colorspace`.

        :type: int
        ©r)   Ú
colorspacerI   s    r$   rŸ   zVideoCodecContext.colorspaceT  s   € ð �x‰x×"Ñ"Ð"r&   c                 ó&   — || j                   _        y r-   rž   r_   s     r$   rŸ   zVideoCodecContext.colorspace_  s   € à#ˆ�‰Õr&   c                 ó.   — | j                   j                  S )zd
        The maximum run of consecutive B frames when encoding a video.

        :type: int
        ©r)   Úmax_b_framesrI   s    r$   r£   zVideoCodecContext.max_b_framesc  s   € ð �x‰x×$Ñ$Ð$r&   c                 ó&   — || j                   _        y r-   r¢   r_   s     r$   r£   zVideoCodecContext.max_b_framesl  r‹   r&   c                 ó.   — | j                   j                  S )z…
        The minimum quantiser value of an encoded stream.

        Wraps :ffmpeg:`AVCodecContext.qmin`.

        :type: int
        ©r)   ÚqminrI   s    r$   r§   zVideoCodecContext.qminp  ó   € ð �x‰x�}‰}Ðr&   c                 ó&   — || j                   _        y r-   r¦   r_   s     r$   r§   zVideoCodecContext.qmin{  ó   € àˆ�‰�r&   c                 ó.   — | j                   j                  S )z…
        The maximum quantiser value of an encoded stream.

        Wraps :ffmpeg:`AVCodecContext.qmax`.

        :type: int
        ©r)   ÚqmaxrI   s    r$   r­   zVideoCodecContext.qmax  r¨   r&   c                 ó&   — || j                   _        y r-   r¬   r_   s     r$   r­   zVideoCodecContext.qmaxŠ  rª   r&   )-Ú__name__Ú
__module__Ú__qualname__r   Úcfuncr   r    ÚAVCodecContextÚconstÚAVCodecr   r.   r   ÚlistrG   rJ   r   rN   rW   Úpropertyr=   Úsetterr
   r>   Úuintr?   rc   Úintr4   rn   rr   ry   r|   rƒ   r†   r‰   rŽ   r�   r“   r—   r›   rŸ   r£   r§   r­   © r&   r$   r(   r(   (   s‚  „ ð ‡\�\ð(à�^‰^˜C×.Ñ.Ñ/ð(ð �~‰~˜fŸl™l¨3¯;©;Ñ7Ñ8ð(ð ˜4‘ò	(ó ð(ð@ ‡\�\ð°¸±ð Àò ó ðð4 ‡\�\ð# 5ò #ó ð#ð ‡\�\ð'¨%ð '¸ò 'ó ð'ð
 ‡\�\ð uò ó ðð$ ñ
ó ð
ð ‡]�]ð(˜[ò (ó ð(ð
 ñó ðð
 ‡\�\ð˜6Ÿ;™;ò ó ðð ñó ðð
 ‡]�]ð ˜FŸK™Kò  ó ð ð ñ.ó ð.ð ×!Ñ!ð/¨6¯:©:ò /ó "ð/ð ñ	+ó ð	+ð ‡^�^ñ.ó ð.ð ñJó ðJð ×ÑñAó ðAð ñó ðð 
‡[�[ñó ðð ñ!ó ð!ð ‡_�_ð"˜fŸj™jò "ó ð"ð
 ñTó ðTð ×ÑñKó  ðKð ñ
;ó ð
;ð ñ+ó ð+ð ñ%ó ð%ð ×Ñð& 6§:¡:ò &ó ð&ð ñ$ó ð$ð ñ%ó ð%ð ñ$ó ð$ð ×Ññ%ó ð%ð ñ(ó ð(ð ×Ññ)ó ð)ð ñ"ó ð"ð ×Ññ#ó ð#ð ñ#ó ð#ð ×Ññ$ó ð$ð ñ%ó ð%ð ×Ññ&ó ð&ð ñó ðð 
‡[�[ñó ðð ñó ðð 
‡[�[ñó ñr&   r(   )'r   Úcython.cimports.libavÚcimportsÚlibavr    Ú cython.cimports.av.codec.contextr   Ú cython.cimports.av.codec.hwaccelr   Úcython.cimports.av.errorr   Úcython.cimports.av.framer   Úcython.cimports.av.packetr   Úcython.cimports.av.utilsr   r	   Úcython.cimports.av.video.formatr
   r   r   Úcython.cimports.av.video.framer   r   Ú$cython.cimports.av.video.reformatterr   Úcython.cimports.libc.stdintr   r²   Ú	exceptvalr   r³   r´   rY   r%   ÚfinalÚcclassr(   r»   r&   r$   ú<module>rÌ      sÑ   ðÛ ß #Ð #Ý 9Ý 4Ý .Ý *Ý ,ß Jß VÑ Vß HÝ AÝ /ð ‡�Ø€×Ñ˜ÔðØ	�‰˜×*Ñ*Ñ	+ðà�n‰n˜VŸ\™\¨#×*;Ñ*;Ñ<Ñ=ðð 	×Ñòó ó ðð. ‡�Ø‡�ôb˜ó bó ó ñbr&   