o
    i\1                     @   s.  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
 d dlZdd	 Zd
d ZG dd de
Zdd Zdd Zdd ZG dd deZG dd deZG dd deZG dd deZG dd deZG dd deZG d d! d!eZG d"d# d#eZehdfd$d%Zd*d&d'Zd*d(d)ZdgZdS )+    )unicode_literals)
basestring   )KwargReprNode)escape_charsget_hash_int)objectNc                 C   s&   d}|D ]}t | |rd} |S q|S )NFT)
isinstance)objtypesZvalidZstream_type r   [/var/www/html/eduruby.in/lip-sync/lip-sync-env/lib/python3.10/site-packages/ffmpeg/nodes.py_is_of_types
   s   
r   c                 C   s   d dd | D S )Nz, c                 S   s   g | ]
}d  |j|jqS )z{}.{})format
__module____name__.0xr   r   r   
<listcomp>       z"_get_types_str.<locals>.<listcomp>)join)r   r   r   r   _get_types_str   s   r   c                   @   sT   e Zd ZdZ	dddZdd Zdd Zd	d
 Zdd Ze	dd Z
e	dd ZdS )Streamz^Represents the outgoing edge of an upstream node; may be used to create more downstream nodes.Nc                 C   s8   t ||stdt|t||| _|| _|| _d S )NzHExpected upstream node to be of one of the following type(s): {}; got {})r   	TypeErrorr   r   typenodelabelselector)selfupstream_nodeupstream_labelZ
node_typesupstream_selectorr   r   r   __init__   s   

zStream.__init__c                 C   s   t t| jt| jgS N)r   hashr   r   r   r   r   r   __hash__'   s   zStream.__hash__c                 C   s   t | t |kS r$   )r%   )r   otherr   r   r   __eq__*   s   zStream.__eq__c                 C   s>   | j jdd}d}| jrd| j}d|| j|| j j}|S )NF)Zinclude_hash z:{}z{}[{!r}{}] <{}>)r   Z	long_reprr   r   r   Z
short_hash)r   Z	node_reprr   outr   r   r   __repr__-   s   zStream.__repr__c                 C   sB   | j durtd| t|tstd|| jj| j|dS )a  
        Select a component (audio, video) of the stream.

        Example:
            Process the audio and video portions of a stream independently::

                input = ffmpeg.input('in.mp4')
                audio = input['a'].filter("aecho", 0.8, 0.9, 1000, 0.3)
                video = input['v'].hflip()
                out = ffmpeg.output(audio, video, 'out.mp4')
        Nz!Stream already has a selector: {}z*Expected string index (e.g. 'a'); got {!r}r   r   )	r   
ValueErrorr   r	   r   r   r   streamr   )r   indexr   r   r   __getitem__7   s
   

zStream.__getitem__c                 C      | d S )a  Select the audio-portion of a stream.

        Some ffmpeg filters drop audio streams, and care must be taken
        to preserve the audio in the final output.  The ``.audio`` and
        ``.video`` operators can be used to reference the audio/video
        portions of a stream so that they can be processed separately
        and then re-combined later in the pipeline.  This dilemma is
        intrinsic to ffmpeg, and ffmpeg-python tries to stay out of the
        way while users may refer to the official ffmpeg documentation
        as to why certain filters drop audio.

        ``stream.audio`` is a shorthand for ``stream['a']``.

        Example:
            Process the audio and video portions of a stream independently::

                input = ffmpeg.input('in.mp4')
                audio = input.audio.filter("aecho", 0.8, 0.9, 1000, 0.3)
                video = input.video.hflip()
                out = ffmpeg.output(audio, video, 'out.mp4')
        ar   r&   r   r   r   audioI      zStream.audioc                 C   r2   )a  Select the video-portion of a stream.

        Some ffmpeg filters drop audio streams, and care must be taken
        to preserve the audio in the final output.  The ``.audio`` and
        ``.video`` operators can be used to reference the audio/video
        portions of a stream so that they can be processed separately
        and then re-combined later in the pipeline.  This dilemma is
        intrinsic to ffmpeg, and ffmpeg-python tries to stay out of the
        way while users may refer to the official ffmpeg documentation
        as to why certain filters drop audio.

        ``stream.video`` is a shorthand for ``stream['v']``.

        Example:
            Process the audio and video portions of a stream independently::

                input = ffmpeg.input('in.mp4')
                audio = input.audio.filter("aecho", 0.8, 0.9, 1000, 0.3)
                video = input.video.hflip()
                out = ffmpeg.output(audio, video, 'out.mp4')
        vr   r&   r   r   r   videob   r5   zStream.videor$   )r   r   __qualname____doc__r#   r'   r)   r,   r1   propertyr4   r7   r   r   r   r   r      s    


r   c                 C   sV   | d u ri }|S t | trd | i}|S t | ttfr"tt| }|S t | tr)| }|S r$   )r	   r   listtupledict	enumeratestream_spec
stream_mapr   r   r   get_stream_map|   s   

rB   c                 C   sB   g }t |  D ]}t|tstdt|||j q|S )NzExpected Stream; got {})	r;   valuesr	   r   r   r   r   appendr   )rA   nodesr/   r   r   r   get_stream_map_nodes   s   
rF   c                 C   s   t | }t|S r$   )rB   rF   r?   r   r   r   get_stream_spec_nodes   s   rG   c                       s\   e Zd ZdZedd Zedd Zedd Zg i f fdd		ZdddZ	dd Z
  ZS )Nodez	Node basec                 C   sX   |d urt ||k rtd|t ||d ur(t ||kr*td|t |d S d S )Nz,Expected at least {} input stream(s); got {}z+Expected at most {} input stream(s); got {})lenr.   r   )clsrA   
min_inputs
max_inputsr   r   r   Z__check_input_len   s   zNode.__check_input_lenc                 C   s8   t | D ]}t||stdt|t|qd S )NzKExpected incoming stream(s) to be of one of the following types: {}; got {})r;   rC   r   r   r   r   r   )rJ   rA   incoming_stream_typesr/   r   r   r   Z__check_input_types   s   
zNode.__check_input_typesc                 C   s2   i }t | D ]\}}|j|j|jf||< q|S r$   )r;   itemsr   r   r   )rJ   rA   incoming_edge_mapZdownstream_labelZupstreamr   r   r   Z__get_incoming_edge_map   s   
zNode.__get_incoming_edge_mapc	                    sR   t |}	| |	|| | |	| | |	}
tt| |
||| || _|| _d S r$   )	rB   _Node__check_input_len_Node__check_input_types_Node__get_incoming_edge_mapsuperrH   r#   _Node__outgoing_stream_typeZ_Node__incoming_stream_types)r   r@   namerM   outgoing_stream_typerK   rL   argskwargsrA   rO   	__class__r   r   r#      s   

zNode.__init__Nc                 C   s   | j | ||dS )z|Create an outgoing stream originating from this node.

        More nodes may be attached onto the outgoing stream.
        r"   )rT   )r   r   r   r   r   r   r/      s   zNode.streamc                 C   s(   t |tr| j|j|jdS | j|dS )aj  Create an outgoing stream originating from this node; syntactic sugar for ``self.stream(label)``.
        It can also be used to apply a selector: e.g. ``node[0:'a']`` returns a stream with label 0 and
        selector ``'a'``, which is the same as ``node.stream(label=0, selector='a')``.

        Example:
            Process the audio and video portions of a stream independently::

                input = ffmpeg.input('in.mp4')
                audio = input[:'a'].filter("aecho", 0.8, 0.9, 1000, 0.3)
                video = input[:'v'].hflip()
                out = ffmpeg.output(audio, video, 'out.mp4')
        r-   )r   )r	   slicer/   startstop)r   itemr   r   r   r1      s   
zNode.__getitem__)NN)r   r   r8   r9   classmethodrP   rQ   rR   r#   r/   r1   __classcell__r   r   rY   r   rH      s    

	

rH   c                          e Zd Zd fdd	Z  ZS )FilterableStreamNc                    s   t t| ||tth| d S r$   )rS   rc   r#   	InputNode
FilterNoder   r    r!   r"   rY   r   r   r#      s   
zFilterableStream.__init__r$   r   r   r8   r#   ra   r   r   rY   r   rc          rc   c                       s2   e Zd ZdZg i f fdd	Zedd Z  ZS )rd   zInputNode typec              
      s$   t t| jd |i tdd||d d S )Nr   r@   rU   rM   rV   rK   rL   rW   rX   )rS   rd   r#   rc   )r   rU   rW   rX   rY   r   r   r#      s   

zInputNode.__init__c                 C      t j| jd S NfilenameospathbasenamerX   r&   r   r   r   
short_repr     zInputNode.short_repr)r   r   r8   r9   r#   r:   rq   ra   r   r   rY   r   rd      s
    rd   c                       s.   e Zd Zdg i f fdd	Z	 dd Z  ZS )re   r   c              
      s&   t t| j||thtd|||d d S Nr   ri   )rS   re   r#   rc   )r   r@   rU   rL   rW   rX   rY   r   r   r#   	     

zFilterNode.__init__c                    s   | j }| j}| jdv rt|g}dd |D }i  t| D ]\}}t|d}t|d}| |< qdd |D } fddt D }|| }	t| jd}
|	rZ|
dd	|	7 }
t|
d	S )
N)splitZasplitc                 S      g | ]}t |d qS \'=:r   r   r   r   r   r         z*FilterNode._get_filter.<locals>.<listcomp>rx   c                 S   rv   rw   ry   )r   r6   r   r   r   r   $  rz   c                    s   g | ]
}d  | | qS )z{}={})r   )r   kZ
out_kwargsr   r   r   %  r   z={}:z\'[],;)
rW   rX   rU   rI   r;   rN   r   sortedr   r   )r   Zoutgoing_edgesrW   rX   Zout_argsr{   r6   Z
arg_paramsZkwarg_paramsparamsZparams_textr   r|   r   _get_filter  s"   





zFilterNode._get_filter)r   r   r8   r#   r   ra   r   r   rY   r   re     s    re   c                       s.   e Zd Zg i f fdd	Zedd Z  ZS )
OutputNodec              
      s&   t t| j||thtdd ||d d S rs   )rS   r   r#   rc   OutputStreamr   r/   rU   rW   rX   rY   r   r   r#   1  rt   zOutputNode.__init__c                 C   rj   rk   rm   r&   r   r   r   rq   =  rr   zOutputNode.short_repr)r   r   r8   r#   r:   rq   ra   r   r   rY   r   r   0  s    r   c                       rb   )r   Nc                    s"   t t| j||ttth|d d S )Nr[   )rS   r   r#   r   
GlobalNodeMergeOutputsNoderf   rY   r   r   r#   C  s   

zOutputStream.__init__r$   rg   r   r   rY   r   r   B  rh   r   c                       s   e Zd Z fddZ  ZS )r   c                    s"   t t| j||thtdd d d S )Nr   )r@   rU   rM   rV   rK   rL   )rS   r   r#   r   )r   streamsrU   rY   r   r   r#   N  s   

zMergeOutputsNode.__init__rg   r   r   rY   r   r   M  s    r   c                       s"   e Zd Zg i f fdd	Z  ZS )r   c              
      s&   t t| j||thtdd||d d S rs   )rS   r   r#   r   r   rY   r   r   r#   [  rt   zGlobalNode.__init__rg   r   r   rY   r   r   Z  s    r   c                    s    fdd}|S )Nc                    s"   p j  fddD   S )Nc                    s   g | ]}t | qS r   )setattr)r   Zstream_classfunc	func_namer   r   r   k  s    z6stream_operator.<locals>.decorator.<locals>.<listcomp>)r   )r   rU   stream_classesr   r   	decoratori  s   
z"stream_operator.<locals>.decoratorr   )r   rU   r   r   r   r   stream_operatorh  s   r   c                 C      t th| dS N)r   rU   )r   rc   rU   r   r   r   filter_operatorq     r   c                 C   r   r   )r   r   r   r   r   r   output_operatoru  r   r   r$   )
__future__r   Zpast.builtinsr   Zdagr   _utilsr   r   builtinsr   rn   r   r   r   rB   rF   rG   rH   rc   rd   re   r   r   r   r   r   r   r   __all__r   r   r   r   <module>   s0    	e	U(
	

