
    g                     N    d Z ddlmZ ddlmZ ddlmZ ddlmZ  G d de      Z	y)	zMImplements VideoFileClip, a class for video clips creation using video files.    )AudioFileClip)convert_path_to_string)FFMPEG_VideoReader)	VideoClipc                   P    e Zd ZdZ ed      	 	 	 	 	 	 	 	 	 	 	 dd       Zd Zd Zy)VideoFileClipa	  A video clip originating from a movie file. For instance:

    .. code:: python

        clip = VideoFileClip("myHolidays.mp4")
        clip.close()
        with VideoFileClip("myMaskVideo.avi") as clip2:
            pass  # Implicit close called by context manager.


    Parameters
    ----------

    filename:
      The name of the video file, as a string or a path-like object.
      It can have any extension supported by ffmpeg:
      .ogv, .mp4, .mpeg, .avi, .mov etc.

    has_mask:
      Set this to 'True' if there is a mask included in the videofile.
      Video files rarely contain masks, but some video codecs enable
      that. For instance if you have a MoviePy VideoClip with a mask you
      can save it to a videofile with a mask. (see also
      ``VideoClip.write_videofile`` for more details).

    audio:
      Set to `False` if the clip doesn't have any audio or if you do not
      wish to read the audio.

    target_resolution:
      Set to (desired_width, desired_height) to have ffmpeg resize the frames
      before returning them. This is much faster than streaming in high-res
      and then resizing. If either dimension is None, the frames are resized
      by keeping the existing aspect ratio.

    resize_algorithm:
      The algorithm used for resizing. Default: "bicubic", other popular
      options include "bilinear" and "fast_bilinear". For more information, see
      https://ffmpeg.org/ffmpeg-scaler.html

    fps_source:
      The fps value to collect from the metadata. Set by default to 'fps', but
      can be set to 'tbr', which may be helpful if you are finding that it is reading
      the incorrect fps from the file.

    pixel_format
      Optional: Pixel format for the video to read. If is not specified
      'rgb24' will be used as the default format unless ``has_mask`` is set
      as ``True``, then 'rgba' will be used.

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


    Attributes
    ----------

    filename:
      Name of the original video file.

    fps:
      Frames per second in the original file.


    Read docs for Clip() and VideoClip() for other, more generic, attributes.

    Lifetime
    --------

    Note that this creates subprocesses and locks files. If you construct one
    of these instances, you must call close() afterwards, or the subresources
    will not be cleaned up until the process ends.

    If copies are made, and close() is called on one, it may cause methods on
    the other copies to fail.
    filenameNc                     t        j                   |       |s|rdnd}t        ||||||
       _         j                  j                   _         j                  j                   _         j                  j                   _         j                  j                   _         j                  j                   _        | _	        |rV fd _
         fd}t        d|      j                   j                         _         j                   j                  _        n
 fd	 _
        |r/ j                  j                  d
   rt        ||||	       _        y y y )N)is_maskrgbargb24)decode_filepixel_formattarget_resolutionresize_algo
fps_sourcec                 R    j                   j                  |       d d d d d df   S )N   reader	get_frametselfs    g/var/www/it7/html/youtubeDownloader/venv/lib/python3.12/site-packages/moviepy/video/io/VideoFileClip.py<lambda>z(VideoFileClip.__init__.<locals>.<lambda>   s%    DKK,A,A!,DQ2A2X,N     c                 T    j                   j                  |       d d d d df   dz  S )Nr   g     o@r   r   s    r   mask_frame_functionz3VideoFileClip.__init__.<locals>.mask_frame_function   s(    {{,,Q/1a85@@r   T)r   frame_functionc                 :    j                   j                  |       S )Nr   r   s    r   r   z(VideoFileClip.__init__.<locals>.<lambda>   s    DKK,A,A!,D r   audio_found)
buffersizefpsnbytes)r   __init__r   r   durationendr$   sizerotationr	   r    with_durationmaskinfosr   audio)r   r	   r   has_maskr.   audio_buffersizer   resize_algorithm	audio_fpsaudio_nbytesr   r   r   r   s   `             r   r&   zVideoFileClip.__init__W   s$     	41 %-67L(#%/(!
 ,,;;'';;??KK$$	,, "NDA "-@mDMM* I !HHDIIM #ED T[[&&}5&+#	DJ 65r   c                 "    | j                         S )ax  Implements ``copy.deepcopy(clip)`` behaviour as ``copy.copy(clip)``.

        VideoFileClip class instances can't be deeply copied because the locked Thread
        of ``proc`` isn't pickleable. Without this override, calls to
        ``copy.deepcopy(clip)`` would raise a ``TypeError``:

        ```
        TypeError: cannot pickle '_thread.lock' object
        ```
        )__copy__)r   memos     r   __deepcopy__zVideoFileClip.__deepcopy__   s     }}r   c                     | j                   r!| j                   j                          d| _         	 | j                  r"| j                  j                          d| _        yy# t        $ r Y yw xY w)zClose the internal reader.N)r   closer.   AttributeError)r   s    r   r9   zVideoFileClip.close   s\    ;;KKDK	zz

  "!
   		s   -A 	A*)A*)FFTi@ NbicubiciD     r$   NF)__name__
__module____qualname____doc__r   r&   r7   r9    r   r   r   r   	   sP    KZ J' "= (=~r   r   N)
r@   moviepy.audio.io.AudioFileClipr   moviepy.decoratorsr   moviepy.video.io.ffmpeg_readerr   moviepy.video.VideoClipr   r   rA   r   r   <module>rF      s"    S 8 5 = -fI fr   