
    \j                         d dl mZ d dlZd dlmZ d dlmZ d dlm	Z	  G d de      Z
ej                  ej                   G d d	e                    Zej                  ej                   G d
 d                    Zy)    )IntEnumN)libav)SideData)uint8_tc                   l    e Zd Zej                  Zej                  Zej                  Z	ej                  Zy)VideoEncParamsTypeN)__name__
__module____qualname__libAV_VIDEO_ENC_PARAMS_NONENONEAV_VIDEO_ENC_PARAMS_VP9VP9AV_VIDEO_ENC_PARAMS_H264H264AV_VIDEO_ENC_PARAMS_MPEG2MPEG2     H/root/.hermes/venv/lib/python3.12/site-packages/av/sidedata/encparams.pyr   r   	   s.    ''D

%
%C''D))Er   r   c                   ~    e Zd Zd Zed        Zed        Zed        Zed        Zed        Z	ed        Z
d Zd	 Zy
)VideoEncParamsc                 V    d| j                    d| j                   d| j                   dS )Nz'<av.sidedata.VideoEncParams, nb_blocks=z, codec_type=z, qp=>)	nb_blocks
codec_typeqpselfs    r   __repr__zVideoEncParams.__repr__   s4    88HVZVeVeUffklplslskttuvvr   c                     t        j                  t         j                  t        j                     | j
                  j                        j                  S )z
        Number of blocks in the array
        May be 0, in which case no per-block information is present. In this case
        the values of blocks_offset / block_size are unspecified and should not
        be accessed.
        )cythoncastpointerr   AVVideoEncParamsptrdatar   r   s    r   r   zVideoEncParams.nb_blocks   s6     {{NN3//0$((--

)	r   c                     t        j                  t         j                  t        j                     | j
                  j                        j                  S )zk
        Offset in bytes from the beginning of this structure at which the array of blocks starts.
        )r#   r$   r%   r   r&   r'   r(   blocks_offsetr   s    r   r*   zVideoEncParams.blocks_offset"   s6    
 {{NN3//0$((--

-	r   c                     t        j                  t         j                  t        j                     | j
                  j                        j                  S )zX
        Size of each block in bytes. May not match sizeof(AVVideoBlockParams).
        )r#   r$   r%   r   r&   r'   r(   
block_sizer   s    r   r,   zVideoEncParams.block_size+   s6    
 {{NN3//0$((--

*	r   c                    t        j                  t         j                  t        j                     | j
                  j                        j                  }t        t        j                  t         j                  |            S )zH
        Type of the parameters (the codec they are used with).
        )
r#   r$   r%   r   r&   r'   r(   typer   int)r    ts     r   r   zVideoEncParams.codec_type4   sR    
 '-kkNN3//0$((--'

$ 	
 "&++fjj!"<==r   c                     t        j                  t         j                  t        j                     | j
                  j                        j                  S )a  
        Base quantisation parameter for the frame. The final quantiser for a
        given block in a given plane is obtained from this value, possibly
        combined with `delta_qp` and the per-block delta in a manner
        documented for each type.
        )r#   r$   r%   r   r&   r'   r(   r   r   s    r   r   zVideoEncParams.qp>   s2     {{6>>#*>*>?ORRRr   c           	      .   t        j                  t         j                  t        j                     | j
                  j                        }t        d      D cg c]+  }t        d      D cg c]  }|j                  |   |    c}- c}}S c c}w c c}}w )z
        Quantisation parameter offset from the base (per-frame) qp for a given
        plane (first index) and AC/DC coefficients (second index).
              )	r#   r$   r%   r   r&   r'   r(   rangedelta_qp)r    pijs       r   r6   zVideoEncParams.delta_qpH   sh     39++NN3//0$((--3
 ?DAhG584aAq!4GG4Gs   B*BBBc                 X    |dk  s|| j                   k\  rt        d      t        | |      S )z?
        Get the encoding parameters for a given block
        r   z$Expected idx in range [0, nb_blocks))r   
ValueErrorVideoBlockParams)r    idxs     r   block_paramszVideoEncParams.block_paramsS   s/    
 7cT^^+CDDc**r   c                 P   ddl }| j                  j                  j                  dz   dz  }| j                  j                  j                  dz   dz  }||z  }t        j                  t
        j                        \  }}}| j                  |k7  rt        d      t        j                  t
        j                  t        j                     | j                  j                        j                  }|t        j                   j"                  k7  r(|t        j                   j$                  k7  rt'        d      |j)                  ||f|j*                        }	t-        |      D ]J  }t/        | |      }
|
j0                  dz  }|
j2                  dz  }| j4                  |
j6                  z   |	||f<   L |	S )z
        Convenience method that creates a 2-D map with the quantization parameters per macroblock.
        Only for MPEG2 and H264 encoded videos.
        r   N      z:Expected frame size to match number of blocks in side datazExpected MPEG2 or H264)dtype)numpyframer'   heightwidthr#   declarer/   r   RuntimeErrorr$   r%   r   r&   r(   r.   AVVideoEncParamsTyper   r   r;   emptyint32r5   r<   src_ysrc_xr   r6   )r    npmb_hmb_wnb_mb	block_idxxyr.   mapblocks              r   qp_mapzVideoEncParams.qp_map]   sd   
 	 JJNN11B62= JJNN0025"< 4K ..4	1a >>U"L  *0NN3//0$((--*

$ 	 C,,FFF00III566 hhd|288h4 u 	1I$T95Er!Ar!A%..0C1I		1 
r   N)r	   r
   r   r!   propertyr   r*   r,   r   r   r6   r>   rW   r   r   r   r   r      s    w 	 	     > > S S H H+%r   r   c                       e Zd Zdedej
                  ddfdZd Zed        Z	ed        Z
ed	        Zed
        Zed        Zy)r<   video_enc_paramsr=   returnNc                 4   t        j                  t         j                  t           |j                  j
                        }|j                  ||j                  z  z   }t        j                  t         j                  t        j                     ||z         | _        y )N)
r#   r$   r%   r   r'   r(   r*   r,   r   AVVideoBlockParams)r    rZ   r=   baseoffsets        r   __init__zVideoBlockParams.__init__   ss    (.NN7#%5%9%9%>%>)
 **S3C3N3N-NN 	 ;;v~~c.D.DEtf}Ur   c                     d| j                    d| j                   d| j                   d| j                   d| j                   dS )Nz$<av.sidedata.VideoBlockParams, src=(z, z), size=rS   z, delta_qp=r   )rM   rL   whr6   r   s    r   r!   zVideoBlockParams.__repr__   sb    5djj\DJJ<xX\X^X^W__`aeagag`hhstx  uB  uB  tC  CD  E  	Er   c                 .    | j                   j                  S )z
        Horizontal distance in luma pixels from the top-left corner of the visible frame
        to the top-left corner of the block.
        Can be negative if top/right padding is present on the coded frame.
        )r'   rM   r   s    r   rM   zVideoBlockParams.src_x        xx~~r   c                 .    | j                   j                  S )z
        Vertical distance in luma pixels from the top-left corner of the visible frame
        to the top-left corner of the block.
        Can be negative if top/right padding is present on the coded frame.
        )r'   rL   r   s    r   rL   zVideoBlockParams.src_y   re   r   c                 .    | j                   j                  S )z3
        Width of the block in luma pixels
        )r'   rb   r   s    r   rb   zVideoBlockParams.w       
 xxzzr   c                 .    | j                   j                  S )z4
        Height of the block in luma pixels
        )r'   rc   r   s    r   rc   zVideoBlockParams.h   rh   r   c                 .    | j                   j                  S )z}
        Difference between this block's final quantization parameter and the
        corresponding per-frame value.
        )r'   r6   r   s    r   r6   zVideoBlockParams.delta_qp   s     xx   r   )r	   r
   r   r   r#   r/   r`   r!   rX   rM   rL   rb   rc   r6   r   r   r   r<   r<      s    V Vfjj VT VE         ! !r   r<   )enumr   r#   cython.cimportsr   r   $cython.cimports.av.sidedata.sidedatar   cython.cimports.libc.stdintr   r   finalcclassr   r<   r   r   r   <module>rq      sx      ( 9 /* * pX p  pf 3! 3!  3!r   