
    djT                        d dl Z d dlZd dlmZmZ d dlmZ 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mZ d dlmZmZ d d	lmZ d d
lmZmZmZmZ d dlm Z  d dl!m"Z" d dl#m$Z%  ej&        e' e'                      Z( ej)        ej*        ej*        ej+                                    Z,ej-        ej.         ej/        d          dej0        dej1        fd                                    Z2ej-        ej.         ej/        d          dej*        ej3                 dej*        ej*        ej4                          dej5        dej1        dej*        ej*        ej6                          dej1        fd                                    Z7ej-         ej/        d          dej*        ej3                 dej*        ej*        ej4                          dej5        dej1        dej*        ej*        ej6                          dej1        fd                        Z8ej-        ej.         ej/        d          dej*        ej3                 dej*        ej4                 dej1        fd                                    Z9ej-         ej/        d          dej*        ej3                 dej*        ej4                 dej1        fd                        Z:ej-        ej.         ej/        d          dej*        ej3                 dej;        fd                                    Z< G d de          Z= G d  d!e          Z>ej?         G d" d#                      Z@	 	 	 	 	 	 	 	 	 	 	 d(d'ZAdS ))    N)FlagIntEnum)Path)timeout_info)InputContainer)OutputContainer)pyio_close_custom_gilpyio_close_gil)	err_checkstash_exception)build_container_format)avdict_to_dictavrational_to_fractiondict_to_avdictto_avrational)int64_t)dereference)CaptureFcheckpreturnc                    t          t          j        t          j        t                   |                     }|j        dk     rdS t          j        5  t          j                    }||j	        k     r2t          t          t          d          d f           	 d d d            dS 	 d d d            n# 1 swxY w Y   ||j	        |j        z   k    rdS dS )Nr   z.Clock has been changed to before timeout start   )r   cythoncastpointerr   timeoutgiltime	monotonic
start_timer   RuntimeError)r   infocurrent_times      L/home/agentuser/manim-venv/lib/python3.11/site-packages/av/container/core.pyinterrupt_cbr'      s(    %V[1Mq%Q%QRRD|aq 
  ~''$/))  !QRR          )               do444q1s   AB//B36B3spburlflagsoptionsc                 t    t           j        5  t          | ||||          cd d d            S # 1 swxY w Y   d S N)r   r   pyav_io_open_gil)r(   r)   r*   r+   r,   s        r&   pyav_io_openr0   9   s     
 < <2sE7;;< < < < < < < < < < < < < < < < < <s   -11c           	         	 t          j        t          t          |           j                  }|t           j        urgt          t          t          j        t           j        t           j        t          j	                          |                    |j
        |j                  }ni }|                    |t           j        urt          j        t          |          nd||          }t          ||j        |t          j        z  dk              }||j        t          j        t$          |j        j                  <   |j        |d<   dS # t(          $ r t+                      cY S w xY w)N)encodingerrors r   )r   r   	Containerr   opaqueNULLr   r   libAVDictionarymetadata_encodingmetadata_errorsio_openstrPyIOFilebuffer_sizeAVIO_FLAG_WRITE
open_filesr   	iocontext	Exceptionr   )	r(   r)   r*   r+   r,   	containeroptions_dictfile	pyio_files	            r&   r/   r/   G   sP   !K	;q>>+@AA	&+%%)Kv~c6F'GH'  
 #4 0  LL L  %(%;%;FKS!!!UL
 
 )'%#2E*E!)K
 
	  	V[)2E2LMMN #1q ! ! !     !s   D?E EEc                 n    t           j        5  t          | |          cd d d            S # 1 swxY w Y   d S r.   )r   r   pyav_io_close_gil)r(   r)   s     r&   pyav_io_closerJ   u   s}     
 ( ( B''( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( ( (s   *..c                    d}	 t          j        t          t          |           j                  }|j        [t          j        t          |j                  |j        v r5t          |          }|j        t          j        t          |j                  = nt          |          }n*# t          $ r t                       t          j        }Y nw xY w|S Nr   )r   r   r5   r   r6   rA   r   r	   r
   rC   r   r8   AVERROR_UNKNOWN)r(   r)   resultrD   s       r&   rI   rI      s     F%K	;q>>+@AA	 ,GRY//93GGG*2..F $V[")%D%DEE#B''F % % %$% Ms   BB" "$C	C	ctxc           
      |   | j         t          j        k    rt          | j                  D ]}| j         |         t          j        k    r| j         |         j        t          j        k    r6t          j        t          j        | j         |         j                             t          j	        t          j
        t          j        t          j        | j         |                                        t          j	        t          j
        t          j        t          j        | j                                        d| _        d S rL   )chaptersr   r7   rangenb_chaptersmetadatar8   av_dict_freeaddressav_freepr   pp_void)rO   is     r&   _free_chaptersrZ      s    
 |v{""s'' 	 	A|A&+--<?+v{::$V^CLO4L%M%MNNNKs|A0O0OPP   	V[1M1MNNOOOCOOO    c                   `   e Zd ZU ej        Zded<   ej        Zded<   ej	        Z
ded<   ej        Zded<   ej        Zd	ed
<   ej        Zded<   ej        Zded<   ej        Zded<   ej        Zded<   ej        Zded<   ej        Zded<   ej        Zded<   ej        Zded<   ej        Z ded<   dS )Flagsz?Generate missing pts even if it requires parsing future frames.gen_ptszIgnore index.ign_idxz-Do not block when reading packets from input.	non_blockz1Ignore DTS on frames that contain both DTS & PTS.ign_dtszWDo not infer any values from other values, just return what is stored in the container.	no_fillinzDo not use AVParsers, you also must set AVFMT_FLAG_NOFILLIN as the fill in code works on frames and no parsing -> no frames. Also seeking to frames can not work if parsing to find frame boundaries has been disabled.no_parsez#Do not buffer frames when possible.	no_bufferzDThe caller has supplied a custom AVIOContext, don't avio_close() it.	custom_ioz Discard frames marked corrupted.discard_corruptz#Flush the AVIOContext every packet.flush_packetszWhen muxing, try to avoid writing any random/volatile data to the output. This includes any random IDs, real-time timestamps/dates, muxer version, etc. This flag is mainly intended for testing.bitexactzTTry to interleave outputted packets by dts (using this flag can slow demuxing down).sort_dtsz3Enable fast, but inaccurate seeks for some formats.	fast_seekz0Add bitstream filters as requested by the muxer.auto_bsfN)!__name__
__module____qualname__r8   AVFMT_FLAG_GENPTSr^   __annotations__AVFMT_FLAG_IGNIDXr_   AVFMT_FLAG_NONBLOCKr`   AVFMT_FLAG_IGNDTSra   AVFMT_FLAG_NOFILLINrb   AVFMT_FLAG_NOPARSErc   AVFMT_FLAG_NOBUFFERrd   AVFMT_FLAG_CUSTOM_IOre   AVFMT_FLAG_DISCARD_CORRUPTrf   AVFMT_FLAG_FLUSH_PACKETSrg   AVFMT_FLAG_BITEXACTrh   AVFMT_FLAG_SORT_DTSri   AVFMT_FLAG_FAST_SEEKrj   AVFMT_FLAG_AUTO_BSFrk    r[   r&   r]   r]      s^        QTQfGNfff"4G_444ADAXI>XXXCFCXG@XXXkn  lCIh  C  C  C kn  kAH  h  A  A  A7:7NI4NNNX[XpIUppp:=:XO7XXX;>;WM8WWW UX  UlH  R  l  l  lgjg~Hd~~~GJG_ID___CFCZH@ZZZZZr[   r]   c                      e Zd ZdZej        Zej        Zej	        Z
ej        Zej        Zej        Zej        Zej        Zej        Zej        Zej        Zej        Zej        Zej        Z ej!        Z"ej#        Z$ej%        Z&ej'        Z(ej)        Z*ej+        Z,ej-        Z.ej/        Z0ej1        Z2ej3        Z4ej5        Z6ej7        Z8ej9        Z:ej;        Z<ej=        Z>ej?        Z@ejA        ZBejC        ZDejE        ZFejG        ZHejI        ZJdS )
AudioCodecz Enumeration for audio codec IDs.N)Krl   rm   rn   __doc__r8   AV_CODEC_ID_NONEnoneAV_CODEC_ID_PCM_ALAWpcm_alawAV_CODEC_ID_PCM_BLURAY
pcm_blurayAV_CODEC_ID_PCM_DVDpcm_dvdAV_CODEC_ID_PCM_F16LE	pcm_f16leAV_CODEC_ID_PCM_F24LE	pcm_f24leAV_CODEC_ID_PCM_F32BE	pcm_f32beAV_CODEC_ID_PCM_F32LE	pcm_f32leAV_CODEC_ID_PCM_F64BE	pcm_f64beAV_CODEC_ID_PCM_F64LE	pcm_f64leAV_CODEC_ID_PCM_LXFpcm_lxfAV_CODEC_ID_PCM_MULAW	pcm_mulawAV_CODEC_ID_PCM_S16BE	pcm_s16beAV_CODEC_ID_PCM_S16BE_PLANARpcm_s16be_planarAV_CODEC_ID_PCM_S16LE	pcm_s16leAV_CODEC_ID_PCM_S16LE_PLANARpcm_s16le_planarAV_CODEC_ID_PCM_S24BE	pcm_s24beAV_CODEC_ID_PCM_S24DAUDpcm_s24daudAV_CODEC_ID_PCM_S24LE	pcm_s24leAV_CODEC_ID_PCM_S24LE_PLANARpcm_s24le_planarAV_CODEC_ID_PCM_S32BE	pcm_s32beAV_CODEC_ID_PCM_S32LE	pcm_s32leAV_CODEC_ID_PCM_S32LE_PLANARpcm_s32le_planarAV_CODEC_ID_PCM_S64BE	pcm_s64beAV_CODEC_ID_PCM_S64LE	pcm_s64leAV_CODEC_ID_PCM_S8pcm_s8AV_CODEC_ID_PCM_S8_PLANARpcm_s8_planarAV_CODEC_ID_PCM_U16BE	pcm_u16beAV_CODEC_ID_PCM_U16LE	pcm_u16leAV_CODEC_ID_PCM_U24BE	pcm_u24beAV_CODEC_ID_PCM_U24LE	pcm_u24leAV_CODEC_ID_PCM_U32BE	pcm_u32beAV_CODEC_ID_PCM_U32LE	pcm_u32leAV_CODEC_ID_PCM_U8pcm_u8AV_CODEC_ID_PCM_VIDCpcm_vidcr~   r[   r&   r   r      s0       **D'H+J%G)I)I)I)I)I)I%G)I)I7)I7)I-K)I7)I)I7)I)I#F1M)I)I)I)I)I)I#F'HHHr[   r   c                   n   e Zd Zd Zd Zd Zd Zd Zd Ze	j
         e	j        dd	          d
e	j        de	j        fd                        Zd Ze	j
        d             Ze	j
        d             Ze	j
        d             Zed             Zej        d
e	j        fd            Zed             Zd Zd ZdS )r5   c           	      	   |t           urt          d          t          | t                    }|s$t          | t                    st          d          t          |t
                    r|| _        n#t          t          |dd                    | _        t          |pd          | _	        t          |pd          | _
        d |pdD             | _        || _        || _        |	| _        || _        || _        |
| _        || _        d }|0d|v r|                    d          \  }}t)          |          | _        t-          j        | j                  }|}|r| xj        dz  c_        | j        r| j        j        n)t5          j        t8          j        |t8          j                  }|t8          j        k    rt=          d	          t8          j        5  t5          j         t9          j!        | j"                  |t8          j        |          }d d d            n# 1 swxY w Y   | #                    |           nt5          j$                    | _"        | j        | j        >tJ          | j"        j&        _'        t9          j!        | j(                  | j"        j&        _)        |t          tT          |          | j"        _+        | j"        xj,        t4          j-        z  c_,        t9          j.        t8          j/        |           | j"        _)        i | _0        t          |tb                    s,te          ||
|          | _3        | j3        j4        | j"        _5        |Atl          | j"        _        tn          | j"        _8        | j"        xj,        t4          j9        z  c_,        |s
| j        r| j        j:        nt8          j        }tw          | j	        | j
                  }| <                    | j                   | =                                 t8          j        5  t5          j>        t9          j!        | j"                  ||t9          j!        |j"                            }d d d            n# 1 swxY w Y   | <                    d            | #                    |           | xj        d
z  c_        |+t          | j"        j@        | j"        jA                  | _        d S d S )Nzcannot construct base Containerz&Container cannot be directly extended.namez<none>r~   c                 ,    g | ]}t          |          S r~   )dict).0xs     r&   
<listcomp>z'Container.__cinit__.<locals>.<listcomp>  s    EEE1tAwwEEEr[   :r   z!Could not determine output format   )B_cinit_sentinelr#   
isinstancer   r   r=   r   getattrr   r,   container_optionsstream_optionshwaccelr:   r;   open_timeoutread_timeoutr?   r<   splitContainerFormatformatosfsencode_myflagoptrr8   av_guess_formatr   r7   
ValueErrornogilavformat_alloc_output_context2rV   ptrr   avformat_alloc_contextr'   interrupt_callbackcallbackinterrupt_callback_infor6   r   audio_codec_idr+   ro   r   p_voidrA   
basestringr>   rF   rB   r)   r0   rJ   	io_close2rw   iptr
Dictionaryset_timeoutstart_timeoutavformat_open_inputr   iformatoformat)selfsentinelfile_format_namer,   r   r   r   r:   r;   r?   r   r   r<   	writeableacodecname_objr   ofmtresifmt	c_optionss                         r&   	__cinit__zContainer.__cinit__   s     ?**@AAA!+D/!B!B	 	ID.!A!A 	IGHHHeS!! 	>DIIGE68<<==DIGMr**!%&7&=2!>!>EE0D"EEE!2.((&"k!!&1&7&7&<&<#V)+66DK +di00&  	FLLALL ;I  (dFKHH 
 v{"" !DEEE  8N48,,K	                NN3 133DH  ,0A0M7C+45;^06 6+2 !*1*f*E*E'#// +fmT:: %,, 	. Y??DI)-DHK+DH!.DHHNNc66NN  	'+{C4;##D"4<1GHHIT.///     -N48,,dD&.:W:W                T"""NN3LLALL01A48CSTTDKKK s%   9HHHAQQQc                     t           j        5  t          j        | j                   d d d            d S # 1 swxY w Y   d S r.   )r   r   r8   avformat_free_contextr   r   s    r&   __dealloc__zContainer.__dealloc__^  s    \ 	0 	0%dh///	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0s   488c                     | S r.   r~   r  s    r&   	__enter__zContainer.__enter__b  s    r[   c                 .    |                                   d S r.   )close)r   exc_typeexc_valexc_tbs       r&   __exit__zContainer.__exit__e  s    

r[   c                     t           r.   )NotImplementedErrorr  s    r&   r  zContainer.closeh  s    !!r[   c                 @    d| j         j         d| j        p| j        dS )Nz<av. >)	__class__rl   rF   r   r  s    r&   __repr__zContainer.__repr__k  s)    Kdn-KK	0FTYKKKKr[   Fr   valuer   c                 .    t          || j                  S )N)filename)r   r   r   r  s     r&   r   zContainer.err_checkn  s     3333r[   c           
         |                                   t                      5 }t          j        | j        ddt          | t                               d d d            n# 1 swxY w Y   d                    d |D                       S )Nr   r4   c              3   &   K   | ]}|d          V  dS )r   Nr~   )r   logs     r&   	<genexpr>z)Container.dumps_format.<locals>.<genexpr>w  s&      ..#s1v......r[   )_assert_open
LogCapturer8   av_dump_formatr   r   r   join)r   logss     r&   dumps_formatzContainer.dumps_formats  s    \\ 	STtxB
40Q0QRRR	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	S 	Sww........s   0AA#&A#c                 >    |d| j         _        d S || j         _        d S )Ng      )r   r   )r   r   s     r&   r   zContainer.set_timeouty  s)    ?37D(0003:D(000r[   c                 @    t          j                    | j        _        d S r.   )r    r!   r   r"   r  s    r&   r   zContainer.start_timeout  s    26.2B2B$///r[   c                 N    | j         t          j        k    rt          d          d S )NzContainer is not open)r   r   r7   AssertionErrorr  s    r&   r  zContainer._assert_open  s(    8v{"" !8999 #"r[   c                 B    |                                   | j        j        S r.   r  r   r+   r  s    r&   r+   zContainer.flags  s    x~r[   c                 F    |                                   || j        _        d S r.   r(  r  s     r&   r+   zContainer.flags  s!    r[   c                     | j         dz  S )Nr   )r   r  s    r&   input_was_openedzContainer.input_was_opened  s    |ar[   c                 f   |                                   g }t          | j        j                  D ]}| j        j        |         }|                    |j        |j        |j        t          t          j        |j                            t          |j        | j        | j                  d           |S )N)idstartend	time_baserT   )r  rR   r   rS   rQ   appendr-  r.  r/  r   r   rV   r0  r   rT   r:   r;   )r   rN   rY   chs       r&   rQ   zContainer.chapters  s    tx+,, 	 	A"1%BMM%X6!7r|8T8T!U!U .T%;T=Q! ! 
 
 
 
 r[   c           
         |                                   t          |          }t          j        5  t	          | j                   d d d            n# 1 swxY w Y   t          j        t          t          j	        |t          j
        t          j        t          j                           z                      }|t          j        k    rt          d          t          |          D ]^}||         }t          j        t          j        t          j                 t          j	        t          j
        t          j                                      }|t          j        k    rt          d          |d         |_        t          j        t"          |d                   |_        t          j        t"          |d                   |_        t)          |d         t          j        |j                             t          j        |_        d|v r9t1          t          j        |j                  |d         | j        | j                   |||<   `|| j        _        || j        _        d S )Nzav_malloc failed for chapterszav_malloc failed for chapterr-  r.  r/  r0  rT   )r  lenr   r   rZ   r   r   AVChapterPtrPtrr8   	av_mallocsizeofr   	AVChapterr7   MemoryErrorrR   r-  r   r.  r/  r   rV   r0  rT   r   r:   r;   rS   rQ   )r   rQ   countch_arrayrY   entryr2  s          r&   set_chapterszContainer.set_chapters  s#   #&x== \ 	% 	%48$$$	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% 	% ;M%&-s}0M"N"NNOO
 
 v{""=>>>u 	 	AQKEs}-fmCM::;; B V[  !"@AAA$KBE{7E'N;;BH[%,77BF%,fnR\.J.JKKK +BKU""N2;//*%*(	   HQKK$$s   AAAN)rl   rm   rn   r   r  r  r  r  r  r   cfunc	exceptvalintr   r"  r   r   r  propertyr+   setterr+  rQ   r=  r~   r[   r&   r5   r5      s       vU vU vUp0 0 0    " " "L L L \Vb&&&4vz 4fj 4 4 4 '& \4/ / / \; ; \; \C C \C \: : \:   X \6:    \     X   &*% *% *% *% *%r[   r5   utf-8strict   c                 F   |3t          |t                    r|dk    s|dk    st          d|           t          | t                    rn,t          | t                    r|  } n|t	          | dd          }|d}t          |	t
                    r(t          |	          dk    st          d          |	\  }}n|	}|	}|                    d          r t          t          | |||||||||||
          S |rt          d          t          t          | ||||d||||||
          S )	a	  open(file, mode='r', **kwargs)

    Main entrypoint to opening files/streams.

    :param str file: The file to open, which can be either a string or a file-like object.
    :param str mode: ``"r"`` for reading and ``"w"`` for writing.
    :param str format: Specific format to use. Defaults to autodect.
    :param dict options: Options to pass to the container and all streams.
    :param dict container_options: Options to pass to the container.
    :param list stream_options: Options to pass to each stream.
    :param str metadata_encoding: Encoding to use when reading or writing file metadata.
        Defaults to ``"utf-8"``.
    :param str metadata_errors: Specifies how to handle encoding errors; behaves like
        ``str.encode`` parameter. Defaults to ``"strict"``.
    :param int buffer_size: Size of buffer for Python input/output operations in bytes.
        Honored only when ``file`` is a file-like object. Defaults to 32768 (32k).
    :param timeout: How many seconds to wait for data before giving up, as a float, or a
        ``(open timeout, read timeout)`` tuple.
    :param callable io_open: Custom I/O callable for opening files/streams.
        This option is intended for formats that need to open additional
        file-like objects to ``file`` using custom I/O.
        The callable signature is ``io_open(url: str, flags: int, options: dict)``, where
        ``url`` is the url to open, ``flags`` is a combination of AVIO_FLAG_* and
        ``options`` is a dictionary of additional options. The callable should return a
        file-like object.
    :param HWAccel hwaccel: Optional settings for hardware-accelerated decoding.
    :rtype: Container

    For devices (via ``libavdevice``), pass the name of the device to ``format``,
    e.g.::

        >>> # Open webcam on MacOS.
        >>> av.open('0', format='avfoundation') # doctest: +SKIP

    For DASH and custom I/O using ``io_open``, add a protocol prefix to the ``file`` to
    prevent the DASH encoder defaulting to the file protocol and using temporary files.
    The custom I/O callable can be used to remove the protocol prefix to reveal the actual
    name for creating the file-like object. E.g.::

        >>> av.open("customprotocol://manifest.mpd", "w", io_open=custom_io) # doctest: +SKIP

    .. seealso:: :ref:`garbage_collection`

    More information on using input and output devices is available on the
    `FFmpeg website <https://www.ffmpeg.org/ffmpeg-devices.html>`_.
    Nrwz%mode must be 'r', 'w', or None, got: moder   z0timeout must be `float` or `tuple[float, float]`zAProvide stream options via Container.add_stream(..., options={}).)r   r=   r   r   r   tupler4  
startswithr   r   r   )rF   rI  r   r,   r   r   r:   r;   r?   r   r<   r   r   r   s                 r&   openrL    s~   z LZc22Lts{{dckkGGGHHH$ +	D$		 +y	tVT**|'5!! 7||q  OPPP%,"lls 

 
 	
   
O
 
 	
   r[   )NNNNNrC  rD  rE  NNN)Br   r    enumr   r   pathlibr   r   cython.cimports.libavcimportslibavr8   !cython.cimports.av.container.corer   "cython.cimports.av.container.inputr   #cython.cimports.av.container.outputr   !cython.cimports.av.container.pyior	   r
   cython.cimports.av.errorr   r   cython.cimports.av.formatr   cython.cimports.av.utilsr   r   r   r   cython.cimports.libc.stdintr   cython.operatorr   
av.loggingr   r  declareobjectr   typedefr   r8  r5  r>  r   r?  r   r@  r'   AVFormatContextAVIOContextp_const_charr9   r0   r/   rJ   rI   voidrZ   r]   r   cclassr5   rL  r~   r[   r&   <module>rd     sg   				                 # # # # # # # # # : : : : : : = = = = = = ? ? ? ? ? ? S S S S S S S S ? ? ? ? ? ? ? ? < < < < < <            0 / / / / / ' ' ' ' ' ' , , , , , , &.22 &.s}0M!NOO FM fj      0 <~c)*<v~co67< 
	< :	<
 ^FN3+;<=< Z< < <   < )!~c)*)!v~co67)! 
	)! :	)!
 ^FN3+;<=)! Z)! )! )!  )!X (~c)*(06s0O(Z( ( (   ( ~c)*06s0OZ    2 s':;       [ [ [ [ [D [ [ [ $( $( $( $( $( $( $( $(P o% o% o% o% o% o% o% o%h 
v v v v v vr[   