
    g                     F    d Z ddlZddlmZ ddlmZ  G d d      Z	 ddZy)	zW
On the long term this will implement several methods to make videos
out of VideoClips
    N)FFPLAY_BINARY)cross_platform_popen_paramsc                   .    e Zd ZdZd Zd Zd Zd Zd Zy)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 || _        y )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         j/var/www/it7/html/youtubeDownloader/venv/lib/python3.12/site-packages/moviepy/video/io/ffplay_previewer.py__init__zFFPLAY_VideoPreviewer.__init__   s{     tAwQ((cM
 3zzRYYI
 HHS1L1	    c                    	 | j                   j                  j                  |j                                y# t        $ rF}| j                   j                         \  }}||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    	!IIOO!!)"3"3"56 
	!"ii335OA|'+224 % ))58 
 %. 
	!s   36 	BAB  Bc                    | j                   r| j                   j                  j                          | j                   j                  $| j                   j                  j                          | j                   j	                          d| _         yy)z@Closes the writer, terminating the subprocess if is still alive.N)r   r   closer   waitr   s    r   r*   zFFPLAY_VideoPreviewer.closeH   s]    99IIOO!!#yy+		  &&(IINNDI r   c                     | S N r,   s    r   	__enter__zFFPLAY_VideoPreviewer.__enter__T   s    r   c                 $    | j                          y 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      s      26! r   r   c                    t        | j                  ||      5 }d}| j                  d|d      D ]@  \  }}|j                  |       |sd}|r|j	                          |s1|j                          B 	 ddd       y# 1 sw Y   yxY w)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_videorG   [   s    @ 
tyy#|	< &	((Dc(Q 	&HAu  ' #NN$OO%	&& & &s   0A<	A< A<<B)rgb24NN)	r9   
subprocessr   moviepy.configr   moviepy.toolsr   r   rG   r/   r   r   <module>rL      s.   
  ( 5L L` BF.&r   