
    g                         d Z ddlZddlmZ ddlmZmZ ddlmZm	Z	  ed       ed      	 dd              Z
 ed	      	 	 	 dd
       Z ed      dd       Z ed      dd       Z ed      	 dd       Zy)z!Miscellaneous bindings to ffmpeg.    N)FFMPEG_BINARY)convert_parameter_to_secondsconvert_path_to_string)ffmpeg_escape_filenamesubprocess_call)	inputfile
outputfile)
start_timeend_timec                 &   |sLt         j                  j                  |       \  }}||fD cg c]  }t        d|z         c}\  }}	d|||	|fz  }t        ddd|z  dt        |       dd||z
  z  dd	d
ddddt        |      g}
t        |
|       yc c}w )a  Makes a new video file playing video file between two times.

    Parameters
    ----------

    inputfile : str
      Path to the file from which the subclip will be extracted.

    start_time : float
      Moment of the input clip that marks the start of the produced subclip.

    end_time : float
      Moment of the input clip that marks the end of the produced subclip.

    outputfile : str, optional
      Path to the output file. Defaults to
      ``<inputfile_name>SUB<start_time>_<end_time><ext>``.
    i  z%sSUB%d_%d%s-yz-ssz%0.2f-iz-tz-map0-vcodeccopy-acodecz-copytsloggerN)ospathsplitextintr   r   r   )r   r
   r   r	   r   nameexttt1t2cmds              f/var/www/it7/html/youtubeDownloader/venv/lib/python3.12/site-packages/moviepy/video/io/ffmpeg_tools.pyffmpeg_extract_subclipr    
   s    . GG$$Y/	c*4h)?@A#dQh-@B#tRS&99
 	*y)8j()z*!C$ C'+ As   B)	videofile	audiofiler	   c                 v    t         ddt        |      dt        |       d|d|t        |      g}t        ||       y)a  Merges video file and audio file into one movie file.

    Parameters
    ----------

    videofile : str
      Path to the video file used in the merge.

    audiofile : str
      Path to the audio file used in the merge.

    outputfile : str
      Path to the output file.

    video_codec : str, optional
      Video codec used by FFmpeg in the merge.

    audio_codec : str, optional
      Audio codec used by FFmpeg in the merge.
    r   r   r   r   r   Nr   r   r   )r!   r"   r	   video_codecaudio_codecr   r   s          r   ffmpeg_merge_video_audior'   ;   sG    < 	y)y)z*C C'    c                 l    t         ddt        |       dd|z  dd|z  t        |      g	}t        ||       y)	a  Extract the sound from a video file and save it in ``outputfile``.

    Parameters
    ----------

    inputfile : str
      The path to the file from which the audio will be extracted.

    outputfile : str
      The path to the file to which the audio will be stored.

    bitrate : int, optional
      Bitrate for the new audio file.

    fps : int, optional
      Frame rate for the new audio file.
    r   r   z-abz%dkz-arz%dr   Nr$   )r   r	   bitratefpsr   r   s         r   ffmpeg_extract_audior,   i   sD    ( 	y)s
z*
C C'r(   c                 p    t         dt        |       dd|d   |d   fz  t        |      g}t        ||       y)a+  Resizes a file to new size and write the result in another.

    Parameters
    ----------

    inputfile : str
      Path to the file to be resized.

    outputfile : str
      Path to the output file.

    size : list or tuple
      New size in format ``[width, height]`` for the output file.
    r   -vfzscale=%d:%dr      r   Nr$   )r   r	   sizer   r   s        r   ffmpeg_resizer1      sE    " 	y)a$q'**z*C C'r(   )r   r	   
output_dirc                 T   |sHt         j                  j                  |       }t         j                  j                  |      \  }}| d| }t         j                  j	                  ||      }t
        dt        |       ddt        |      g}|r|j                  d       t        ||       y)a>  
    Stabilizes ``filename`` and write the result to ``output``.

    Parameters
    ----------

    inputfile : str
      The name of the shaky video.

    outputfile : str, optional
      The name of new stabilized video. Defaults to appending '_stabilized' to
      the input file name.

    output_dir : str, optional
      The directory to place the output video in. Defaults to the current
      working directory.

    overwrite_file : bool, optional
      If ``outputfile`` already exists in ``output_dir``, then overwrite
      ``outputfile`` Defaults to True.
    _stabilizedr   r.   deshaker   r   N)	r   r   basenamer   joinr   r   appendr   )	r   r	   r2   overwrite_filer   without_dirr   r   r   s	            r   ffmpeg_stabilize_videor;      s    2 gg&&y1GG$$[1	cv[.
j*5Jy)z*C 

4C'r(   )Nbar)r   r   r<   )i  iD  r<   )r<   )N Tr<   )__doc__r   moviepy.configr   moviepy.decoratorsr   r   moviepy.toolsr   r   r    r'   r,   r1   r;    r(   r   <module>rC      s    ' 	 ( S A 3489=B,( : 5,(^ @A
 *( B*(Z 34( 5(@ 34( 5(6 ABKP*( C*(r(   