U
    h                     @   s   d dl Z d dlZd dlZd dlZd dlmZ d dlZddlm	Z	m
Z
 e dZdd Ze dd	 Zd
d ZdddZdd Zdd ZdS )    N)	lru_cache   )FNAME_PER_PLATFORMget_platformZimageio_ffmpegc                  C   s.   t dd} | r| S t } | r"| S tddS )a=  
    Get the ffmpeg executable file. This can be the binary defined by
    the IMAGEIO_FFMPEG_EXE environment variable, the binary distributed
    with imageio-ffmpeg, an ffmpeg binary installed with conda, or the
    system ffmpeg (in that order). A RuntimeError is raised if no valid
    ffmpeg could be found.
    ZIMAGEIO_FFMPEG_EXENzpNo ffmpeg exe could be found. Install ffmpeg on your system, or set the IMAGEIO_FFMPEG_EXE environment variable.)osgetenv_get_ffmpeg_exeRuntimeError)exe r   G/var/www/html/venv/lib/python3.8/site-packages/imageio_ffmpeg/_utils.pyget_ffmpeg_exe   s    
r   c                  C   s   t  } tjt t| d}|r:tj|r:t|r:|S | 	drZtjt
jddd}ntjt
jdd}|rtj|rt|r|S d}t|r|S d S )N winLibrarybinz
ffmpeg.exeZffmpeg)r   r   pathjoin_get_bin_dirr   getisfile_is_valid_exe
startswithsysprefix)platr
   r   r   r   r   '   s    
r   c               	   C   sP   t jdk rtjdd} ntjdd }tj|} | }W 5 Q R X t|jS )N)   	   zimageio_ffmpeg.binariesz__init__.py)	r   version_info	importlib	resourcesr   filesZas_filestrparent)contextrefr   r   r   r   r   A   s    

r   Fc                 C   st   d }d }d}t jdr0t }| jtjO  _| rLt jdrFd}ntj}d}t	dd
 |krhd }|||dS )Nr   r   i   )r   0falsenoZ IMAGEIO_FFMPEG_NO_PREVENT_SIGINTr   )startupinfocreationflags
preexec_fn)r   platformr   
subprocessZSTARTUPINFOZdwFlagsZSTARTF_USESHOWWINDOWr   setpgrpr   lower)Zprevent_sigintr)   r+   r*   Zfalsyr   r   r   _popen_kwargsM   s"    r0   c              
   C   sf   | dg}z:t tjd"}tj|f|tjdt  W 5 Q R X W dS  tttj	fk
r`   Y dS X d S )N-versionw)stdoutstderrTF)
openr   devnullr-   
check_callSTDOUTr0   OSError
ValueErrorCalledProcessError)r
   cmdnullr   r   r   r   i   s     r   c                  C   s^   t  } tj| dgft ddd }|jdd }|ddd  d	dd  }|S )
zF
    Get the version of the used ffmpeg executable (as a string).
    r1      
r   r   ignore)errorsversion )r   r-   check_outputr0   splitdecodestriplstrip)r
   linerA   r   r   r   get_ffmpeg_versionu   s     $rJ   )F)loggingr   r-   r   	functoolsr   importlib.resourcesr   Z_definitionsr   r   	getLoggerloggerr   r   r   r0   r   rJ   r   r   r   r   <module>   s   


