Ë
    ÛÍ:j /  ã                   ó  — d dl Z d dlmZ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 d d	lmZmZ d d
lmZmZ e j.                  defd„«       Ze j4                  e j6                   G d„ de«      «       «       Zy)é    N)ÚCodecContextÚwrap_codec_context)ÚStreamContainer)Ú
Dictionary)Ú	err_check)ÚPacket)ÚStreamÚwrap_stream)Úavdict_to_dict)Úint64_tÚuint8_t)ÚfreeÚmallocÚselfc                 ó  — t        «       | _        t        j                  5  | j                  dz  rGt
        j                  t        j                  | j                  «      «       | xj                  dz  c_        d d d «       y # 1 sw Y   y xY w)Né   éýÿÿÿ)	r   ÚstreamsÚcythonÚnogilÚ_myflagÚlibÚavformat_close_inputÚaddressÚptr©r   s    úg/home/mcse/projects/srt_converter/srt-converter-venv/lib/python3.12/site-packages/av/container/input.pyÚclose_inputr      s]   € ä"Ó$€D„LÜ	�‰ñ Ø�<‰<˜!Òä×$Ñ$¤V§^¡^°D·H±HÓ%=Ô>Ø�LŠL˜BÑ�L÷	÷ ñ ús    AB Â B	c                   ó  — e Zd Zd„ Zd„ Zed„ «       Zed„ «       Zed„ «       Zed„ «       Z	d„ Z
d„ Zd	„ Zd
dddddœdej                  dej                  dedz  dej                  dej                  f
d„Zej"                  d„ «       Zy)ÚInputContainerc           	      óR  — t         j                  }| j                  j                  }| j                  r|dk(  rt        d«      ‚| j                  s| j                  �rr|dkD  �rlt        | j                  «      }t        j                  t         j                  t         j                  t        j                        t        |t        j                  t         j                  «      z  «      «      }t        |«      D ]Ö  }t         j                  ||<   |t!        | j                  «      k  rr| j                  rf|j#                  «       }|j%                  | j                  |   «       t        j'                  t        j(                  ||   «      |j                  d«       Œ t        j'                  t        j(                  ||   «      |j                  d«       ŒØ | j+                  | j,                  «       | j/                  «        t         j0                  5  t        j3                  | j                  |«      }d d d «       | j+                  d «       | j5                  «       |rFt        |«      D ]-  }t        j7                  t        j(                  ||   «      «       Œ/ t9        |«       d}	t;        «       | _        t        | j                  j                  «      D ]ã  }| j                  j<                  |   }
t        j?                  |
j@                  jB                  «      }|rut        jE                  |«      }t5        t        jG                  ||
j@                  «      «       |
jH                  |_%        tM        ||| jN                  «      }|jP                  rd}	nd }| j<                  jS                  tU        | |
|«      «       Œå | jN                  r#| jN                  jV                  s|	stY        d«      ‚t[        | j                  j\                  | j^                  | j`                  «      | _.        y # 1 sw Y   �ŒôxY w)Nr   z�stream_options were provided, but this format does not expose its streams before avformat_find_stream_info (e.g. MPEG). Per-stream options cannot be applied.FTzAHardware accelerated decode requested but no stream is compatible)1r   ÚNULLr   Ú
nb_streamsÚstream_optionsÚ
ValueErrorÚoptionsr   ÚcastÚpointerr   ÚAVDictionaryr   ÚsizeofÚp_voidÚrangeÚlenÚcopyÚupdateÚav_dict_copyr   Úset_timeoutÚopen_timeoutÚstart_timeoutr   Úavformat_find_stream_infor   Úav_dict_freer   r   r   Úavcodec_find_decoderÚcodecparÚcodec_idÚavcodec_alloc_context3Úavcodec_parameters_to_contextÚ	time_baseÚpkt_timebaser   ÚhwaccelÚ
is_hwaccelÚ
add_streamr
   Úallow_software_fallbackÚRuntimeErrorr   ÚmetadataÚmetadata_encodingÚmetadata_errors)r   ÚargsÚkwargsÚ	c_optionsÚnb_streams_beforeÚ	base_dictÚiÚstream_dictÚretÚ at_least_one_accelerated_contextÚstreamÚcodecÚcodec_contextÚpy_codec_contexts                 r   Ú	__cinit__zInputContainer.__cinit__   sF  € ô GMÇkÁkˆ	ð *.¯©×)<Ñ)<ÐØ×ÒÐ#4¸Ò#9Üð8óð ð �LŠL˜D×/Ó/Ð5FÈÓ5JÜ" 4§<¡<Ó0ˆIÜŸ™Ü—‘œvŸ~™~¬c×.>Ñ.>Ñ?Ñ@ÜÐ(¬6¯=©=¼¿¹Ó+GÑGÓHóˆIô Ð,Ó-ò U�Ü%Ÿ{™{�	˜!‘Ø”s˜4×.Ñ.Ó/Ò/°D×4GÒ4GØ"+§.¡.Ó"2�KØ×&Ñ& t×':Ñ':¸1Ñ'=Ô>Ü×$Ñ$¤V§^¡^°I¸a±LÓ%AÀ;Ç?Á?ÐTUÕVä×$Ñ$¤V§^¡^°I¸a±LÓ%AÀ9Ç=Á=ÐRSÕTðUð 	×Ñ˜×*Ñ*Ô+Ø×ÑÔÜ�\‰\ñ 	EÜ×/Ñ/°·±¸)ÓDˆC÷	Eà×Ñ˜ÔØ�‰�sÔáÜÐ,Ó-ò ?�Ü× Ñ ¤§¡°	¸!±Ó!=Õ>ð?ä�ŒOà+0Ð(ä&Ó(ˆŒÜ�t—x‘x×*Ñ*Ó+ò 	QˆAØ—X‘X×%Ñ% aÑ(ˆFÜ×,Ñ,¨V¯_©_×-EÑ-EÓFˆEÙÜ #× :Ñ :¸5Ó A�ÜÜ×5Ñ5°mÀVÇ_Á_ÓUôð .4×-=Ñ-=�Ô*Ü#5Ø! 5¨$¯,©,ó$Ð ð $×.Ò.Ø7;Ñ4ð $(Ð Ø�L‰L×#Ñ#¤K°°fÐ>NÓ$OÕPð#	Qð( �LŠLØ—L‘L×8Ò8Ù4äØSóð ô 'Ø�H‰H×Ñ˜t×5Ñ5°t×7KÑ7Kó
ˆ�÷S	Eñ 	Eús   È	!PÐP&c                 ó   — t        | «       y ©N©r   r   s    r   Ú__dealloc__zInputContainer.__dealloc__l   ó
   € Ü�DÕó    c                 óž   — | j                  «        | j                  j                  t        j                  k7  r| j                  j                  S y rT   )Ú_assert_openr   Ú
start_timer   ÚAV_NOPTS_VALUEr   s    r   r[   zInputContainer.start_timeo   s;   € à×ÑÔØ�8‰8×Ñ¤#×"4Ñ"4Ò4Ø—8‘8×&Ñ&Ð&ð 5rX   c                 óž   — | j                  «        | j                  j                  t        j                  k7  r| j                  j                  S y rT   )rZ   r   Údurationr   r\   r   s    r   r^   zInputContainer.durationu   s;   € à×ÑÔØ�8‰8×Ñ¤× 2Ñ 2Ò2Ø—8‘8×$Ñ$Ð$ð 3rX   c                 óN   — | j                  «        | j                  j                  S rT   )rZ   r   Úbit_rater   s    r   r`   zInputContainer.bit_rate{   s   € à×ÑÔØ�x‰x× Ñ Ð rX   c                 ót   — | j                  «        t        j                  | j                  j                  «      S rT   )rZ   r   Ú	avio_sizer   Úpbr   s    r   ÚsizezInputContainer.size€   s%   € à×ÑÔÜ�}‰}˜TŸX™XŸ[™[Ó)Ð)rX   c                 ó   — t        | «       y rT   rU   r   s    r   ÚclosezInputContainer.close…   rW   rX   c           	   /   óÒ  K  — | j                  «         | j                  j                  |i |¤Ž}| j                  j                  dk(  ryt        j                  t
        j                  t           t        | j                  j                  t        j                  t        «      z  «      «      }|t
        j                  k(  r
t        «       ‚| j                  | j                  «       	 t        | j                  j                  «      D ]  }d||<   Œ	 |D ];  }|j                   }|| j                  j                  k\  rt#        d|› d�«      ‚d||<   Œ= t
        j$                  5  t&        j)                  «       }ddd«       t
        j                  k(  rt        d«      ‚	 t
        j$                  5  t&        j+                  |«       ddd«       	 | j-                  «        t
        j$                  5  t&        j/                  | j                  |«      }ddd«       | j1                  «       ||j4                     rÀ|j4                  t7        | j                  «      k  ržt9        «       }	t
        j$                  5  t&        j;                  |	j                  |«       ddd«       | j                  |	j                  j4                     |	_        |	j<                  j                  j>                  |	j                  _        |	–— �ŒZ# 1 sw Y   �ŒƒxY w# 1 sw Y   �ŒCxY w# 1 sw Y   �ŒxY w# t2        $ r Y nw xY w# 1 sw Y   ŒœxY wt        | j                  j                  «      D ]Y  }||   sŒ	t9        «       }	| j                  |   |	_        |	j<                  j                  j>                  |	j                  _        |	–— Œ[ 	 | j                  d«       tA        |«       |t
        j                  k7  r)t&        jC                  t        jD                  |«      «       yy# | j                  d«       tA        |«       t
        j                  k7  r)t&        jC                  t        jD                  |«      «       w w xY w­w)a0  demux(streams=None, video=None, audio=None, subtitles=None, data=None)

        Yields a series of :class:`.Packet` from the given set of :class:`.Stream`::

            for packet in container.demux():
                # Do something with `packet`, often:
                for frame in packet.decode():
                    # Do something with `frame`.

        .. seealso:: :meth:`.StreamContainer.get` for the interpretation of
            the arguments.

        .. note:: The last packets are dummy packets that when decoded will flush the buffers.

        r   Nzstream index z out of rangeé   zCould not allocate packet)#rZ   r   Úgetr   r#   r   r'   r(   r   r   r*   r"   ÚMemoryErrorr1   Úread_timeoutr,   Úindexr%   r   r   Úav_packet_allocÚav_packet_unrefr3   Úav_read_framer   ÚEOFErrorÚstream_indexr-   r   Úav_packet_move_refÚ_streamr;   r   Úav_packet_freer   )
r   rE   rF   r   Úinclude_streamrJ   rN   Úread_packetrL   Úpackets
             r   ÚdemuxzInputContainer.demuxˆ   s}  è ø€ ð  	×ÑÔà 0 §¡× 0Ñ 0°$Ð A¸&Ñ AˆØ�8‰8×Ñ !Ò#ØÜ28·+±+Ü�N‰Nœ7Ñ#Ü�4—8‘8×&Ñ&¬¯©´wÓ)?Ñ?Ó@ó3
ˆð œVŸ[™[Ò(Ü“-Ðð 	×Ñ˜×*Ñ*Ô+ð7	@Ü˜4Ÿ8™8×.Ñ.Ó/ò &�Ø$%�˜qÒ!ð&à!ò &�Ø—L‘L�Ø˜Ÿ™×+Ñ+Ò+Ü$ }°Q°C°}Ð%EÓFÐFØ$%�˜qÒ!ð	&ô —‘ñ 4Ü!×1Ñ1Ó3�÷4àœfŸk™kÒ)Ü!Ð"=Ó>Ð>àä—\‘\ñ 5Ü×'Ñ'¨Ô4÷5ðØ×&Ñ&Ô(ÜŸ™ñ GÜ!×/Ñ/°·±¸+ÓF˜÷Gà—N‘N 3Ô'ð " +×":Ñ":Ò;ð
 #×/Ñ/´#°d·l±lÓ2CÒCô "(£˜Ü#Ÿ\™\ñ LÜ×2Ñ2°6·:±:¸{ÔK÷Là)-¯©°f·j±j×6MÑ6MÑ)N˜œà/5¯~©~×/AÑ/A×/KÑ/K˜Ÿ
™
Ô,Ø$šñ5 ÷4ñ 4ú÷5ñ 5ú÷Gñ Gûô  ò Ùðú÷Lð Lúô ˜4Ÿ8™8×.Ñ.Ó/ò !�Ø! !Ó$Ü#›X�FØ%)§\¡\°!¡_�F”NØ+1¯>©>×+=Ñ+=×+GÑ+G�F—J‘JÔ(Ø “Lñ!ð ×Ñ˜TÔ"Ü�Ô ØœfŸk™kÒ)Ü×"Ñ"¤6§>¡>°+Ó#>Õ?ð *øð ×Ñ˜TÔ"Ü�Ô ØœfŸk™kÒ)Ü×"Ñ"¤6§>¡>°+Ó#>Õ?ð *üs®   ‚C!Q'Ã$A9P
 ÅK3Å27P
 Æ)L Æ?P
 Ç L Ç(!LÈ	L È"AP
 É-!L)ÊA%P
 Ë3K=Ë8P
 Ì L
ÌP
 ÌLÌL Ì	L&Ì#P
 Ì%L&Ì&P
 Ì)L2Ì..P
 ÍAP
 Î1AQ'Ð
AQ$Ñ$Q'c              /   óŒ   K  — | j                  «         | j                  |i |¤ŽD ]  }|j                  «       D ]  }|–— Œ Œ y­w)a`  decode(streams=None, video=None, audio=None, subtitles=None, data=None)

        Yields a series of :class:`.Frame` from the given set of streams::

            for frame in container.decode():
                # Do something with `frame`.

        .. seealso:: :meth:`.StreamContainer.get` for the interpretation of
            the arguments.

        N)rZ   rx   Údecode)r   rE   rF   rw   Úframes        r   rz   zInputContainer.decodeã   sM   è ø€ ð 	×ÑÔØ �d—j‘j $Ð1¨&Ñ1ò 	ˆFØŸ™›ò �Ø“ññ	ùs   ‚AATFN)ÚbackwardÚ	any_framerN   Úunsupported_frame_offsetÚunsupported_byte_offsetr|   r}   rN   r~   r   c                ó  — | j                  «        t        |t        «      st        dt	        |«      «      ‚|}d}|r|t
        j                  z  }|r|t
        j                  z  }|r|t
        j                  z  }|r|t
        j                  z  }|r|j                  nd}	t        j                  5  t
        j                  | j                  |	||«      }
ddd«       t        
«       | j!                  «        y# 1 sw Y   Œ%xY w)a)  seek(offset, *, backward=True, any_frame=False, stream=None)

        Seek to a (key)frame nearest to the given timestamp.

        :param int offset: Time to seek to, expressed in``stream.time_base`` if ``stream``
            is given, otherwise in :data:`av.time_base`.
        :param bool backward: If there is not a (key)frame at the given offset,
            look backwards for it.
        :param bool any_frame: Seek to any frame, not just a keyframe.
        :param Stream stream: The stream who's ``time_base`` the ``offset`` is in.

        :param bool unsupported_frame_offset: ``offset`` is a frame
            index instead of a time; not supported by any known format.
        :param bool unsupported_byte_offset: ``offset`` is a byte
            location in the file; not supported by any known format.

        After seeking, packets that you demux should correspond (roughly) to
        the position you requested.

        In most cases, the defaults of ``backwards = True`` and ``any_frame = False``
        are the best course of action, followed by you demuxing/decoding to
        the position that you want. This is because to properly decode video frames
        you need to start from the previous keyframe.

        .. seealso:: :ffmpeg:`avformat_seek_file` for discussion of the flags.

        z+Container.seek only accepts integer offset.r   éÿÿÿÿN)rZ   Ú
isinstanceÚintÚ	TypeErrorÚtyper   ÚAVSEEK_FLAG_BACKWARDÚAVSEEK_FLAG_ANYÚAVSEEK_FLAG_FRAMEÚAVSEEK_FLAG_BYTErl   r   r   Úav_seek_framer   r   Úflush_buffers)r   Úoffsetr|   r}   rN   r~   r   Úc_offsetÚflagsrq   rL   s              r   ÚseekzInputContainer.seekô   sâ   € ðJ 	×ÑÔä˜&¤#Ô&ÜÐIÌ4ÐPVË<ÓXÐXà"ˆØˆñ Ø”S×-Ñ-Ñ-ˆEÙØ”S×(Ñ(Ñ(ˆEñ $Ø”S×*Ñ*Ñ*ˆEÙ"Ø”S×)Ñ)Ñ)ˆEá39 6§<¢<¸rˆÜ�\‰\ñ 	MÜ×#Ñ# D§H¡H¨l¸HÀeÓLˆC÷	Mä�#Œà×ÑÕ÷		Mð 	Mús   Â.#C5Ã5C>c                 ó„   — | j                  «        | j                  D ]!  }|j                  }|sŒ|j                  «        Œ# y rT   )rZ   r   rP   r‹   )r   rN   rP   s      r   r‹   zInputContainer.flush_buffers4  s=   € à×ÑÔð
 —l‘lò 	.ˆFØ"×0Ñ0ˆMÚØ×+Ñ+Õ-ñ	.rX   )Ú__name__Ú
__module__Ú__qualname__rR   rV   Úpropertyr[   r^   r`   rd   rf   rx   rz   r   Úbintr	   r�   Úcfuncr‹   © rX   r   r    r       så   „ òP
òdð ñ'ó ð'ð
 ñ%ó ð%ð
 ñ!ó ð!ð ñ*ó ð*òòY@òvð* !%Ø!&Ø $Ø05Ø/4ò>ð —+‘+ð	>ð
 —;‘;ð>ð ˜‘ð>ð #)§+¡+ð>ð "(§¡ó>ð@ ‡\�\ñ	.ó ñ	.rX   r    )r   Ú cython.cimports.av.codec.contextr   r   Ú$cython.cimports.av.container.streamsr   Úcython.cimports.av.dictionaryr   Úcython.cimports.av.errorr   Úcython.cimports.av.packetr   Úcython.cimports.av.streamr	   r
   Úcython.cimports.av.utilsr   Úcython.cimports.libc.stdintr   r   Úcython.cimports.libc.stdlibr   r   r–   r    r   ÚfinalÚcclassÚ	Containerr—   rX   r   ú<module>r¤      sp   ðÛ ß MÝ @Ý 4Ý .Ý ,ß 9Ý 3ß 8ß 4ð ‡�ð�nò ó ðð ‡�Ø‡�ôe.�Yó e.ó ó ñe.rX   