
    4pf\1                        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 Zd	 Z G d
 de
          Zd Zd Zd Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          Z G d de          ZehdfdZd"d Zd"d!ZdgZdS )#    )unicode_literals)
basestring   )KwargReprNode)escape_charsget_hash_int)objectNc                 <    d}|D ]}t          | |          rd} n|S )NFT)
isinstance)objtypesvalidstream_types       L/var/www/html/nettyfy-visnx/env/lib/python3.11/site-packages/ffmpeg/nodes.py_is_of_typesr   
   s>    E  c;'' 	EE	 L    c                 @    d                     d | D                       S )Nz, c                 N    g | ]"}d                      |j        |j                  #S )z{}.{})format
__module____name__.0xs     r   
<listcomp>z"_get_types_str.<locals>.<listcomp>   s*    NNN1gnnQ\1:>>NNNr   )join)r   s    r   _get_types_strr      s#    99NNNNNOOOr   c                   `    e Zd ZdZ	 d
dZd Zd Zd Zd Ze	d             Z
e	d	             ZdS )Streamz^Represents the outgoing edge of an upstream node; may be used to create more downstream nodes.Nc                     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_label
node_typesupstream_selectors        r   __init__zStream.__init__   sk     M:66 	Zaa":..]0C0C   
 "	#
)r   c                 l    t          t          | j                  t          | j                  g          S N)r   hashr#   r$   r&   s    r   __hash__zStream.__hash__'   s'    T$)__d4:.>.>?@@@r   c                 B    t          |           t          |          k    S r-   )r.   )r&   others     r   __eq__zStream.__eq__*   s    DzzT%[[((r   c                     | j                             d          }d}| j        rd                    | j                  }d                    || j        || j         j                  }|S )NF)include_hash z:{}z{}[{!r}{}] <{}>)r#   	long_reprr%   r   r$   
short_hash)r&   	node_reprr%   outs       r   __repr__zStream.__repr__-   sh    I''U';;	= 	3||DM22H&&tz8TY-A
 
 
r   c                    | j         "t          d                    |                     t          |t                    s"t          d                    |                    | j                            | j        |          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&   indexs     r   __getitem__zStream.__getitem__7   sw     =$@GGMMNNNE:.. 	XHOOPUVVWWWydj5AAAr   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')
        a r/   s    r   audiozStream.audioI       . Cyr   c                     | d         S )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')
        vrD   r/   s    r   videozStream.videob   rF   r   r-   )r   r   __qualname____doc__r+   r0   r3   r;   rA   propertyrE   rI   rD   r   r   r   r      s        hh LP* * * *A A A) ) )  B B B$   X0   X  r   r   c                     | i }njt          | t                    rd | i}nPt          | t          t          f          rt	          t          |                     }nt          | t                    r| }|S r-   )r   r   listtupledict	enumeratestream_spec
stream_maps     r   get_stream_maprU   |   sw    

	K	(	( !K(

	K$	/	/ !)K0011

	K	&	& ! 
r   c                    g }t          |                                           D ]`}t          |t                    s/t	          d                    t          |                              |                    |j                   a|S )NzExpected Stream; got {})	rN   valuesr   r   r!   r   r"   appendr#   )rT   nodesr?   s      r   get_stream_map_nodesrZ      s|    Ez((**++ " "&&)) 	L5<<T&\\JJKKKV[!!!!Lr   c                 >    t          |           }t          |          S r-   )rU   rZ   rR   s     r   get_stream_spec_nodesr\      s    ,,J
+++r   c                   x     e Zd ZdZed             Zed             Zed             Zg i f fd	Zd	dZ	d Z
 xZS )
Nodez	Node basec                    |Ct          |          |k     r0t          d                    |t          |                              |Ct          |          |k    r2t          d                    |t          |                              d S d S )Nz,Expected at least {} input stream(s); got {}z+Expected at most {} input stream(s); got {})lenr>   r   )clsrT   
min_inputs
max_inputss       r   __check_input_lenzNode.__check_input_len   s    !c*oo
&B&B>EEJ   
 #J*(D(D=DDJ    $#(D(Dr   c           	          t          |                                          D ]O}t          ||          s=t          d                    t          |          t          |                              Pd S )NzKExpected incoming stream(s) to be of one of the following types: {}; got {})rN   rW   r   r!   r   r   r"   )ra   rT   incoming_stream_typesr?   s       r   __check_input_typeszNode.__check_input_types   s    :,,..// 	 	F(=>> ahh&'<==tF||   	 	r   c                     i }t          |                                          D ]\  }}|j        |j        |j        f||<   |S r-   )rN   itemsr#   r$   r%   )ra   rT   incoming_edge_mapdownstream_labelupstreams        r   __get_incoming_edge_mapzNode.__get_incoming_edge_map   sZ    *.z/?/?/A/A*B*B 	 	&h!3.//
 ! r   c	                    t          |          }	|                     |	||           |                     |	|           |                     |	          }
t	          t
          |                               |
|||           || _        || _        d S r-   )	rU   _Node__check_input_len_Node__check_input_types_Node__get_incoming_edge_mapsuperr^   r+   _Node__outgoing_stream_type_Node__incoming_stream_types)r&   rS   namerf   outgoing_stream_typerb   rc   argskwargsrT   rj   	__class__s              r   r+   zNode.__init__   s     $K00
z:zBBB  -BCCC 88DDdD""#4dD&III&:#'<$$$r   Nc                 2    |                      | ||          S )z|Create an outgoing stream originating from this node.

        More nodes may be attached onto the outgoing stream.
        r*   )rs   )r&   r$   r%   s      r   r?   zNode.stream   s    
 **4(*SSSr   c                     t          |t                    r!|                     |j        |j                  S |                     |          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&   items     r   rA   zNode.__getitem__   sD     dE"" 	+;;TZ$);DDD;;T;***r   )NN)r   r   rJ   rK   classmethodro   rp   rq   r+   r?   rA   __classcell__ry   s   @r   r^   r^      s        O  [   [ ! ! [!$ = = = = = =(T T T T+ + + + + + +r   r^   c                         e Zd Zd fd	Z xZS )FilterableStreamNc                 v    t          t          |                               ||t          t          h|           d S r-   )rr   r   r+   	InputNode
FilterNoder&   r'   r(   r*   ry   s       r   r+   zFilterableStream.__init__   s?    %%..>Iz+BDU	
 	
 	
 	
 	
r   r-   r   r   rJ   r+   r   r   s   @r   r   r      s=        
 
 
 
 
 
 
 
 
 
r   r   c                   >     e Zd ZdZg i f fd	Zed             Z xZS )r   zInputNode typec           
      r    t          t          |                               d |i t          dd||           d S )Nr   rS   ru   rf   rv   rb   rc   rw   rx   )rr   r   r+   r   )r&   ru   rw   rx   ry   s       r   r+   zInputNode.__init__   sL    i''"$!1 	( 		
 		
 		
 		
 		
r   c                 V    t           j                            | j        d                   S Nfilenameospathbasenamerx   r/   s    r   
short_reprzInputNode.short_repr      wJ 7888r   )r   r   rJ   rK   r+   rL   r   r   r   s   @r   r   r      sc        "$R 

 

 

 

 

 

 9 9 X9 9 9 9 9r   r   c                   .     e Zd Zdg i f fd	Z	 d Z xZS )r   r   c           
      ~    t          t          |                               ||t          ht          d|||           d S Nr   r   )rr   r   r+   r   )r&   rS   ru   rc   rw   rx   ry   s         r   r+   zFilterNode.__init__	  sO    j$((##3"4!1! 	) 		
 		
 		
 		
 		
r   c                    | j         }| j        }| j        dv rt          |          g}d |D             }i t	          |                                          D ]*\  }}t          |d          }t          |d          }||<   +d |D             }fdt                    D             }||z   }	t          | j        d          }
|	r+|
d                    d	                    |	                    z  }
t          |
d          S )	N)splitasplitc                 .    g | ]}t          |d           S \'=:r   r   s     r   r   z*FilterNode._get_filter.<locals>.<listcomp>  s"    <<<!LH--<<<r   r   c                 .    g | ]}t          |d           S r   r   )r   rH   s     r   r   z*FilterNode._get_filter.<locals>.<listcomp>$  s"    BBBAl1h//BBBr   c                 H    g | ]}d                      ||                   S )z{}={})r   )r   k
out_kwargss     r   r   z*FilterNode._get_filter.<locals>.<listcomp>%  s+    UUUQq*Q-88UUUr   z={}:z\'[],;)
rw   rx   ru   r`   rN   ri   r   sortedr   r   )r&   outgoing_edgesrw   rx   out_argsr   rH   
arg_paramskwarg_paramsparamsparams_textr   s              @r   _get_filterzFilterNode._get_filter  s   y9+++''(D<<t<<<
(( 	 	DAqQ))AQ))AJqMMBBBBB
UUUU&BTBTUUUl*"49h77 	:5<<(8(8999KK444r   )r   r   rJ   r+   r   r   r   s   @r   r   r     sX        56R 

 

 

 

 

 

 5 5 5 5 5 5 5r   r   c                   :     e Zd Zg i f fd	Zed             Z xZS )
OutputNodec           
      ~    t          t          |                               ||t          ht          dd ||           d S r   )rr   r   r+   r   OutputStreamr&   r?   ru   rw   rx   ry   s        r   r+   zOutputNode.__init__1  sO    j$((#3"4!- 	) 		
 		
 		
 		
 		
r   c                 V    t           j                            | j        d                   S r   r   r/   s    r   r   zOutputNode.short_repr=  r   r   )r   r   rJ   r+   rL   r   r   r   s   @r   r   r   0  s]        *,R 

 

 

 

 

 

 9 9 X9 9 9 9 9r   r   c                         e Zd Zd fd	Z xZS )r   Nc                     t          t          |                               ||t          t          t
          h|           d S )Nr{   )rr   r   r+   r   
GlobalNodeMergeOutputsNoder   s       r   r+   zOutputStream.__init__C  sH    lD!!**%56/	 	+ 	
 	
 	
 	
 	
r   r-   r   r   s   @r   r   r   B  s=        
 
 
 
 
 
 
 
 
 
r   r   c                        e Zd Z fdZ xZS )r   c                 z    t          t          |                               ||t          ht          dd            d S )Nr   )rS   ru   rf   rv   rb   rc   )rr   r   r+   r   )r&   streamsru   ry   s      r   r+   zMergeOutputsNode.__init__N  sI    %%..#/.!- 	/ 	
 	
 	
 	
 	
r   r   r   s   @r   r   r   M  s8        
 
 
 
 
 
 
 
 
r   r   c                   $     e Zd Zg i f fd	Z xZS )r   c           
      ~    t          t          |                               ||t          ht          dd||           d S r   )rr   r   r+   r   r   s        r   r+   zGlobalNode.__init__[  sN    j$((#/.!- 	) 		
 		
 		
 		
 		
r   r   r   s   @r   r   r   Z  sB        *,R 

 

 

 

 

 

 

 

 

 

r   r   c                       fd}|S )Nc                 <     p j          fdD               S )Nc                 2    g | ]}t          |          S rD   )setattr)r   stream_classfunc	func_names     r   r   z6stream_operator.<locals>.decorator.<locals>.<listcomp>k  s%    SSSLy$	/	/SSSr   )r   )r   r   ru   stream_classess   `@r   	decoratorz"stream_operator.<locals>.decoratori  s3    )DM	SSSSSNSSSSr   rD   )r   ru   r   s   `` r   stream_operatorr   h  s*         
 r   c                 0    t          t          h|           S N)r   ru   )r   r   ru   s    r   filter_operatorr   q  s    +;*<4HHHHr   c                 0    t          t          h|           S r   )r   r   r   s    r   output_operatorr   u  s    <.tDDDDr   r-   )
__future__r   past.builtinsr   dagr   _utilsr   r   builtinsr	   r   r   r   r   rU   rZ   r\   r^   r   r   r   r   r   r   r   r   r   r   __all__rD   r   r   <module>r      s   ' ' ' ' ' ' $ $ $ $ $ $       . . . . . . . .       				  P P Pb b b b bV b b bJ	 	 	  , , ,
R+ R+ R+ R+ R+= R+ R+ R+j
 
 
 
 
v 
 
 
9 9 9 9 9 9 9 9*$5 $5 $5 $5 $5 $5 $5 $5P9 9 9 9 9 9 9 9$
 
 
 
 
6 
 
 
	
 	
 	
 	
 	
t 	
 	
 	

 
 
 
 
 
 
 
 %+8$    I I I IE E E E *r   