
    -i                     N    d Z ddlZddlmZ ddlmZ  G d d          Z	 d	dZdS )
zW
On the long term this will implement several methods to make videos
out of VideoClips
    N)FFPLAY_BINARY)cross_platform_popen_paramsc                   0    e Zd ZdZd Zd Zd Zd Zd ZdS )FFPLAY_VideoPreviewerae  A class for FFPLAY-based video preview.

    Parameters
    ----------

    size : tuple or list
      Size of the output video in pixels (width, height).

    fps : int
      Frames per second in the output video file.

    pixel_format : str
      Pixel format for the output video file, ``rgb24`` for normal video, ``rgba``
      if video with mask.
    c                     t           dddd|dd|d         |d         fz  d	d
|z  dg}t          t          j        t          j        t          j        d          }t          j        |fi || _        d S )Nz	-autoexitz-frawvideoz-pixel_formatz-video_sizez%dx%dr      z
-frameratez%.02f-)stdoutstderrstdin)r   r   spDEVNULLSTDOUTPIPEPopenproc)selfsizefpspixel_formatcmdpopen_paramss         _/var/www/html/speakWrite/venv/lib/python3.11/site-packages/moviepy/video/io/ffplay_previewer.py__init__zFFPLAY_VideoPreviewer.__init__   s     tAwQ((cM
 3zRYII
 
 HS11L11			    c                    	 | j         j                            |                                           dS # t          $ rM}| j                                         \  }}||                                }| d| }t	          |          d}~ww xY w)zWrites one frame in the file.NzR

MoviePy error: FFPLAY encountered the following error while previewing clip :

 )r   r   writetobytesIOErrorcommunicatedecode)r   	img_arrayerr_ffplay_errorerrors         r   
show_framez FFPLAY_VideoPreviewer.show_frame8   s    	!IO!!)"3"3"5"566666 
	! 
	! 
	!"i3355OA|'+2244  8 8)58 8 
 %.. 
	!s   15 
BABBc                     | j         rj| j         j                                         | j         j        | j         j                                         | j                                          d| _         dS dS )z@Closes the writer, terminating the subprocess if is still alive.N)r   r   closer   waitr   s    r   r*   zFFPLAY_VideoPreviewer.closeH   sk    9 	IO!!###y+	 &&(((INNDIII	 	r   c                     | S N r,   s    r   	__enter__zFFPLAY_VideoPreviewer.__enter__T   s    r   c                 .    |                                   d S r.   )r*   )r   exc_type	exc_value	tracebacks       r   __exit__zFFPLAY_VideoPreviewer.__exit__W   s    

r   N)	__name__
__module____qualname____doc__r   r(   r*   r0   r5   r/   r   r   r   r      si          2 2 26! ! !         r   r   rgb24c                 0   t          | j        ||          5 }d}|                     d|d          D ]J\  }}|                    |           |r.d}|r|                                 |r|                                 K	 ddd           dS # 1 swxY w Y   dS )a  Preview the clip using ffplay. See VideoClip.preview for details
    on the parameters.

    Parameters
    ----------

    clip : VideoClip
      The clip to preview

    fps : int
      Number of frames per seconds in the displayed video.

    pixel_format : str, optional
      Warning: This is not used anywhere in the code and should probably
      be removed.
      It is believed pixel format rgb24 does not work properly for now because
      it requires applying a mask on CompositeVideoClip and that is believed to
      not be working.

      Pixel format for the output video file, ``rgb24`` for normal video, ``rgba``
      if video with mask

    audio_flag : Thread.Event, optional
      A thread event that video will wait for. If not provided we ignore audio

    video_flag : Thread.Event, optional
      A thread event that video will set after first frame has been shown. If not
      provided, we simply ignore
    Tuint8)
with_timesr   dtypeFN)r   r   iter_framesr(   setr+   )	clipr   r   
audio_flag
video_flag	previewerfirst_frametframes	            r   ffplay_preview_videorH   [   s    @ 
ty#|	<	< &	((Dc(QQ 	& 	&HAu  '''  &# %NN$$$ &OO%%%	&& & & & & & & & & & & & & & & & & &s   A&BBB)r:   NN)	r9   
subprocessr   moviepy.configr   moviepy.toolsr   r   rH   r/   r   r   <module>rL      s    
     ( ( ( ( ( ( 5 5 5 5 5 5L L L L L L L L` BF.& .& .& .& .& .&r   