o
    2j                     @   s   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 deZ
ejejG dd	 d	eZejejG d
d dZdS )    )IntEnumN)libav)SideData)uint8_tc                   @   s$   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 r   r   P/var/www/html/whisper/venv/lib/python3.10/site-packages/av/sidedata/encparams.pyr   	   s
    
r   c                   @   sl   e Zd Zdd Zedd Zedd Zedd Zed	d
 Zedd Z	edd Z
dd Zdd ZdS )VideoEncParamsc                 C   s   d| j  d| j d| j dS )Nz'<av.sidedata.VideoEncParams, nb_blocks=z, codec_type=z, qp=>)	nb_blocks
codec_typeqpselfr   r   r   __repr__   s   zVideoEncParams.__repr__c                 C      t 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   r   r   r   r      s
   zVideoEncParams.nb_blocksc                 C   r   )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   r   r   r   r$   "   
   zVideoEncParams.blocks_offsetc                 C   r   )zX
        Size of each block in bytes. May not match sizeof(AVVideoBlockParams).
        )r   r   r    r
   r!   r"   r#   
block_sizer   r   r   r   r&   +   r%   zVideoEncParams.block_sizec                 C   s,   t t jtj | jjj}tt t j	|S )zH
        Type of the parameters (the codec they are used with).
        )
r   r   r    r
   r!   r"   r#   typer   int)r   tr   r   r   r   4   s   zVideoEncParams.codec_typec                 C   r   )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   r   r   r   r   >   s   zVideoEncParams.qpc                    s.   t t jtj | jj  fd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                    s$   g | ]  fd dt dD qS )c                    s   g | ]	}j   | qS r   )delta_qp).0j)ipr   r   
<listcomp>Q   s    z6VideoEncParams.delta_qp.<locals>.<listcomp>.<listcomp>   )range)r+   r.   )r-   r   r/   Q   s   $ z+VideoEncParams.delta_qp.<locals>.<listcomp>   )r   r   r    r
   r!   r"   r#   r1   r   r   r2   r   r*   H   s   zVideoEncParams.delta_qpc                 C   s$   |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   idxr   r   r   block_paramsS   s   
zVideoEncParams.block_paramsc                 C   s   ddl }| jjjd d }| jjjd d }|| }ttj\}}}| j|kr,t	dt
tjtj | jjj}|tjjkrI|tjjkrItd|j||f|jd}	t|D ]}t| |}
|
jd }|
jd }| j|
j |	||f< qW|	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   r4   emptyint32r1   r5   src_ysrc_xr   r*   )r   npmb_hmb_wnb_mb	block_idxxyr'   mapblockr   r   r   qp_map]   s0   



zVideoEncParams.qp_mapN)r   r   r	   r   propertyr   r$   r&   r   r   r*   r7   rO   r   r   r   r   r      s     



	
	


r   c                   @   sh   e Zd ZdedejddfddZdd Zed	d
 Z	edd Z
edd Zedd Zedd ZdS )r5   video_enc_paramsr6   returnNc                 C   sD   t t jt |jj}|j||j  }t t jtj	 || | _d S )N)
r   r   r    r   r"   r#   r$   r&   r
   AVVideoBlockParams)r   rQ   r6   baseoffsetr   r   r   __init__   s   zVideoBlockParams.__init__c                 C   s.   d| j  d| j d| j d| j d| j dS )Nz$<av.sidedata.VideoBlockParams, src=(z, z), size=rK   z, delta_qp=r   )rE   rD   whr*   r   r   r   r   r      s   .zVideoBlockParams.__repr__c                 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"   rE   r   r   r   r   rE         zVideoBlockParams.src_xc                 C   rY   )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"   rD   r   r   r   r   rD      rZ   zVideoBlockParams.src_yc                 C   rY   )z3
        Width of the block in luma pixels
        )r"   rW   r   r   r   r   rW         zVideoBlockParams.wc                 C   rY   )z4
        Height of the block in luma pixels
        )r"   rX   r   r   r   r   rX      r[   zVideoBlockParams.hc                 C   rY   )z}
        Difference between this block's final quantization parameter and the
        corresponding per-frame value.
        )r"   r*   r   r   r   r   r*      s   zVideoBlockParams.delta_qp)r   r   r	   r   r   r(   rV   r   rP   rE   rD   rW   rX   r*   r   r   r   r   r5      s    	



r5   )enumr   r   cython.cimportsr   r
   $cython.cimports.av.sidedata.sidedatar   cython.cimports.libc.stdintr   r   finalcclassr   r5   r   r   r   r   <module>   s    s