
    F`j#              	          d dl 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 ej                   e e             Zej&                  d	ed
ej*                  ej,                     dedefd       Zej4                   G d d             Zej4                   G d de             Zej4                   G d de             Zy)    )FlagN)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     4/usr/local/lib/python3.12/dist-packages/av/stream.pyr   r      sc    G
CHGFGFOMLLHLHIKJr-   r   	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.streamr4   av.subtitles.streamr5   av.video.streamr6   codecpar
codec_typelibAVMEDIA_TYPE_VIDEO__new___cinit_bypass_sentinelAVMEDIA_TYPE_AUDIOAVMEDIA_TYPE_SUBTITLEAVMEDIA_TYPE_ATTACHMENTAttachmentStreamAVMEDIA_TYPE_DATA
DataStreamStream_init)r/   r0   r1   r4   r5   r6   	py_streams          r.   wrap_streamrL   (   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                   z   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y)rI   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)rB   RuntimeErrorselfnames     r.   	__cinit__zStream.__cinit___   s    ))?@@r-   r/   streamr1   c                 :   || _         || _        t        | j                        | _        || _        | j                  r|j
                  | j                  _        t        |j                  | j                   j                  | j                   j                        | _        y N)encodingerrors)r/   r7   r   index_entriesr1   r9   stream_indexr   r(   metadata_encodingmetadata_errors)rQ   r/   rT   r1   s       r.   rJ   zStream._initd   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 )NrR   <av. # z<notype>/	<nocodec> at 0xx>)getattr	__class__r   r9   typeidrP   s     r.   __repr__zStream.__repr__y   sb    tVT*4>>**+2djj\499;R
:SST"{#6"T(1Q8	
r-   c                    |dk(  r| j                  |       y |dk(  r|| j                  _        y |dk(  r4t        |t	        j
                  | j                  j                               y | j                  t        | j                  ||       y y )Nri   disposition	time_base)	_set_idr7   rl   r
   cythonaddressrm   r1   setattr)rQ   rR   values      r.   __setattr__zStream.__setattr__   s|    4<LL= #(DHH ;%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 rV   )r	   ro   rp   r7   r(   r/   r[   r\   r1   rm   numr   r?   avcodec_parameters_from_contextr=   rQ   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

        r7   ri   rw   s    r.   ri   z	Stream.id   s     xx{{r-   c                 N    |d| j                   _        y || j                   _        y )Nr   rz   )rQ   rr   s     r.   rn   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]
        )r1   profilesrw   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)r1   profilerw   s    r.   r   zStream.profile   s"     %%---r-   c                 .    | j                   j                  S )zZ
        The index of this stream in its :class:`.Container`.

        :type: int
        )r7   r9   rw   s    r.   r9   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   ro   rp   r7   rm   rw   s    r.   rm   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)r7   
start_timer?   AV_NOPTS_VALUErw   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)r7   durationr?   r   rw   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
        )r7   	nb_framesrw   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(   getrw   s    r.   r   zStream.language       }}  ,,r-   c                 @    t        | j                  j                        S N)r   r7   rl   rw   s    r.   rl   zStream.disposition  s    488//00r-   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)r?   av_get_media_type_stringr7   r=   r>   ro   NULL)rQ   
media_types     r.   rh   zStream.type  s:     11$((2C2C2N2NO
&&++5yE:Er-   N)r   r   r   __doc__rS   ro   cfunc	Containerpointerr?   AVStreamCodecContextrJ   rj   rs   rx   propertyri   rn   r}   r   r9   rm   r   r   r   r   rl   rh   r,   r-   r.   rI   rI   M   sh    A
 \\

 s||,
 $	
 
(
5 \\
 
*   \\    	 	 	 	   J J ' ' % % " " - - 1 1 F Fr-   rI   c                   "    e Zd Zd Zed        Zy)rH   c           
          d| j                   j                   d| j                   d| j                  xs d dt	        |       dd	S )Nr^   r_   z data/rb   rc   rd   re   )rg   r   r9   rR   ri   rw   s    r.   rj   zDataStream.__repr__  sG    4>>**+2djj\yy'K(r$xl!=	
r-   c                     t        j                  | j                  j                  j                        }|t
        j                  k(  ry |j                  S r   )r?   avcodec_descriptor_getr7   r=   codec_idro   r   rR   )rQ   descs     r.   rR   zDataStream.name"  sB     &&txx'8'8'A'AB 	 6;;yyr-   N)r   r   r   rj   r   rR   r,   r-   r.   rH   rH     s    
  r-   rH   c                   @    e Zd ZdZed        Zed        Zed        Zy)rF   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   rw   s    r.   rR   zAttachmentStream.name3  r   r-   c                 8    | j                   j                  d      S )zV
        Returns the MIME type of the attachment.

        :rtype: str | None
        mimetyper   rw   s    r.   r   zAttachmentStream.mimetype<  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-   )	r7   r=   	extradataextradata_sizero   r   	bytearrayrangebytes)rQ   r   sizepayloadis        r.   datazAttachmentStream.dataE  sx     %)HH$5$5$?$?	"&(("3"3"B"B#tqyD/t 	&A"1GAJ	& W~r-   N)r   r   r   r   r   rR   r   r   r,   r-   r.   rF   rF   ,  sC    
 - - - -  r-   rF   )enumr   ro   cython.cimportsr   r?   cython.cimports.av.errorr   cython.cimports.av.indexr   cython.cimports.av.utilsr   r   r	   r
   r   declareobjectrB   r   r   r   r   r   rI   rL   cclassrH   rF   r,   r-   r.   <module>r      s      ( . 7 $ , (9  !!nnS\\*!  ! 	! !H IF IF IFX   " $v $ $r-   