o
    ߥi=                     @   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]
    torchr   )ctxg       @g      ?g        )step   
   g     o@   )decordbridge
set_bridger   r   get_avg_fpsfloatlennpcliproundarangeastypeint32listr   r   copydeepcopyappendpermute)
video_path
target_fpsvrcur_fpsintervalstart
vid_lengthdurationsampled_idxsimgsibiasimg r,   ^/home/ubuntu/.local/lib/python3.10/site-packages/modelscope/models/multi_modal/soonet/utils.pydecode_video   sD   r.   )r   )
r   r   numpyr   r   r   decord._ffi.baser   r   r.   r,   r,   r,   r-   <module>   s   