o
    *j=                     @   sN   d dl Z d dlZd dlZd dlmZmZ d dlmZ d dlmZ dddZ	dS )	    N)VideoReadercpu)DECORDError)tqdm   c              	   C   s0  t jd t| tdd}| }||kr%t|t| }t|d }nd}d}t|}|| }t	t
tj|t||dd|d tj}t }	t|D ]C}
d}|d	krrz||
|  }W n tym   |d7 }Y nw |d	ksX|d	krt|	d
 }|	| qP|d }|ddd}|	| qP|	|fS )aF  
        Decode video from 'video_path' and return the sampled frames based on target_fps.
        The default value of target_fps is 5.

        Args:
            video_path: the absolute path of video.
            target_fps: the number of sampled video frames per second.

        Returns:
            [imgs, duration]
    Ztorchr   )ctxg       @g      ?g        )step   
   g     o@   )decordZbridgeZ
set_bridger   r   Zget_avg_fpsfloatlennpZcliproundZarangeZastypeZint32listr   r   copydeepcopyappendZpermute)Z
video_pathZ
target_fpsZvrZcur_fpsintervalstartZ
vid_lengthdurationZsampled_idxsZimgsiZbiasZimg r   k/var/www/html/Deteccion_Ine/venv/lib/python3.10/site-packages/modelscope/models/multi_modal/soonet/utils.pydecode_video   sD   r   )r   )
r   r   numpyr   r   r   Zdecord._ffi.baser   r   r   r   r   r   r   <module>   s   