
    9i                     j    d dl Z d dlZd dlZddlmZ  G d dej                  Zd ZddZd	 Z	d
 Z
dS )    N   )loggerc                   B    e Zd ZdZd Zd Zed             Zd	dZd Z	dS )

LogCatcherzThread to keep reading from stderr so that the buffer does not
    fill up and stalls the ffmpeg process. On stderr a message is send
    on every few frames with some meta information. We only keep the
    last ones.
    c                     || _         d| _        g | _        d| _        t          j                            |            d| _        d| _        | 	                                 d S )N     TF)
_file_header_lines
_remainder	threadingThread__init__daemon_should_stopstart)selffiles     \C:\Users\betacode\Desktop\descargarYoutube\venv\Lib\site-packages\imageio_ffmpeg/_parsing.pyr   zLogCatcher.__init__   sU    
!!$'''!

r	   c                     d| _         d S )NT)r   r   s    r   stop_mezLogCatcher.stop_me   s     r	   c                     | j         S )z>Get header text. Empty string if the header is not yet parsed.)r   r   s    r   headerzLogCatcher.header   s     |r	   r   c                    |dk    rt          j                     |z   }|                                 rVt          j                     |k     r?t          j        d           |                                 rt          j                     |k     ?d                    | j                  }| j        dz   |                    dd          z   S )aG  Get the whole text written to stderr so far. To preserve
        memory, only the last 50 to 100 frames are kept.

        If a timeout is given, wait for this thread to finish. When
        something goes wrong, we stop ffmpeg and want a full report of
        stderr, but this thread might need a tiny bit more time.
        r   g{Gz?   

utf-8ignore)timeis_alivesleepjoinr   r   decode)r   timeoutetimeliness       r   get_textzLogCatcher.get_text!   s     Q;;IKK')E--// !dikkE&9&9
4    --// !dikkE&9&9 

4;''|d"U\\'8%D%DDDr	   c                    t           }| j        sIt          j        d           	 | j                            d          }n# t          $ r Y nw xY w|sn|                    dd                              dd          }|                    d          }| j	        |d         z   |d<   |
                    d          | _	        | j                            |           | j        sSt          | j                  r>d                    | j                  }| xj        |                    dd          z  c_        n| j        r || j                  | _        | j        I	 | j                                         d S # t$          $ r Y d S w xY w)	Nr         r   s   

r   r    )limit_linesr   r!   r#   r
   read
ValueErrorreplacesplitr   popr   extendr   get_output_video_liner$   r%   close	Exception)r   limit_lines_localliner(   r   s        r   runzLogCatcher.run3   s   '# 	=JqMMMzr**    <<u--55guEEDJJu%%Eq1E!H#iimmDOKu%%%< =(55 E"ZZ44FLLFMM'8$D$DDLL =//<<+ # 	=2	J 	 	 	DD	s#   A   
AAE5 5
FFN)r   )
__name__
__module____qualname____doc__r   r   propertyr   r)   r:    r	   r   r   r      s~           ! ! !   XE E E E$         r	   r   c                     d}| D ]M}|                                 }|                    d          rd}.|r|                    d          rd|v r|c S NdS )z[Get the line that defines the video stream that ffmpeg outputs,
    and which we read.
    Fs   Output Ts   Stream s    Video:Nlstrip
startswith)r(   	in_outputr9   slines       r   r5   r5   V   s~     I  J'' 	II 	
++ 
e0C0C r	       c                 P    t          |           d|z  k    rdg| | d         z   } | S )z(When number of lines > 2*N, reduce to N.   s#   ... showing only last few lines ...N)len)r(   Ns     r   r.   r.   d   s3    
5zzAE785!:ELr	   c                     t          |           dk    rt          | d                   S t          |           dk    r.dt          | d                   z  t          | d                   z   S t          |           dk    rGdt          | d                   z  dt          | d                   z  z   t          | d                   z   S dS )zZconverts a time to second. Either cvsecs(min, secs) or
    cvsecs(hours, mins, secs).
    r   r   rI   <      i  N)rJ   float)argss    r   cvsecsrQ   k   s     4yyA~~T!W~~	TaE$q'NN"U47^^33	TaeDGnn$rE$q'NN'::U47^^KK 
r	   c                    |                                  }i }|d                             dd          d                             d          d         }|                                dz   |d                                         z   |d<   d |D             }|d         }|                    d	d          d                                                             dd          d                                         |d
<   t	          j        d|                    d	d          d                   d                                         |d<   d |D             }t          |          dk    re|d         }|                    dd          d                                                             dd          d                                         |d<   d}|d         fD ]F}t	          j        d|          }	|	r-t          |	d         d                                                   }G||d<   |d         }t	          j        d|          }
||
	                                |

                                dz
                               d          }t          t          t          |                    |d<   |d         }t	          j        d|          }
||
	                                |

                                dz
                               d          }t          t          t          |                    |d<   |d         |d         k    r4t          j        d                    |d         |d                              t	          j        d          }|                    |           }
d}|
|
                                d         }t          |          |d<   d |D             d         }t	          j        d|          }
d}|
M||
	                                dz   |

                                                             d          }t'          | }||d<   |S )Nr   versionr   r-   	Copyright ffmpeg_versionc                 h    g | ]/}|                                                     d           rd|v -|0S )Stream z Video: rB   .0ls     r   
<listcomp>z'parse_ffmpeg_header.<locals>.<listcomp>   B       AHHJJ11)<<AKqr	   zVideo: codecz,\s*(?![^()]*\))pix_fmtc                 h    g | ]/}|                                                     d           rd|v -|0S )rX   z Audio: rB   rY   s     r   r\   z'parse_ffmpeg_header.<locals>.<listcomp>   r]   r	   zAudio: audio_codecz ([0-9]+\.?[0-9]*) (fps)fpsz [0-9]*x[0-9]*(,| )xsource_sizesizezIThe frame size for reading {} is different from the source frame size {}.zrotate\s+:\s([0-9]+)rotatec                     g | ]}d |v |	S )z
Duration: r@   rY   s     r   r\   z'parse_ffmpeg_header.<locals>.<listcomp>   s"    222! 1 1A 1 1 1r	   z, [0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9]:duration)
splitlinesr2   striprC   rerJ   findallrO   searchr   endtuplemapintr   warningformatcompilegroupsrQ   )textr(   metaver
videolinesr9   
audiolines
audio_linerb   matchesmatchparts
reo_rotaterf   ri   hmss                   r   parse_ffmpeg_headerr   w   s   OOED
 (..A
&
&r
*
0
0
=
=a
@C YY[[3.q1A1AAD	   J
 a=DJJy!,,R07799??QGGJPPRRDMh 	

9a  $	 	 		 
 	O   J :]
Y**2.5577==c1EEaHNNPP 	] CA / /*8$?? 	/
1++--..CDK a=DI+T22Eq0177<<EC00D b>DI+T22Eq0177<<ES%))DL Md6l**77=vVd=18 8	
 	
 	
 344Jd##EF"[[DN 32u22215DIDdKKEH5;;==1$uyy{{2399#>>3<DKr	   )rG   )rl   r   r!   _utilsr   r   r   r5   r.   rQ   r   r@   r	   r   <module>r      s    				           K K K K K! K K K\     	L 	L 	LY Y Y Y Yr	   