
    i"                         d dl Z d dl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 d dlmZ 	 d dlZdZee	 	 	 dd              Zee	 	 	 dd	              Z	 	 dd
Zy# e$ r dZY 2w xY w)    N)DEVNULL)get_setting)requires_durationuse_clip_fps_by_default)subprocess_callTFc                    t        j                  |
      }
t        j                  j	                  |      \  }}t        j                  d| j                  d|z        }g } |
d|z          |
d       |
j                  t        t        |                  D ]4  \  }}d||dz   fz  }|j                  |       | j                  ||d	
       6 t        d|z        }|dk(  rK |
d       t        d      dd|z  dd|rdndz  dd|z  d|z  ddd|z  dz   dd|z  g|	dd|	z  gng z   |gz   }n0|dk(  r+t        d      dd d!d"t        |      d#|d$z   d"t        |      |g}	 t!        |
%        |
d&|z         |D ]  }t        j&                  |        y# t"        t$        f$ r,}d'|d(t        |      d)}|dk(  r|d*z   }t#        |      d}~ww xY w)+a*   Write the VideoClip to a GIF file.


    Converts a VideoClip into an animated GIF using ImageMagick
    or ffmpeg. Does the same as write_gif (see this one for more
    docstring), but writes every frame to a file instead of passing
    them in the RAM. Useful on computers with little RAM.

    r         ?zMoviePy - Building file %s
messagez!MoviePy - - Generating GIF frames)tz%s_GIFTEMP%04d.png   T)withmask      Y@ImageMagickz.MoviePy - - Optimizing GIF with ImageMagick...IMAGEMAGICK_BINARY-delay%d-dispose   -loopz%s_GIFTEMP*.png	-coalesce-fuzzz%02d%-layersz%sN-colorsffmpegFFMPEG_BINARY-y-fimage2-r-iz_GIFTEMP%04d.png)loggerzMoviePy - GIF ready: %s.zMoviePy Error: creation of ) failed because of the following error:

.

.zThis error can be due to the fact that ImageMagick is not installed on your computer, or (for Windows users) that you didn't specify the path to the ImageMagick binary in file config_defaults.py.)proglogdefault_bar_loggerospathsplitextnparangedurationiter_barlist	enumerateappend
save_frameintr   strr   IOErrorOSErrorremove)clipfilenamefpsprogramoptfuzzverboseloopdisposecolorsr#   fileNameexttt	tempfilesir   namedelaycmderrerrorfs                          Z/var/www/html/eduruby.in/venv/lib/python3.12/site-packages/moviepy/video/io/gif_writers.pywrite_gif_with_tempfilesrN      s#    ''/FGG$$X.MHc	1T]]CG	,BI
1H<=
67 $y}"56 01#XqsO3a$/	0 c	NE-GH/0e$W!4T	(vd{S(c .4-?)T&[)RI J	 
H	?+TXtCHX00CH	F+1H<=  
		! G  2:3s8E m# M OE
 ens   F G"'G		Gc                    d|z  }t        j                  |      }| j                  d}t        d      ddddd	d
d	dd|z  dd| j                  | j
                  fz  d|rdndddg}t        t        t        d}t        j                  dk(  rd|d<   |dk(  rBt        j                  |d<   t        |d<   t        j                  |d|rdnddd|z  |gz   fi |}nAt        j                  |d<   t        j                  |d<   t        j                  |g dz   fi |}|dk(  rt        d      dd|z  dd |	rd!nd"z  d#d |z  dd$g	}|d%v r3|j                  |d<   t        |d<   t        j                  ||gz   fi |}n<|j                  |d<   t        j                  |d<   t        j                  |d&gz   fi |}|rUt        d      dd'd |z  d(z   d)|g|
d*d |
z  gng z   |gz   }|j                  |d<   t        |d<   t        j                  |fi |} |d+|z  ,        |d-,       	 | j                  ||d.d/0      D ]t  \  }}|rDd1| j                  j                  |      z  }t        j                   ||g      j#                  d/      }|j$                  j'                  |j)                                v 	 |dk(  r	 |d6,       |j$                  j/                          |j1                          |dk(  r"j1                          |rj1                           |d7|z  ,       y# t*        $ r,}d2|d3t-        |      d4}|dk(  r|d5z   }t+        |      d}~ww xY w)8aC   Write the VideoClip to a GIF file, without temporary files.

    Converts a VideoClip into an animated GIF using ImageMagick
    or ffmpeg.


    Parameters
    -----------

    filename
      Name of the resulting gif file.

    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).

    program
      Software to use for the conversion, either 'ImageMagick' or
      'ffmpeg'.

    opt
      (ImageMagick only) optimalization to apply, either
      'optimizeplus' or 'OptimizeTransparency'.

    fuzz
      (ImageMagick only) Compresses the GIF by considering that
      the colors that are less than fuzz% different are in fact
      the same.


    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 ::

        >>> # slow down clip 50% and make it a gif
        >>> myClip.speedx(0.5).write_gif('myClip.gif')

    r   NFr   r   z	-loglevelrK   r   rawvideo-vcodecr!   z%.02fz-sz%dx%dz-pix_fmtrgbargb24r"   -)stdoutstderrstdinnti   creationflagsr   rW   rU   )r   
image2piperQ   bmprT   r   r   r   r   r   r   r   r   r   )FNzgif:-r   r   r   r   zMoviePy - Building file  %sr
   z"MoviePy - - Generating GIF frames.Tuint8)r:   r#   
with_timesdtype   z[MoviePy] Error: creation of r$   r%   zThis can be due to the fact that ImageMagick is not installed on your computer, or (for Windows users) that you didn't specify the path to the ImageMagick binary in file config_defaults.py.z,MoviePy - - Optimizing GIF with ImageMagick.zMoviePy - - File ready: %s.)r&   r'   maskr   whr   r(   rG   spPIPEPopenrU   iter_frames	get_framer+   dstackastyperW   writetostringr5   r4   closewait)r8   r9   r:   r;   r<   r=   r>   r   r?   r@   rA   r#   rH   cmd1popen_paramsproc1cmd2proc2cmd3proc3r   framer`   rJ   rK   s                            rM   	write_gifrv   ^   s   | 9E''/Fyy($W*j$'466466**8#D &%$&L 
ww$(2_%( "W!(X
xVW $gck8= = N@LN !#W!#XJJ )') -018We_Dw!A6dC6 = $)LLL!%,L"HHT8*_==E %*LLL!%'WWL"HHT7)^<|<E 45sT$Ys]Is282Dy$v+."N OD
 %*LLL!%,L"HHT2\2E 08;<
78''C37 ( I 	0GAeTYY0033		5$-077@KKenn./	0& -EF	KK	JJL-

JJL
08;<)   2:3s8E m# M OE
 ens   BL 	M
'MM
c                 ,   |d}t        j                  |      }t        st        d      || j                  }|dk7  rdnd}t        j                  |d|z  |||      }	 |d|z  	       | j                  ||d
      D ]  }
|	j                  |
        y)zt
    Writes the gif with the Python library ImageIO (calls FreeImage).

    Parameters
    -----------
    opt

    N   zVWriting a gif with imageio requires ImageIO installed, with e.g. 'pip install imageio'r   nqr	   )r-   	quantizerpalettesizer?   z(MoviePy - Building file %s with imageio.r
   r\   )r:   r#   r^   )	r&   r'   IMAGEIO_FOUNDImportErrorr:   imageiosaverf   append_data)r8   r9   r:   r<   r?   rA   r>   r#   rz   writerru   s              rM   write_gif_with_image_ior      s     ~''/F < = 	= {hhAX4I\\S
F =HI!!c&!H "5!"    )	Nr   OptimizeTransparencyr   Tr   TNbar)
Nr   r   r   TTr   TNr   )Nr   r   NTr   )r(   
subprocessrc   numpyr+   r&   moviepy.compatr   moviepy.configr   moviepy.decoratorsr   r   moviepy.toolsr   r~   r|   r}   rN   rv   r    r   rM   <module>r      s    	    " & I )M
 @M3716E  ER 1>FJ5:W=  W=t CD>C#"W  Ms   A A%$A%