
    3j /                        S SK r S SKJrJr  S SKJr  S SKJr  S SKJ	r	  S SK
Jr  S SKJrJr  S SKJr  S S	KJrJr  S S
KJrJr  \ R.                  S\4S j5       r\ R4                  \ R6                   " S S\5      5       5       rg)    N)CodecContextwrap_codec_context)StreamContainer)
Dictionary)	err_check)Packet)Streamwrap_stream)avdict_to_dict)int64_tuint8_t)freemallocselfc                 .   [        5       U l        [        R                     U R                  S-  (       aH  [
        R                  [        R                  " U R                  5      5        U =R                  S-  sl        S S S 5        g ! , (       d  f       g = f)N   )	r   streamscythonnogil_myflaglibavformat_close_inputaddressptrr   s    L/home/wildlama/miniconda3/lib/python3.13/site-packages/av/container/input.pyclose_inputr      sR    "$DL	<<!$$V^^DHH%=>LLBL	 
s   AB
Bc                      \ rS rSrS rS r\S 5       r\S 5       r\S 5       r	\S 5       r
S rS	 rS
 rSSSSSS.S\R                  S\R                  S\S-  S\R                  S\R                  4
S jjr\R$                  S 5       rSrg)InputContainer   c           	         [         R                  nU R                  R                  nU R                  (       a  US:X  a  [        S5      eU R                  (       d  U R                  (       Ga}  US:  Gav  [        U R                  5      n[         R                  " [         R                  [         R                  [        R                        [        U[         R                  " [         R                  5      -  5      5      n[        U5       H  n[         R                  X6'   U[!        U R                  5      :  ax  U R                  (       ag  UR#                  5       nUR%                  U R                  U   5        [        R'                  [         R(                  " X6   5      UR                  S5        M  [        R'                  [         R(                  " X6   5      UR                  S5        M     U R+                  U R,                  5        U R/                  5         [         R0                     [        R3                  U R                  U5      nS S S 5        U R+                  S 5        U R5                  W5        U(       aH  [        U5       H.  n[        R7                  [         R(                  " X6   5      5        M0     [9        U5        Sn	[;        5       U l        [        U R                  R                  5       H  nU R                  R<                  U   n
[        R?                  U
R@                  RB                  5      nU(       ax  [        RE                  U5      n[5        [        RG                  XR@                  5      5        U
RH                  Ul%        [M        XU RN                  5      nURP                  (       a  Sn	OS nU R<                  RS                  [U        X
U5      5        M     U RN                  (       a-  U RN                  RV                  (       d  U	(       d  [Y        S5      e[[        U R                  R\                  U R^                  U R`                  5      U l.        g ! , (       d  f       GN= f)Nr   zstream_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__InputContainer.__cinit__   s    GMkk	 *.)<)<#4#98  LLD///5F5J"4<<0Iv~~c.>.>?@(6==+GGHI ,-%{{	s4..//D4G4G"+.."2K&&t':':1'=>$$V^^IL%A;??TUV$$V^^IL%A9==RST . 	**+\\//)DC s,-  	!=> .O+0(&(txx**+AXX%%a(F,,V__-E-EFE # : :5 A55m__U .4-=-=*#5!$,,$  $..7;4 $( LL##K>N$OP# ,( LLLL884S  'HHt55t7K7K
S \s   $!Q
Q%c                     [        U 5        g Nr   r   s    r   __dealloc__InputContainer.__dealloc__l   
    D    c                     U R                  5         U R                  R                  [        R                  :w  a  U R                  R                  $ g rV   )_assert_openr   
start_timer   AV_NOPTS_VALUEr   s    r   r^   InputContainer.start_timeo   s;    88#"4"4488&&& 5r[   c                     U R                  5         U R                  R                  [        R                  :w  a  U R                  R                  $ g rV   )r]   r   durationr   r_   r   s    r   rb   InputContainer.durationu   s;    88 2 2288$$$ 3r[   c                 N    U R                  5         U R                  R                  $ rV   )r]   r   bit_rater   s    r   re   InputContainer.bit_rate{   s    xx   r[   c                 t    U R                  5         [        R                  U R                  R                  5      $ rV   )r]   r   	avio_sizer   pbr   s    r   sizeInputContainer.size   s%    }}TXX[[))r[   c                     [        U 5        g rV   rW   r   s    r   closeInputContainer.close   rZ   r[   c           	   /   *	  #    U R                  5         U R                  R                  " U0 UD6nU R                  R                  S:X  a  g[
        R                  " [
        R                  [           [        U R                  R                  [
        R                  " [        5      -  5      5      nU[
        R                  :X  a
  [        5       eU R                  U R                  5         [        U R                  R                  5       H  nSXE'   M	     U H;  nUR                   nXPR                  R                  :  a  [#        SU S35      eSXE'   M=     [
        R$                     [&        R)                  5       nSSS5        W[
        R                  :X  a  [        S5      e [
        R$                     [&        R+                  U5        SSS5         U R-                  5         [
        R$                     [&        R/                  U R                  U5      nSSS5        U R1                  W5        XGR4                     (       a  UR4                  [7        U R                  5      :  a  [9        5       n	[
        R$                     [&        R;                  U	R                  U5        SSS5        U R                  U	R                  R4                     U	l        U	R<                  R                  R>                  U	R                  l        U	v   GM`  ! , (       d  f       GN= f! , (       d  f       GNS= f! , (       d  f       GN= f! [2         a     Of = f! , (       d  f       N= f[        U R                  R                  5       H_  nXE   (       d  M  [9        5       n	U R                  U   U	l        U	R<                  R                  R>                  U	R                  l        U	v   Ma     U R                  S5        [A        U5        U[
        R                  :w  a*  [&        RC                  [
        RD                  " U5      5        gg! U R                  S5        [A        U5        W[
        R                  :w  a*  [&        RC                  [
        RD                  " U5      5        f f = f7f)a  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)#r]   r   getr   r$   r   r(   r)   r   r   r+   r#   MemoryErrorr2   read_timeoutr-   indexr&   r   r   av_packet_allocav_packet_unrefr4   av_read_framer   EOFErrorstream_indexr.   r   av_packet_move_ref_streamr<   r   av_packet_freer   )
r   rF   rG   r   include_streamrK   rO   read_packetrM   packets
             r   demuxInputContainer.demux   s<      	 $ 0 0$ A& A88!#28++NN7#488&&w)??@3
 V[[(- 	**+7	@488../$%! 0!LL+++$}QC}%EFF$%!	 " !113 fkk)!"=>>\\''4 "&&(!//+F &NN3' "":":;
 #//#dll2CC "(#\\226::{K *)-fjj6M6M)N/5~~/A/A/K/K

,$5   "\ &    *\ 488../!$$#XF%)\\!_FN+1>>+=+=+G+GFJJ( L 0 T" fkk)""6>>+#>? * T" fkk)""6>>+#>? *s   C%R(A;P4 #L 88P4 0LP4  L6 /!L$L6 )AP4 9!MA&P4  
L
P4 
L!P4 $
L3.L6 6
M P4 MP4 
M0P4 AP4 AR4ARRc              /      #    U R                  5         U R                  " U0 UD6 H  nUR                  5        H  nUv   M	     M      g7f)a0  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)r]   r   decode)r   rF   rG   r   frames        r   r   InputContainer.decode   s@      	jj$1&1F ) 2s   AATFN)backward	any_framerO   unsupported_frame_offsetunsupported_byte_offsetr   r   rO   r   r   c                F   U R                  5         [        U[        5      (       d  [        S[	        U5      5      eUnSnU(       a  U[
        R                  -  nU(       a  U[
        R                  -  nU(       a  U[
        R                  -  nU(       a  U[
        R                  -  nU(       a  UR                  OSn	[        R                     [
        R                  U R                  XU5      n
SSS5        [        W
5        U R!                  5         g! , (       d  f       N*= f)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)r]   
isinstanceint	TypeErrortyper   AVSEEK_FLAG_BACKWARDAVSEEK_FLAG_ANYAVSEEK_FLAG_FRAMEAVSEEK_FLAG_BYTErt   r   r   av_seek_framer   r   flush_buffers)r   offsetr   r   rO   r   r   c_offsetflagsry   rM   s              r   seekInputContainer.seek   s    J 	&#&&I4PV<XX" S---ES(((E $S***E"S)))E396<<r\\##DHHleLC #	 \s   "D
D c                     U R                  5         U R                   H(  nUR                  nU(       d  M  UR                  5         M*     g rV   )r]   r   rQ   r   )r   rO   rQ   s      r   r   InputContainer.flush_buffers4  s:    
 llF"00M}++- #r[   )rC   r   )__name__
__module____qualname____firstlineno__rS   rX   propertyr^   rb   re   rj   rm   r   r   r   bintr	   r   cfuncr   __static_attributes__ r[   r   r    r       s    P
d ' '
 % %
 ! ! * *Y@v* !%!& $05/4> ++	>
 ;;> > #)++> "(>@ \\	. 	.r[   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   r[   r   <module>r      sp     M @ 4 . , 9 3 8 4 n   e.Y e.  e.r[   