
    \j&              	          d dl mZmZ d dlZd dlmZ d dlmZ d dl	m
Z
 d dlmZmZmZmZ  G d de      Z G d	 d
e      Z ej$                  e e             Zej*                  dedej.                  ej0                     dedefd       Zej8                   G d d             Zej:                  ej8                   G d de                    Zej:                  ej8                   G d de                    Zy)    )IntEnumIntFlagN)libav)	err_check)wrap_index_entries)avdict_to_dictavrational_to_fractiondict_to_avdictto_avrationalc                   X    e Zd ZdZdZdZdZdZdZdZ	dZ
d	Zd
ZdZdZdZdZdZdZdZdZdZy)Disposition                   @         i   i   i   i   i   i   i   i   i   i    N)__name__
__module____qualname__defaultduboriginalcommentlyricskaraokeforcedhearing_impairedvisual_impairedclean_effectsattached_pictimed_thumbnailsnon_diegeticcaptionsdescriptionsmetadata	dependentstill_image
multilayer     </root/.hermes/venv/lib/python3.12/site-packages/av/stream.pyr   r      sc    G
CHGFGFOMLLHLHIKJr.   r   c                       e Zd Zej                  Zej                  Zej                  Z	ej                  Zej                  Zej                  Zej                   Zy)DiscardN)r   r   r   libAVDISCARD_NONEnoneAVDISCARD_DEFAULTr   AVDISCARD_NONREFnonrefAVDISCARD_BIDIRbidirAVDISCARD_NONINTRAnonintraAVDISCARD_NONKEYnonkeyAVDISCARD_ALLallr-   r.   r/   r1   r1   %   sO    D##G!!FE%%H!!F


Cr.   r1   	containerc_streamcodec_contextreturnc                 j   | j                   j                  |j                     |k(  sJ ddlm} ddlm} ddlm} |j                  j                  t        j                  k(  r|j                  |t              }n&|j                  j                  t        j                  k(  r|j                  |t              }n|j                  j                  t        j                   k(  r|j                  |t              }n|j                  j                  t        j"                  k(  rt$        j                  t$        t              }nd|j                  j                  t        j&                  k(  rt(        j                  t(        t              }nt*        j                  t*        t              }|j-                  | ||       |S )zBuild an av.Stream for an existing AVStream.

    The AVStream MUST be fully constructed and ready for use before this is called.
    r   )AudioStream)SubtitleStream)VideoStream)ptrstreamsindexav.audio.streamrE   av.subtitles.streamrF   av.video.streamrG   codecpar
codec_typer2   AVMEDIA_TYPE_VIDEO__new___cinit_bypass_sentinelAVMEDIA_TYPE_AUDIOAVMEDIA_TYPE_SUBTITLEAVMEDIA_TYPE_ATTACHMENTAttachmentStreamAVMEDIA_TYPE_DATA
DataStreamStream_init)r@   rA   rB   rE   rF   rG   	py_streams          r/   wrap_streamr\   2   s9    ==  0H<<< ,2+##s'='==''5KL					%	%)?)?	?''5KL					%	%)B)B	B"**>;QR					%	%)D)D	D$,,-=?UV					%	%)>)>	>&&z3IJ	NN6+AB	OOIx7r.   c                      e Zd ZdZd Zej                  dedej                  e	j                     defd       Zd Zd Zej                  d	        Zed
        Zej                  d        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zed        Zy)rY   a  
    A single stream of audio, video or subtitles within a :class:`.Container`.

    ::

        >>> fh = av.open(video_path)
        >>> stream = fh.streams.video[0]
        >>> stream
        <av.VideoStream #0 h264, yuv420p 1280x720 at 0x...>

    This encapsulates a :class:`.CodecContext`, located at :attr:`Stream.codec_context`.
    Attribute access is passed through to that context when attributes are missing
    on the stream itself. E.g. ``stream.options`` will be the options on the
    context.
    c                 *    |t         u ry t        d      )Nz"cannot manually instantiate Stream)rR   RuntimeErrorselfnames     r/   	__cinit__zStream.__cinit__i   s    ))?@@r.   r@   streamrB   c                 :   || _         || _        t        | j                        | _        || _        | j                  r|j
                  | j                  _        t        |j                  | j                   j                  | j                   j                        | _        y N)encodingerrors)r@   rH   r   index_entriesrB   rJ   stream_indexr   r)   metadata_encodingmetadata_errors)ra   r@   rd   rB   s       r/   rZ   zStream._initn   ss     #/9*.4llD+&OO^^55>>11
r.   c                     t        | dd       }d| j                  j                   d| j                   d| j                  xs d d|xs d dt        |       d	d
S )Nrb   <av. # z<notype>/	<nocodec> at 0xx>)getattr	__class__r   rJ   typeidr`   s     r/   __repr__zStream.__repr__   sb    tVT*4>>**+2djj\499;R
:SST"{#6"T(1Q8	
r.   c                 n   |dk(  r| j                  |       y |dk(  r|| j                  _        y |dk(  r%t        |      j                  | j                  _        y |dk(  r4t        |t        j                  | j                  j                               y | j                  t        | j                  ||       y y )Nry   dispositiondiscard	time_base)_set_idrH   r|   r1   valuer}   r   cythonaddressr~   rB   setattr)ra   rb   r   s      r/   __setattr__zStream.__setattr__   s    4<LL= #(DHH 9&u~33DHH;%0B0B!CD )D&&e4 *r.   c                    t        t        j                  | j                  j                        | j                  | j
                  j                  | j
                  j                         | j                  y | j                  j                  j                  s/| j                  j                  j                  | j                  _	        t        t        j                  | j                  j                  | j                  j                               y rf   )r
   r   r   rH   r)   r@   rk   rl   rB   r~   numr   r2   avcodec_parameters_from_contextrN   ra   s    r/   _finalize_for_outputzStream._finalize_for_output   s    NN488,,-MM^^55>>11		
 %xx!!%%!%!3!3!7!7!A!ADHH 	//!!4#5#5#9#9	
r.   c                 .    | j                   j                  S )zM
        The format-specific ID of this stream.

        :type: int

        rH   ry   r   s    r/   ry   z	Stream.id   s     xx{{r.   c                 N    |d| j                   _        y || j                   _        y )Nr   r   )ra   r   s     r/   r   zStream._set_id   s    =DHHKDHHKr.   c                 J    | j                   r| j                   j                  S g S )zX
        List the available profiles for this stream.

        :type: list[str]
        )rB   profilesr   s    r/   r   zStream.profiles   s$     %%...Ir.   c                 H    | j                   r| j                   j                  S y)zA
        The profile of this stream.

        :type: str
        N)rB   profiler   s    r/   r   zStream.profile   s"     %%---r.   c                 .    | j                   j                  S )zZ
        The index of this stream in its :class:`.Container`.

        :type: int
        )rH   rJ   r   s    r/   rJ   zStream.index   s     xx~~r.   c                 f    t        t        j                  | j                  j                              S )z
        The unit of time (in fractional seconds) in which timestamps are expressed.

        :type: fractions.Fraction | None

        )r	   r   r   rH   r~   r   s    r/   r~   zStream.time_base   s"     &fnnTXX5G5G&HIIr.   c                 ~    | j                   j                  t        j                  k7  r| j                   j                  S y)z
        The presentation timestamp in :attr:`time_base` units of the first
        frame in this stream.

        :type: int | None
        N)rH   
start_timer2   AV_NOPTS_VALUEr   s    r/   r   zStream.start_time   s1     88#"4"4488&&& 5r.   c                 ~    | j                   j                  t        j                  k7  r| j                   j                  S y)ze
        The duration of this stream in :attr:`time_base` units.

        :type: int | None

        N)rH   durationr2   r   r   s    r/   r   zStream.duration   s1     88 2 2288$$$ 3r.   c                 .    | j                   j                  S )z{
        The number of frames this stream contains.

        Returns ``0`` if it is not known.

        :type: int
        )rH   	nb_framesr   s    r/   frameszStream.frames  s     xx!!!r.   c                 8    | j                   j                  d      S )zH
        The language of the stream.

        :type: str | None
        languager)   getr   s    r/   r   zStream.language       }}  ,,r.   c                 @    t        | j                  j                        S N)r   rH   r|   r   s    r/   r|   zStream.disposition  s    488//00r.   c                 @    t        | j                  j                        S )aH  
        Controls which packets of this stream are discarded by the demuxer.

        Set this to e.g. :attr:`Discard.all` on streams you don't need so that
        :meth:`.Container.demux` and :meth:`.Container.seek` skip them, avoiding
        the cost of synchronizing streams you never read.

        :type: Discard
        )r1   rH   r}   r   s    r/   r}   zStream.discard  s     txx''((r.   c                     t        j                  | j                  j                  j                        }|t
        j                  k(  rdS |S )zu
        The type of the stream.

        :type: Literal["audio", "video", "subtitle", "data", "attachment"]
        unknown)r2   av_get_media_type_stringrH   rN   rO   r   NULL)ra   
media_types     r/   rx   zStream.type)  s:     11$((2C2C2N2NO
&&++5yE:Er.   N)r   r   r   __doc__rc   r   cfunc	Containerpointerr2   AVStreamCodecContextrZ   rz   r   r   propertyry   r   r   r   rJ   r~   r   r   r   r   r|   r}   rx   r-   r.   r/   rY   rY   W   s|    A
 \\

 s||,
 $	
 
(
5$ \\
 
*   \\    	 	 	 	   J J ' ' % % " " - - 1 1 
) 
) F Fr.   rY   c                   "    e Zd Zd Zed        Zy)rX   c           
          d| j                   j                   d| j                   d| j                  xs d dt	        |       dd	S )Nrn   ro   z data/rr   rs   rt   ru   )rw   r   rJ   rb   ry   r   s    r/   rz   zDataStream.__repr__7  sG    4>>**+2djj\yy'K(r$xl!=	
r.   c                     t        j                  | j                  j                  j                        }|t
        j                  k(  ry |j                  S r   )r2   avcodec_descriptor_getrH   rN   codec_idr   r   rb   )ra   descs     r/   rb   zDataStream.name=  sB     &&txx'8'8'A'AB 	 6;;yyr.   N)r   r   r   rz   r   rb   r-   r.   r/   rX   rX   4  s    
  r.   rX   c                   @    e Zd ZdZed        Zed        Zed        Zy)rV   z
    An :class:`AttachmentStream` represents a stream of attachment data within a media container.
    Typically used to attach font files that are referenced in ASS/SSA Subtitle Streams.
    c                 8    | j                   j                  d      S )zV
        Returns the file name of the attachment.

        :rtype: str | None
        filenamer   r   s    r/   rb   zAttachmentStream.nameO  r   r.   c                 8    | j                   j                  d      S )zV
        Returns the MIME type of the attachment.

        :rtype: str | None
        mimetyper   r   s    r/   r   zAttachmentStream.mimetypeX  r   r.   c                    | j                   j                  j                  }| j                   j                  j                  }|t        j
                  k(  s|dk  ryt        |      }t        |      D ]
  }||   ||<    t        |      S )z+Return the raw attachment payload as bytes.r   r.   )	rH   rN   	extradataextradata_sizer   r   	bytearrayrangebytes)ra   r   sizepayloadis        r/   datazAttachmentStream.dataa  sx     %)HH$5$5$?$?	"&(("3"3"B"B#tqyD/t 	&A"1GAJ	& W~r.   N)r   r   r   r   r   rb   r   r   r-   r.   r/   rV   rV   G  sC    
 - - - -  r.   rV   ) enumr   r   r   cython.cimportsr   r2   cython.cimports.av.errorr   cython.cimports.av.indexr   cython.cimports.av.utilsr   r	   r
   r   r   r1   declareobjectrR   r   r   r   r   r   rY   r\   cclassfinalrX   rV   r-   r.   r/   <module>r      s   !  ( . 7 ' ,g  (9  !!nnS\\*!  ! 	! !H YF YF YFx    " $v $  $r.   