o
    +i                     @   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_platformimageio_ffmpegc                  C   s*   t dd} | r
| S t } | r| S td)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.
    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   H/var/www/html/venv/lib/python3.10/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r-tjt
jddd}n	tjt
jdd}|rDtj|rDt|rD|S d}t|rL|S d S )N winLibrarybinz
ffmpeg.exe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   sd   t jdk rtjdd} ntjdd }tj|} | }W d    n1 s(w   Y  t|jS )N)   	   zimageio_ffmpeg.binariesz__init__.py)	r   version_info	importlib	resourcesr   filesas_filestrparent)contextrefr   r   r   r   r   A   s   

r   Fc                 C   st   d }d }d}t jdrt }| jtjO  _| r&t jdr#d}ntj}d}t	dd
 |vr4d }|||dS )Nr   r   i   )r   0falseno IMAGEIO_FFMPEG_NO_PREVENT_SIGINTr   )startupinfocreationflags
preexec_fn)r   platformr   
subprocessSTARTUPINFOdwFlagsSTARTF_USESHOWWINDOWr   setpgrpr	   lower)prevent_sigintr.   r0   r/   falsyr   r   r   _popen_kwargsM   s"   r:   c              
   C   sx   | dg}z)t tjd}tj|f|tjdt  W d    W dS 1 s&w   Y  W dS  tttj	fy;   Y dS w )N-versionw)stdoutstderrTF)
openr   devnullr2   
check_callSTDOUTr:   OSError
ValueErrorCalledProcessError)r   cmdnullr   r   r   r   i   s"   
r   c                  C   sb   t  } tj| dgfi 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).
    r;      
r   r   ignore)errorsversion )r   r2   check_outputr:   splitdecodestriplstrip)r   linerK   r   r   r   get_ffmpeg_versionu   s   $rT   )F)loggingr   r2   r   	functoolsr   importlib.resourcesr"   _definitionsr   r   	getLoggerloggerr   r
   r   r:   r   rT   r   r   r   r   <module>   s    


