
    h/Q              %          S SK r S SKrS SKJr  S SKJrJr  S SKrSSKJ	r	  SSK
Jr   \	" S5        S	r\r\" S S5      r " S S5      r " S S5      rS\\\4   SS4S jrS\R,                  S\R,                  S\R,                  S\R,                  S\R,                  S\R,                  S\4S jrS\R,                  S\R,                  S\\\4   S\R,                  4S jrSS	S S S S S\S	S S S\4S\S \S!\S"\S#\S$\S%\S&\\\4   S'\S(\S)\S*\S\\\4   S+\S\\R,                  \R,                  \4   4S, jjrS\S\\\   \\   \4   4S- jrS\S\4S. jr               S<S/\R,                  S \S!\S"\S#\S$\S%\S&\\\4   S0\S1\S(\S)\S*\S\\\4   S2\S3\S\\R,                  \R,                  4   4"S4 jjr S/\R,                  S\\\   \\   \4   4S5 jr!S/\R,                  S\4S6 jr"   S=S\S7\\\4   S8\\\\4      S9\S\\R,                  \R,                  \#\\4   4   4
S: jjr$ S>S\S9\S\\\\   \\   4   \\   4   4S; jjr%g! \\4 a    S
r GN&f = f)?    N)Fraction)OptionalUnion   )_load_library   ) _raise_video_deprecation_warningvideo_readerTFc                   <    \ rS rSr\\S.rSS/rS\S\SS4S jrSrg)	Timebase   	numeratordenominatorr   r   returnNc                     Xl         X l        g )Nr   )selfr   r   s      Q/var/www/auris/envauris/lib/python3.13/site-packages/torchvision/io/_video_opt.py__init__Timebase.__init__   s    
 #&    )r   r   )	__name__
__module____qualname____firstlineno__int__annotations__	__slots__r   __static_attributes__ r   r   r   r      s7    $'<Om,I'' ' 
	'r   r   c            	       <    \ rS rSr\\\\\\\\S.r/ SQrSS jr	Sr
g)VideoMetaData%   )	has_videovideo_timebasevideo_duration	video_fps	has_audioaudio_timebaseaudio_durationaudio_sample_rateNc                     SU l         [        SS5      U l        SU l        SU l        SU l        [        SS5      U l        SU l        SU l        g )NFr   r   g        )	r$   r   r%   r&   r'   r(   r)   r*   r+   )r   s    r   r   VideoMetaData.__init__;   sK    &q!n!&q!n!!$r   )r*   r+   r)   r(   r$   r&   r'   r%   )r   N)r   r   r   r   boolr   floatr   r   r   r   r    r   r   r"   r"   %   s-    """	O	I%r   r"   	pts_ranger   c                 ^    U S   U S   s=:  a  S:  a  O  g [        SU S    SU S    35      eg )Nr   r   z=Start pts should not be smaller than end pts, got start pts: z and end pts: )
ValueError)r0   s    r   _validate_ptsr3   F   sG    |il&Q&KIVWL>Yghqrshtguv
 	
 'r   	vtimebasevfps	vduration	atimebaseasample_rate	adurationc                    [        5       nU R                  5       S:  a  [        [        U S   R	                  5       5      [        U S   R	                  5       5      5      Ul        U S   R	                  5       [        U S   R	                  5       5      -  nUR                  5       S:  a(  SUl        [        UR	                  5       5      U-  Ul        UR                  5       S:  a  [        UR	                  5       5      Ul	        UR                  5       S:  a  [        [        US   R	                  5       5      [        US   R	                  5       5      5      Ul
        US   R	                  5       [        US   R	                  5       5      -  nUR                  5       S:  a(  SUl        [        UR	                  5       5      U-  Ul        UR                  5       S:  a  [        UR	                  5       5      Ul        U$ )z=
Build update VideoMetaData struct with info about the video
r   r   T)r"   numelr   r   itemr%   r/   r$   r&   r'   r)   r(   r*   r+   )r4   r5   r6   r7   r8   r9   metatimebases           r   
_fill_infor?   N   s    ?D1&s9Q<+<+<+>'?Yq\EVEVEXAYZQ<$$&y|/@/@/B)CC??q !DN"'	(8"9H"DDzz|atyy{+1&s9Q<+<+<+>'?Yq\EVEVEXAYZQ<$$&y|/@/@/B)CC??q !DN"'	(8"9H"DDa!&|'8'8':!;Kr   aframes
aframe_ptsaudio_pts_rangec                    US   US   pCU R                  S5      n[        XC-
  S-   5      [        U5      -  nSnUnX2S   :  a  [        US   U-
  U-  5      nUS   S:w  a  XBS   :  a  [        US   U-
  U-  5      nXU2S S 24   $ )Nr   r   )sizer/   r   )	r@   rA   rB   startendnum_samplesstep_per_aframes_idxe_idxs	            r   _align_audio_framesrL   n   s     A
23,,q/KCK!O,u[/AAOEEq!!_Q'%/?BCqRC!*<$<_Q'#-@A;>""r         ?r   rD   filenameseek_frame_marginread_video_streamvideo_widthvideo_heightvideo_min_dimensionvideo_max_dimensionvideo_pts_ranger%   read_audio_streamaudio_samplesaudio_channelsr)   c                    [        5         [        U5        [        U5        [        R                  R                  R                  U USUUUUUUS   US   UR                  UR                  U	U
UUS   US   UR                  UR                  5      nUu
  nnnnnnnnnn[        UUUUUU5      nUR                  5       S:  a  [        UUU5      nUUU4$ )a  
Reads a video from a file, returning both the video frames and the audio frames

Args:
filename (str): path to the video file
seek_frame_margin (double, optional): seeking frame in the stream is imprecise. Thus,
    when video_start_pts is specified, we seek the pts earlier by seek_frame_margin seconds
read_video_stream (int, optional): whether read video stream. If yes, set to 1. Otherwise, 0
video_width/video_height/video_min_dimension/video_max_dimension (int): together decide
    the size of decoded frames:

        - When video_width = 0, video_height = 0, video_min_dimension = 0,
            and video_max_dimension = 0, keep the original frame resolution
        - When video_width = 0, video_height = 0, video_min_dimension != 0,
            and video_max_dimension = 0, keep the aspect ratio and resize the
            frame so that shorter edge size is video_min_dimension
        - When video_width = 0, video_height = 0, video_min_dimension = 0,
            and video_max_dimension != 0, keep the aspect ratio and resize
            the frame so that longer edge size is video_max_dimension
        - When video_width = 0, video_height = 0, video_min_dimension != 0,
            and video_max_dimension != 0, resize the frame so that shorter
            edge size is video_min_dimension, and longer edge size is
            video_max_dimension. The aspect ratio may not be preserved
        - When video_width = 0, video_height != 0, video_min_dimension = 0,
            and video_max_dimension = 0, keep the aspect ratio and resize
            the frame so that frame video_height is $video_height
        - When video_width != 0, video_height == 0, video_min_dimension = 0,
            and video_max_dimension = 0, keep the aspect ratio and resize
            the frame so that frame video_width is $video_width
        - When video_width != 0, video_height != 0, video_min_dimension = 0,
            and video_max_dimension = 0, resize the frame so that frame
            video_width and  video_height are set to $video_width and
            $video_height, respectively
video_pts_range (list(int), optional): the start and end presentation timestamp of video stream
video_timebase (Fraction, optional): a Fraction rational number which denotes timebase in video stream
read_audio_stream (int, optional): whether read audio stream. If yes, set to 1. Otherwise, 0
audio_samples (int, optional): audio sampling rate
audio_channels (int optional): audio channels
audio_pts_range (list(int), optional): the start and end presentation timestamp of audio stream
audio_timebase (Fraction, optional): a Fraction rational number which denotes time base in audio stream

Returns
    vframes (Tensor[T, H, W, C]): the `T` video frames
    aframes (Tensor[L, K]): the audio frames, where `L` is the number of points and
        `K` is the number of audio_channels
    info (Dict): metadata for the video and audio. Can contain the fields video_fps (float)
        and audio_fps (int)
r   r   )r	   r3   torchopsr
   read_video_from_filer   r   r?   r;   rL   )rO   rP   rQ   rR   rS   rT   rU   rV   r%   rW   rX   rY   rB   r)   resultvframes_vframe_ptsr4   r5   r6   r@   rA   r7   r8   r9   infos                             r   _read_video_from_filerb   }   s    @ %&/"/"YY##88	  ""  ""'F* qwmG[)T9gz9Vbdmiy)\9UD}}%gz?KGT!!r   c                 "   [         R                  R                  R                  U SSSSSSSSSSSSSSSSSS5      nUu
  p#pEpgpp[	        XEXiX5      nUR                  5       R                  5       nUR                  5       R                  5       nX8U4$ )z
Decode all video- and audio frames in the video. Only pts
(presentation timestamp) is returned. The actual frame pixel data is not
copied. Thus, it is much faster than read_video(...)
r   r   rD   )r[   r\   r
   r]   r?   numpytolist)rO   r^   _vframes
vframe_ptsr4   r5   r6   _aframesrA   r7   r8   r9   ra   s                r    _read_video_timestamps_from_fileri      s     YY##88								
						
		'F* rxnH)9
Wciy\UD!!#**,J!!#**,J4''r   c                     [        5         [        R                  R                  R	                  U 5      nUu  p#pEpg[        X#XEXg5      nU$ )zG
Probe a video file and return VideoMetaData with info about the video
)r	   r[   r\   r
   probe_video_from_filer?   )	rO   r^   r4   r5   r6   r7   r8   r9   ra   s	            r   _probe_video_from_filerl     sC     %&YY##99(CFEKBIY<iy\UDKr   
video_datavideo_timebase_numeratorvideo_timebase_denominatoraudio_timebase_numeratoraudio_timebase_denominatorc                 @   [        5         [        U5        [        U5        [        U [        R                  5      (       dV  [
        R                  " 5          [
        R                  " SSS9  [        R                  " U [        R                  S9n SSS5        [        R                  R                  R                  U USUUUUUUS   US   UU	U
UUUS   US   UU5      nUu
  nnnnnnnnnnUR                  5       S:  a  [        UUU5      nUU4$ ! , (       d  f       N= f)a  
Reads a video from memory, returning both the video frames as the audio frames
This function is torchscriptable.

Args:
video_data (data type could be 1) torch.Tensor, dtype=torch.int8 or 2) python bytes):
    compressed video content stored in either 1) torch.Tensor 2) python bytes
seek_frame_margin (double, optional): seeking frame in the stream is imprecise.
    Thus, when video_start_pts is specified, we seek the pts earlier by seek_frame_margin seconds
read_video_stream (int, optional): whether read video stream. If yes, set to 1. Otherwise, 0
video_width/video_height/video_min_dimension/video_max_dimension (int): together decide
    the size of decoded frames:

        - When video_width = 0, video_height = 0, video_min_dimension = 0,
            and video_max_dimension = 0, keep the original frame resolution
        - When video_width = 0, video_height = 0, video_min_dimension != 0,
            and video_max_dimension = 0, keep the aspect ratio and resize the
            frame so that shorter edge size is video_min_dimension
        - When video_width = 0, video_height = 0, video_min_dimension = 0,
            and video_max_dimension != 0, keep the aspect ratio and resize
            the frame so that longer edge size is video_max_dimension
        - When video_width = 0, video_height = 0, video_min_dimension != 0,
            and video_max_dimension != 0, resize the frame so that shorter
            edge size is video_min_dimension, and longer edge size is
            video_max_dimension. The aspect ratio may not be preserved
        - When video_width = 0, video_height != 0, video_min_dimension = 0,
            and video_max_dimension = 0, keep the aspect ratio and resize
            the frame so that frame video_height is $video_height
        - When video_width != 0, video_height == 0, video_min_dimension = 0,
            and video_max_dimension = 0, keep the aspect ratio and resize
            the frame so that frame video_width is $video_width
        - When video_width != 0, video_height != 0, video_min_dimension = 0,
            and video_max_dimension = 0, resize the frame so that frame
            video_width and  video_height are set to $video_width and
            $video_height, respectively
video_pts_range (list(int), optional): the start and end presentation timestamp of video stream
video_timebase_numerator / video_timebase_denominator (float, optional): a rational
    number which denotes timebase in video stream
read_audio_stream (int, optional): whether read audio stream. If yes, set to 1. Otherwise, 0
audio_samples (int, optional): audio sampling rate
audio_channels (int optional): audio audio_channels
audio_pts_range (list(int), optional): the start and end presentation timestamp of audio stream
audio_timebase_numerator / audio_timebase_denominator (float, optional):
    a rational number which denotes time base in audio stream

Returns:
    vframes (Tensor[T, H, W, C]): the `T` video frames
    aframes (Tensor[L, K]): the audio frames, where `L` is the number of points and
        `K` is the number of channels
ignore The given buffer is not writablemessagedtypeNr   r   )r	   r3   
isinstancer[   Tensorwarningscatch_warningsfilterwarnings
frombufferuint8r\   r
   read_video_from_memoryr;   rL   )rm   rP   rQ   rR   rS   rT   rU   rV   rn   ro   rW   rX   rY   rB   rp   rq   r^   r_   r`   r4   r5   r6   r@   rA   r7   r8   r9   s                              r   _read_video_from_memoryr     s   J %&/"/"j%,,//$$&##H6XY))*EKKHJ '
 YY##::	 " "'F, qwmG[)T9gz9Vbdm}}%gz?KGC '&s   9D
Dc                 B   [        U [        R                  5      (       dV  [        R                  " 5          [        R
                  " SSS9  [        R                  " U [        R                  S9n SSS5        [        R                  R                  R                  U SSSSSSSSSSSSSSSSSS5      n[        5         Uu
  p#pEpgpp[        XEXiX5      nUR                  5       R                  5       nUR                  5       R                  5       nX8U4$ ! , (       d  f       N= f)	z
Decode all frames in the video. Only pts (presentation timestamp) is returned.
The actual frame pixel data is not copied. Thus, read_video_timestamps(...)
is much faster than read_video(...)
rs   rt   ru   rw   Nr   r   rD   )ry   r[   rz   r{   r|   r}   r~   r   r\   r
   r   r	   r?   rd   re   )rm   r^   rf   rg   r4   r5   r6   rh   rA   r7   r8   r9   ra   s                r   "_read_video_timestamps_from_memoryr   z  s    j%,,//$$&##H6XY))*EKKHJ ' YY##::								
						
		'F* %&qwnH)9
Wciy\UD!!#**,J!!#**,J4''? '&s   9D
Dc                    [        5         [        U [        R                  5      (       dV  [        R
                  " 5          [        R                  " SSS9  [        R                  " U [        R                  S9n SSS5        [        R                  R                  R                  U 5      nUu  p#pEpg[        X#XEXg5      nU$ ! , (       d  f       NL= f)zm
Probe a video in memory and return VideoMetaData with info about the video
This function is torchscriptable
rs   rt   ru   rw   N)r	   ry   r[   rz   r{   r|   r}   r~   r   r\   r
   probe_video_from_memoryr?   )	rm   r^   r4   r5   r6   r7   r8   r9   ra   s	            r   _probe_video_from_memoryr     s     %&j%,,//$$&##H6XY))*EKKHJ ' YY##;;JGFEKBIY<iy\UDK '&s   9B>>
C	start_ptsend_ptspts_unitc           
      z  ^^^ [        5         Tc  [        S5      mTS:X  a  [        R                  " S5        [	        U 5      nUR
                  nUR                  nUUU4S jnSn[        n	U(       a<  [        UR                  R                  UR                  R                  5      n	U" U	5      nSn
[        nU(       a<  [        UR                  R                  UR                  R                  5      nU" U5      n
[        U SUU	SU
US9u  pn0 nU(       a  UR                  US'   U(       a  UR                  US	'   XU4$ )
NinfptsmThe pts_unit 'pts' gives wrong results and will be removed in a follow-up version. Please use pts_unit 'sec'.c                    > TnTnTS:X  aY  [        [        R                  " TSU -  -  5      5      nU[        S5      :w  a%  [        [        R                  " TSU -  -  5      5      nU[        S5      :X  a  SnX4$ )Nsecr   r   rD   )r   mathfloorr/   ceil)	time_basestart_offset
end_offsetr   r   r   s      r   get_pts_read_video.<locals>.get_pts  ss     
utzz)q9}*EFGLU5\) 7a)m+D!EF
u%J''r   rN   T)rQ   rV   r%   rW   rB   r)   r'   	audio_fps)r	   r/   r{   warnrl   r$   r(   default_timebaser   r%   r   r   r)   rb   r'   r+   )rO   r   r   r   ra   r$   r(   r   rV   r%   rB   r)   r_   r@   _infos    ```           r   _read_videor     s'    %&,5>	

 "(+DII	( O%N!$"5"5"?"?ATATA`A`a!.1O%N!$"5"5"?"?ATATA`A`a!.12'%'%Gd E!^^k!33kU""r   c                 T   [        5         US:X  a  [        R                  " S5        [        U 5      u  p#nUS:X  aH  [	        UR
                  R                  UR
                  R                  5      nU Vs/ s H  ofU-  PM	     nnUR                  (       a  UR                  OS nX'4$ s  snf )Nr   r   r   )
r	   r{   r   ri   r   r%   r   r   r$   r'   )rO   r   r   _ra   video_time_basexr'   s           r   _read_video_timestampsr     s     %&5>	
 4H=LCD5"4#6#6#@#@$BUBUBaBab,/0Cq?"C0"&..dI>	 1s   3B%)rM   r   r   r   r   r   rN   r   r   r   r   r   rN   r   r   )r   Nr   )r   )&r   r{   	fractionsr   typingr   r   r[   	extensionr   _video_deprecation_warningr	   _HAS_CPU_VIDEO_DECODERImportErrorOSError_HAS_VIDEO_OPTr   r   r"   tupler   r3   rz   r?   rL   strr/   r.   rb   listri   rl   r   r   r   dictr   r   r    r   r   <module>r      sg      "  % H#.!! (Aq> 

' 
'% %B
U38_ 
 
||
,, || ||	
 ,, || @#\\#',||#FKCQTHo#
\\#"  $"  './"'./^"^"^" ^" 	^"
 ^" ^" ^" 38_^" ^" ^" ^" ^" 38_^" ^" 5<<}45^"B (s  (uT#YS	S`=`7a  (FS ]   $  '.$%&''.$%&'!kkk k 	k
 k k k 38_k "k !$k k k k 38_k "k  !$!k" 5<<%&#k\((((
49d3i./((V* )*04	;#;#UH_%;# eE8O,-;# 	;#
 5<<tCJ'778;#~ $) 
5cDN*+Xe_<=O 	W #"#s   
I 
II