o
    wi!                  	   @   s   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 deZeee Zejd	ed
ejej dedefddZejG dd dZejG dd deZejG dd deZdS )    )FlagN)libav)	err_check)Packet)avdict_to_dictavrational_to_fractiondict_to_avdictto_avrationalc                   @   sX   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dS )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 r*   r*   F/home/ubuntu/sommelier/.venv/lib/python3.10/site-packages/av/stream.pyr
      s(    r
   	containerc_streamcodec_contextreturnc                 C   s   | j j|j |ksJ ddlm} ddlm} ddlm} |j	j
tjkr+||t}n>|j	j
tjkr9||t}n0|j	j
tjkrG||t}n"|j	j
tjkrUttt}n|j	j
tjkrcttt}nttt}|| || |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.streamr0   av.subtitles.streamr1   av.video.streamr2   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,   r-   r.   r0   r1   r2   	py_streamr*   r*   r+   wrap_stream(   s"   rH   c                   @   s   e Zd ZdZdd Zejdedeje	j
 defddZd	d
 Zdd Zejdd Zedd Zejdd Zedd Zedd Zedd Zedd Zedd Zedd Zedd  Zed!d" Zed#d$ Zed%d& Zd'S )(rE   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                 C   s   |t u rd S td)Nz"cannot manually instantiate Stream)r>   RuntimeErrorselfnamer*   r*   r+   	__cinit___   s   zStream.__cinit__r,   streamr.   c                 C   s@   || _ || _|| _| jr|j| j_t|j| j j| j jd| _d S N)encodingerrors)	r,   r3   r.   r5   stream_indexr   r&   metadata_encodingmetadata_errors)rK   r,   rN   r.   r*   r*   r+   rF   d   s   
zStream._initc                 C   sF   t | dd }d| jj d| j d| jpd d|pd dt| d	d
S )NrL   <av. # z<notype>/	<nocodec> at 0xx>)getattr	__class__r   r5   typeidrJ   r*   r*   r+   __repr__x   s    zStream.__repr__c                 C   sj   |dkr|  | d S |dkr|| j_d S |dkr%t|t| jj d S | jd ur3t| j|| d S d S )Nr`   disposition	time_base)	_set_idr3   rb   r	   cythonaddressrc   r.   setattr)rK   rL   valuer*   r*   r+   __setattr__   s   

zStream.__setattr__c                 C   sX   t t| jj| j| jj| jjd | jjj	s| j
jj| j_tt| jj| j
j d S rO   )r   re   rf   r3   r&   r,   rS   rT   rc   numr.   r   r;   avcodec_parameters_from_contextr9   rK   r*   r*   r+   _finalize_for_output   s   
zStream._finalize_for_outputc                 C      | j jS )zM
        The format-specific ID of this stream.

        :type: int

        r3   r`   rl   r*   r*   r+   r`      s   z	Stream.idc                 C   s    |d u r
d| j _d S || j _d S )Nr   ro   )rK   rh   r*   r*   r+   rd      s   zStream._set_idc                 C   s   | j r| j jS g S )zX
        List the available profiles for this stream.

        :type: list[str]
        )r.   profilesrl   r*   r*   r+   rp         zStream.profilesc                 C   s   | j r| j jS dS )zA
        The profile of this stream.

        :type: str
        N)r.   profilerl   r*   r*   r+   rr      rq   zStream.profilec                 C   rn   )zZ
        The index of this stream in its :class:`.Container`.

        :type: int
        )r3   r5   rl   r*   r*   r+   r5      s   zStream.indexc                 C   s   t t| jjS )z
        The unit of time (in fractional seconds) in which timestamps are expressed.

        :type: fractions.Fraction | None

        )r   re   rf   r3   rc   rl   r*   r*   r+   rc      s   zStream.time_basec                 C      | j jtjkr| j jS dS )z
        The presentation timestamp in :attr:`time_base` units of the first
        frame in this stream.

        :type: int | None
        N)r3   
start_timer;   AV_NOPTS_VALUErl   r*   r*   r+   rt         zStream.start_timec                 C   rs   )ze
        The duration of this stream in :attr:`time_base` units.

        :type: int | None

        N)r3   durationr;   ru   rl   r*   r*   r+   rw      rv   zStream.durationc                 C   rn   )z{
        The number of frames this stream contains.

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

        :type: int
        )r3   	nb_framesrl   r*   r*   r+   frames   s   	zStream.framesc                 C      | j dS )zH
        The language of the stream.

        :type: str | None
        languager&   getrl   r*   r*   r+   r{         zStream.languagec                 C   s   t | jjS N)r
   r3   rb   rl   r*   r*   r+   rb     s   zStream.dispositionc                 C   s   t | jjjS )zu
        The type of the stream.

        :type: Literal["audio", "video", "subtitle", "data", "attachment"]
        )r;   av_get_media_type_stringr3   r9   r:   rl   r*   r*   r+   r_     s   zStream.typeN)r   r   r   __doc__rM   re   cfunc	Containerpointerr;   AVStreamCodecContextrF   ra   ri   rm   propertyr`   rd   rp   rr   r5   rc   rt   rw   ry   r{   rb   r_   r*   r*   r*   r+   rE   M   sN    


	




	







rE   c                   @   s    e Zd Zdd Zedd ZdS )rD   c              	   C   s0   d| j j d| j d| jpd dt| dd	S )NrU   rV   z data/rY   rZ   r[   r\   )r^   r   r5   rL   r`   rl   r*   r*   r+   ra     s   zDataStream.__repr__c                 C   s$   t | jjj}|tjkrd S |jS r   )r;   avcodec_descriptor_getr3   r9   codec_idre   NULLrL   )rK   descr*   r*   r+   rL     s
   
zDataStream.nameN)r   r   r   ra   r   rL   r*   r*   r*   r+   rD     s    rD   c                   @   s(   e Zd ZdZedd Zedd ZdS )rB   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                 C   rz   )zV
        Returns the file name of the attachment.

        :rtype: str | None
        filenamer|   rl   r*   r*   r+   rL   .  r~   zAttachmentStream.namec                 C   rz   )zV
        Returns the MIME type of the attachment.

        :rtype: str | None
        mimetyper|   rl   r*   r*   r+   r   7  r~   zAttachmentStream.mimetypeN)r   r   r   r   r   rL   r   r*   r*   r*   r+   rB   '  s    
rB   )enumr   re   cython.cimportsr   r;   cython.cimports.av.errorr   cython.cimports.av.packetr   cython.cimports.av.utilsr   r   r   r	   r
   declareobjectr>   r   r   r   r   r   rE   rH   cclassrD   rB   r*   r*   r*   r+   <module>   s2    
$ H