
    g                     F    d Z ddlZddlZddlmZ ddlmZ  G d de      Zy)zXImplements ImageSequenceClip, a class to create a video clip from a set
of image files.
    N)imread)	VideoClipc                   "    e Zd ZdZ	 	 	 	 	 ddZy)ImageSequenceClipa   A VideoClip made from a series of images.

    Parameters
    ----------

    sequence
      Can be one of these:

      - The name of a folder (containing only pictures). The pictures
        will be considered in alphanumerical order.
      - A list of names of image files. In this case you can choose to
        load the pictures in memory pictures
      - A list of Numpy arrays representing images. In this last case,
        masks are not supported currently.

    fps
      Number of picture frames to read per second. Instead, you can provide
      the duration of each image with durations (see below)

    durations
      List of the duration of each picture.

    with_mask
      Should the alpha layer of PNG images be considered as a mask ?

    is_mask
      Will this sequence of pictures be used as an animated mask.

    load_images
      Specify that all images should be loaded into the RAM. This is only
      interesting if you have a small number of images that will be used
      more than once.
    Nc           	      $    ||t        d      t        j                   |       d}t        |t              r6t        |d   t
              r |r|D cg c]  }t        |       }}d}nRd}nOd}nLd}t        t        j                  |      D cg c]"  }t        j                  j                  ||      $ c}      }t        |d   t
              rt        |d         j                  }	n|d   j                  }	|D ]9  }
|
}t        |
t
              rt        |
      }|	|j                  k7  s0t        d       | _        |n|D 
cg c]  }
d|z  	 }}
t        t!        |            D cg c]8  }d|z  |z  t#        j$                  t"        j&                        j(                  z
  : c} _        n'dgt	        t#        j,                  |            z    _        | _        t1        |       _         j2                   _        | _        | j2                  t!        |      z   _         fd|rd  _        d  _         fd	}|rt         j6                  d         j                  d
   dk(  rt        d       _        d  j<                  _        d  j<                  _         fd}| j<                  _         |d      j                  d d
 d d d    j<                  _         ny fd}|rq j6                  d   j                  d
   dk(  rRt        d       _         fd}| j<                  _         |d      j                  d d
 d d d    j<                  _         | _         |d      j                  d d
 d d d    _         y c c}w c c}w c c}
w c c}w )Nz+Please provide either 'fps' or 'durations'.)is_maskTr   FzBMoviePy: ImageSequenceClip requires all images to be the same size      ?c                     t        t        t        j                              D cg c]  }j                  |   | k  s| c}      S c c}w )N)maxrangelensequenceimages_starts)tiselfs     k/var/www/it7/html/youtubeDownloader/venv/lib/python3.12/site-packages/moviepy/video/io/ImageSequenceClip.pyfind_image_indexz4ImageSequenceClip.__init__.<locals>.find_image_indexs   sB    !#dmm"45Tq9K9KA9NRS9ST Ts
   A
A
c                      |       }|j                   k7  r0t        j                  |         d d d d d df   _        |_         j                  S N   )
last_indexr   r   
last_imager   indexr   r   s     r   frame_functionz2ImageSequenceClip.__init__.<locals>.frame_function|   sN    (+DOO+&,T]]5-A&B1a!8&LDO&+DO&          c                 &    |       }|j                   j                  k7  rZt        j                  |         d d d d df   }|j	                  t
              dz  j                   _        |j                   _        j                   j                  S )Nr      )maskr   r   r   astypefloatr   )r   r   framer   r   s      r   mask_frame_functionz7ImageSequenceClip.__init__.<locals>.mask_frame_function   ss    ,Q/E		 4 44 &t}}U'; <Q1W E/4||E/BS/H		,/4		,99///r   c                 J     |       }j                   |   d d d d d df   S r   r   r   s     r   r   z2ImageSequenceClip.__init__.<locals>.frame_function   s+    (+}}U+Aq"1"H55r   c                 R     |       }dj                   |   d d d d df   z  dz  S )Nr	   r   r!   r)   r   s     r   r&   z7ImageSequenceClip.__init__.<locals>.mask_frame_function   s1    ,Q/Eu!5aAg!>>DDr   )!
ValueErrorr   __init__
isinstanceliststrr   sortedoslistdirpathjoinshape	Exceptionfpsr   r   npfinfofloat32epsr   cumsum	durationssumdurationendr   r   r   r"   r   size)r   r   r7   r=   	with_maskr   load_images	fromfilesfilerA   imageimage1r   r   r&   r   s   `              @r   r,   zImageSequenceClip.__init__0   s/    Ki/JKK41 	h%(1+s+9ABtBHB %I $I "	 I:<**X:NO$h-OH
 hqk3'(1+&,,DA;$$D 	EF%%v||#X 	 ?089us9I9BGHBV"=>a# 4 8 88"D #$tBIIi,@'A!AD"I== ;}}s8}4DH	
 "DO"DO' fT]]1%56<<Q?1D%d3	'+		$'+		$0 ,?		(!4Q!7!=!=bq!A$B$!G		6 dmmA.44Q71<%d3	E ,?		(!4Q!7!=!=bq!A$B$!G		,"1%++BQ/"5	C  C P( :"s   M>'NN'=N)NNTFF)__name__
__module____qualname____doc__r,    r   r   r   r      s     J w6r   r   )	rK   r1   numpyr8   
imageio.v2r   moviepy.video.VideoClipr   r   rL   r   r   <module>rP      s&    
   -Z6	 Z6r   