o
    2j                     @   st   d dl Z d dlmZ d dlmZ d dlmZ e e	e	 Z
e je jG dd deZe je jG dd dZdS )	    N)libav)SideData)	uintptr_tc                   @   sP   e Zd ZdedejfddZdd Zdd Zdej	fd	d
Z
dd Zdd ZdS )MotionVectorsframeindexc                 C   s0   t | ||| i | _| jjttj | _	d S N)
r   __init___vectorsptrsizecythonsizeoflibAVMotionVector_len)selfsentinelr   r    r   T/var/www/html/whisper/venv/lib/python3.10/site-packages/av/sidedata/motionvectors.pyr	      s   zMotionVectors.__init__c              	   C   s.   d| j j dt|  dtt| j jddS )Nz<av.sidedata.MotionVectors z
 bytes of z vectors at 0x0x>)r   r   lenr   castr   datar   r   r   r   __repr__   s   zMotionVectors.__repr__c                 C   s   | j S r   )r   r   r   r   r   __len__   s   zMotionVectors.__len__c                 C   sL   z| j | W S  ty   Y nw || jkrt|tt| | }| j |< |S r   )r
   KeyErrorr   
IndexErrorMotionVector_cinit_bypass_sentinel)r   r   vectorr   r   r   __getitem__   s   
zMotionVectors.__getitem__c                 c   s     t | jD ]}| | V  qdS )z Iterate over all motion vectors.N)ranger   )r   ir   r   r   __iter__(   s   zMotionVectors.__iter__c                 C   s$   ddl }|j| |jg ddddS )z
        Convert motion vectors to a NumPy structured array.

        Returns a NumPy array with fields corresponding to the AVMotionVector structure.
        r   N))sourceint32)wuint8)hr*   )src_xint16)src_yr-   )dst_xr-   )dst_yr-   )flagsuint64)motion_xr(   )motion_yr(   )motion_scaleuint16T)align)dtype)numpy
frombufferr8   )r   npr   r   r   
to_ndarray-   s   zMotionVectors.to_ndarrayN)__name__
__module____qualname__Framer   intr	   r   r   
Py_ssize_tr#   r&   r<   r   r   r   r   r   	   s    r   c                   @   s   e Zd ZdZdedej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e	dd Ze	dd Ze	dd Ze	dd Ze	dd ZdS )r    z
    Represents a single motion vector from video frame data.

    Motion vectors describe the motion of a block of pixels between frames.
    parentr   c                 C   s<   |t urtd|| _ttjtj |jj	}|| | _d S )Nz(cannot manually instantiate MotionVector)
r!   RuntimeErrorrC   r   r   pointerr   r   r   r   )r   r   rC   r   baser   r   r   r	   S   s   zMotionVector.__init__c                 C   s6   d| j  d| j d| j d| j d| j d| j dS )Nz<av.sidedata.MotionVector xz from (,z) to (z)>)r)   r+   r,   r.   r/   r0   r   r   r   r   r   \   s   zMotionVector.__repr__c                 C      | j jS r   )r   r'   r   r   r   r   r'   b      zMotionVector.sourcec                 C   rI   r   )r   r)   r   r   r   r   r)   f   rJ   zMotionVector.wc                 C   rI   r   )r   r+   r   r   r   r   r+   j   rJ   zMotionVector.hc                 C   rI   r   )r   r,   r   r   r   r   r,   n   rJ   zMotionVector.src_xc                 C   rI   r   )r   r.   r   r   r   r   r.   r   rJ   zMotionVector.src_yc                 C   rI   r   )r   r/   r   r   r   r   r/   v   rJ   zMotionVector.dst_xc                 C   rI   r   )r   r0   r   r   r   r   r0   z   rJ   zMotionVector.dst_yc                 C   rI   r   )r   r3   r   r   r   r   r3   ~   rJ   zMotionVector.motion_xc                 C   rI   r   )r   r4   r   r   r   r   r4      rJ   zMotionVector.motion_yc                 C   rI   r   )r   r5   r   r   r   r   r5      rJ   zMotionVector.motion_scaleN)r=   r>   r?   __doc__r   r   rA   r	   r   propertyr'   r)   r+   r,   r.   r/   r0   r3   r4   r5   r   r   r   r   r    J   s0    	








r    )r   cython.cimportsr   r   $cython.cimports.av.sidedata.sidedatar   cython.cimports.libc.stdintr   declareobjectr!   finalcclassr   r    r   r   r   r   <module>   s    ?