
    -i                     \   d Z ddlZddlZddlZddlmZ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d Zd ZdS )z!Miscellaneous bindings to ffmpeg.    N)FFMPEG_BINARYFFPLAY_BINARY)convert_parameter_to_secondsconvert_path_to_string)ffmpeg_escape_filenamesubprocess_call)	inputfile
outputfile)
start_timeend_timebarc                    |s<t           j                            |           \  }}d ||fD             \  }}d||||fz  }t          ddd|z  dt	          |           dd||z
  z  dd	d
ddddt	          |          g}	t          |	|           dS )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>``.
    c                 2    g | ]}t          d |z            S )i  )int).0ts     [/var/www/html/speakWrite/venv/lib/python3.11/site-packages/moviepy/video/io/ffmpeg_tools.py
<listcomp>z*ffmpeg_extract_subclip.<locals>.<listcomp>%   s"    @@@A#dQh--@@@    z%sSUB%d_%d%s-yz-ssz%0.2f-iz-tz-map0-vcodeccopy-acodecz-copytsloggerN)ospathsplitextr   r   r   )
r	   r   r   r
   r   nameextt1t2cmds
             r   ffmpeg_extract_subclipr&      s    .  :G$$Y//	c@@*h)?@@@B#tRS&99
 	*y))8j()z**!C$ C''''''r   )	videofile	audiofiler
   r   c                     t           ddt          |          dt          |           d|d|t          |          g}t          ||           dS )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-   =   s_    < 	y))y))z**C C''''''r     D  c                     t           ddt          |           dd|z  dd|z  t          |          g	}t          ||           dS )	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_audior3   k   sY    ( 	y))s
z**
C C''''''r   c                     t           dt          |           dd|d         |d         fz  t          |          g}t          ||           dS )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_resizer8      sZ    " 	y))a$q'**z**C C''''''r   )r	   r
   
output_dir Tc                 x   |sHt           j                            |           }t           j                            |          \  }}| d| }t           j                            ||          }t
          dt          |           ddt          |          g}|r|                    d           t          ||           dS )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   r5   deshaker   r   N)	r   r   basenamer    joinr   r   appendr   )	r	   r
   r9   overwrite_filer   without_dirr!   r"   r%   s	            r   ffmpeg_stabilize_videorC      s    2  /g&&y11G$$[11	c....
j*55Jy))z**C  

4C''''''r   c                     t           dddg} t          j        | ddd          }|j                                        d                                         d         }t          j        d|                              d          }||fS )	a  
    Retrieve the FFmpeg version.

    This function retrieves both the full and numeric version of FFmpeg
    by executing the `ffmpeg -version` command. The full version includes
    additional details like build information, while the numeric version
    contains only the version numbers (e.g., '7.0.2').

    Return
    ------
    tuple
        A tuple containing:
        - `full_version` (str): The complete version string (e.g., '7.0.2-static').
        - `numeric_version` (str): The numeric version string (e.g., '7.0.2').

    Example
    -------
    >>> ffmpeg_version()
    ('7.0.2-static', '7.0.2')

    Raises
    ------
    subprocess.CalledProcessError
        If the FFmpeg command fails to execute properly.
    -versionz-vquietTcapture_outputtextcheckr      ^[0-9.]+)	r   
subprocessrunstdout
splitlinessplitrematchgroupr%   resultfull_versionnumeric_versions       r   ffmpeg_versionrY      s    6 		C ^C4tLLLF =++--a06688;Lh{L99??BBO/**r   c                  
   t           dg} t          j        | ddd          }|j                                        d                                         d         }t          j        d|                              d          }||fS )a  
    Retrieve the FFplay version.

    This function retrieves both the full and numeric version of FFplay
    by executing the `ffplay -version` command. The full version includes
    additional details like build information, while the numeric version
    contains only the version numbers (e.g., '6.0.1').

    Return
    ------
    tuple
        A tuple containing:
        - `full_version` (str): The complete version string (e.g., '6.0.1-static').
        - `numeric_version` (str): The numeric version string (e.g., '6.0.1').

    Example
    -------
    >>> ffplay_version()
    ('6.0.1-static', '6.0.1')

    Raises
    ------
    subprocess.CalledProcessError
        If the FFplay command fails to execute properly.
    rE   TrG   r   rK   rL   )	r   rM   rN   rO   rP   rQ   rR   rS   rT   rU   s       r   ffplay_versionr[      s~    6 	C
 ^C4tLLLF=++--a06688;Lh{L99??BBO/**r   )Nr   )r   r   r   )r.   r/   r   )r   )Nr:   Tr   )__doc__r   rR   rM   moviepy.configr   r   moviepy.decoratorsr   r   moviepy.toolsr   r   r&   r-   r3   r8   rC   rY   r[    r   r   <module>ra      s   ' ' 				 				     7 7 7 7 7 7 7 7 S S S S S S S S A A A A A A A A 344899=B,( ,( ,( :9 54,(^ @AA
 *( *( *( BA*(Z 344( ( ( 54(@ 344( ( ( 54(6 ABBKP*( *( *( CB*(Z&+ &+ &+R#+ #+ #+ #+ #+r   