
    W|h                        S r SSKrSSKrSSKrSSKJrJr  SSKJrJ	r	  SSK
JrJr  \	" S5      \" S5       SS j5       5       r\	" S	5         SS
 j5       r\	" S5      SS j5       r\	" S5      SS j5       r\	" S5       SS j5       rS rS rg)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_timec                 "   U(       dJ  [         R                  R                  U 5      u  pVX4 Vs/ s H  n[        SU-  5      PM     snu  pSXXX4-  n[        SSSU-  S[        U 5      SSX!-
  -  SS	S
SSSS[        U5      /n
[        XS9  gs  snf )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              W/home/james-whalen/.local/lib/python3.13/site-packages/moviepy/video/io/ffmpeg_tools.pyffmpeg_extract_subclipr!      s    . GG$$Y/	*4)?@)?A#dQh-)?@#t&99
 	*y)8()z*!C$ C'+ As   B)	videofile	audiofiler
   c                 n    [         SS[        U5      S[        U 5      SUSU[        U5      /n[        XeS9  g)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(   =   sE    < 	y)y)z*C C'    c                 d    [         SS[        U 5      SSU-  SSU-  [        U5      /	n[        XTS9  g)	ak  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-   k   sB    ( 	y)s
z*
C C'r)   c                 h    [         S[        U 5      SSUS   US   4-  [        U5      /n[        XCS9  g)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_resizer2      sC    " 	y)a$q'**z*C C'r)   )r	   r
   
output_dirc                 \   U(       dG  [         R                  R                  U 5      n[         R                  R                  U5      u  pgU SU 3n[         R                  R	                  X!5      n[
        S[        U 5      SS[        U5      /nU(       a  UR                  S5        [        XS9  g)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
   r3   overwrite_filer   without_dirr   r   r   s	            r    ffmpeg_stabilize_videor<      s    2 gg&&y1GG$$[1	v[.
j5Jy)z*C 

4C'r)   c                      [         SSS/n [        R                  " U SSSS9nUR                  R	                  5       S   R                  5       S   n[        R                  " SU5      R                  S5      nX#4$ )	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_versionrR      sx    6 		C ^^C4tLF ==++-a0668;Lhh{L9??BO**r)   c                      [         S/n [        R                  " U SSSS9nUR                  R	                  5       S   R                  5       S   n[        R                  " SU5      R                  S5      nX#4$ )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.
r>   Tr@   r   rD   rE   )	r   rF   rG   rH   rI   rJ   rK   rL   rM   rN   s       r    ffplay_versionrT      sp    6 	C
 ^^C4tLF==++-a0668;Lhh{L9??BO**r)   )Nbar)r   r   rU   )i  iD  rU   )rU   )N TrU   )__doc__r   rK   rF   moviepy.configr   r   moviepy.decoratorsr   r   moviepy.toolsr   r   r!   r(   r-   r2   r<   rR   rT    r)   r    <module>r\      s    ' 	 	  7 S A 3489=B,( : 5,(^ @A
 *( B*(Z 34( 5(@ 34( 5(6 ABKP*( C*(Z&+R#+r)   