
    3j                         S SK r S SKJr  S SKJr  S SKJr  S SKJ	r	  S SK
Jr  S SKJr  S SKJr  \ R                   \ R"                   " S	 S
\5      5       5       rg)    N)libav)Packet)Stream)avrational_to_fraction)
VideoFrame)int32_t)memcpyc                   4   \ rS rSrS rS r\R                  SS\S-  4S jj5       r	\R                  SS\
S-  4S jj5       r\R                  S	 5       r\R                  S
 5       rS rSS jr\S 5       r\S 5       r\S 5       r\S 5       r\S 5       rSrg)VideoStream   c                 Z   U R                   c  SU R                   S[        U 5      S S3$ SU R                   SU R                   SU R                  (       a  U R                  R                  OS  SU R                   R
                   SU R                   R                   S[        U 5      S S3$ )Nz<av.VideoStream #z video/<nocodec> at 0xx> z, z at 0x)codec_contextindexidnameformatwidthheightselfs    I/home/wildlama/miniconda3/lib/python3.13/site-packages/av/video/stream.py__repr__VideoStream.__repr__   s    %&tzzl2HDRSTUVV

|1TYYKr#';;t{{D94;M;M;S;S:TTU!!(()4|1>	
    c                     US;   a%  [        S[        U 5      R                   SU S35      eU R                  c%  [        S[        U 5      R                   SU S35      e[	        U R                  U5      $ )N)	frameraterate'z' object has no attribute ')AttributeErrortype__name__r   getattr)r   r   s     r   __getattr__VideoStream.__getattr__   s    (( DJ''((CD6K  % DJ''((CD6K  t))400r   Nframec                     U R                   R                  U5      nU H.  nXl        U R                  R                  UR                  l        M0     U$ )z
Encode an :class:`.VideoFrame` and return a list of :class:`.Packet`.

:rtype: list[Packet]

.. seealso:: This is mostly a passthrough to :meth:`.CodecContext.encode`.
)r   encode_streamptrr   stream_index)r   r(   packetspackets       r   r*   VideoStream.encode"   sD     $$++E2F!N&*hhnnFJJ#  r   r/   c                 8    U R                   R                  U5      $ )z
Decode a :class:`.Packet` and return a list of :class:`.VideoFrame`.

:rtype: list[VideoFrame]

.. seealso:: This is a passthrough to :meth:`.CodecContext.decode`.
)r   decode)r   r/   s     r   r2   VideoStream.decode3   s     !!((00r   c                     [         R                  " U 5        U R                  b#  U R                  (       a  U R	                  5         g g g N)r   _finalize_for_outputr   _has_display_matrix_apply_display_matrixr   s    r   r6    VideoStream._finalize_for_output>   s;    ##D) )d.F.F&&( /G)r   c                    S[         R                  " [        5      -  n[        R                  " [         R
                  " U R                  R                  R                  5      [         R
                  " U R                  R                  R                  5      [        R                  US5      nU[         R                  :X  a  [        S5      e[        UR                  U R                  U5        g )N	   r   z+could not allocate display matrix side data)cythonsizeofr   libav_packet_side_data_newaddressr,   codecparcoded_side_datanb_coded_side_dataAV_PKT_DATA_DISPLAYMATRIXNULLMemoryErrorr	   data_display_matrix)r   nsds      r   r8   !VideoStream._apply_display_matrixF   s    FMM'22363N3NNN488,,<<=NN488,,??@))4
 KLLrww,,a0r   c                     Uc  SU l         gU Vs/ s H  n[        U5      PM     nn[        U5      S:w  a  [        S5      e[	        S5       H  nX4   U R
                  U'   M     SU l         gs  snf )a"  Set the display matrix written to the container as coded side data.

``matrix`` is a sequence of 9 integers in FFmpeg's ``AV_PKT_DATA_DISPLAYMATRIX``
layout, or ``None`` to clear. Must be called before the first frame is
encoded. See :meth:`set_display_rotation` for a higher-level helper.
NFr;   z+display matrix must have exactly 9 elementsT)r7   intlen
ValueErrorrangerH   )r   matrixvvalsis        r   set_display_matrixVideoStream.set_display_matrixU   sp     >',D$ &'1A't9>JKKqA&*gD  # #'  (s   A,c                     [         R                  " U R                  [        U5      * 5        [         R                  " U R                  [        U5      [        U5      5        SU l        g)a@  Set the container display matrix from a rotation and optional flips.

``degrees`` is a counter-clockwise rotation (matching the value read back
from :attr:`VideoFrame.rotation`); ``hflip`` / ``vflip`` mirror after it.
Together these express all eight EXIF orientations. Must be called before
the first frame is encoded.
TN)r>   av_display_rotation_setrH   floatav_display_matrix_flipboolr7   )r   degreeshflipvflips       r   set_display_rotation VideoStream.set_display_rotationh   sH     	##D$8$85>/J""4#7#7ed5kR#' r   c                 h    [        [        R                  " U R                  R                  5      5      $ )z
The average frame rate of this video stream.

This is calculated when the file is opened by looking at the first
few frames and averaging their rate.

:type: fractions.Fraction | None
)r   r<   r@   r,   avg_frame_rater   s    r   average_rateVideoStream.average_ratev   s"     &fnnTXX5L5L&MNNr   c                 h    [        [        R                  " U R                  R                  5      5      $ )z
The base frame rate of this stream.

This is calculated as the lowest framerate at which the timestamps of
frames can be represented accurately. See :ffmpeg:`AVStream.r_frame_rate`
for more.

:type: fractions.Fraction | None
)r   r<   r@   r,   r_frame_rater   s    r   	base_rateVideoStream.base_rate   s"     &fnnTXX5J5J&KLLr   c                     [         R                  " [        R                  U R                  [        R                  5      n[        [        R                  " U5      5      $ )zThe guessed frame rate of this stream.

This is a wrapper around :ffmpeg:`av_guess_frame_rate`, and uses multiple
heuristics to decide what is "the" frame rate.

:type: fractions.Fraction | None
)r>   av_guess_frame_rater<   rE   r,   r   r@   )r   vals     r   guessed_rateVideoStream.guessed_rate   s=     "55KK6;;
 &fnnS&9::r   c                     [         R                  " U R                  R                  U R                  [        R
                  5      n[        [        R                  " U5      5      $ )zThe guessed sample aspect ratio (SAR) of this stream.

This is a wrapper around :ffmpeg:`av_guess_sample_aspect_ratio`, and uses multiple
heuristics to decide what is "the" sample aspect ratio.

:type: fractions.Fraction | None
)r>   av_guess_sample_aspect_ratio	containerr,   r<   rE   r   r@   )r   sars     r   sample_aspect_ratioVideoStream.sample_aspect_ratio   sC     ">>NN&++
 &fnnS&9::r   c                    [         R                  " [        R                  5      n[        R                  " [         R
                  " UR                  5      [         R
                  " UR                  5      U R                  R                  U R                  R                  -  U R                  R                  U R                  R                  -  S5        [        [         R
                  " U5      5      $ )zThe guessed display aspect ratio (DAR) of this stream.

This is calculated from :meth:`.VideoStream.guessed_sample_aspect_ratio`.

:type: fractions.Fraction | None
i   )r<   declarer>   
AVRational	av_reducer@   numdenr   r   rr   r   r   )r   dars     r   display_aspect_ratio VideoStream.display_aspect_ratio   s     nnS^^,NN377#NN377#KK 8 8 < <<KK!9!9!=!==	
 &fnnS&9::r   )r7   r5   )FF)r$   
__module____qualname____firstlineno__r   r&   r<   ccallr   r*   r   r2   cfuncr6   r8   rU   r_   propertyrc   rg   rl   rr   r{   __static_attributes__ r   r   r   r      s    
	1 \\J-    \\1Vd] 1 1 \\) ) \\1 1(&( 	O 	O 
M 
M ; ; ; ; ; ;r   r   )r<   cython.cimportsr   r>   cython.cimports.av.packetr   cython.cimports.av.streamr   cython.cimports.av.utilsr   cython.cimports.av.video.framer   cython.cimports.libc.stdintr   cython.cimports.libc.stringr	   finalcclassr   r   r   r   <module>r      sK     ( , , ; 5 / . o;& o;  o;r   