
    g                       d Z ddlZddlZddlZddlmZ ddlmZm	Z	m
Z
m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mZ ddlmZ erdd	lmZ dd
lmZ ddlmZm Z m!Z!m"Z"m#Z#m$Z$m%Z%m&Z&m'Z' ddl(m)Z)m*Z*m+Z+ ddl,m-Z- ddl.m/Z/ ddl0m1Z1 ddl2m3Z3 ddl4m5Z5  G d de      Z6 G d de6      Z7 G d de6      Z8	  G d de6      Z9 G d de9      Z: G d de9      Z; G d de6      Z<y) zImplements VideoClip (base class for video clips) and its main subclasses:

- Animated clips:     VideoFileClip, ImageSequenceClip, BitmapClip
- Static image clips: ImageClip, ColorClip, TextClip,
    N)Real)TYPE_CHECKINGCallableListUnion)imread)imwrite)Image	ImageDraw	ImageFont)ffplay_preview_video)Effect)Clip)	add_mask_if_noneapply_to_maskconvert_masks_to_RGBconvert_parameter_to_secondsconvert_path_to_stringoutplacerequires_durationrequires_fpsuse_clip_fps_by_default)compute_positionextensions_dictfind_extension)Crop)ResizeRotate)ffmpeg_write_videowrite_gif_with_imageioc                        e Zd ZdZ	 d@ fd	Zed        Zed        Zed        Zee	e
d                      Zd ZeZ edg      edAd	              Ze	ee eg d
      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dBd                            Ze	ee	 dCd                     Ze	e ed      	 	 	 dDd                     Ze edg      dAd              Ze	e	 dEd              Z	 dFded   fdZdGdZdHdZdej8                  dej8                  fdZdej>                  de dej>                  fdZ!dIdZ"e#de$e gej>                  f   fd       Z%e#d        Z&e#dJde'd e(f   fd        Z)e#d!        Z*e+e#d"               Z,e-e#dKd#              Z.e-e#d$               Z/dLd%Z0	 	 	 	 	 	 dMd&e d'e(d(e(d)e1d*e2d+e2d,e2fd-Z3	 	 	 	 	 	 	 	 dNd.e4d/e4d0e4d1e4d2e4d3e4d4e4d5e4fd6Z5 edg      dOd7       Z6dPd8Z7d9 Z8e#d:        Z9 fd;Z: fd<Z; fd=Z<d> Z=d? Z> xZ?S )Q	VideoClipaa  Base class for video clips.

    See ``VideoFileClip``, ``ImageClip`` etc. for more user-friendly classes.


    Parameters
    ----------

    is_mask
      `True` if the clip is going to be used as a mask.

    duration
      Duration of the clip in seconds. If None we got a clip of infinite
      duration

    has_constant_size
      Define if clip size is constant or if it may vary with time. Default
      to True



    Attributes
    ----------

    size
      The size of the clip, (width,height), in pixels.

    w, h
      The width and height of the clip, in pixels.

    is_mask
      Boolean set to `True` if the clip is a mask.

    frame_function
      A function ``t-> frame at time t`` where ``frame`` is a
      w*h*3 RGB array.

    mask (default None)
      VideoClip mask attached to this clip. If mask is ``None``,
                The video clip is fully opaque.

    audio (default None)
      An AudioClip instance containing the audio of the video clip.

    pos
      A function ``t->(x,y)`` where ``x,y`` is the position
      of the clip when it is composed with other clips.
      See ``VideoClip.set_pos`` for more details

    relative_pos
      See variable ``pos``.

    layer
      Indicates which clip is rendered on top when two clips overlap in
      a CompositeVideoClip. The highest number is rendered on top.
      Default is 0.

    c                    t         |           d | _        d | _        d | _        d| _        d| _        |r0|| _        | j                  d      j                  d d d d d   | _
        || _        || _        ||| _        || _        y y )Nc                      y)Nr   r    ts    `/var/www/it7/html/youtubeDownloader/venv/lib/python3.12/site-packages/moviepy/video/VideoClip.py<lambda>z$VideoClip.__init__.<locals>.<lambda>o   s        Fr      )super__init__maskaudioposrelative_poslayer_indexframe_function	get_frameshapesizeis_maskhas_constant_sizedurationend)selfr7   r;   r=   r<   	__class__s        r+   r1   zVideoClip.__init__i   s     		
#!"0Dq)//3DbD9DI!2$DMDH  r-   c                      | j                   d   S )zReturns the width of the video.r   r:   r?   s    r+   wzVideoClip.w{        yy|r-   c                      | j                   d   S )z Returns the height of the video.   rB   rC   s    r+   hzVideoClip.h   rE   r-   c                 F    | j                   t        | j                        z  S )z&Returns the aspect ratio of the video.)rD   floatrH   rC   s    r+   aspect_ratiozVideoClip.aspect_ratio   s     vvdff%%r-   c                 F    t        | j                  | j                  z        S )z*Returns the number of frames of the video.)intr=   fpsrC   s    r+   n_frameszVideoClip.n_frames   s    
 4==488+,,r-   c                     | j                   }|j                  |      }| j                  D ]4  }t        | |      }|dv rt	        j
                  |      }t        |||       6 |S )a  Mixed copy of the clip.

        Returns a shallow copy of the clip whose mask and audio will
        be shallow copies of the clip's mask and audio if they exist.

        This method is intensively used to produce new clips every time
        there is an outplace transformation of the clip (clip.resize,
        clip.subclipped, etc.)

        Acts like a deepcopy except for the fact that readers and other
        possible unpickleables objects are not copied.
        )r2   r3   )r@   __new____dict__getattr_copycopysetattr)r?   clsnew_clipattrvalues        r+   __copy__zVideoClip.__copy__   sd     nn;;s#MM 	+DD$'E((

5)HdE*		+
 r-   r*   c                    | j                  |      }|rQ| j                  Ed| j                  j                  |      z  }t        j                  ||g      j	                  d      }n|j	                  d      }t        ||       y)a  Save a clip's frame to an image file.

        Saves the frame of clip corresponding to time ``t`` in ``filename``.
        ``t`` can be expressed in seconds (15.35), in (min, sec),
        in (hour, min, sec), or as a string: '01:03:05.35'.

        Parameters
        ----------

        filename : str
          Name of the file in which the frame will be stored.

        t : float or tuple or str, optional
          Moment of the frame to be saved. As default, the first frame will be
          saved.

        with_mask : bool, optional
          If is ``True`` the mask is saved in the alpha layer of the picture
          (only works with PNGs).
        N   uint8)r8   r2   npdstackastyper	   )r?   filenamer*   	with_maskimr2   s         r+   
save_framezVideoClip.save_frame   sl    . ^^A.,,Q//DB:&--g6B7#B"r-   )rb   temp_audiofiletemp_audiofile_pathc                 f   t         j                  j                  t         j                  j                  |            \  }}|dd j	                         }t        j                  |      }|	 t        |   d   d   }|	
|dv rd}	nd}	n|	d	k(  rd
}	n|	dk(  rd}	t        |t              r|nd}|du xr |du xr | j                  du}|r|r|}nD|rBt        |	      }t         j                  j                  ||t        j                   z   d|z  z         } |d|z         |r#| j                  j#                  |||||	|
||       t%        | |||||||||||       |r6|r4t         j                  j'                  |      rt        j(                  |        |d|z         y# t        $ r t        d      w xY w)a  Write the clip to a videofile.

        Parameters
        ----------

        filename
          Name of the video file to write in, as a string or a path-like object.
          The extension must correspond to the "codec" used (see below),
          or simply be '.avi' (which will work with any codec).

        fps
          Number of frames per second in the resulting video file. If None is
          provided, and the clip has an fps attribute, this fps will be used.

        codec
          Codec to use for image encoding. Can be any codec supported
          by ffmpeg. If the filename is has extension '.mp4', '.ogv', '.webm',
          the codec will be set accordingly, but you can still set it if you
          don't like the default. For other extensions, the output filename
          must be set accordingly.

          Some examples of codecs are:

          - ``'libx264'`` (default codec for file extension ``.mp4``)
            makes well-compressed videos (quality tunable using 'bitrate').
          - ``'mpeg4'`` (other codec for extension ``.mp4``) can be an alternative
            to ``'libx264'``, and produces higher quality videos by default.
          - ``'rawvideo'`` (use file extension ``.avi``) will produce
            a video of perfect quality, of possibly very huge size.
          - ``png`` (use file extension ``.avi``) will produce a video
            of perfect quality, of smaller size than with ``rawvideo``.
          - ``'libvorbis'`` (use file extension ``.ogv``) is a nice video
            format, which is completely free/ open source. However not
            everyone has the codecs installed by default on their machine.
          - ``'libvpx'`` (use file extension ``.webm``) is tiny a video
            format well indicated for web videos (with HTML5). Open source.

        audio
          Either ``True``, ``False``, or a file name.
          If ``True`` and the clip has an audio clip attached, this
          audio clip will be incorporated as a soundtrack in the movie.
          If ``audio`` is the name of an audio file, this audio file
          will be incorporated as a soundtrack in the movie.

        audio_fps
          frame rate to use when generating the sound.

        temp_audiofile
          the name of the temporary audiofile, as a string or path-like object,
          to be created and then used to write the complete video, if any.

        temp_audiofile_path
          the location that the temporary audiofile is placed, as a
          string or path-like object. Defaults to the current working directory.

        audio_codec
          Which audio codec should be used. Examples are 'libmp3lame'
          for '.mp3', 'libvorbis' for 'ogg', 'libfdk_aac':'m4a',
          'pcm_s16le' for 16-bit wav and 'pcm_s32le' for 32-bit wav.
          Default is 'libmp3lame', unless the video extension is 'ogv'
          or 'webm', at which case the default is 'libvorbis'.

        audio_bitrate
          Audio bitrate, given as a string like '50k', '500k', '3000k'.
          Will determine the size/quality of audio in the output file.
          Note that it mainly an indicative goal, the bitrate won't
          necessarily be the this in the final file.

        preset
          Sets the time that FFMPEG will spend optimizing the compression.
          Choices are: ultrafast, superfast, veryfast, faster, fast, medium,
          slow, slower, veryslow, placebo. Note that this does not impact
          the quality of the video, only the size of the video file. So
          choose ultrafast when you are in a hurry and file size does not
          matter.

        threads
          Number of threads to use for ffmpeg. Can speed up the writing of
          the video on multicore computers.

        ffmpeg_params
          Any additional ffmpeg parameters you would like to pass, as a list
          of terms, like ['-option1', 'value1', '-option2', 'value2'].

        write_logfile
          If true, will write log files for the audio and the video.
          These will be files ending with '.log' with the name of the
          output file in them.

        logger
          Either ``"bar"`` for progress bar or ``None`` or any Proglog logger.

        pixel_format
          Pixel format for the output video file.

        Examples
        --------

        .. code:: python

            from moviepy import VideoFileClip
            clip = VideoFileClip("myvideo.mp4").subclipped(100,120)
            clip.write_videofile("my_new_video.mp4")
            clip.close()

        rG   Ncodecr   zoMoviePy couldn't find the codec associated with the filename. Provide the 'codec' parameter in write_videofile.)ogvwebm	libvorbis
libmp3lameraw16	pcm_s16leraw32	pcm_s32leTz
wvf_snd.%szMoviePy - Building video %s.)message)bitratewrite_logfilelogger)rs   presetrt   	audiofilethreadsffmpeg_paramsru   pixel_formatzMoviePy - video ready %s)ospathsplitextbasenamelowerproglogdefault_bar_loggerr   KeyError
ValueError
isinstancestrr3   r   joinr   _TEMP_FILES_PREFIXwrite_audiofiler    existsremove)r?   rb   rN   ri   rs   r3   	audio_fpsrv   audio_nbytesaudio_codecaudio_bitrateaudio_bufsizerf   rg   remove_temprt   rx   ry   ru   rz   nameextrw   
make_audio	audio_exts                            r+   write_videofilezVideoClip.write_videofile   s   H GG$$RWW%5%5h%?@	c!"gmmo++F3=',W5a8 o%)*G#%KG#%K's3E	$PUd]P49O 	 .&I&{3I#t...	1III 	5@AJJ&&%+ ' 	 	''%	
 :ww~~i(		)$1H<=C   4 s   +F F0c                 (   t        j                  |      }t        j                  d| j                  d|z        }g }|j                  t        t        |                  D ]/  \  }}||z  }	|j                  |	       | j                  |	||       1 |S )a  Writes the videoclip to a sequence of image files.

        Parameters
        ----------

        name_format
          A filename specifying the numerotation format and extension
          of the pictures. For instance "frame%03d.png" for filenames
          indexed with 3 digits and PNG format. Also possible:
          "some_folder/frame%04d.jpeg", etc.

        fps
          Number of frames per second to consider when writing the
          clip. If not specified, the clip's ``fps`` attribute will
          be used if it has one.

        with_mask
          will save the clip's mask (if any) as an alpha canal (PNGs only).

        logger
          Either ``"bar"`` for progress bar or ``None`` or any Proglog logger.


        Returns
        -------

        names_list
          A list of all the files generated.

        Notes
        -----

        The resulting image sequence can be read using e.g. the class
        ``ImageSequenceClip``.

        r         ?r)   rc   )
r   r   r_   aranger=   iter_barlist	enumerateappendre   )
r?   name_formatrN   rc   ru   timings	filenamesir*   r   s
             r+   write_images_sequencezVideoClip.write_images_sequence  s    T ++F3 ))At}}cCi8	OOd9W+=&>O? 	:DAq?DT"OOD!yO9	: r-   rb   c                 $    t        | ||||       y)a  Write the VideoClip to a GIF file.

        Converts a VideoClip into an animated GIF using imageio

        Parameters
        ----------

        filename
          Name of the resulting gif file, as a string or a path-like object.

        fps
          Number of frames per second (see note below). If it
          isn't provided, then the function will look for the clip's
          ``fps`` attribute (VideoFileClip, for instance, have one).

        loop : int, optional
          Repeat the clip using ``loop`` iterations in the resulting GIF.

        progress_bar
          If True, displays a progress bar


        Notes
        -----

        The gif will be playing the clip in real time (you can
        only change the frame rate). If you want the gif to be played
        slower than the clip you will use

        .. code:: python

            # slow down clip 50% and make it a gif
            myClip.multiply_speed(0.5).to_gif('myClip.gif')

        )rN   loopru   Nr!   )r?   rb   rN   r   ru   s        r+   	write_gifzVideoClip.write_gif  s    ` 		
r-   c                     | j                         }|j                  |      }t        j                  |j	                  d            }|j                          y)a  Splashes the frame of clip corresponding to time ``t``.

        Parameters
        ----------

        t : float or tuple or str, optional
        Time in seconds of the frame to display.

        with_mask : bool, optional
        ``False`` if the clip has a mask but you want to see the clip without
        the mask.

        Examples
        --------

        .. code:: python

            from moviepy import *

            clip = VideoFileClip("media/chaplin.mp4")
            clip.show(t=4)
        r^   N)rU   r8   r
   	fromarrayra   show)r?   r*   rc   clipframepil_imgs         r+   r   zVideoClip.show  s?    2 yy{ q!//%,,w"78r-   c                 "   |xr | j                   du}d}d}|rht        j                         }t        j                         }t        j                  | j                   j                  |||||f      }|j                          t        | |||       y)a-  Displays the clip in a window, at the given frames per second.

        It will avoid that the clip be played faster than normal, but it
        cannot avoid the clip to be played slower than normal if the computations
        are complex. In this case, try reducing the ``fps``.

        Parameters
        ----------

        fps : int, optional
        Number of frames per seconds in the displayed video. Default to ``15``.

        audio : bool, optional
        ``True`` (default) if you want the clip's audio be played during
        the preview.

        audio_fps : int, optional
        The frames per second to use when generating the audio sound.

        audio_buffersize : int, optional
        The sized of the buffer used generating the audio sound.

        audio_nbytes : int, optional
        The number of bytes used generating the audio sound.

        Examples
        --------

        .. code:: python

            from moviepy import *
            clip = VideoFileClip("media/chaplin.mp4")
            clip.preview(fps=10, audio=False)
        N)targetargs)r   rN   
audio_flag
video_flag)r3   	threadingEventThreadaudiopreviewstartr   )	r?   rN   r3   r   audio_buffersizer   r   r   audiothreads	            r+   previewzVideoClip.preview7  s    N 24::T1

 #*J"*J#**zz..$ 	K  	3:*	
r-   effectsr   c                 (   |dk(  rdn| j                  d|      } | j                  ||      j                  |fi |}|dn| j                  |      }|||fD cg c]  }||	 }	}ddlm}
  |
|	      j	                  | j
                        S c c}w )a  Apply a transformation to a part of the clip.

        Returns a new clip in which the function ``fun`` (clip->clip)
        has been applied to the subclip between times `start_time` and `end_time`
        (in seconds).

        Examples
        --------

        .. code:: python

            # The scene between times t=3s and t=6s in ``clip`` will be
            # be played twice slower in ``new_clip``
            new_clip = clip.with_sub_effect(MultiplySpeed(0.5), 3, 6)

        r   N)
start_timeconcatenate_videoclips)
subclippedwith_effects,moviepy.video.compositing.CompositeVideoClipr   
with_startr   )r?   r   r   end_timekwargsleftcenterrightr   clipsr   s              r+   with_effects_on_subclipz!VideoClip.with_effects_on_subclip  s    & #atdooa.LCX6CCGVvV!)80T#'"7L$4;KLL 	X%e,77

CC Ms   B"Bc                 :    |xs g }| j                  fd|      S )zModifies the images of a clip by replacing the frame `get_frame(t)` by
        another frame,  `image_func(get_frame(t))`.
        c                        | |            S Nr(   )r8   r*   
image_funcs     r+   r,   z+VideoClip.image_transform.<locals>.<lambda>  s    :il3K r-   )	transform)r?   r   apply_tos    ` r+   image_transformzVideoClip.image_transform  s      >r~~KXVVr-   c                 T   |j                   }|d   |d   z
  }|d   |d   z
  }|}|dk  r	|d|d    }n+|dkD  r&g dg|d   z  g|z  }t        j                  ||f      }|dk  r|ddd|d   f   }|S |dkD  r0g dg|z  g|j                   d   z  }t        j                  ||f      }|S )a  Fills an array to match the specified shape.

        If the `pre_array` is smaller than the desired shape, the missing rows
        or columns are added with ones to the bottom or right, respectively,
        until the shape matches. If the `pre_array` is larger than the desired
        shape, the excess rows or columns are cropped from the bottom or right,
        respectively, until the shape matches.

        The resulting array with the filled shape is returned.

        Parameters
        ----------
        pre_array (numpy.ndarray)
          The original array to be filled.

        shape (tuple)
          The desired shape of the resulting array.
        r   rG   N)rG   rG   rG   )r9   r_   vstackhstack)r?   	pre_arrayr9   	pre_shapedxdy
post_arrayx_1s           r+   
fill_arrayzVideoClip.fill_array  s    & OO	1X	!$1X	!$
6":U1X.J!V;1-.3CIs#34J6#AzqzM2J  !V;#$z'7'7'::CJ#45Jr-   
backgroundreturnc                    || j                   z
  }| j                  |      j                  d      }t        j                  |      }| j
                  | j
                  j                  |      dz  j                  d      }t        j                  |      j                  d      }|j                  |j                  k7  rk|j                  \  }}	|j                  \  }
}||
kD  s|	|kD  r|j                  dd|
|f      }n-t        j                  d|
|fd      }|j                  |d       |}|j                  d      }|j                  |       | j                  |      }t        |j                  |j                  || j                        }|j                  d   dk7  r&|j                  d   dk7  r|j                  ||       |S |j                  d   dk7  r|j                  d      }|j                  d   dk7  r|j                  d      }t        j                  d|j                   |j"                  fd	      }|j                  ||       t        j$                  ||      }|S )
aq  Returns the result of the clip's frame at time `t` on top
        on the given `picture`, the position of the clip being given
        by the clip's ``pos`` attribute. Meant for compositing.

        If the clip/backgrounds have transparency the transparency will
        be accounted for.

        The return is a Pillow Image

        Parameters
        ----------
        backrgound (Image)
          The background image to apply current clip on top of
          if the background image is transparent it must be given as a RGBA image

        t
          The time of clip to apply on top of clip

        Return
        r^   r]   Lr   r'   RGBAr/   Ar   r   r   r   )r   r8   ra   r
   r   r2   convertr:   cropnewpasteputalphar4   r   r5   modewidthheightalpha_composite)r?   r   r*   ct
clip_frameclip_img	clip_maskclip_mask_img
mask_widthmask_height	img_width
img_heightnew_maskr4   canvasresults                   r+   
compose_onzVideoClip.compose_on  s   * ^ ^^B'..w7
??:.99 ,,R036>>wGI!OOI6>>sCM !!X]]2*7*<*<'
K(0%	:	)[:-E$1$6$61i7T$UM  %yyy*.EqIHNN=&9$,M''/Hm, hhrlx}}joosDDUDUV ==#
(;s(BXs+
 ??2#%#++F3J==#''/H 6J$4$4j6G6G#H,WXs#&&z6:r-   background_maskc                     || j                   z
  }| j                  |      j                  d      }|j                  \  }}|j                  \  }}| j	                  |      }	t        ||f||f|	| j                        }	t        t        |	d   d            }
t        t        |	d   |z   |            }t        t        |	d   d            }t        t        |	d   |z   |            }t        t        d|	d                }t        |t        ||
z
  ||z
        z         }t        t        d|	d                }t        |t        ||z
  ||z
        z         }||||
|f   |||||f   d||||
|f   z
  z  z   ||||
|f<   |S )a  Returns the result of the clip's mask at time `t` composited
        on the given `background_mask`, the position of the clip being given
        by the clip's ``pos`` attribute. Meant for compositing.

        (warning: only use this function to blit two masks together, never images)

        Parameters
        ----------
        background_mask:
          The underlying mask onto which the clip mask will be composed.

        t:
          The time position in the clip at which to extract the mask.
        rJ   r   rG   )
r   r8   ra   r9   r4   r   r5   rM   maxmin)r?   r   r*   r   r   bg_hbg_wclip_hclip_wr4   x_startx_endy_starty_endclip_x_start
clip_x_endclip_y_start
clip_y_ends                     r+   compose_maskzVideoClip.compose_mask  s    ^NN2&--g6	 %**
d" hhrl/$sDDUDUV c#a&!n%CA./c#a&!n%CA./
 3q3q6'?+UW_@U(WWX
3q3q6'?+UW_@U(WWX
" 9HEM75=(9
l:-|J/FFGwu} <==
9
wu}45 r-   c                 "   ddl m} || j                  }|d}|At        ||| j                        j                  |      } ||| j                  |      g      }n || j                  |      g||      }t        | t              rt        |d      s|| j                  t        | j                  t              rV|j                         }|j                  |j                  j                         |_
        |j                  |j                        S |S )a  Place the clip on a colored background.

        Returns a clip made of the current clip overlaid on a color
        clip of a possibly bigger size. Can serve to flatten transparent
        clips.

        Parameters
        ----------

        size
          Size (width, height) in pixels of the final clip.
          By default it will be the size of the current clip.

        color
          Background color of the final clip ([R,G,B]).

        pos
          Position of the clip in the final clip. 'center' is the default

        opacity
          Parameter in 0..1 indicating the opacity of the colored
          background.
        r   )CompositeVideoClipr   )colorr=   )r:   bg_color__call__)r   r	  r:   	ColorClipr=   with_opacitywith_positionr   	ImageCliphasattrr2   to_ImageClipwith_duration)	r?   r:   r
  r4   opacityr	  	colorclipr   
new_results	            r+   with_background_colorzVideoClip.with_background_colorY  s    0 	T<99D;C!EDMMl7#  (D4F4Fs4K(LMF'##C()uF
 tY'S*-))#
499i(H,,.J{{&"(++":":"<
++FOO<<r-   r7   c                 d    || _         | j                  d      j                  dd ddd   | _        y)zChange the clip's ``get_frame``.

        Returns a copy of the VideoClip instance, with the frame_function
        attribute set to `mf`.
        r   Nr.   r/   )r7   r8   r9   r:   )r?   r7   s     r+   with_updated_frame_functionz%VideoClip.with_updated_frame_function  s2     -NN1%++BQ/"5	r-   c                     || _         y)zAttach an AudioClip to the VideoClip.

        Returns a copy of the VideoClip instance, with the `audio`
        attribute set to ``audio``, which must be an AudioClip instance.
        Nr3   )r?   	audioclips     r+   
with_audiozVideoClip.with_audio  s     
r-   r2   c                      |dk(  r> j                   r t         j                  dd      }| _        y fd}t        d|      }| _        y)a<  
        Set the clip's mask.

        Returns a copy of the VideoClip with the mask attribute set to
        ``mask``, which must be a greyscale (values in 0-1) VideoClip.

        Parameters
        ----------
        mask : Union["VideoClip", str], optional
            The mask to apply to the clip.
            If set to "auto", a default mask will be generated:
            - If the clip has a constant size, a solid mask with a value of 1.0
            will be created.
            - Otherwise, a dynamic solid mask will be created based on the frame size.
        autor   Tr;   c                 r    t        j                  j                  |       j                  d d t              S )Nr.   )dtype)r_   onesr8   r9   rJ   r*   r?   s    r+   r7   z+VideoClip.with_mask.<locals>.frame_function  s*    774>>!#4#:#:2A#>eLLr-   )r;   r7   N)r<   r  r:   r$   r2   )r?   r2   r7   s   `  r+   rc   zVideoClip.with_mask  sK    " 6>%% C> 		M !nM	r-   c                     d| _         y)zRemove the clip's mask.N)r2   rC   s    r+   without_maskzVideoClip.without_mask  s     	r-   c                 L    | j                   j                  fd      | _         y)zSet the opacity/transparency level of the clip.

        Returns a semi-transparent copy of the clip where the mask is
        multiplied by ``op`` (any float, normally between 0 and 1).
        c                     | z  S r   r(   )picr  s    r+   r,   z(VideoClip.with_opacity.<locals>.<lambda>  s    'C- r-   N)r2   r   )r?   r  s    `r+   r  zVideoClip.with_opacity  s     II--.GH	r-   c                 P    || _         t        d      r| _        yfd| _        y)a=  Set the clip's position in compositions.

        Sets the position that the clip will have when included
        in compositions. The argument ``pos`` can be either a couple
        ``(x,y)`` or a function ``t-> (x,y)``. `x` and `y` mark the
        location of the top left corner of the clip, and can be
        of several types.

        Examples
        --------

        .. code:: python

            clip.with_position((45,150)) # x=45, y=150

            # clip horizontally centered, at the top of the picture
            clip.with_position(("center","top"))

            # clip is at 40% of the width, 70% of the height:
            clip.with_position((0.4,0.7), relative=True)

            # clip's position is horizontally centered, and moving up !
            clip.with_position(lambda t: ('center', 50+t))

        r  c                     S r   r(   )r*   r4   s    r+   r,   z)VideoClip.with_position.<locals>.<lambda>  s     r-   N)r5   r  r4   )r?   r4   relatives    ` r+   r  zVideoClip.with_position  s%    8 %3
#DH$DHr-   c                     || _         y)zSet the clip's layer in compositions. Clips with a greater ``layer``
        attribute will be displayed on top of others.

        Note: Only has effect when the clip is used in a CompositeVideoClip.
        N)r6   )r?   indexs     r+   with_layer_indexzVideoClip.with_layer_index  s     !r-   c                 @    | j                  t        ||||      g      S )zReturns a video clip that is a resized version of the clip.
        For info on the parameters, please see ``vfx.Resize``
        )new_sizer   r   r   )r   r   )r?   r1  r   r   r   s        r+   resizedzVideoClip.resized  s0       %!"/		
 		
r-   angleunitresampleexpandr   	translater  c                 F    | j                  t        |||||||      g      S )a  Rotates the specified clip by ``angle`` degrees (or radians) anticlockwise
        If the angle is not a multiple of 90 (degrees) or ``center``, ``translate``,
        and ``bg_color`` are not ``None``.
        For info on the parameters, please see ``vfx.Rotate``
        )r3  r4  r5  r6  r   r7  r  )r   r   )r?   r3  r4  r5  r6  r   r7  r  s           r+   rotatedzVideoClip.rotated	  s9       %!!'%

 	
r-   x1y1x2y2r   r   x_centery_centerc	                 H    | j                  t        ||||||||      g      S )aR  Returns a new clip in which just a rectangular subregion of the
        original clip is conserved. x1,y1 indicates the top left corner and
        x2,y2 is the lower right corner of the cropped region.
        All coordinates are in pixels. Float numbers are accepted.
        For info on the parameters, please see ``vfx.Crop``
        )r:  r;  r<  r=  r   r   r>  r?  )r   r   )	r?   r:  r;  r<  r=  r   r   r>  r?  s	            r+   croppedzVideoClip.cropped&  s<    "   !%%	
 	
r-   c                     t        | j                  |      | j                  |      }|r,| j                   | j                  j	                  |      |_        |S )z
        Returns an ImageClip made out of the clip's frame at time ``t``,
        which can be expressed in seconds (15.35), in (min, sec),
        in (hour, min, sec), or as a string: '01:03:05.35'.
        r;   r=   )r  r8   r;   r2   r  )r?   r*   rc   r=   rX   s        r+   r  zVideoClip.to_ImageClipI  sF     T^^A.xX. II2215HMr-   c                 Z    | j                   r| S | j                  fd      }d|_         |S )z.Return a mask a video clip made from the clip.c                 (    d| d d d d f   z  dz  S )Nr   r]   r(   )r)  canals    r+   r,   z#VideoClip.to_mask.<locals>.<lambda>Z  s    c!Q+>N8NQT8T r-   Tr;   r   )r?   rF  rX   s    ` r+   to_maskzVideoClip.to_maskU  s-    <<K++,TUH#HOr-   c                 T    | j                   r| j                  d       }d|_         |S | S )z;Return a non-mask video clip made from the mask video clip.c                 X    t        j                  dd| z  gz        j                  d      S )N   r]   r^   )r_   r`   ra   )r)  s    r+   r,   z"VideoClip.to_RGB.<locals>.<lambda>b  s$    BIIa39+o6==gF r-   FrG  )r?   rX   s     r+   to_RGBzVideoClip.to_RGB^  s0    <<++FH  %HOKr-   c                     d| _         y)z\Remove the clip's audio.

        Return a copy of the clip with audio set to None.
        Nr  rC   s    r+   without_audiozVideoClip.without_audiol  s     
r-   c                     t        |t              r/ddlm} | j                  |j                  k(  rdnd} || |g|      S t
        t        |   |      S )Nr   r   chaincompose)method)r   r$   r   r   r:   r0   __add__)r?   otherr   rR  r@   s       r+   rS  zVideoClip.__add__t  sM    eY' !%		UZZ 7WYF)4-GGY-e44r-   c                 l    t        |t              rddlm}  || |gg      S t        t        |   |      S )z
        Implement the or (self | other) to produce a video with self and other
        placed side by side horizontally.
        r   clips_arrayr   r$   r   rW  r0   __or__r?   rT  rW  r@   s      r+   rY  zVideoClip.__or__~  s5    
 eY'Pu//Y,U33r-   c                 n    t        |t              rddlm}  || g|gg      S t        t        |   |      S )zp
        Implement division (self / other) to produce a video with self
        placed on top of other.
        r   rV  rX  rZ  s      r+   __truediv__zVideoClip.__truediv__  s8    
 eY'P011Y,U33r-   c                 j    t        |t              st        S ddlm} | j                   ||      g      S )zl
        Implement matrice multiplication (self @ other) to rotate a video
        by other degrees
        r   r   )r   r   NotImplementedmoviepy.video.fx.Rotater   r   )r?   nr   s      r+   
__matmul__zVideoClip.__matmul__  s.    
 !T"!!2  &)--r-   c                 $    | j                  |      S )zq
        Implement the and (self & other) to produce a video with other
        used as a mask for self.
        r   )r?   r2   s     r+   __and__zVideoClip.__and__  s    
 ~~d##r-   )NFNT)r   T)NNNTiD  medium   NNi  N TFNNbarN)NTrg  )Nr   rg  )   Ti"V  i  r.   )r   Nr   )r'   )Nr   r   r   NN)r  )F)NNNT)degbicubicFNNN)NNNNNNNN)r   TN)r   )@__name__
__module____qualname____doc__r1   propertyrD   rH   rK   r   r   rO   r[   rU   r   r   re   r   r   r   r   r   r   r   r   r   r   r   r
   r   r_   ndarrayrJ   r  r  r   r   r  r  r   r   rc   r&  r   r  r   r  r/  r2  booltupler9  rM   rA  r  rH  rL  rN  rS  rY  r\  ra  rc  __classcell__r@   s   @r+   r$   r$   -   s   9x TX $     & & -   -, D
 "3%(  )< QR )H> S   H>T <A4   4l J' 3
 (  3
p !3%(% ) %N WXA
  A
N ?CDH~D@W!FJU[[ J JX?BJJ ?5 ?RZZ ?B3j 	6&w

':;	6 	6   eK$45  6   I  I %  %@ !  !
$ !

 
 	

 
 
 
 
> 

 
 	

 
 
 
 
 
F "3%(	 )		  5	4	4
.$r-   r$   c                       e Zd ZdZddZy)DataVideoClipao  
    Class of video clips whose successive frames are functions
    of successive datasets

    Parameters
    ----------
    data
      A list of datasets, each dataset being used for one frame of the clip

    data_to_frame
      A function d -> video frame, where d is one element of the list `data`

    fps
      Number of frames per second in the animation
    c           	           | _         | _        | _         fd}t        j	                   ||dt        |      z  |z  |       y )Nc                 l    j                  j                  t        j                  | z                 S r   )data_to_framedatarM   rN   r$  s    r+   r7   z.DataVideoClip.__init__.<locals>.frame_function  s*    %%diiDHHqL0A&BCCr-   r   )r;   r=   r<   )r{  rz  rN   r$   r1   len)r?   r{  rz  rN   r;   r<   r7   s   `      r+   r1   zDataVideoClip.__init__  sP    	*	D 	3t9_s*/ 	 	
r-   N)FTrl  rm  rn  ro  r1   r(   r-   r+   rw  rw    s     
r-   rw  c                       e Zd ZdZddZy)UpdatedVideoClipa  
    Class of clips whose frame_function requires some objects to
    be updated. Particularly practical in science where some
    algorithm needs to make some steps before a new frame can
    be generated.

    UpdatedVideoClips have the following frame_function:

    .. code:: python

        def frame_function(t):
            while self.world.clip_t < t:
                world.update() # updates, and increases world.clip_t
            return world.to_frame()

    Parameters
    ----------

    world
      An object with the following attributes:
      - world.clip_t: the clip's time corresponding to the world's state.
      - world.update() : update the world's state, (including increasing
      world.clip_t of one time step).
      - world.to_frame() : renders a frame depending on the world's state.

    is_mask
      True if the clip is a WxH mask with values in 0-1

    duration
      Duration of the clip, in seconds

    Nc                 T      _          fd}t        j                   |||       y )Nc                     j                   j                  | k  r*j                          j                   j                  | k  r*j                         S r   )worldclip_tupdateto_frame)r*   r?   r  s    r+   r7   z1UpdatedVideoClip.__init__.<locals>.frame_function  s?    **##a' **##a'>>##r-   r7   r;   r=   )r  r$   r1   )r?   r  r;   r=   r7   s   ``   r+   r1   zUpdatedVideoClip.__init__  s-    
	$
 	8 	 	
r-   )FNr}  r(   r-   r+   r  r    s    B

r-   r  c                   F    e Zd ZdZ	 ddZddZed	d       Zed
d       Zy)r  a  Class for non-moving VideoClips.

    A video clip originating from a picture. This clip will simply
    display the given picture at all times.

    Examples
    --------

    >>> clip = ImageClip("myHouse.jpeg")
    >>> clip = ImageClip( someArray ) # a Numpy array represent

    Parameters
    ----------

    img
      Any picture file (png, tiff, jpeg, etc.) as a string or a path-like object,
      or any array representing an RGB image (for instance a frame from a VideoClip).

    is_mask
      Set this parameter to `True` if the clip is a mask.

    transparent
      Set this parameter to `True` (default) if you want the alpha layer
      of the picture (if it exists) to be used as a mask.

    Attributes
    ----------

    img
      Array representing the image of the clip.

    Nc                    t         j                  | ||       t        t        j                        st              t        j                        dk(  rj                  d   dk(  r]|rdd d d d df   z  dz  n\|rdd d d d df   z  dz  nG|rEt        dd d d d df   z  dz  d	      | _	        d d d d d df   n|rdd d d d df   z  dz  fd
| _
        j                  d d d d d   | _        | _        y )NrC  rK  r.   re  r   r]   r   Tr   c                     S r   r(   )r*   imgs    r+   r,   z$ImageClip.__init__.<locals>.<lambda><       r-   r/   )r$   r1   r   r_   rq  	imread_v2r|  r9   r  r2   r7   r:   r  )r?   r  r;   transparent	fromalphar=   s    `    r+   r1   zImageClip.__init__%  s    	48D#rzz*C.Csyy>Qyy|q Aq!G,s2CAq!G,s2C  )#Aq!G*<s*BD QDIaBQBh-CC1aL(3. ,IIbqM$B$'	r-   c                 V    |g }t         j                  | |||      }t         |_        |S )zGeneral transformation filter.

        Equivalent to VideoClip.transform. The result is no more an
        ImageClip, it has the class VideoClip (since it may be animated)
        )r   keep_duration)r$   r   r@   )r?   funcr   r  rX   s        r+   r   zImageClip.transform@  s>     H &&$ ' 
 'r-   c                     |g } || j                  d            j                  dd ddd   | _        fd| _        | _        |D ]0  }t        | |d      }||j                  |      }t        | ||       2 y)zImage-transformation filter.

        Does the same as VideoClip.image_transform, but for ImageClip the
        transformed clip is computed once and for all at the beginning,
        and not for each 'frame'.
        Nr   r.   r/   c                     S r   r(   )r*   arrs    r+   r,   z+ImageClip.image_transform.<locals>.<lambda>\  r  r-   )r8   r9   r:   r7   r  rS   r   rV   )r?   r   r   rY   anew_ar  s         @r+   r   zImageClip.image_transformP  s     H*+IIbqM$B$'	+ 	+DdD)A}))*5dE*		+r-   c                 z    |ddg}|D ]0  }t        | |d      }||j                  |      }t        | ||       2 y)a  Time-transformation filter.

        Applies a transformation to the clip's timeline
        (see Clip.time_transform).

        This method does nothing for ImageClips (but it may affect their
        masks or their audios). The result is still an ImageClip.
        Nr2   r3   )rS   time_transformrV   )r?   	time_funcr   r  rY   r  r  s          r+   r  zImageClip.time_transforme  sR     (H 	+DdD)A}((3dE*		+r-   )FTFN)NTr   NF)	rl  rm  rn  ro  r1   r   r   r   r  r(   r-   r+   r  r    sA    D OS6  + +( + +r-   r  c                   $     e Zd ZdZd fd	Z xZS )r  a  An ImageClip showing just one color.

    Parameters
    ----------

    size
      Size tuple (width, height) in pixels of the clip.

    color
      If argument ``is_mask`` is False, ``color`` indicates
      the color in RGB of the clip (default is black). If `is_mask``
      is True, ``color`` must be  a float between 0 and 1 (default is 1)

    is_mask
      Set to true if the clip will be used as a mask.

    c                 `   |\  }}|r)||f}|d}net        j                  |      sPt        d      |d}n2t        |d      st        d      t	        |t
              rt        d      ||t        |      f}t        | !  t        j                  |||z        j                  |      ||       y )Nr   z*Color has to be a scalar when mask is trueri  __getitem__z$Color has to contain RGB of the clipz<Color cannot be string. Color has to contain RGB of the cliprC  )r_   isscalar	Exceptionr  r   r   r|  r0   r1   tilereshape)	r?   r:   r
  r;   r=   rD   rH   r9   r@   s	           r+   r1   zColorClip.__init__  s    1FE}[[' LMM}!UM2 FGGE3'R  3u:&EGGE1q5!))%0'H 	 	
r-   )NFN)rl  rm  rn  ro  r1   rt  ru  s   @r+   r  r  x  s    $
 
r-   r  c                   N    e Zd ZdZ ed      	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 	 dd       Zy)TextClipa	  Class for autogenerated text clips.

    Creates an ImageClip originating from a script-generated text image.

    Parameters
    ----------

    font
      Path to the font to use. Must be an OpenType font.

    text
      A string of the text to write. Can be replaced by argument
      ``filename``.

    filename
      The name of a file in which there is the text to write,
      as a string or a path-like object.
      Can be provided instead of argument ``text``

    font_size
      Font size in point. Can be auto-set if method='caption',
      or if method='label' and size is set.

    size
      Size of the picture in pixels. Can be auto-set if
      method='label' and font_size is set, but mandatory if method='caption'.
      the height can be None for caption if font_size is defined,
      it will then be auto-determined.

    margin
      Margin to be added arround the text as a tuple of two (symmetrical) or
      four (asymmetrical). Either ``(horizontal, vertical)`` or
      ``(left, top, right, bottom)``. By default no margin (None, None).
      This is especially usefull for auto-compute size to give the text some
      extra room.

    color
      Color of the text. Default to "black". Can be
      a RGB (or RGBA if transparent = ``True``) ``tuple``, a color name, or an
      hexadecimal notation.

    bg_color
      Color of the background. Default to None for no background. Can be
      a RGB (or RGBA if transparent = ``True``) ``tuple``, a color name, or an
      hexadecimal notation.

    stroke_color
      Color of the stroke (=contour line) of the text. If ``None``,
      there will be no stroke.

    stroke_width
      Width of the stroke, in pixels. Must be an int.

    method
      Either 'label' (default, the picture will be autosized so as to fit
      exactly the size) or 'caption' (the text will be drawn in a picture
      with fixed size provided with the ``size`` argument). If `caption`,
      the text will be wrapped automagically.

    text_align
      center | left | right. Text align similar to css. Default to ``left``.

    horizontal_align
      center | left | right. Define horizontal align of text bloc in image.
      Default to ``center``.

    vertical_align
      center | top | bottom. Define vertical align of text bloc in image.
      Default to ``center``.

    interline
      Interline spacing. Default to ``4``.

    transparent
      ``True`` (default) if you want to take into account the
      transparency in the image.

    duration
        Duration of the clip
    rb   Nc                   %& dt         t           fd%	 	 d&dt        t        t        f   f%fd&	 	 d&&fd	}	 t	        j
                  |      }|r3t        |d      5 }|j                         j                         }d d d        |t        d      |\  }}|dk(  rb|t        d	      ||t        d
      | ||||
||||d      }| &||||
|||d      d   }dj                   %|||||
||            }nX|dk(  rH||t        d      | ||||
||||      }| &||||
||      d   }| &||||
|||      d   }nt        d      t        |      dk(  r)t        |d   xs d      x}}t        |d   xs d      x}}nbt        |      dk(  rIt        |d   xs d      }t        |d   xs d      }t        |d   xs d      }t        |d   xs d      }nt        d      |||z   z  }|||z   z  }|rdnd}||rd}t        j                  |||f|      }t	        j
                  ||      }t!        j"                  |      } &||||
|||      \  } }!d}"|d k(  r|| z
  |z
  |z
  }"n|d!k(  r||z
  |z
  | z
  dz  }"|"|z  }"d}#|d"k(  r||!z
  |z
  |z
  }#n|d!k(  r||z
  |z
  |!z
  dz  }#|#|z  }#|#|!dz  z  }#|j%                  |"|#f||||||
|	d#$	       t'        j(                  |      }$t*        j-                  | |$||%       || _        || _        |	| _        y # t        $ r }t        dj                  ||            d }~ww xY w# 1 sw Y   xY w)'Nr   c           	      v   t        j                  dd      }t        j                  ||      }t	        j
                  |      }	g }
d}|j                  d      }|D ]J  }|r|dz   |z   n|}|	j                  d|||||      \  }}}}||z
  }|| k  r|}8|
j                  |       |}L |r|
j                  |       |
S )z$Break text to never overflow a widthRGBrG   rG   rf   r'   )fontspacingalignstroke_width)	r
   r   r   truetyper   Drawsplitmultiline_textbboxr   )r   textr  	font_sizer  r  r  r  font_pildrawlinescurrent_linewordsword	temp_line	temp_lefttemp_top
temp_righttemp_bottom
temp_widths                       r+   
break_textz%TextClip.__init__.<locals>.break_text  s     ))E6*C ))$	:H>>#&DELJJsOE (9EL3.54	?C?V?V!#!- @W @<	8Z ()3
&#,LLL.#'L!($ \*Lr-   c           	         t        j                  dd      }t        j                  ||      }	t	        j
                  |      }
||s9|
j                  d| |	|||d      \  }}}}t        ||z
        t        ||z
        fS  || |||||      }|
j                  ddj                  |      |	|||d      \  }}}}t        ||z
        t        ||z
        fS )zBFind dimensions a text will occupy, return a tuple (width, height)r  r  r'   lm)r  r  r  r  anchorr   r  r  r  r  r  r  
)	r
   r   r   r  r   r  r  rM   r   )r  r  r  r  r  r  	max_widthallow_breakr  r  r  r   topr   bottomr  r  s                   r+   find_text_sizez)TextClip.__init__.<locals>.find_text_size-  s    ))E6*C ))$	:H>>#&D +/+B+B!#!- ,C ,(c5& EDL)3v|+<==#)E (,'>'>		% ) (? ($D#uf %s6C<'899r-   c           
          |}d}	|	|k  rAt        ||	z   dz        }
 | ||
|||||      \  }}||k  r|||k  r|
dz   }	n|
dz
  }|	|k  rA | ||	|||||      \  }}||k  r	|||k  r|	S |	dz
  S )z7Find the best font size to fit as optimally as possiblerG   r.   )r  r  rM   )r  r  r  r  r  r   r   r  max_font_sizemin_font_sizeavg_font_size
text_widthtext_heightr  s                r+   find_optimum_font_sizez1TextClip.__init__.<locals>.find_optimum_font_size_  s     "MM  -/ #]]%Bq$H I*8! # +	+'
K &FNkV>S$1A$5M$1A$5M!  -/& '5'	'#J U"+:O$$$q((r-   z6Invalid font {}, pillow failed to use it with error {}rzNo text nor filename providedcaptionz(Size is mandatory when method is captionz@Height is mandatory when method is caption and font size is NoneT)r  r  r  r  r  r   r   r  )r  r  r  r  r  r  r  r  rG   r  r  labelz<Font size is mandatory when method is label and size is None)r  r  r  r  r  r   r   )r  r  r  r  r  r  r   )r  r  r  r  r  r  r  z+Method must be either `caption` or `label`.r.   re  rK  z1Margin must be a tuple of either 2 or 4 elements.r   r  r   )r
  r   r   r  r  )	xyr  fillr  r  r  r  stroke_fillr  )r  r  r=   r  )r   r   rs  rM   r   r  r  r   formatopenreadrstripr   r|  r
   r   r   r  multiline_textr_   arrayr  r1   r  r
  stroke_color)'r?   r  r  rb   r  r:   marginr
  r  r  r  rR  
text_alignhorizontal_alignvertical_align	interliner  r=   r  _efiler   r   left_marginright_margin
top_marginbottom_marginimg_moder  pil_fontr  r  r  xy	img_numpyr  r  s'                                        @@r+   r1   zTextClip.__init__  s   * 	#Y 	R 0	: 38_0	:r /	)b	""4(A h$ ,yy{))+, <<== !%	:Y  !KLL!i&7 V   2!-$%#% $		 !+'!-$%' $	 	
 99#'!-$%
D w Y%6 R   2!-$%#%	  *'!-$% 	 !+'!-$%' 
 JKK v;!),VAY^!)<<K,),VAY^!)<<J[AfQin1-KVAY^!,Jvay~A.Lq	Q/MPQQ[<//	j=00
 )6e#Hii9j"9J%%dI6~~c" #1%#

K w&J&4|CA)[(<7*DIA	[X%[(:5EAx'j(=8;F!KA	Z 	
[1_1v%$ 	 
	
 HHSM	i[8 	 	
 	
(q  	HOOPTVWX 	, ,s#   L M
	M'MM
M)NNNNNr  blackNNr   r  r   r   r   re  TN)rl  rm  rn  ro  r   r1   r(   r-   r+   r  r    sV    Ob J' !%S) (S)r-   r  c                   \    e Zd ZdZdddddddd	d
dd
Z edg      dddddd       ZddZy)
BitmapClipzAClip made of color bitmaps. Mainly designed for testing purposes.)r]   r   r   )r   r]   r   )r   r   r]   ri  )r]   r]   r]   )Y      >   )q      l   )         )9         )r     !   )
RGBOWr   CDEFr=   NF)rN   r=   
color_dictr;   c          	         |J |r|n| j                   | _        g }|D ][  }g }|D ].  }	|j                  |	D 
cg c]  }
| j                  |
    c}
       0 |j                  t        j                  |             ] t        j                  |      t              | _        | j                  |z  n| j                  z  }t        j                  | fd||       | _	        yc c}
w )a  Creates a VideoClip object from a bitmap representation. Primarily used
        in the test suite.

        Parameters
        ----------

        bitmap_frames
          A list of frames. Each frame is a list of strings. Each string
          represents a row of colors. Each color represents an (r, g, b) tuple.
          Example input (2 frames, 5x3 pixel size)::

              [["RRRRR",
                "RRBRR",
                "RRBRR"],
               ["RGGGR",
                "RGGGR",
                "RGGGR"]]

        fps
          The number of frames per second to display the clip at. `duration` will
          calculated from the total number of frames. If both `fps` and `duration`
          are set, `duration` will be ignored.

        duration
          The total duration of the clip. `fps` will be calculated from the total
          number of frames. If both `fps` and `duration` are set, `duration` will
          be ignored.

        color_dict
          A dictionary that can be used to set specific (r, g, b) values that
          correspond to the letters used in ``bitmap_frames``.
          eg ``{"A": (50, 150, 150)}``.

          Defaults to::

              {
                "R": (255, 0, 0),
                "G": (0, 255, 0),
                "B": (0, 0, 255),
                "O": (0, 0, 0),  # "O" represents black
                "W": (255, 255, 255),
                # "A", "C", "D", "E", "F" represent arbitrary colors
                "A": (89, 225, 62),
                "C": (113, 157, 108),
                "D": (215, 182, 143),
                "E": (57, 26, 252),
              }

        is_mask
          Set to ``True`` if the clip is going to be used as a mask.
        Nc                 &    t        | z           S r   r  )r*   rN   frame_arrays    r+   r,   z%BitmapClip.__init__.<locals>.<lambda>  s    [QW%> r-   r  )
DEFAULT_COLOR_DICTr  r   r_   r  r|  total_framesr$   r1   rN   )r?   bitmap_framesrN   r=   r  r;   
frame_listinput_frameoutput_framerowr
  r  s     `        @r+   r1   zBitmapClip.__init__]  s    n ("666(2*8O8O
( 	6KL" O##$MT__U%;$MNObhh|45		6 hhz*,;##h.C((3.H>	 	 	
 # %Ns   C+c           	      p   |xs | j                   }g }| j                         D ]  }|j                  g        |D ]x  }|d   j                  d       |D ]]  }t        |j	                               t        |j                               j                  t        |               }|d   dxx   |z  cc<   _ z  |S )zReturns a valid bitmap list that represents each frame of the clip.
        If `color_dict` is not specified, then it will use the same `color_dict`
        that was used to create the clip.
        r/   rf  )r  iter_framesr   r   keysvaluesr.  rs  )r?   r  bitmapr   linepixelletters          r+   	to_bitmapzBitmapClip.to_bitmap  s    
  24??
%%' 	-EMM" -r
!!"%! -E!*//"34Z..0177eEF 2JrNf,N	--	- r-   r   )rl  rm  rn  ro  r  r   r1   r  r(   r-   r+   r  r  M  sZ    K  ":,/$(4DRWO 0Obr-   r  )=ro  rU   rT   r{   r   numbersr   typingr   r   r   r   numpyr_   r   
imageio.v2r   r  
imageio.v3r	   PILr
   r   r   !moviepy.video.io.ffplay_previewerr   moviepy.Effectr   moviepy.Clipr   moviepy.decoratorsr   r   r   r   r   r   r   r   r   moviepy.toolsr   r   r   moviepy.video.fx.Cropr   moviepy.video.fx.Resizer   r_  r   moviepy.video.io.ffmpeg_writerr    moviepy.video.io.gif_writersr"   r$   rw  r  r  r  r  r  r(   r-   r+   <module>r.     s     	   7 7   *  + + B % 
 
 
 L K & * * = ?x$ x$v#
I 
D,
y ,
^Ir+	 r+j)
	 )
Xf)y f)Rt tr-   