
    d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         G d d	e                      Zej         G d
 d                      ZdS )    )IntEnumN)libav)SideData)uint8_tc                   F    e Zd Zej        Zej        Zej        Z	ej
        ZdS )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     P/home/agentuser/manim-venv/lib/python3.11/site-packages/av/sidedata/encparams.pyr   r   	   s.        'D

%C'D)EEEr   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d
S )VideoEncParamsc                 8    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__   s-    vvvVZVevvlplsvv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   s.     {N3/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!   s.    
 {N3/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*   s.    
 {N3/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_type3   sL    
 '-kN3/0$(-'
 '

 	
 "&+fj!"<"<===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=   s'     {6>#*>?OORRr   c                     t          j        t           j        t          j                 | j        j                  fdt          d          D             S )z
        Quantisation parameter offset from the base (per-frame) qp for a given
        plane (first index) and AC/DC coefficients (second index).
        c                 J    g | ]fd t          d          D             S )c                 6    g | ]}j                  |         S r   )delta_qp).0jips     r   
<listcomp>z6VideoEncParams.delta_qp.<locals>.<listcomp>.<listcomp>P   s$    444aAq!444r      )range)r6   r8   r9   s    @r   r:   z+VideoEncParams.delta_qp.<locals>.<listcomp>P   s8    GGG44444588444GGGr      )r#   r$   r%   r   r&   r'   r(   r<   )r    r9   s    @r   r5   zVideoEncParams.delta_qpG   sL     39+N3/0$(-3
 3
 HGGGeAhhGGGGr   c                 b    |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_paramsR   s8    
 77cT^++CDDDc***r   c                    ddl }| j        j        j        dz   dz  }| j        j        j        dz   dz  }||z  }t          j        t
          j                  \  }}}| j        |k    rt          d          t          j
        t
          j        t          j                 | j        j                  j        }|t          j        j        k    r$|t          j        j        k    rt'          d          |                    ||f|j                  }	t-          |          D ]:}t/          | |          }
|
j        dz  }|
j        dz  }| j        |
j        z   |	||f<   ;|	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int32r<   r@   src_ysrc_xr   r5   )r    npmb_hmb_wnb_mb	block_idxxyr.   mapblocks              r   qp_mapzVideoEncParams.qp_map\   sW   
 	 JN1B62= JN025"< 4K .44	1a >U""L   *0N3/0$(-*
 *

 	 C,FFF0III5666 hhd|28h44 u 	1 	1I$T955Er!Ar!A%.0C1II
r   N)r	   r
   r   r!   propertyr   r*   r,   r   r   r5   rB   r[   r   r   r   r   r      s        w w w 	 	 X	   X   X > > X> S S XS H H X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dS )r@   video_enc_paramsrA   returnNc                     t          j        t           j        t                   |j        j                  }|j        ||j        z  z   }t          j        t           j        t          j	                 ||z             | _        d S )N)
r#   r$   r%   r   r'   r(   r*   r,   r   AVVideoBlockParams)r    r^   rA   baseoffsets        r   __init__zVideoBlockParams.__init__   sh    (.N7#%5%9%>)
 )
 *S3C3N-NN 	 ;v~c.DEtf}UUr   c                 X    d| j          d| j         d| j         d| j         d| j         dS )Nz$<av.sidedata.VideoBlockParams, src=(z, z), size=rW   z, delta_qp=r   )rQ   rP   whr5   r   s    r   r!   zVideoBlockParams.__repr__   sn     Edj  E  EDJ  E  EX\X^  E  Eaeag  E  Etx  uB  E  E  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'   rQ   r   s    r   rQ   zVideoBlockParams.src_x        x~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'   rP   r   s    r   rP   zVideoBlockParams.src_y   ri   r   c                     | j         j        S )z3
        Width of the block in luma pixels
        )r'   rf   r   s    r   rf   zVideoBlockParams.w       
 xzr   c                     | j         j        S )z4
        Height of the block in luma pixels
        )r'   rg   r   s    r   rg   zVideoBlockParams.h   rl   r   c                     | j         j        S )z}
        Difference between this block's final quantization parameter and the
        corresponding per-frame value.
        )r'   r5   r   s    r   r5   zVideoBlockParams.delta_qp   s     x  r   )r	   r
   r   r   r#   r/   rd   r!   r\   rQ   rP   rf   rg   r5   r   r   r   r@   r@      s        V Vfj VT V V V VE E E   X   X   X   X ! ! X! ! !r   r@   )enumr   r#   cython.cimportsr   r   $cython.cimports.av.sidedata.sidedatar   cython.cimports.libc.stdintr   r   cclassr   r@   r   r   r   <module>rt      s          ( ( ( ( ( ( 9 9 9 9 9 9 / / / / / /* * * * * * * * p p p p pX p p pf 3! 3! 3! 3! 3! 3! 3! 3! 3! 3!r   