U
    a+d	                     @   sh   d 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dZ	dd	d
Z
dddZdddZdd ZdS )z* Misc. bindings to ffmpeg and ImageMagick.    N)get_setting)subprocess_call   vc                 C   s\   dd|  d }t dddddd	| d
tj||d | dd| dd	| | g}t| dS )z^
    Writes a movie out of the frames (picture files) in a folder.
    Almost deprecated.
    %z%02dzd.pngFFMPEG_BINARY-yz-fZimage2z-r%d-i/z-b%dkN)r   ospathjoinr   )filenamefolderfpsdigitsbitratescmd r   A/tmp/pip-unpacked-wheel-0yp4gafk/moviepy/video/io/ffmpeg_tools.pyffmpeg_movie_from_frames   s        r   c           	      C   sx   t j| \}}|s:dd ||fD \}}d||||f }tdddd| d| d	d||  d
ddddd|g}t| dS )ze Makes a new video file playing video file ``filename`` between
        the times ``t1`` and ``t2``. c                 S   s   g | ]}t d | qS )i  )int).0tr   r   r   
<listcomp>    s     z*ffmpeg_extract_subclip.<locals>.<listcomp>z%sSUB%d_%d.%sr   r   z-ssz%0.2fr
   z-tz-map0-vcodeccopy-acodecN)r   r   splitextr   r   )	r   t1t2Z
targetnamenameextZT1ZT2r   r   r   r   ffmpeg_extract_subclip   s(       
      r'   r    Fbarc                 C   s.   t ddd|d| d|d||g}t||d dS )z^ merges video file ``video`` and audio file ``audio`` into one
        movie file ``output``. r   r   r
   r   r!   )loggerNr   r   )videoaudiooutputZvcodecZacodecZffmpeg_outputr)   r   r   r   r   ffmpeg_merge_video_audio,   s        r.     D  c              	   C   s.   t ddd| dd| dd| |g	}t| dS )	z? extract the sound from a video file and save it in ``output`` r   r   r
   z-abr   z-arr	   Nr*   )Z	inputfiler-   r   r   r   r   r   r   ffmpeg_extract_audio7   s      r1   c                 C   s0   t dd| dd|d |d f |g}t| dS )zY resizes ``video`` to new size ``size`` and write the result
        in file ``output``. r   r
   z-vfzscale=%d:%dr      Nr*   )r+   r-   sizer   r   r   r   ffmpeg_resize>   s    r4   )r   r   )N)r    r    Fr(   )r/   r0   )__doc__r   
subprocessspsysZmoviepy.configr   Zmoviepy.toolsr   r   r'   r.   r1   r4   r   r   r   r   <module>   s   

     

