Ë
    Eü´j|†  ã                   ó�   — d Z ddlZddlZddlZddlZddlZddlm	Z	 ddl
mZmZmZ  G d„ d«      Zdd„Z G d„ d	«      Z	 	 	 	 dd
„Zy)zGImplements all the functions to read a video or a picture using ffmpeg.é    N)ÚFFMPEG_BINARY)Úconvert_to_secondsÚcross_platform_popen_paramsÚffmpeg_escape_filenamec                   óh   — e Zd ZdZ	 	 	 	 	 	 	 	 dd„Zdd„Zdd„Zd„ Zd„ Ze	d„ «       Z
d	„ Zdd
„Zd„ Zy)ÚFFMPEG_VideoReaderz/Class for video byte-level reading with ffmpeg.Nc
                 ó¢  — || _         d | _        t        |||	||¬«      }
|
j                  dd«      | _        |
j                  dd«      | _        t        |
j                  dd«      «      | _        | j                  dv r#| j
                  d	   | j
                  d   g| _        |rqd |v rfd	}t        |«      D ]  \  }}|sŒ	|| j
                  |   z  }Œ t        | j
                  d   |z  «      t        | j
                  d	   |z  «      f| _        n|| _        || _
        |
j                  d
d«      | _        |
j                  dd«      | _        |
j                  dd«      | _        |
j                  dd«      | _        |
| _        || _        |d   dk(  rdnd| _        |€$| j
                  \  }}| j"                  |z  |z  dz   }|| _        | j'                  «        y )N)Úcheck_durationÚ
fps_sourceÚdecode_fileÚprint_infosÚ	video_fpsç      ð?Ú
video_size)é   r   Úvideo_rotationr   )éZ   i  r   Úvideo_durationç        ÚdurationÚvideo_n_framesÚvideo_bitrateéÿÿÿÿÚaé   é   éd   )ÚfilenameÚprocÚffmpeg_parse_infosÚgetÚfpsÚsizeÚabsÚrotationÚ	enumerateÚintÚresize_algor   Úffmpeg_durationÚn_framesÚbitrateÚinfosÚpixel_formatÚdepthÚbufsizeÚ
initialize)Úselfr   r   r   r/   r-   r
   Útarget_resolutionr(   r   r,   ÚratioÚidxÚtargetÚwÚhs                   ú\/root/workspace/ytshorts/venv/lib/python3.12/site-packages/moviepy/video/io/ffmpeg_reader.pyÚ__init__zFFMPEG_VideoReader.__init__   s¾  € ð !ˆŒØˆŒ	Ü"ØØ)Ø!Ø#Ø#ô
ˆð —9‘9˜[¨#Ó.ˆŒà—I‘I˜l¨FÓ3ˆŒ	ô ˜EŸI™IÐ&6¸Ó:Ó;ˆŒØ�=‰=˜IÑ%ØŸ™ 1™ t§y¡y°¡|Ð4ˆDŒIáØÐ(Ñ(Ø�Ü#,Ð->Ó#?ò 8‘K�C˜ÚØ &¨¯©°3©Ñ 7™ð8ô ! §¡¨1¡°Ñ!5Ó6¼¸D¿I¹IÀa¹LÈ5Ñ<PÓ8QÐR�•	à-�”	Ø&ˆÔàŸ	™	Ð"2°CÓ8ˆŒØ$Ÿy™y¨°SÓ9ˆÔØŸ	™	Ð"2°AÓ6ˆŒØ—y‘y °!Ó4ˆŒàˆŒ
à(ˆÔØ& rÑ*¨cÒ1‘Q°qˆŒ
ð ˆ?Ø—9‘9‰DˆAˆqØ—j‘j 1‘n qÑ(¨3Ñ.ˆGàˆŒØ�‰Õó    c                 óF  — | j                  d¬«       | j                  |«      | _        | j                  dk7  r | j                  d| j                  z  z  dz
  }nd}|dk7  r1t	        d|«      }dd||z
  z  d	t        | j                  «      dd|z  g}nd	t        | j                  «      g}| j                  d
k(  r4| j                  j                  d«      }|dk(  rddg|z   }n|dk(  rddg|z   }t        g|z   ddddddt        | j                  «      z  d| j                  d| j                  dddgz   }t        | j                   t"        j$                  t"        j$                  t"        j&                  dœ«      }t#        j(                  |fi |¤Ž| _        | j-                  «       | _        y)z¨
        Opens the file, creates the pipe.

        Sets self.pos to the appropriate value (1 if start_time == 0 because
        it pre-reads the first frame).
        F)Údelete_lastreadr   r   çñhãˆµøä>r   z-ssz%.06fú-ir   Úvideo_codec_nameÚvp9z-c:vz
libvpx-vp9Úvp8Úlibvpxz	-loglevelÚerrorú-fÚ
image2pipez-vfzscale=%d:%dz
-sws_flagsz-pix_fmtz-vcodecÚrawvideoú-©r/   ÚstdoutÚstderrÚstdinN)ÚcloseÚget_frame_numberÚposr"   Úminr   r   r.   r,   r!   r   Útupler#   r(   r-   r   r/   ÚspÚPIPEÚDEVNULLÚPopenr   Ú
read_frameÚ	last_read)r1   Ú
start_timeÚoffsetÚi_argÚ
codec_nameÚcmdÚpopen_paramss          r8   r0   zFFMPEG_VideoReader.initializeS   s®  € ð 	�
‰
 5ˆ
Ô)ð
 ×(Ñ(¨Ó4ˆŒð �8‰8�qŠ=ØŸ™ Q¨¯©¡\Ñ2°WÑ<‰JàˆJà˜Š?Ü˜˜JÓ'ˆFàØ˜:¨Ñ.Ñ/ØÜ& t§}¡}Ó5ØØ˜&Ñ ð‰Eð Ô1°$·-±-Ó@ÐAˆEð �:‰:˜Š?ØŸ™Ÿ™Ð(:Ó;ˆJØ˜UÒ"Ø Ð.°Ñ6‘Ø˜uÒ$Ø Ð*¨UÑ2�ô ˆOØñð ØØØØØ¤ d§i¡iÓ 0Ñ0ØØ× Ñ ØØ×!Ñ!ØØØðñð 	ô( 3àŸ<™<ÜŸ'™'ÜŸ'™'ÜŸ™ñ	ó
ˆô —H‘H˜SÑ1 LÑ1ˆŒ	ØŸ™Ó*ˆ�r:   c                 óÖ   — | j                   \  }}t        |«      D ]7  }| j                  j                  j	                  | j
                  |z  |z  «       Œ9 | xj                  |z  c_        y)zReads and throws away n framesN)r#   Úranger   rI   Úreadr.   rN   )r1   Únr6   r7   Úis        r8   Úskip_frameszFFMPEG_VideoReader.skip_frames©   sV   € à�y‰y‰ˆˆ1Ü�q“ò 	6ˆAØ�I‰I×Ñ×!Ñ! $§*¡*¨q¡.°1Ñ"4Õ5ð	6ð 	�Š�A‰Žr:   c           
      óØ  — | j                   \  }}| j                  |z  |z  }| j                  j                  j	                  |«      }t        |«      |k7  r¡t        j                  d| j                  |t        |«      | j                  | j                  d| j                  z  | j                  z  | j                  fz  t        «       t        | d«      st        d| j                  › d�«      ‚| j                   }n_t        t"        d«      rt#        j$                  |d¬«      }nt#        j&                  |d¬«      }||t        |«      ||z  z  f|_        || _        | xj                  d	z  c_	        |S )
z¶
        Reads the next frame from the file.
        Note that upon (re)initialization, the first frame will already have been read
        and stored in ``self.last_read``.
        z˜In file %s, %d bytes wanted but %d bytes read at frame index %d (out of a total %d frames), at time %.02f/%.02f sec. Using the last valid frame instead.r   rV   z<MoviePy error: failed to read the first frame of video file zí. That might mean that the file is corrupted. That may also mean that you are using a deprecated version of FFMPEG. On Ubuntu/Debian for instance the version in the repos is deprecated. Please update to a recent version from the website.Ú
frombufferÚuint8)Údtyper   )r#   r.   r   rI   r_   ÚlenÚwarningsÚwarnr   rN   r*   r"   r   ÚUserWarningÚhasattrÚIOErrorrV   Únprd   Ú
fromstringÚshape)r1   r6   r7   ÚnbytesÚsÚresults         r8   rU   zFFMPEG_VideoReader.read_frame²   sE  € ð �y‰y‰ˆˆ1Ø—‘˜a‘ !Ñ#ˆà�I‰I×Ñ×!Ñ! &Ó)ˆäˆq‹6�VÒÜ�M‰Mð;ð
 —M‘MØÜ˜“FØ—H‘HØ—M‘MØ˜$Ÿ(™(‘N T§X¡XÑ-Ø—M‘Mðñô ôô" ˜4 Ô-Üð&Ø&*§m¡m _ð 5NðNó	ð 	ð —^‘^‰Fô ”r˜<Ô(ÜŸ™ q°Ô8‘äŸ™ q°Ô8�Ø˜q¤# a£&¨Q°©UÑ"3Ð4ˆFŒLØ#ˆDŒNð 	�Š�A‰�àˆr:   c                 óª  — | j                  |«      dz   }| j                  s(t        d«       | j                  |«       | j                  S || j
                  k(  r| j                  S || j
                  k  s|| j
                  dz   kD  r| j                  |«       | j                  S | j                  || j
                  z
  dz
  «       | j                  «       }|S )a5  Read a file video frame at time t.

        Note for coders: getting an arbitrary frame in the video with
        ffmpeg can be painfully slow if some decoding has to be done.
        This function tries to avoid fetching arbitrary frames
        whenever possible, by moving between adjacent frames.
        r   zProc not detectedr   )rM   r   Úprintr0   rV   rN   rb   rU   )r1   ÚtrN   rr   s       r8   Ú	get_framezFFMPEG_VideoReader.get_frameê   s´   € ð ×#Ñ# AÓ&¨Ñ*ˆð �yŠyÜÐ%Ô&Ø�O‰O˜AÔØ—>‘>Ð!à�$—(‘(Š?Ø—>‘>Ð!Ø�D—H‘HŠn #¨¯©°3©Ò"6à�O‰O˜AÔØ—>‘>Ð!ð ×Ñ˜S 4§8¡8™^¨aÑ/Ô0Ø—_‘_Ó&ˆFØˆMr:   c                 ó   — | j                   S )zGAlias of `self.last_read` for backwards compatibility with MoviePy 1.x.)rV   ©r1   s    r8   ÚlastreadzFFMPEG_VideoReader.lastread  s   € ð �~‰~Ðr:   c                 ó8   — t        | j                  |z  dz   «      S )z6Helper method to return the frame number at time ``t``r=   )r'   r"   )r1   ru   s     r8   rM   z#FFMPEG_VideoReader.get_frame_number  s   € ô �4—8‘8˜a‘< 'Ñ)Ó*Ð*r:   c                 óz  — | j                   r�| j                   j                  «       €|| j                   j                  «        | j                   j                  j	                  «        | j                   j
                  j	                  «        | j                   j                  «        d| _         |rt        | d«      r| `yyy)z<Closes the reader terminating the process, if is still open.NrV   )	r   ÚpollÚ	terminaterI   rL   rJ   Úwaitrk   rV   )r1   r<   s     r8   rL   zFFMPEG_VideoReader.close  sƒ   € à�9Š9Ø�y‰y�~‰~ÓÐ'Ø—	‘	×#Ñ#Ô%Ø—	‘	× Ñ ×&Ñ&Ô(Ø—	‘	× Ñ ×&Ñ&Ô(Ø—	‘	—‘Ô ØˆDŒIÙœw t¨[Ô9Ø‘ð  :ˆ?r:   c                 ó$   — | j                  «        y ©N)rL   rx   s    r8   Ú__del__zFFMPEG_VideoReader.__del__!  s   € Ø�
‰
�r:   )TFNÚrgb24TNÚbicubicr"   )r   )r   )T)Ú__name__Ú
__module__Ú__qualname__Ú__doc__r9   r0   rb   rU   rv   Úpropertyry   rM   rL   r�   © r:   r8   r   r      s_   „ Ù9ð
 ØØØØØØØó<ó|T+ólò6òpð< ñó ðò+ó
ór:   r   c                 óL   — |s|rdnd}t        | |d¬«      }|j                  }~|S )aÒ  Read an image file (PNG, BMP, JPEG...).

    Wraps FFMPEG_Videoreader to read just one image.
    Returns an ImageClip.

    This function is not meant to be used directly in MoviePy.
    Use ImageClip instead to make clips out of image files.

    Parameters
    ----------

    filename
      Name of the image file. Can be of any format supported by ffmpeg.

    with_mask
      If the image has a transparency layer, ``with_mask=true`` will save
      this layer as the mask of the returned ImageClip

    pixel_format
      Optional: Pixel format for the image to read. If is not specified
      'rgb24' will be used as the default format unless ``with_mask`` is set
      as ``True``, then 'rgba' will be used.

    Úrgbar‚   F)r-   r
   )r   rV   )r   Ú	with_maskr-   ÚreaderÚims        r8   Úffmpeg_read_imager�   %  s6   € ñ2 Ù!*‘v°ˆÜØ˜|¸Eô€Fð 
×	Ñ	€BØØ€Ir:   c                   óZ   — e Zd ZdZ	 	 	 dd„Zd„ Zd„ Zd„ Zd„ Zd„ Z	d„ Z
d	„ Zd
„ Zd„ Zd„ Zy)ÚFFmpegInfosParsera.  Finite state ffmpeg `-i` command option file information parser.
    Is designed to parse the output fast, in one loop. Iterates line by
    line of the `ffmpeg -i <filename> [-f null -]` command output changing
    the internal state of the parser.

    Parameters
    ----------

    filename
      Name of the file parsed, only used to raise accurate error messages.

    infos
      Information returned by FFmpeg.

    fps_source
      Indicates what source data will be preferably used to retrieve fps data.

    check_duration
      Enable or disable the parsing of the duration of the file. Useful to
      skip the duration check, for example, for images.

    decode_file
      Indicates if the whole file has been decoded. The duration parsing strategy
      will differ depending on this argument.
    c                 ór   — || _         || _        || _        || _        |rdnd| _        | j                  «        y )Nútime=ú
Duration: )r,   r   r
   r   Úduration_tag_separatorÚ_reset_state)r1   r,   r   r   r
   r   s         r8   r9   zFFmpegInfosParser.__init__c  s9   € ð ˆŒ
Ø ˆŒØ,ˆÔØ$ˆŒÙ1<¡gÀ,ˆÔ#à×ÑÕr:   c                 ó‚   — d| _         d| _        i | _        dg i| _        d| _        d| _        ddi g dœ| _        d| _        y)z€Reinitializes the state of the parser. Used internally at
        initialization and at the end of the parsing process.
        FÚstreamsN)Úvideo_foundÚaudio_foundÚmetadataÚinputs)Ú_inside_file_metadataÚ_inside_outputÚ_default_streamsÚ_current_input_fileÚ_current_streamÚ_current_chapterrr   Ú_last_metadata_field_addedrx   s    r8   r–   zFFmpegInfosParser._reset_states  s_   € ð &+ˆÔ"ð $ˆÔð !#ˆÔð %.¨r ?ˆÔ Ø#ˆÔØ $ˆÔð !Ø ØØñ	
ˆŒð +/ˆÕ'r:   c                 ó   — g }| j                   j                  «       dd D �]  }| j                  dk(  r/| j                  r#d|v r| j	                  |«      | j
                  d<   ŒB| j                  s|d   dk7  r%| j                  dk(  sŒf| j                  rŒsd| _        Œ{| j                  s|j                  d«      rd| _        Œ |j                  d	«      rÄd
| _        | j                  r-| j                  dk(  r| j	                  |«      | j
                  d<   t        j                  d|«      }|rt        |j                  d«      «      nd| j
                  d<   t        j                  d|«      }|rt        |j                  d«      «      nd| j
                  d<   �Œu| j                  rY| j                  |«      \  }}|dk(  r%| j                  }| j
                  d   |   dz   |z   }n|| _        || j
                  d   |<   �ŒÚ|j!                  «       j                  d«      �rÓ| j"                  r(| j$                  d   j'                  | j"                  «       t        j                  d|j!                  «       «      }|j)                  «       \  }}	}
}t        |«      }t        |	«      }	|j+                  «       }|
dk(  rd}
||	||
|| j,                  vxr |j/                  d«      dœ| _        | j"                  d   r| j"                  | j,                  |<   | j0                  r%||   j'                  | j0                  «       d| _        d| j$                  vr|| j$                  d<   nf| j$                  d   |k7  rTt3        |«      |dz   k\  r||   | j$                  d<   | j
                  d   j'                  | j$                  «       d|i| _        	 | j5                  ||«      }| j"                  j7                  |«       �ŒÍ|j                  d«      r�Œà| j"                  rÆd| j"                  vri | j"                  d<   | j                  |«      \  }}| j"                  d   d k(  r>| jC                  ||«      \  }}|d!k(  r|| j
                  d"<   n|d#k(  r|| j
                  d"<   |dk(  r%| j                  }| j"                  d   |   dz   |z   }n|| _        || j"                  d   |<   �Œ²|j                  d$«      rÃ| j0                  rZt3        |«      | j0                  d   dz   k  r|j'                  g «       || j0                  d      j'                  | j0                  «       t        j                  d%|«      }|j)                  «       \  }}}}t        |«      t        |«      t        |«      t        |«      d&œ| _        �Œ†| j0                  s�Œ”d| j0                  vri | j0                  d<   | j                  |«      \  }}|dk(  r%| j                  }| j0                  d   |   dz   |z   }n|| _        || j0                  d   |<   �Œ
 | j$                  r›| j$                  d   j'                  | j"                  «       d| j$                  v r=t3        |«      | j$                  d   dz   k(  r|| j$                  d      | j$                  d<   | j
                  d   j'                  | j$                  «       | j$                  d   D ]+  }|d   | j,                  vsŒ|| j,                  |d   <   d|d<   Œ- | j,                  jE                  «       D �]  \  }}|d   | j
                  d'|› d(�<   |d)   | j
                  d'|› d*�<   |d+k(  r4d| j
                  d,<   |d-   | j
                  d.<   |d   | j
                  d/<   Œl|d k(  sŒrd| j
                  d0<   |jG                  d1d«      | j
                  d2<   |jG                  dd«      | j
                  d3<   |d-   | j
                  d4<   |jG                  d5d«      | j
                  d6<   |jG                  d7d«      | j
                  d8<   �Œ | j
                  d0   rk| j                  r_| j
                  d   | j
                  d9<   t        | j
                  d   | j
                  jG                  d4d«      z  «      | j
                  d:<   nd| j
                  d:<   d;| j
                  d9<   | j
                  d,   r‡| j
                  jG                  d/«      sld| j
                  d/<   | j
                  d   D ]K  }|d   D ]0  }|d   d+k(  sŒ|jG                  d«      sŒ|d   | j
                  d/<    n | j
                  d/   €ŒK n | j
                  }| jI                  «        |S # t8        $ r=}t;        j<                  t?        |«      › d| j                   › �t@        «       Y d}~�	Œ¨d}~ww xY w)<z»Parses the information returned by FFmpeg in stderr executing their binary
        for a file with ``-i`` option and returns a dictionary with all data needed
        by MoviePy.
        r   Nr“   r   r   ú Tz  Metadata:z  Duration:Fr”   zbitrate: (\d+) k(i?)b/sr+   zstart: (\d+\.?\d+)ÚstartÚ r›   ú
zStream r˜   z6^Stream\s#(\d+):(\d+)(?:\[\w+\])?\(?(\w+)?\)?:\s(\w+):Úundz	(default))Úinput_numberÚstream_numberÚstream_typeÚlanguageÚdefaultr®   rª   Úchaptersrœ   z
ffmpeg output:

z    Metadata:r¬   ÚvideoÚrotater   Údisplaymatrixz    Chapterz?^    Chapter #(\d+):(\d+): start (\d+\.?\d+?), end (\d+\.?\d+?))rª   Úchapter_numberr¦   ÚendÚdefault_Ú_input_numberr«   Ú_stream_numberÚaudiorš   r"   Ú	audio_fpsÚaudio_bitrater™   r#   r   r   r   rZ   r?   ÚprofileÚvideo_profiler   r   r   )%r,   Ú
splitlinesr•   r
   Úparse_durationrr   rž   r�   Ú
startswithÚreÚsearchr'   ÚgroupÚfloatÚparse_metadata_field_valuer£   Úlstripr¡   r    ÚappendÚgroupsÚlowerrŸ   Úendswithr¢   rg   Úparse_data_by_stream_typeÚupdateÚNotImplementedErrorrh   ri   Ústrrj   Úvideo_metadata_type_castingÚitemsr!   r–   )r1   Úinput_chaptersÚlineÚbitrate_matchÚstart_matchÚfieldÚvalueÚmain_info_matchrª   r«   r­   r¬   Ústream_type_lowerÚstream_dataÚexcÚchapter_data_matchr³   r¦   r´   ÚstreamÚstreams_inputrr   s                         r8   ÚparsezFFmpegInfosParser.parse˜  sš	  € ð ˆà—J‘J×)Ñ)Ó+¨A¨BÐ/ó m	AˆDà×+Ñ+¨wÒ6Ø×'Ò'Ø˜t‘Oð +/×*=Ñ*=¸dÓ*C�—‘˜JÒ'Ø×$Ò$¨¨Q©°3ªØ×.Ñ.°'Ó9À$×BUÓBUØ*.�DÕ'à×/Ò/°D·O±OÀMÔ4Rà-1�Õ*Ø—‘ Ô/à-2�Ô*Ø×&Ò&¨4×+FÑ+FÈ,Ò+VØ.2×.AÑ.AÀ$Ó.G�D—K‘K 
Ñ+ô !#§	¡	Ð*DÀdÓ K�á3@”C˜×+Ñ+¨AÓ.Ô/Àdð —‘˜IÑ&ô
 !Ÿi™iÐ(=¸tÓD�á3>”E˜+×+Ñ+¨AÓ.Ô/ÀDð —‘˜GÓ$ð ×+Ò+à#×>Ñ>¸tÓD‘��uð ˜B’;Ø ×;Ñ;�EØ ŸK™K¨
Ñ3°EÑ:¸TÑAÀEÑI‘Eà6;�DÔ3Ø16�—‘˜JÑ'¨Ó.Ø—‘“×)Ñ)¨)Õ4à×'Ò'Ø×,Ñ,¨YÑ7×>Ñ>¸t×?SÑ?SÔTô #%§)¡)ØMØ—K‘K“Mó#�ð $×*Ñ*Ó,ñØ Ø!ØØä" <Ó0�Ü # MÓ 2�Ø$/×$5Ñ$5Ó$7Ð!à˜uÒ$Ø#�Hð %1Ø%2Ø#4Ø (Ø 1¸×9NÑ9NÐ Nò  3ØŸ™ kÓ2ñ(�Ô$ð ×'Ñ'¨	Ò2Ø?C×?SÑ?S�D×)Ñ)Ð*;Ñ<ð ×(Ò(Ø" <Ñ0×7Ñ7¸×8MÑ8MÔNØ,0�DÔ)à!¨×)AÑ)AÑAà?K�D×,Ñ,¨^Ò<Ø×-Ñ-¨nÑ=ÀÒMô ˜>Ó*¨l¸QÑ.>Ò>Ø?MØ(ñ@˜×0Ñ0°Ñ<ð
 —K‘K Ñ)×0Ñ0°×1IÑ1IÔJØ0>ÀÐ/M�DÔ,ð=Ø"&×"@Ñ"@ÀÈdÓ"S�Kð ×(Ñ(×/Ñ/°Ö<Ø—‘ Ô1áØ×%Ò%à T×%9Ñ%9Ñ9Ø79�D×(Ñ(¨Ñ4à#×>Ñ>¸tÓD‘��uà×'Ñ'¨Ñ6¸'ÒAØ#'×#CÑ#CÀEÈ5Ó#Q‘L�E˜5à Ò(Ø8=˜Ÿ™Ð$4Ò5Ø /Ò1Ø8=˜Ÿ™Ð$4Ñ5ð ˜B’;Ø ×;Ñ;�EØ ×0Ñ0°Ñ<¸UÑCÀdÑJÈUÑR‘Eà6;�DÔ3Ø:?�×$Ñ$ ZÑ0°Ó7Ø—‘ Ô/à×(Ò(ä˜>Ó*¨T×-BÑ-BÀ>Ñ-RÐUVÑ-VÒVØ&×-Ñ-¨bÔ1à" 4×#8Ñ#8¸Ñ#HÑI×PÑPØ×-Ñ-ôô
 &(§Y¡YØVØó&Ð"ð <N×;TÑ;TÓ;VÑ8�˜n¨e°Sô %(¨Ó$5Ü&)¨.Ó&9Ü" 5›\Ü  ›:ñ	)�Ö%ð ×&Ô&à T×%:Ñ%:Ñ:Ø8:�D×)Ñ)¨*Ñ5Ø#×>Ñ>¸tÓD‘��uð ˜B’;Ø ×;Ñ;�EØ ×1Ñ1°*Ñ=¸eÑDÀtÑKÈeÑS‘Eà6;�DÔ3Ø;@�×%Ñ% jÑ1°%Ó8ð[m	Að` ×#Ò#Ø×$Ñ$ YÑ/×6Ñ6°t×7KÑ7KÔLð  $×":Ñ":Ñ:Ü˜Ó'¨4×+CÑ+CÀNÑ+SÐVWÑ+WÒWà7EØ×,Ñ,¨^Ñ<ñ8�×(Ñ(¨Ñ4ð �K‰K˜Ñ!×(Ñ(¨×)AÑ)AÔBð ×.Ñ.¨yÑ9ò 	)ˆFØ�mÑ$¨D×,AÑ,AÒAØ?E�×%Ñ% f¨]Ñ&;Ñ<Ø$(��yÒ!ð	)ð /3×.CÑ.C×.IÑ.IÓ.Kó 	PÑ*Ð˜{ØGRØñHˆD�K‰K˜(Ð#4Ð"5°]ÐCÑDð ITØñIˆD�K‰K˜(Ð#4Ð"5°^ÐDÑEð ! GÒ+Ø-1�—‘˜MÑ*Ø+6°uÑ+=�—‘˜KÑ(Ø/:¸9Ñ/E�—‘˜OÒ,Ø" gÓ-Ø-1�—‘˜MÑ*Ø,7¯O©O¸FÀDÓ,I�—‘˜LÑ)Ø/:¯©¸yÈ$Ó/O�—‘˜OÑ,Ø+6°uÑ+=�—‘˜KÑ(Ø2=·/±/À,ÐPTÓ2U�—‘Ð.Ñ/Ø/:¯©¸yÈ$Ó/O�—‘˜OÓ,ð%	Pð* �;‰;�}Ò%¨$×*=Ò*=Ø,0¯K©K¸
Ñ,CˆD�K‰KÐ(Ñ)Ü,/Ø—‘˜JÑ'¨$¯+©+¯/©/¸+ÀqÓ*IÑIó-ˆD�K‰KÐ(Ò)ð -.ˆD�K‰KÐ(Ñ)Ø,/ˆD�K‰KÐ(Ñ)ð
 �;‰;�}Ò%¨d¯k©k¯o©o¸oÔ.NØ+/ˆD�K‰K˜Ñ(Ø!%§¡¨XÑ!6ò �Ø+¨IÑ6ò �FØ˜mÑ,°Ó7¸F¿J¹JÀyÕ<QØ7=¸iÑ7H˜Ÿ™ OÑ4Ùðð
 —;‘;˜Ñ/Ñ;Ùðð —‘ˆð 	×ÑÔàˆøôW +ò Ü—M‘MÜ˜s›8˜*Ð$8¸¿¹¸ÐEÄ{÷ò ûðús   Î>fæ	gæ2gçgc                 ó‚   — 	  | j                   | j                  d„ dœ|   |«      S # t        $ r t        |› d�«      ‚w xY w)z1Parses data from "Stream ... {stream_type}" line.c                 ó   — i S r€   r‰   )Ú_lines    r8   ú<lambda>z=FFmpegInfosParser.parse_data_by_stream_type.<locals>.<lambda>œ  s   €  b€ r:   )ÚAudioÚVideoÚDataz? stream parsing is not supported by moviepy and will be ignored)Úparse_audio_stream_dataÚparse_video_stream_dataÚKeyErrorrÌ   )r1   r¬   rÑ   s      r8   rÊ   z+FFmpegInfosParser.parse_data_by_stream_type–  sl   € ð
	ðØ×5Ñ5Ø×5Ñ5Ù(ñð ñ	ð  ó	!ð !øô
 ò 	Ü%Ø�-ð  #ð #óð ð	ús   ‚#& ¦>c                 ó  — i }	 t        t        j                  d|«      j                  d«      «      |d<   t        j                  d|«      }|rt        |j                  d«      «      nd|d<   |S # t        t
        f$ r d|d<   Y ŒOw xY w)z)Parses data from "Stream ... Audio" line.z	 (\d+) Hzr   r"   Úunknownú(\d+) k(i?)b/sNr+   )r'   rÀ   rÁ   rÂ   ÚAttributeErrorÚ
ValueError)r1   rÑ   rØ   Úmatch_audio_bitrates       r8   rå   z)FFmpegInfosParser.parse_audio_stream_data¤  s‘   € àˆð	+Ü!$¤R§Y¡Y¨|¸TÓ%B×%HÑ%HÈÓ%KÓ!LˆK˜Ñô
 !Ÿi™iÐ(9¸4Ó@Ðá1DŒCÐ#×)Ñ)¨!Ó,Ô-È$ð 	�IÑð Ðøô ¤
Ð+ò 	+ð "+ˆK˜Óð	+ús   „1A. Á.BÂBc                 óº  — i }	 t        j                  d|«      }|r*|j                  «       D �cg c]  }t        |«      ‘Œ c}|d<   t        j                  d|«      }|rt        |j                  d«      «      nd|d<   | j                  d	k(  r	 | j                  |«      }nH| j                  d
k(  r	 | j                  |«      }n&t        d| j                  ›d| j                  ›d�«      ‚d}dD ]"  }||k7  sŒ	t        |||z  z
  «      dk  sŒ||z  }Œ$ ||d	<   t        j                  d|j                  «       «      }	|	�|	j                  «       \  }
}|
|d<   ||d<   |S c c}w # t        $ r& t        d| j                  ›d| j                  ›�«      ‚w xY w# t        t        f$ r | j                  |«      }Y ŒÌw xY w# t        t        f$ r | j                  |«      }Y Œòw xY w)z)Parses data from "Stream ... Video" line.z (\d+)x(\d+)[,\s]r#   z8MoviePy error: failed to read video dimensions in file 'z/'.
Here are the file infos returned byffmpeg:

rê   r   Nr+   r"   Útbrzfps source 'z#' not supported parsing the video 'ú'g	.lñÐ÷ï?)é   é   é   é   é2   g{®Gáz„?zVideo:\s(\w+)?\s?(\([^)]+\))?rZ   r»   )rÀ   rÁ   rÇ   r'   Ú	Exceptionrl   r   r,   rÂ   r   Ú	parse_fpsrë   rì   Ú	parse_tbrr$   rÅ   )r1   rÑ   rØ   Úmatch_video_sizeÚnumÚmatch_bitrater"   ÚcoefÚxrÖ   rZ   r»   s               r8   ræ   z)FFmpegInfosParser.parse_video_stream_data³  sì  € àˆð	Ü!Ÿy™yÐ)=¸tÓDÐÙà;K×;RÑ;RÓ;TÖ&U°C¤s¨3¥xÒ&U�˜FÑ#ô Ÿ	™	Ð"3°TÓ:ˆÙ@M¤ ]×%8Ñ%8¸Ó%;Ô!<ÐSWˆ�IÑð �?‰?˜eÒ#ð+Ø—n‘n TÓ*‘ð �_‰_ Ò%ð+Ø—n‘n TÓ*‘õ à—?“? D§M£Mð3óð ð ˆØ%ò 	ˆAØ�q“œc #¨¨D©¡.Ó1°DÓ8Ø˜$‘h‘ð	ð !ˆ�EÑô Ÿ)™)Ø,Ø�K‰K‹Mó
ˆð Ð&Ø$3×$:Ñ$:Ó$<Ñ!ˆZ˜Ø(2ˆK˜Ñ%Ø%,ˆK˜	Ñ"àÐùòq 'VøÜò 	Ýð —=“= $§*¢*ð.óð ð	ûô0 #¤JÐ/ò +Ø—n‘n TÓ*’ð+ûô
 #¤JÐ/ò +Ø—n‘n TÓ*’ð+ús@   „*E ®EÁ E ÂF Â/F7 ÅE Å/FÆ F4Æ3F4Æ7 GÇGc                 ó^   — t        t        j                  d|«      j                  d«      «      S )zEParses number of FPS from a line of the ``ffmpeg -i`` command output.z (\d+.?\d*) fpsr   ©rÃ   rÀ   rÁ   rÂ   )r1   rÑ   s     r8   r÷   zFFmpegInfosParser.parse_fpsõ  s$   € ä”R—Y‘YÐ1°4Ó8×>Ñ>¸qÓAÓBÐBr:   c                 óœ   — t        j                  d|«      j                  d«      }|d   dk(  rt        |dd «      dz  }|S t        |«      }|S )zEParses number of TBS from a line of the ``ffmpeg -i`` command output.z (\d+.?\d*k?) tbrr   r   ÚkNiè  )rÀ   rÁ   rÂ   rÃ   )r1   rÑ   Ús_tbrrï   s       r8   rø   zFFmpegInfosParser.parse_tbrù  sX   € ä—	‘	Ð.°Ó5×;Ñ;¸AÓ>ˆð �‰9˜ÒÜ˜˜c˜r˜
Ó# dÑ*ˆCð ˆ
ô ˜“,ˆCØˆ
r:   c                 ó  — 	 |j                  | j                  «      d   }t        j                  d|«      }t	        |j                  d«      «      S # t        $ r& t        d| j                  ›d| j                  ›�«      ‚w xY w)z]Parse the duration from the line that outputs the duration of
        the container.
        r   z-([0-9][0-9]:[0-9][0-9]:[0-9][0-9].[0-9][0-9])r   z4MoviePy error: failed to read the duration of file 'z0'.
Here are the file infos returned by ffmpeg:

)
Úsplitr•   rÀ   rÁ   r   rÂ   rö   rl   r   r,   )r1   rÑ   Útime_raw_stringÚmatch_durations       r8   r¾   z FFmpegInfosParser.parse_duration  s|   € ð	Ø"Ÿj™j¨×)DÑ)DÓEÀbÑIˆOÜŸY™YØ@ØóˆNô & n×&:Ñ&:¸1Ó&=Ó>Ð>øÜò 	Ýð
 —=“= $§*¢*ð	.óð ð	ús   ‚AA Á/A?c                 ó’   — |j                  dd«      }t        |«      dk(  r'|\  }}|j                  d«      |j                  d«      fS y)zjReturns a tuple with a metadata field-value pair given a ffmpeg `-i`
        command output line.
        ú:r   é   r¥   )r§   r§   )r  rg   Ústrip)r1   rÑ   ÚinfoÚ	raw_fieldÚ	raw_values        r8   rÄ   z,FFmpegInfosParser.parse_metadata_field_value  sI   € ð �z‰z˜#˜qÓ!ˆÜˆt‹9˜Š>Ø#'Ñ ˆI�yØ—O‘O CÓ(¨)¯/©/¸#Ó*>Ð?Ð?àr:   c                 ó¤   — |dk(  r|t        |«      fS |dk(  r6t        j                  d|«      }|r|t        |j                  «       «      dz  fS ||fS )zFCast needed video metadata fields to other types than the default str.r±   r²   z[-+]?\d+(\.\d+)?r   rÿ   )r1   rÔ   rÕ   Úmatchs       r8   rÎ   z-FFmpegInfosParser.video_metadata_type_casting&  s\   € à�HÒØœ5 ›<Ð(Ð(à�oÒ%Ü—I‘IÐ1°5Ó9ˆEÙð œu U§[¡[£]Ó3°bÑ8Ð9Ð9à�uˆ~Ðr:   N)r"   TF)r„   r…   r†   r‡   r9   r–   rÝ   rÊ   rå   ræ   r÷   rø   r¾   rÄ   rÎ   r‰   r:   r8   r‘   r‘   H  sO   „ ñð< ØØóò #/òJ|ò|òò@òDCò	òò(ór:   r‘   c                 ó°  — t         ddt        | «      g}|r|j                  g d¢«       t        dt        j
                  t        j
                  t        j                  dœ«      }t	        j                  |fi |¤Ž}|j                  «       \  }}	|	j                  dd¬«      }
|j                  «        ~|rt        |
«       	 t        |
| |||¬	«      j                  «       S # t        $ rp}t        j                   j#                  | «      rt%        d
| › d�«      ‚t        j                   j'                  | «      st)        d
| › d�«      ‚t+        d|
› �«      |‚d}~ww xY w)aÜ  Get the information of a file using ffmpeg.

    Returns a dictionary with next fields:

    - ``"duration"``
    - ``"metadata"``
    - ``"inputs"``
    - ``"video_found"``
    - ``"video_fps"``
    - ``"video_n_frames"``
    - ``"video_duration"``
    - ``"video_bitrate"``
    - ``"video_metadata"``
    - ``"audio_found"``
    - ``"audio_fps"``
    - ``"audio_bitrate"``
    - ``"audio_metadata"``
    - ``"video_codec_name"``
    - ``"video_profile"``

    Note that "video_duration" is slightly smaller than "duration" to avoid
    fetching the incomplete frames at the end, which raises an error.

    Parameters
    ----------

    filename
      Name of the file parsed, only used to raise accurate error messages.

    infos
      Information returned by FFmpeg.

    fps_source
      Indicates what source data will be preferably used to retrieve fps data.

    check_duration
      Enable or disable the parsing of the duration of the file. Useful to
      skip the duration check, for example, for images.

    decode_file
      Indicates if the whole file must be read to retrieve their duration.
      This is needed for some files in order to get the correct duration (see
      https://github.com/Zulko/moviepy/pull/1222).
    z-hide_bannerr>   )rD   ÚnullrG   i † rH   Úutf8Úignore)Úerrors)r   r
   r   rð   z' is a directoryz' not foundz+Error passing `ffmpeg -i` command output:

N)r   r   Úextendr   rQ   rR   rS   rT   ÚcommunicateÚdecoder}   rt   r‘   rÝ   rö   ÚosÚpathÚisdirÚIsADirectoryErrorÚexistsÚFileNotFoundErrorrl   )r   r
   r   r   r   r[   r\   r   ÚoutputrC   r,   rÙ   s               r8   r    r    5  s>  € ôh ˜.¨$Ô0FÀxÓ0PÐ
Q€CÙØ�
‰
Ò&Ô'ä.àÜ—g‘gÜ—g‘gÜ—Z‘Zñ		
ó€Lô �8‰8�CÑ(˜<Ñ(€DØ×&Ñ&Ó(�O€VˆUØ�L‰L˜¨ˆLÓ1€Eà‡N�NÔØáäˆeŒðXÜ ØØØ!Ø)Ø#ô
÷ ‰%‹'ð	øô ò XÜ�7‰7�=‰=˜Ô"Ü# a¨ zÐ1AÐ$BÓCÐCÜ—‘—‘ Ô)Ü# a¨ z°Ð$=Ó>Ð>ÜÐEÀeÀWÐMÓNÐTWÐWûðXús   Â>C Ã	EÃ%A+EÅE)TN)Tr"   FF)r‡   r  rÀ   Ú
subprocessrQ   rh   Únumpyrm   Úmoviepy.configr   Úmoviepy.toolsr   r   r   r   r�   r‘   r    r‰   r:   r8   ú<module>r#     sY   ðÙ Mã 	Û 	Û Û ã å (÷ñ ÷Pñ Póf ÷Fjñ jð^ ØØØôYXr:   