
    W|h,                     j    S r SSKrSSKJr  SSKJr  SSKJr  SSK	J
r
   " S S5      r\ S
S	 j5       rg)z"MoviePy audio writing with ffmpeg.    N)FFPLAY_BINARY)requires_duration)cross_platform_popen_params)ffmpeg_toolsc                   D    \ rS rSrSr  SS jrS rS rS rS r	S r
S	rg
)FFPLAY_AudioPreviewer   ah  
A class to preview an AudioClip.

Parameters
----------

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

nbytes:
  Number of bytes to encode the sound: 1 for 8bit sound, 2 for
  16bit, 4 for 32bit sound. Default is 2 bytes, it's fine.

nchannels:
  Number of audio channels in the clip. Default to 2 channels.
c                    [         SSSSSU-  -  SSU-  /n[        R                  " 5       S   n[        UR	                  S	5      S
   5      S:  a  USUS:X  a  SOS/-  nO
USSU-  /-  nUSS/-  n[        [        R                  [        R                  [        R                  S.5      n[        R                  " U40 UD6U l        g )Nz	-autoexitz-nodispz-fzs%dle   z-arz%d   .r      z
-ch_layout   stereomonoz-acz-i-)stdoutstderrstdin)r   r   ffplay_versionintsplitr   spDEVNULLSTDOUTPIPEPopenproc)self	fps_inputnbytes	nchannelscmdr   popen_paramss          `/home/james-whalen/.local/lib/python3.13/site-packages/moviepy/audio/io/ffplay_audiopreviewer.py__init__FFPLAY_AudioPreviewer.__init__   s     q6z"9
 &446q9~##C(+,1%N C
 y  C
 	
 	

 3zzRYYI
 HHS1L1	    c                     U R                   R                  R                  UR                  5       5        g! [         aF  nU R                   R                  5       u  p4Ub  UR                  5       nU SU 3n[	        U5      eSnAff = f)zASend a raw audio frame (a chunck of audio) to ffplay to be playedNzB

MoviePy error: FFPLAY encountered the following error while :

 )r   r   writetobytesIOErrorcommunicatedecode)r   frames_arrayerr_ffplay_errorerrors         r%   write_frames"FFPLAY_AudioPreviewer.write_framesG   s    	!IIOO!!,"6"6"89 
	!"ii335OA'+224 % %( 
 %. 
	!s   36 
B ABBc                    [        U S5      (       a  U R                  (       a  U R                  R                  R                  5         SU R                  l        U R                  R                  b5  U R                  R                  R                  5         SU R                  l        U R                  R                  5         SU l        ggg)z@Closes the writer, terminating the subprocess if is still alive.r   N)hasattrr   r   closer   waitr   s    r%   r8   FFPLAY_AudioPreviewer.closeW   s    4  TYYIIOO!!#"DIIOyy+		  &&(#'		 IINNDI &/ r(   c                 $    U R                  5         g Nr8   r:   s    r%   __del__FFPLAY_AudioPreviewer.__del__c   s    

r(   c                     U $ r=    r:   s    r%   	__enter__FFPLAY_AudioPreviewer.__enter__i   s    r(   c                 $    U R                  5         g r=   r>   )r   exc_type	exc_value	tracebacks       r%   __exit__FFPLAY_AudioPreviewer.__exit__l   s    

r(   )r   N)r   r   )__name__
__module____qualname____firstlineno____doc__r&   r4   r8   r?   rC   rI   __static_attributes__rB   r(   r%   r   r      s.    * 	'2R! 
r(   r   c                 f   U(       d   U R                   (       d  SnOU R                   n[        XU R                  5       nSnU R                  USX1S9 HC  nU(       a(  SnUb  UR	                  5         Ub  UR                  5         UR                  U5        ME     SSS5        g! , (       d  f       g= f)a7  
A function that wraps the FFPLAY_AudioPreviewer to preview an AudioClip

Parameters
----------

fps
   Frame rate of the sound. 44100 gives top quality, but may cause
   problems if your computer is not fast enough and your clip is
   complicated. If the sound jumps during the preview, lower it
   (11025 is still fine, 5000 is tolerable).

buffersize
  The sound is not generated all at once, but rather made by bunches
  of frames (chunks). ``buffersize`` is the size of such a chunk.
  Try varying it if you meet audio problems (but you shouldn't
  have to).

nbytes:
  Number of bytes to encode the sound: 1 for 8bit sound, 2 for
  16bit, 4 for 32bit sound. 2 bytes is fine.

audio_flag, video_flag:
  Instances of class threading events that are used to synchronize
  video and audio during ``VideoClip.preview()``.
iD  T)	chunksizequantizer!   fpsFN)rT   r   r"   iter_chunkssetr9   r4   )	cliprT   
buffersizer!   
audio_flag
video_flag	previewerfirst_framechunks	            r%   ffplay_audiopreviewr^   p   s    < xxC((C	sDNN	;y%% 4 & 
E #)NN$)OO%""5)
 
<	;	;s   AB""
B0)Ni  r   NN)rO   
subprocessr   moviepy.configr   moviepy.decoratorsr   moviepy.toolsr   moviepy.video.ior   r   r^   rB   r(   r%   <module>rd      s;    (  ( 0 5 )b bJ KO2* 2*r(   