
    W|h                       S r SSKrSSKrSSKrSSKJr  SSKJrJ	r	J
r
Jr  SSKrSSKrSSKJr  SSKJr  SSKJrJrJr  SSKJr  \(       a  SS	KJr  SS
KJr  SSKJrJ r J!r!J"r"J#r#J$r$J%r%J&r&J'r'  SSK(J)r)J*r*J+r+  SSK,J-r-  SSK.J/r/  SSK0J1r1  SSK2J3r3  SSK4J5r5   " S S\5      r6 " S S\65      r7 " S S\65      r8  " S S\65      r9 " S S\95      r: " S S\95      r; " S S\65      r<g) 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                   B  ^  \ rS rSrSr SBU 4S jjr\S 5       r\S 5       r\S 5       r	\\
\S 5       5       5       rS r\r\" S	/5      \SCS
 j5       5       r\
\\\" / SQ5                        SDS j5       5       5       5       r\
\\ SES j5       5       5       r\
\\" S5         SFS j5       5       5       r\\" S	/5      SCS j5       5       r\
\ SGS j5       5       r SHS\S   4S jjrSIS jrSJS jrS\R:                  S\R:                  4S jrS\R@                  S	\!S\R@                  4S jr"SKS jr#\$S\%\!/\R@                  4   4S j5       r&\$S 5       r'\$SLS \(S \)4   4S! jj5       r*\$S" 5       r+\,\$S# 5       5       r-\.\$SMS$ j5       5       r/\.\$S% 5       5       r0SNS& jr1      SOS'\!S(\)S)\)S*\2S+\3S,\3S-\34S. jjr4        SPS/\5S0\5S1\5S2\5S3\5S4\5S5\5S6\54S7 jjr6\" S	/5      SQS8 j5       r7SRS9 jr8S: r9\$S; 5       r:U 4S< jr;U 4S= jr<U 4S> jr=S? r>S@ r?SAr@U =rA$ )S	VideoClip-   a  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U ]  5         S U l        S U l        S U l        SU l        SU l        U(       a/  Xl        U R                  S5      R                  S S S S S2   U l
        X l        X@l        Ub  X0l        X0l        g g )Nc                     g)Nr   r    ts    Q/home/james-whalen/.local/lib/python3.13/site-packages/moviepy/video/VideoClip.py<lambda>$VideoClip.__init__.<locals>.<lambda>o   s    V    Fr      )super__init__maskaudioposrelative_poslayer_indexframe_function	get_frameshapesizeis_maskhas_constant_sizedurationend)selfr9   r=   r?   r>   	__class__s        r,   r3   VideoClip.__init__i   s     		
#!"0q)//3DbD9DI!2$MH  r/   c                      U R                   S   $ )zReturns the width of the video.r   r<   rA   s    r,   wVideoClip.w{        yy|r/   c                      U R                   S   $ )z Returns the height of the video.   rE   rF   s    r,   hVideoClip.h   rI   r/   c                 F    U R                   [        U R                  5      -  $ )z&Returns the aspect ratio of the video.)rG   floatrL   rF   s    r,   aspect_ratioVideoClip.aspect_ratio   s     vvdff%%r/   c                 F    [        U R                  U R                  -  5      $ )z*Returns the number of frames of the video.)intr?   fpsrF   s    r,   n_framesVideoClip.n_frames   s    
 4==488+,,r/   c                     U R                   nUR                  U5      nU R                   H6  n[        X5      nUS;   a  [        R
                  " U5      n[        X#U5        M8     U$ )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.
)r4   r5   )rB   __new____dict__getattr_copycopysetattr)rA   clsnew_clipattrvalues        r,   __copy__VideoClip.__copy__   s[     nn;;s#MMDD'E((

5)HE*	 "
 r/   r+   c                    U R                  U5      nU(       aR  U R                  bE  SU R                  R                  U5      -  n[        R                  " XE/5      R	                  S5      nOUR	                  S5      n[        X5        g)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)r:   r4   npdstackastyper	   )rA   filenamer+   	with_maskimr4   s         r,   
save_frameVideoClip.save_frame   sh    . ^^A.,,Q//DB:&--g6B7#Br/   )rj   temp_audiofiletemp_audiofile_pathc                    [         R                  R                  [         R                  R                  U5      5      u  nnUSS R	                  5       n[
        R                  " U5      nUc   [        U   S   S   nU	c  US;   a  Sn	OSn	OU	S	:X  a  S
n	OU	S:X  a  Sn	[        U[        5      (       a  UOSnUSL =(       a    USL =(       a    U R                  SLnU(       a
  U(       a  UnOIU(       aB  [        U	5      n[         R                  R                  UU[        R                   -   SU-  -   5      nU" SU-  S9  U(       a"  U R                  R#                  UUUUU	U
UUS9  Sn	[%        U UUUUUUUU	UUUUS9  U(       aA  U(       a:  [         R                  R'                  U5      (       a  [         R(                  " U5        U" SU-  S9  g! [         a    [        S5      ef = f)aG  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()

rK   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loggerr\   )	r|   presetr}   	audiofileaudio_codecthreadsffmpeg_paramsr~   pixel_formatzMoviePy - video ready %s)ospathsplitextbasenamelowerproglogdefault_bar_loggerr   KeyError
ValueError
isinstancestrr5   r   joinr   _TEMP_FILES_PREFIXwrite_audiofiler    existsremove)rA   rj   rT   rr   r|   r5   	audio_fpsr   audio_nbytesr   audio_bitrateaudio_bufsizero   rp   remove_tempr}   r   r   r~   r   nameextr   
make_audio	audio_exts                            r,   write_videofileVideoClip.write_videofile   s   H GG$$RWW%5%5h%?@	c!"gmmo++F3=',W5a8 o%)*G#%KG#%K's33E	$PUd]P49O 	 .&I&{3I#t...	1III 	5@AJJ&&%+ ' 	 !K'#'%	
  :ww~~i((		)$1H<=K   4 s   -G G"c                    [         R                  " U5      n[        R                  " SU R                  SU-  5      n/ nUR                  [        [        U5      5      S9 H*  u  pxX-  n	UR                  U	5        U R                  XUS9  M,     U$ )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*   rk   )
r   r   rg   aranger?   iter_barlist	enumerateappendrm   )
rA   name_formatrT   rk   r~   timings	filenamesir+   r   s
             r,   write_images_sequenceVideoClip.write_images_sequence  s    T ++F3 ))At}}cCi8	OOd9W+=&>O?DA?DT"OODyO9 @ r/   rj   c                     [        U UUUUS9  g)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')

)rT   loopr~   Nr!   )rA   rj   rT   r   r~   s        r,   	write_gifVideoClip.write_gif  s    ` 		
r/   c                     U R                  5       nUR                  U5      n[        R                  " UR	                  S5      5      nUR                  5         g)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)
rf   N)r\   r:   r
   	fromarrayri   show)rA   r+   rk   clipframepil_imgs         r,   r   VideoClip.show  s?    2 yy{ q!//%,,w"78r/   c                 ,   U=(       a    U R                   SLnSnSnU(       ah  [        R                  " 5       n[        R                  " 5       n[        R                  " U R                   R                  UUUUU4S9nUR                  5         [        XXgS9  g)au  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   rT   
audio_flag
video_flag)r5   	threadingEventThreadaudiopreviewstartr   )	rA   rT   r5   r   audio_buffersizer   r   r   audiothreads	            r,   previewVideoClip.preview;  s    N 24::T1

 #*J"*J#**zz..$ 	K  	:	
r/   effectsr   c                 *   US:X  a  SOU R                  SU5      nU R                  X#5      R                  " U40 UD6nUc  SOU R                  US9nXVU4 Vs/ s H	  oc  M  UPM     n	nSSKJn
  U
" U	5      R	                  U R
                  5      $ s  snf )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   )rA   r   r   end_timekwargsleftcenterrightr   clipsr   s              r,   with_effects_on_subclip!VideoClip.with_effects_on_subclip  s    & #atdooa.L6CCGVvV!)80T#'"7L"7$"7L 	X%e,77

CC Ms   B!Bc                 F   ^ U=(       d    / nU R                  U4S jU5      $ )zsModifies the images of a clip by replacing the frame `get_frame(t)` by
another frame,  `image_func(get_frame(t))`.
c                     > T" U " U5      5      $ Nr)   )r:   r+   
image_funcs     r,   r-   +VideoClip.image_transform.<locals>.<lambda>  s    :il3Kr/   )	transform)rA   r   apply_tos    ` r,   image_transformVideoClip.image_transform  s      >r~~KXVVr/   c                 \   UR                   nUS   US   -
  nUS   US   -
  nUnUS:  a	  USUS    nO,US:  a&  / SQ/US   -  /U-  n[        R                  " X45      nUS:  a  USS2SUS   24   nU$ US:  a0  / SQ/U-  /UR                   S   -  n[        R                  " Xg45      nU$ )a7  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   rK   N)rK   rK   rK   )r;   rg   vstackhstack)rA   	pre_arrayr;   	pre_shapedxdy
post_arrayx_1s           r,   
fill_arrayVideoClip.fill_array  s    & OO	1X	!$1X	!$
6":U1X.J!V;1-.3CI#34J6#AzqzM2J  !V;#$z'7'7'::CJ#45Jr/   
backgroundreturnc                    X R                   -
  nU R                  U5      R                  S5      n[        R                  " U5      nU R
                  b  U R
                  R                  U5      S-  R                  S5      n[        R                  " U5      R                  S5      nUR                  UR                  :w  ah  UR                  u  pUR                  u  pX:  d  X:  a  UR                  SSX45      nO-[        R                  " SX4S5      nUR                  US5        UnUR                  S5      nUR                  U5        U R                  U5      n[        UR                  UR                  XR                  5      nUR                  S   S:w  a&  UR                  S   S:w  a  UR                  X]5        U$ UR                  S   S:w  a  UR                  S5      nUR                  S   S:w  a  UR                  S5      n[        R                  " SUR                   UR"                  4S	5      nUR                  X]5        [        R$                  " X5      nU$ )
a  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
rf   re   Lr   r(   RGBAr1   Ar   r   r   r   )r   r:   ri   r
   r   r4   convertr<   cropnewpasteputalphar6   r   r7   modewidthheightalpha_composite)rA   r   r+   ct
clip_frameclip_img	clip_maskclip_mask_img
mask_widthmask_height	img_width
img_heightnew_maskr6   canvasresults                   r,   
compose_onVideoClip.compose_on  s   * ^ ^^B'..w7
??:.99 ,,R036>>wGI!OOI6>>sCM !!X]]2*7*<*<'
(0%	)[-E$1$6$61i7T$UM  %yyy.EqIHNN=&9$,M''/Hm, hhrlx}}joosDUDUV ==#
(;s(BX+
 ??2#%#++F3J==#''/H 6J$4$4j6G6G#H,WX#&&z:r/   background_maskc                    X R                   -
  nU R                  U5      R                  S5      nUR                  u  pVUR                  u  pxU R	                  U5      n	[        X4Xe4XR                  5      n	[        [        U	S   S5      5      n
[        [        U	S   U-   U5      5      n[        [        U	S   S5      5      n[        [        U	S   U-   U5      5      n[        [        SU	S   * 5      5      n[        U[        X-
  X-
  5      -   5      n[        [        SU	S   * 5      5      n[        U[        X-
  UU-
  5      -   5      nUX2X24   UUU2X24   SXU2X24   -
  -  -   XU2X24'   U$ )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.
rO   r   rK   )
r   r:   ri   r;   r6   r   r7   rS   maxmin)rA   r
  r+   r   r   bg_hbg_wclip_hclip_wr6   x_startx_endy_starty_endclip_x_start
clip_x_endclip_y_start
clip_y_ends                     r,   compose_maskVideoClip.compose_mask  s    ^NN2&--g6	 %**
" hhrl/$sDUDUV c#a&!n%CA./c#a&!n%CA./
 3q3q6'?+U_@U(WWX
3q3q6'?+U_@U(WWX
" 9HM7=(9
l:-|/FFGw} <==
9
w}45 r/   c                 8   SSK Jn  Uc  U R                  nUc  SnUb<  [        XU R                  S9R                  U5      nU" X`R                  U5      /5      nOU" U R                  U5      /XS9n[        U [        5      (       a  [        US5      (       d  U R                  b  [        U R                  [        5      (       aW  UR                  5       nUR                  b  UR                  R                  5       Ul
        UR                  UR                  5      $ U$ )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hasattrr4   to_ImageClipwith_duration)	rA   r<   r  r6   opacityr  	colorclipr  
new_results	            r,   with_background_colorVideoClip.with_background_color]  s    0 	T<99D;C!DMMl7#  (4F4Fs4K(LMF'##C()F
 tY''S*--))#
499i(H(H,,.J{{&"(++":":"<
++FOO<<r/   r9   c                 b    Xl         U R                  S5      R                  SS SSS2   U l        g)z{Change the clip's ``get_frame``.

Returns a copy of the VideoClip instance, with the frame_function
attribute set to `mf`.
r   Nr0   r1   )r9   r:   r;   r<   )rA   r9   s     r,   with_updated_frame_function%VideoClip.with_updated_frame_function  s0     -NN1%++BQ/"5	r/   c                     Xl         g)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r5   )rA   	audioclips     r,   
with_audioVideoClip.with_audio  s	     
r/   r4   c                    ^  US:X  a7  T R                   (       a  [        T R                  SSS9nOU 4S jn[        SUS9nUT l        g)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                 n   > [         R                  " TR                  U 5      R                  S S [        S9$ )Nr0   )dtype)rg   onesr:   r;   rO   r+   rA   s    r,   r9   +VideoClip.with_mask.<locals>.frame_function  s*    774>>!#4#:#:2A#>eLLr/   )r=   r9   N)r>   r!  r<   r$   r4   )rA   r4   r9   s   `  r,   rk   VideoClip.with_mask  sB    " 6>%% C>M !nM	r/   c                     SU l         g)zRemove the clip's mask.N)r4   rF   s    r,   without_maskVideoClip.without_mask  s     	r/   c                 N   ^ U R                   R                  U4S j5      U l         g)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                    > TU -  $ r   r)   )picr(  s    r,   r-   (VideoClip.with_opacity.<locals>.<lambda>  s	    'C-r/   N)r4   r   )rA   r(  s    `r,   r"  VideoClip.with_opacity  s     II--.GH	r/   c                 Z   ^ X l         [        TS5      (       a  TU l        gU4S jU l        g)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                    > T$ r   r)   )r+   r6   s    r,   r-   )VideoClip.with_position.<locals>.<lambda>  s    r/   N)r7   r%  r6   )rA   r6   relatives    ` r,   r#  VideoClip.with_position  s&    8 %3
##DH$DHr/   c                     Xl         g)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)r8   )rA   indexs     r,   with_layer_indexVideoClip.with_layer_index  s
     !r/   c           	      :    U R                  [        UUUUS9/5      $ )zrReturns 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   )rA   rP  r   r   r   s        r,   resizedVideoClip.resized  s0       %!"/		
 		
r/   angleunitresampleexpandr   	translater  c                 @    U R                  [        UUUUUUUS9/5      $ )zRotates 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``
)rS  rT  rU  rV  r   rW  r  )r   r   )rA   rS  rT  rU  rV  r   rW  r  s           r,   rotatedVideoClip.rotated  s9       %!!'%

 	
r/   x1y1x2y2r   r   x_centery_centerc	                 B    U R                  [        UUUUUUUUS9/5      $ )a*  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   )	rA   r[  r\  r]  r^  r   r   r_  r`  s	            r,   croppedVideoClip.cropped*  s<    "   !%%	
 	
r/   c                     [        U R                  U5      U R                  US9nU(       a-  U R                  b   U R                  R	                  U5      Ul        U$ )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$  r:   r=   r4   r&  )rA   r+   rk   r?   r_   s        r,   r&  VideoClip.to_ImageClipM  sF     T^^A.xX. II2215HMr/   c                 f   ^ U R                   (       a  U $ U R                  U4S j5      nSUl         U$ )z.Return a mask a video clip made from the clip.c                 (   > SU S S 2S S 2T4   -  S-  $ )Nr   re   r)   )rC  canals    r,   r-   #VideoClip.to_mask.<locals>.<lambda>^  s    c!Q+>N8NQT8Tr/   Tr=   r   )rA   ri  r_   s    ` r,   to_maskVideoClip.to_maskY  s-    <<K++,TUH#HOr/   c                 ^    U R                   (       a  U R                  S 5      nSUl         U$ U $ )z;Return a non-mask video clip made from the mask video clip.c                 Z    [         R                  " SSU -  /-  5      R                  S5      $ )N   re   rf   )rg   rh   ri   )rC  s    r,   r-   "VideoClip.to_RGB.<locals>.<lambda>f  s"    BIIa39+o6==gFr/   Frk  )rA   r_   s     r,   to_RGBVideoClip.to_RGBb  s0    <<++FH  %HOKr/   c                     SU l         g)zLRemove the clip's audio.

Return a copy of the clip with audio set to None.
Nr1  rF   s    r,   without_audioVideoClip.without_audiop  s     
r/   c                    > [        U[        5      (       a,  SSKJn  U R                  UR                  :X  a  SOSnU" X/US9$ [
        [        U ]  U5      $ )Nr   r   chaincompose)method)r   r$   r   r   r<   r2   __add__)rA   otherr   rz  rB   s       r,   r{  VideoClip.__add__x  sN    eY'' !%		UZZ 7WYF)4-GGY-e44r/   c                 t   > [        U[        5      (       a  SSKJn  U" X//5      $ [        [        U ]  U5      $ )zj
Implement the or (self | other) to produce a video with self and other
placed side by side horizontally.
r   clips_arrayr   r$   r   r  r2   __or__rA   r|  r  rB   s      r,   r  VideoClip.__or__  s6    
 eY''P//Y,U33r/   c                 x   > [        U[        5      (       a  SSKJn  U" U /U//5      $ [        [        U ]  U5      $ )zX
Implement division (self / other) to produce a video with self
placed on top of other.
r   r  r  r  s      r,   __truediv__VideoClip.__truediv__  s;    
 eY''P011Y,U33r/   c                 t    [        U[        5      (       d  [        $ SSKJn  U R                  U" U5      /5      $ )zT
Implement matrice multiplication (self @ other) to rotate a video
by other degrees
r   r   )r   r   NotImplementedmoviepy.video.fx.Rotater   r   )rA   nr   s      r,   
__matmul__VideoClip.__matmul__  s1    
 !T""!!2  &)--r/   c                 $    U R                  U5      $ )zY
Implement the and (self & other) to produce a video with other
used as a mask for self.
r   )rA   r4   s     r,   __and__VideoClip.__and__  s    
 ~~d##r/   )r5   r?   r@   r9   r>   r=   r8   r4   r6   r7   r<   )NFNT)r   T)NNNTiD  medium   NNi  N TFNNbarN)NTr  )Nr   r  )   Ti"V  i  r0   )r   Nr   )r(   )Nr   r   r   NN)r6  )F)NNNT)degbicubicFNNN)NNNNNNNN)r   TN)r   )B__name__
__module____qualname____firstlineno____doc__r3   propertyrG   rL   rP   r   r   rU   rb   r\   r   r   rm   r   r   r   r   r   r   r   r   r   r   r   r
   r  rg   ndarrayrO   r  r+  r   r   r.  r3  r   r   rk   r?  r   r"  r   r#  rM  rQ  booltuplerY  rS   rb  r&  rl  rr  ru  r{  r  r  r  r  __static_attributes____classcell__rB   s   @r,   r$   r$   -   s   9x TX $     & & -   -, D
 "3%(  )< QR )L> S   L>\ <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                   "    \ rS rSrSrSS jrSrg)DataVideoClipi  aC  
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           	         ^  UT l         UT l        UT l        U 4S jn[        R	                  T UUS[        U5      -  U-  US9  g )Nc                 l   > TR                  TR                  [        TR                  U -  5         5      $ r   )data_to_framedatarS   rT   r;  s    r,   r9   .DataVideoClip.__init__.<locals>.frame_function  s*    %%diiDHHqL0A&BCCr/   r   )r=   r?   r>   )r  r  rT   r$   r3   len)rA   r  r  rT   r=   r>   r9   s   `      r,   r3   DataVideoClip.__init__  sP    	*	D 	3t9_s*/ 	 	
r/   )r  r  rT   N)FTr  r  r  r  r  r3   r  r)   r/   r,   r  r    s     
r/   r  c                   "    \ rS rSrSrSS jrSrg)UpdatedVideoClipi  aQ  
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                 N   ^ ^ TT l         U U4S jn[        R                  T XBUS9  g )Nc                    > TR                   R                  U :  a,  TR                  5         TR                   R                  U :  a  M,  TR                  5       $ r   )worldclip_tupdateto_frame)r+   rA   r  s    r,   r9   1UpdatedVideoClip.__init__.<locals>.frame_function  s?    **##a' **##a'>>##r/   r9   r=   r?   )r  r$   r3   )rA   r  r=   r?   r9   s   ``   r,   r3   UpdatedVideoClip.__init__  s+    
	$
 	8 	 	
r/   )r  )FNr  r)   r/   r,   r  r    s    B

r/   r  c                   V    \ rS rSrSr S	S jrS
S jr\SS j5       r\SS j5       r	Sr
g)r$  i  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                 6  ^ [         R                  XUS9  [        T[        R                  5      (       d  [        T5      m[        TR                  5      S:X  a  TR                  S   S:X  ai  U(       a  STS S 2S S 2S4   -  S-  mOhU(       a  STS S 2S S 2S4   -  S-  mONU(       a-  [        STS S 2S S 2S4   -  S-  SS	9U l	        TS S 2S S 2S S24   mOU(       a  STS S 2S S 2S4   -  S-  mU4S
 jU l
        TR                  S S S S S2   U l        TU l        g )Nre  rp  r0   r  r   re   r   Tr7  c                    > T$ r   r)   )r+   imgs    r,   r-   $ImageClip.__init__.<locals>.<lambda>@      r/   r1   )r$   r3   r   rg   r  	imread_v2r  r;   r$  r4   r9   r<   r  )rA   r  r=   transparent	fromalphar?   s    `    r,   r3   ImageClip.__init__)  s
    	48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                 N    Uc  / n[         R                  XX#S9n[         Ul        U$ )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   rB   )rA   funcr   r  r_   s        r,   r   ImageClip.transformD  s:     H && ' 
 'r/   c                   ^ Uc  / nU" U R                  S5      5      mTR                  SS SSS2   U l        U4S jU l        TU l        U H1  n[        XS5      nUc  M  UR                  U5      n[        XU5        M3     g)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   r0   r1   c                    > T$ r   r)   )r+   arrs    r,   r-   +ImageClip.image_transform.<locals>.<lambda>`  r  r/   )r:   r;   r<   r9   r  rZ   r   r]   )rA   r   r   r`   anew_ar  s         @r,   r   ImageClip.image_transformT  s     H*+IIbqM$B$'	+DD)A}))*5E*	 r/   c                     Uc  SS/nU H1  n[        XS5      nUc  M  UR                  U5      n[        XU5        M3     g)zTime-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.
Nr4   r5   )rZ   time_transformr]   )rA   	time_funcr   r  r`   r  r  s          r,   r  ImageClip.time_transformi  sI     (HDD)A}((3E*	 r/   )r9   r  r4   r<   )FTFN)NTr   NF)r  r  r  r  r  r3   r   r   r   r  r  r)   r/   r,   r$  r$    sA    D OS6  + +( + +r/   r$  c                   0   ^  \ rS rSrSrSU 4S jjrSrU =r$ )r!  i|  aw  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                   > Uu  pVU(       a0  Xe4nUc  SnOv[         R                  " U5      (       d  [        S5      eOOUc  SnO<[        US5      (       d  [        S5      e[	        U[
        5      (       a  [        S5      eXe[        U5      4n[        TU ]!  [         R                  " X%U-  5      R                  U5      X4S9  g )Nr   z*Color has to be a scalar when mask is truer  __getitem__z$Color has to contain RGB of the clipz<Color cannot be string. Color has to contain RGB of the clipre  )rg   isscalar	Exceptionr%  r   r   r  r2   r3   tilereshape)	rA   r<   r  r=   r?   rG   rL   r;   rB   s	           r,   r3   ColorClip.__init__  s    FE}[['' LMM ( }!UM22 FGGE3''R  3u:&EGGEq5!))%0' 	 	
r/   r)   )NFN)r  r  r  r  r  r3   r  r  r  s   @r,   r!  r!  |  s    $
 
r/   r!  c                       \ rS rSrSr\" S5                       SS j5       rS\\   4S jr	  SS\
\\4   4S jjr  SS	 jrS
rg)TextClipi  a*  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. If set to None
  (default) will use Pillow default 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 the text
      either by auto-computing font size if width is provided or auto-computing
      width and eight if font size is defined

    - 'caption' the text will be drawn in a picture with fixed size provided
      with the ``size`` argument. The text will be wrapped automagically,
      either by auto-computing font size if width and height are provided or adding
      line break when necesarry if font size is defined

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

.. note::

  ** About final TextClip size **

  The final TextClip size will be of the absolute maximum height possible
  for the font and the number of line. It specifically mean that the final
  height might be a bit bigger than the real text height, i.e, absolute
  bottom pixel of text - absolute top pixel of text.
  This is because in a font, some letter go above standard top line (e.g
  letters with accents), and bellow standard baseline (e.g letters such as
  p, y, g).

  This notion is knowned under the name ascent and descent meaning the
  highest and lowest pixel above and below baseline

  If your first line dont have an "accent character" and your last line
  dont have a "descent character", you'll have some "fat" arround
rj   Nc                    Ub   [         R                  " U5      nU(       a3  [        US5       nUR                  5       R                  5       nS S S 5        Uc  [        S5      eUS;  a  [        S5      e[        U5      S:X  a3  [        US   =(       d    S5      =nn[        US   =(       d    S5      =nnOw[        U5      S	:X  a]  [        US   =(       d    S5      n[        US   =(       d    S5      n[        US   =(       d    S5      n[        US
   =(       d    S5      nO[        S5      eUu  nnUS:X  ay  Uc  [        S5      eUc  Uc  [        S5      eUc  U R                  UUU
UUUUSS9nSR                  U R                  UUUUU
UUS95      nUc  U R                  UUUU
UUUSS9S   nOdUS:X  a^  Uc  Uc  [        S5      eUc  U R                  UUU
UUUUS9nUc  U R                  UUUU
UUS9S   nUc  U R                  UUUU
UUUS9S   nUUU-   -  nUUU-   -  nU(       a  SOSnUc	  U(       a  Sn[        R                  " UUU4US9nU(       a  [         R                  " X5      nO[         R                   " U5      n["        R$                  " U5      nU R                  UUUU
UUUS9u  nn Sn!US:X  a  UU-
  U-
  U-
  n!OUS:X  a  UU-
  U-
  U-
  S-  n!Sn"US:X  a  UU -
  U-
  U-
  n"OUS:X  a  UU-
  U-
  U -
  S-  n"UR'                  5       u  n#nU"U#-  n"U"U-  n"U!U-  n!U"U
-  n"U!U
-  n!UR)                  U!U"4UUUUUU
U	S S!9	  [*        R,                  " U5      n$[.        R1                  U U$UUS"9  X l        Xpl        Xl        g ! [         a   n[        SR	                  UU5      5      eS nAff = f! , (       d  f       GNq= f)#Nz6Invalid font {}, pillow failed to use it with error {}rzNo text nor filename provided)captionlabelz+Method must be either `caption` or `label`.r0   r   rK   r  rp  z1Margin must be a tuple of either 2 or 4 elements.r  z(Size is mandatory when method is captionz@Height is mandatory when method is caption and font size is NoneT)textfontstroke_widthalignspacingr   r   allow_break
r   r  r  	font_sizer  r  r  )r  r  r  r  r  r  	max_widthr  r  z<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   RGBr   )r  r   r   bottomls)	xyr  fillr  r  r  r  stroke_fillanchor)r  r  r?   )r   truetyper  r   formatopenreadrstripr  rS   !_TextClip__find_optimum_font_sizer   _TextClip__break_text_TextClip__find_text_sizer
   r   load_defaultr   Draw
getmetricsmultiline_textrg   arrayr$  r3   r  r  stroke_color)%rA   r  r  rj   r  r<   marginr  r  r   r  rz  
text_alignhorizontal_alignvertical_align	interliner  r?   _efileleft_marginright_margin
top_marginbottom_marginr  r  img_moder  pil_fontdraw
text_widthtext_heightxyascent	img_numpys%                                        r,   r3   TextClip.__init__  s   * &&t, h$yy{))+ % <<==--JKK v;!),VAY^!)<<K,),VAY^!)<<J[AfQin1-KVAY^!,Jvay~A.Lq	Q/MPQQ !%	:Y  !KLL!i&7 V    99!-$%#% $ : 		 99!!#'!-$% " 
D !!22'!-$%' $ 3 	 	
 w Y%6 R    99!-$%#% : 	   11'!-$% 2  	 !!22'!-$%' 3  
 	[<//	j=00
 )6e#Hii9j"9J ))$:H --i8H~~c" #'"7"7% #8 #

K w&J&4|CA)[(<7*DIAX%[(:5EAx'j(=8;F!KA ))+	V 	
Z	[	\	\1v%$ 	 
	
 HHSM	i[8 	 	
 	
({   LSSa  %$s"   N
 N7

N4N//N47
Or   c           
         [         R                  " SS5      nU(       a  [        R                  " X45      n	O[        R                  " U5      n	[
        R                  " U5      n
/ nSnSn[        U5       H{  u  pUS:X  a  UnX-   nU
R                  SUU	UUUS9u  nnnnUU-
  nUU:  aD  U(       a#  UR                  USU 5        UUS-   US-    nSnM_  UR                  USU 5        UnSnMy  UnM}     U(       a  UR                  U5        U$ )	z$Break text to never overflow a widthr  rK   rK   r  r    r(   )r  r  r  r  rK   )
r
   r   r   r  r  r   r  r   multiline_textbboxr   )rA   r   r  r  r  r  r  r  r  font_pilr  linescurrent_line
last_spacerL  char	temp_line	temp_lefttemp_top
temp_righttemp_bottom
temp_widths                         r,   __break_textTextClip.__break_text  s(    iiv& ))$:H --i8H~~c" 
$T?KEs{"
$+I;?;R;R) <S <8Ix[ $i/JU" LL1Z!89#,Z!^eai#HL!"JLLa!67#'L!"J(9 +< LL&r/   c	           
      \   [         R                  " SS5      n	U(       a  [        R                  " X#5      n
O[        R                  " U5      n
U
R                  5       u  pX-   n[        R                  " U	5      nUb-  U(       a&  U R                  UUUUUUUS9nSR                  U5      nUR                  SUU
UUUSS9u  nnnn UR                  XU5      nUR                  S5      nUU-  nXS-  -   n[        UU-   5      n[        UU-
  5      U4$ ! [         a    [        UU-
  5      n N*f = f)	u  Find *real* dimensions a text will occupy, return a tuple (width, height)

.. note::
    Text height calculation is quite complex due to how `Pillow` works.
    When calculating line height, `Pillow` actually uses the letter ``A``
    as a reference height, adding the spacing and the stroke width.
    However, ``A`` is a simple letter and does not account for ascent and
    descent, such as in ``Ô``.

    This means each line will be considered as having a "standard"
    height instead of the real maximum font size (``ascent + descent``).

    When drawing each line, `Pillow` will offset the new line by
    ``standard height * number of previous lines``.
    This mostly works, but if the spacing is not big enough,
    lines will overlap if a letter with an ascent (e.g., ``d``) is above
    a letter with a descent (e.g., ``p``).

    For our case, we use the baseline as the text anchor. This means that,
    no matter what, we need to draw the absolute top of our first line at
    ``0 + ascent + stroke_width`` to ensure the first pixel of any possible
    letter is aligned with the top border of the image (ignoring any
    additional margins, if needed).

    Therefore, our first line height will not start at ``0`` but at
    ``ascent + stroke_width``, and we need to account for that. Each
    subsequent line will then be drawn at
    ``index * standard height`` from this point. The position of the last
    line can be calculated as:
    ``(total_lines - 1) * standard height``.

    Finally, as we use the baseline as the text anchor, we also need to
    consider that the real size of the last line is not "standard" but
    rather ``standard + descent + stroke_width``.

    To summarize, the real height of the text is:
      ``initial padding + (lines - 1) * height + end padding``
    or:
      ``(ascent + stroke_width) + (lines - 1) * height + (descent + stroke_width)``
    or:
      ``real_font_size + (stroke_width * 2) + (lines - 1) * height``
r  r  r  r  r(   r  )r  r  r  r  r  r0   )r
   r   r   r  r  r  r   r  r  r   r  _multiline_spacingcountrS   AttributeError)rA   r  r  r  r  r  r  r  r  r  r  r  descentreal_font_sizer  r  r   topr   r  line_heightline_breakslines_heightpaddingsr   s                            r,   __find_text_sizeTextClip.__find_text_size  sW   j iiv& ))$:H --i8H"--/)~~c"  [%%#) & E 99U#D $(#:#:% $; $
 c5&	'11(\RK**T*K&4L%q(88H01F EDL!6**  	'#&F	's   =D D+*D+c	                     Un	Sn
X:  aG  [        X-   S-  5      nU R                  UUUUUUUUS9u  pX::  a  Ub  X::  a  US-   n
OUS-
  n	X:  a  MG  U R                  UUU
UUUUUS9u  pX::  a
  Ub  X::  a  U
$ U
S-
  $ )zeFind the best font size to fit as optimally as possible
in a box of some width and optionally height
rK   r0   )r  r  )rS   r  )rA   r  r  r  r  r  r   r   r  max_font_sizemin_font_sizeavg_font_sizer  r  s                 r,   __find_optimum_font_size!TextClip.__find_optimum_font_size  s      +!>1 DEM&*&;&;' '< 	'#J "+:O - 1 - 1! +& #'"7"7# #8 	#

 FNk6K   1$$r/   )r  r   r  )NNNNNNr;  blackNNr   r  r   r   r   r  TNr  )r  r  r  r  r  r   r3   r   r   r  r  rS   r  r  r  r)   r/   r,   r  r    s    gR J' !%T) (T)l2	c2x c+ 
sCxc+Z 2%r/   r  c                   h    \ rS rSrSrSSSSSSS	S
SSS.
r\" S/5      SSSSS.S j5       rSS jrSr	g)
BitmapClipi  zAClip made of color bitmaps. Mainly designed for testing purposes.)re   r   r   )r   re   r   )r   r   re   r  )re   re   re   )Y      >   )q      l   )         )9         )r@     !   )
RGBOWr   CDEFr?   NF)rT   r?   
color_dictr=   c          	        ^^ Tc  Uc   eU(       a  UOU R                   U l        / nU Ha  n/ nU H1  n	UR                  U	 V
s/ s H  oR                  U
   PM     sn
5        M3     UR                  [        R                  " U5      5        Mc     [        R                  " U5      m[        T5      U l        Tc  U R                  U-  mOU R                  T-  n[        R                  U UU4S jUUS9  TU l	        gs  sn
f )ak  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[        U T-  5         $ r   )rS   )r+   rT   frame_arrays    r,   r-   %BitmapClip.__init__.<locals>.<lambda>  s    [QW%>r/   r  )
DEFAULT_COLOR_DICTrV  r   rg   r  r  total_framesr$   r3   rT   )rA   bitmap_framesrT   r?   rV  r=   
frame_listinput_frameoutput_framerowr  rY  s     `        @r,   r3   BitmapClip.__init__  s    n ("666(2*8O8O
(KL"##$M__U%;$MN #bhh|45	 ) hhz*,;##h.C((3.H>	 	 	
 # %Ns   C9c           	         U=(       d    U R                   n/ nU R                  5        H  nUR                  / 5        U H{  nUS   R                  S5        U H^  n[        UR	                  5       5      [        UR                  5       5      R                  [        U5      5         nUS   S==   U-  ss'   M`     M}     M     U$ )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.
r1   r  )rV  iter_framesr   r   keysvaluesrL  r  )rA   rV  bitmapr   linepixelletters          r,   	to_bitmapBitmapClip.to_bitmap  s    
  24??
%%'EMM"r
!!"%!E!*//"34Z..0177eEF 2JrNf,N	 "  ( r/   )rV  rT   r\  r   )
r  r  r  r  r  r[  r   r3   rk  r  r)   r/   r,   r>  r>    sZ    K  ":,/$(4DRWO 0Obr/   r>  )=r  r\   r[   r   r   numbersr   typingr   r   r   r   numpyrg   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$   r  r  r$  r!  r  r>  r)   r/   r,   <module>r|     s     	   7 7   *  + + B % 
 
 
 L K & * * = ?|$ |$~#
I 
D,
y ,
^Ir+	 r+j)
	 )
XL%y L%^t tr/   