o
    ϯi                     @   s\   d dl mZmZ d dlmZmZmZ d dlZd dlm	Z	 G dd de
ZG dd deZdS )	    )ABCabstractmethod)BinaryIODictOptionalN)	g_pathmgrc                   @   s$   e Zd ZdZdddZdd	d
ZdS )VideoPathHandlerzq
    Utility class that handles all deciphering and caching of video paths for
    encoded and frame videos.
    returnNc                 C   s
   i | _ d S Npath_order_cacheself r   K/home/ubuntu/.local/lib/python3.10/site-packages/pytorchvideo/data/video.py__init__   s   
zVideoPathHandler.__init__Fpyav   c           	      C   s   zt |}t |}W n ty   d}d}Y nw |r)ddlm} ||||S |r@ddlm} |r7J d|j	||| j
dS t| d)	NTFr   )EncodedVideo)
FrameVideoz0decode_audio must be False when using FrameVideor   z not found.)r   isfileisdirNotImplementedErrorpytorchvideo.data.encoded_videor   	from_pathpytorchvideo.data.frame_videor   from_directoryr   FileNotFoundError)	r   filepathdecode_audiodecoderfpsis_fileis_dirr   r   r   r   r   video_from_path   s"   
z VideoPathHandler.video_from_path)r	   N)Fr   r   )__name__
__module____qualname____doc__r   r$   r   r   r   r   r   
   s    
r   c                
   @   s~   e Zd ZdZe		ddedee deddfdd	Z	e
edefd
dZedededeeeej f fddZdd ZdS )VideozM
    Video provides an interface to access clips from a video container.
    NTfile
video_namer   r	   c                 C      dS )z
        Args:
            file (BinaryIO): a file-like object (e.g. io.BytesIO or io.StringIO) that
                contains the encoded video.
        Nr   )r   r*   r+   r   r   r   r   r   4   s   zVideo.__init__c                 C   r,   )zG
        Returns:
            duration of the video in seconds
        Nr   r   r   r   r   durationB   s   zVideo.duration	start_secend_secc                 C   r,   )a  
        Retrieves frames from the internal video at the specified start and end times
        in seconds (the video always starts at 0 seconds).

        Args:
            start_sec (float): the clip start time in seconds
            end_sec (float): the clip end time in seconds
        Returns:
            video_data_dictonary: A dictionary mapping strings to tensor of the clip's
                underlying data.

        Nr   )r   r.   r/   r   r   r   get_clipK   s   zVideo.get_clipc                 C   s   d S r
   r   r   r   r   r   close]   s   zVideo.close)NT)r%   r&   r'   r(   r   r   r   strboolr   propertyfloatr-   r   torchTensorr0   r1   r   r   r   r   r)   /   s4    r)   )abcr   r   typingr   r   r   r6   iopath.common.file_ior   objectr   r)   r   r   r   r   <module>   s   %