Ë
    Eü´j›  ã                   óp   — d Z ddlZddlZddlmZ ddlmZ ddlm	Z	m
Z
  G d„ d«      Ze	 	 	 	 	 d	d„«       Zy)
z"MoviePy audio writing with ffmpeg.é    N)ÚFFMPEG_BINARY)Úrequires_duration)Úcross_platform_popen_paramsÚffmpeg_escape_filenamec                   óD   — e Zd ZdZ	 	 	 	 	 	 	 d	d„Zd„ Zd„ Zd„ Zd„ Zd„ Z	y)
ÚFFMPEG_AudioWritera¢  
    A class to write an AudioClip into an audio file.

    Parameters
    ----------

    filename
      Name of any video or audio file, like ``video.mp4`` or ``sound.wav`` etc.

    size
      Size (width,height) in pixels of the output video.

    fps_input
      Frames per second of the input audio (given by the AudioClip being
      written down).

    nbytes : int, optional
      Number of bytes per sample. Default is 2 (16-bit audio).

    nchannels : int, optional
      Number of audio channels. Default is 2 (stereo).

    codec : str, optional
        The codec to use for the output. Default is ``libfdk_aac``.

    bitrate:
      A string indicating the bitrate of the final video. Only
      relevant for codecs which accept a bitrate.

    input_video : str, optional
      Path to an input video file. If provided, the audio will be muxed with this video.
      If not provided, the output will be audio-only.

    logfile : file-like object or None, optional
      A file object where FFMPEG logs will be written. If None, logs are suppressed.

    ffmpeg_params : list of str, optional
      Additional FFMPEG command-line parameters to customize the output.
    Nc
                 óâ  — |€t         j                  }|| _        || _        || _        | j                  j                  d«      d   | _        t        dd|t         j                  k(  rdndddd	|z  z  d
dd	|z  z  dd|z  dd|z  ddg}
|€|
j                  dg«       n|
j                  dt        |«      ddg«       |
j                  d
|gdd|z  gz   «       |
j                  ddg«       |�|
j                  d|g«       |	�|
j                  |	«       |
j                  t        |«      g«       t        t         j                  |t         j                  dœ«      }t        j                  |
fi |¤Ž| _        y )Nú.éÿÿÿÿz-yz	-loglevelÚerrorÚinfoz-fzs%dleé   z-acodecz	pcm_s%dlez-arz%dz-acz-iú-z-vnz-vcodecÚcopyz-strictz-2z-ab)ÚstdoutÚstderrÚstdin)ÚspÚPIPEÚlogfileÚfilenameÚcodecÚsplitÚextr   Úextendr   r   ÚDEVNULLÚPopenÚproc)Úselfr   Ú	fps_inputÚnbytesÚ	nchannelsr   ÚbitrateÚinput_videor   Úffmpeg_paramsÚcmdÚpopen_paramss               úa/root/workspace/ytshorts/venv/lib/python3.12/site-packages/moviepy/audio/io/ffmpeg_audiowriter.pyÚ__init__zFFMPEG_AudioWriter.__init__5   sq  € ð ˆ?Ü—g‘gˆGØˆŒØ ˆŒØˆŒ
Ø—=‘=×&Ñ& sÓ+¨BÑ/ˆŒô ØØØ¤"§'¡'Ò)‰G¨vØØ�q˜6‘zÑ"ØØ˜1˜v™:Ñ&ØØ�9ÑØØ�9ÑØØð
ˆð  ÐØ�J‰J˜�wÕà�J‰J˜Ô4°[ÓAÀ9ÈfÐUÔVà�
‰
�I˜uÐ%¨°°yÑ0@Ð(AÑAÔBØ�
‰
�I˜tÐ$Ô%ØÐØ�J‰J˜˜wÐ'Ô(ØÐ$Ø�J‰J�}Ô%Ø�
‰
Ô*¨8Ó4Ð5Ô6ä2Ü—z‘z¨W¼r¿w¹wÑGó
ˆô —H‘H˜SÑ1 LÑ1ˆ�	ó    c                 ór  — 	 | j                   j                  j                  |j                  «       «       y# t        $ r÷}| j                   j                  «       \  }}|�|j                  «       }n5| j                  j                  d«       | j                  j                  «       }|› d| j                  › d|› �}d|v r|d| j                  › d�z  }t	        |«      ‚d|v r+|d	| j                  › d
| j                  › d�z  }t	        |«      ‚d|v r|dz  }t	        |«      ‚d|v r|dz  }t	        |«      ‚d}~ww xY w)zGSend the audio frame (a chunck of ``AudioClip``) to ffmpeg for writtingNr   zK

MoviePy error: FFMPEG encountered the following error while writing file z:

 zUnknown encoderz\

The audio export failed because FFMPEG didn't find the specified codec for audio encoding z´. Please install this codec or change the codec when calling write_videofile or write_audiofile.
For instance for mp3:
   >>> write_videofile('myvid.mp4', audio_codec='libmp3lame')zincorrect codec parameters ?zN

The audio export failed, possibly because the codec specified for the video z, is not compatible with the given extension z¤. Please specify a valid 'codec' argument in write_audiofile or 'audio_codoc'argument in write_videofile. This would be 'libmp3lame' for mp3, 'libvorbis' for ogg...zbitrate not specifiedzr

The audio export failed, possibly because the bitrate you specified was too high or too low for the audio codec.zInvalid encoder typezd

The audio export failed because the codec or file extension you provided is not suitable for audio)r   r   ÚwriteÚtobytesÚIOErrorÚcommunicateÚdecoder   ÚseekÚreadr   r   r   )r   Úframes_arrayÚerrÚ_Úffmpeg_errorr   s         r(   Úwrite_frameszFFMPEG_AudioWriter.write_framesl   s|  € ð1	!Ø�I‰I�O‰O×!Ñ! ,×"6Ñ"6Ó"8Õ9øÜò /	!Ø"Ÿi™i×3Ñ3Ó5‰OˆAˆ|ØÐ'Ø+×2Ñ2Ó4‘ð —‘×!Ñ! !Ô$Ø#Ÿ|™|×0Ñ0Ó2�ð �%ð  Ø $§¡˜¨f°\°NðDð ð
 ! LÑ0Øð:Ø:>¿*¹*¸ð FTðTñ�ô> ˜%“.Ð ð/ 0°<Ñ?Øð5Ø59·Z±Z°Lð A1Ø15·±°
ð ;CðCñ�ô, ˜%“.Ð ð )¨LÑ8Øð'ñ�ô ˜%“.Ð ð (¨<Ñ7ØðOñ�ô
 ˜%“.Ð ûð_/	!ús   ‚36 ¶	D6¿C2D1Ä1D6c                 óz  — t        | d«      r¯| j                  r¢| j                  j                  j                  «        d| j                  _        | j                  j                  �5| j                  j                  j                  «        d| j                  _        | j                  j                  «        d| _        yyy)z@Closes the writer, terminating the subprocess if is still alive.r   N)Úhasattrr   r   Úcloser   Úwait©r   s    r(   r:   zFFMPEG_AudioWriter.close¡   s€   € ä�4˜Ô  T§Y¢YØ�I‰I�O‰O×!Ñ!Ô#Ø"ˆD�I‰IŒOØ�y‰y×ÑÐ+Ø—	‘	× Ñ ×&Ñ&Ô(Ø#'�—	‘	Ô à�I‰I�N‰NÔØˆD�Ið &/Ð r*   c                 ó$   — | j                  «        y ©N©r:   r<   s    r(   Ú__del__zFFMPEG_AudioWriter.__del__­   s   € à�
‰
�r*   c                 ó   — | S r>   © r<   s    r(   Ú	__enter__zFFMPEG_AudioWriter.__enter__³   s   € Øˆr*   c                 ó$   — | j                  «        y r>   r?   )r   Úexc_typeÚ	exc_valueÚ	tracebacks       r(   Ú__exit__zFFMPEG_AudioWriter.__exit__¶   s   € Ø�
‰
�r*   )é   rI   Ú
libfdk_aacNNNN)
Ú__name__Ú
__module__Ú__qualname__Ú__doc__r)   r7   r:   r@   rC   rH   rB   r*   r(   r   r      s?   „ ñ&ðX ØØØØØØó52òn3!òj
òòór*   r   c
           
      óV  — |rt        |dz   d«      }
nd}
t        j                  |	«      }	 |	d|z  ¬«       t        |||| j                  |||
|¬«      }| j                  |d|||	¬«      D ]  }|j                  |«       Œ |j                  «        |r|
j                  «         |	d	¬«       y)
z[
    A function that wraps the FFMPEG_AudioWriter to write an AudioClip
    to a file.
    z.logzw+NzMoviePy - Writing audio in %s)Úmessage)r   r#   r   r%   T)Ú	chunksizeÚquantizer!   ÚfpsÚloggerzMoviePy - Done.)ÚopenÚproglogÚdefault_bar_loggerr   r"   Úiter_chunksr7   r:   )Úclipr   rS   r!   Ú
buffersizer   r#   Úwrite_logfiler%   rT   r   ÚwriterÚchunks                r(   Úffmpeg_audiowriter^   º   s½   € ñ" Ü�x &Ñ(¨$Ó/‰àˆÜ×'Ñ'¨Ó/€FÙ
Ð2°XÑ=Õ>ÜØØØØ�‰ØØØØ#ô	€Fð ×!Ñ!Ø t°FÀÈFð "ó ò #ˆð 	×Ñ˜EÕ"ð#ð
 ‡L�L„NáØ�‰ŒÙ
Ð$Ö%r*   )Ú	libvorbisNFNÚbar)rN   Ú
subprocessr   rV   Úmoviepy.configr   Úmoviepy.decoratorsr   Úmoviepy.toolsr   r   r   r^   rB   r*   r(   ú<module>re      sI   ðÙ (ã ã å (Ý 0ß M÷kñ kð\ ð ØØØØò*&ó ñ*&r*   