
    m il              	       &   d dl Z d dlmZ d dlZd dlmZ d dlmZ d dlm	Z	 d dl
mZmZ d dlmZ d dlmZ  e            Zh d	Zej        d
efd            Z G d de          Zej        dej        fd            Zej        dedej        dej        dej        fd            Zej        dedej        fd            Zej        	 ddedej        defd            Zej        dedej        fd            Zej          G d de!                      ZdS )     N)IntEnum)	err_checkget_display_rotation)check_ndarray)get_pix_fmtget_video_format
VideoPlane)uint8_t>T   abgrargbbgr8bgragbrpgraynv12pal8rgb8rgbabgr24gbrapgray8rgb24bgr48bebgr48legbrp9begbrp9legray9begray9lergb48bergb48leyuv420pyuv444pyuyv422bgra64bebgra64legbrp10begbrp10legbrp12begbrp12legbrp14begbrp14legbrp16begbrp16legray10begray10legray12begray12legray14begray14legray16begray16lergba64bergba64lergbf32bergbf32leyuvj420pyuvj444p	gbrap10be	gbrap10le	gbrap12be	gbrap12le	gbrap14be	gbrap14le	gbrap16be	gbrap16le	gbrpf32be	gbrpf32le	grayf32be	grayf32le	rgbaf16be	rgbaf16le	rgbaf32be	rgbaf32le
gbrapf32be
gbrapf32lebayer_bggr8bayer_gbrg8bayer_grbg8bayer_rggb8yuv422p10leyuv444p16beyuv444p16leyuva444p16beyuva444p16lebayer_bggr16bebayer_bggr16lebayer_gbrg16bebayer_gbrg16lebayer_grbg16bebayer_grbg16lebayer_rggb16bebayer_rggb16lereturnc                  *    t          t                    S )zGet a mostly uninitialized VideoFrame.

    You MUST call VideoFrame._init(...) or VideoFrame._init_user_attributes()
    before exposing to the user.

    )
VideoFrame_cinit_bypass_sentinel     N/var/www/html/auto_sub_bot/venv/lib/python3.11/site-packages/av/video/frame.pyalloc_video_framerh   g   s     ,---rf   c                   ~    e Zd Zej        Zej        Zej        Z	ej
        Zej        Zej        Zej        Zej        ZdS )PictureTypeN)__name__
__module____qualname__libAV_PICTURE_TYPE_NONENONEAV_PICTURE_TYPE_IIAV_PICTURE_TYPE_PPAV_PICTURE_TYPE_BBAV_PICTURE_TYPE_SSAV_PICTURE_TYPE_SISIAV_PICTURE_TYPE_SPSPAV_PICTURE_TYPE_BIBIre   rf   rg   rj   rj   r   sN        #DAAAA		B		B		BBBrf   rj   
big_endianc                 V    t           j        dk    |k    r|                                 S | S )Nbig)sys	byteorderbyteswap)arrayr   s     rg   byteswap_arrayr   }   s)    :--~~Lrf   planebytes_per_pixelflip_horizontalflip_verticalc                    | }d}|j         |z  }|}d}	t          |j                  }
t          j        t          j                  \  }}}|r|j        dz
  }d}d}nd}|j        }d}t          |||          D ]g}||z  }|rDt          d||          D ]1}t          |          D ]}|||z   |z
  |z
  |z            ||	|z   |z   <    2n||||z            ||	|	|z   <   |	|
z  }	hd S )Nr      )widthabs	line_sizecythondeclareintheightrange)	img_bytesr   r   r   r   i_bufi_posi_strideo_bufo_poso_stride	start_rowend_rowsteprowijs                    rg   copy_bytes_to_planer      sQ    '0EE#kO;HEE!%/22H%~fj99Iw L1$		,Y.. 
 
h 	N1h88  //  A+0(1,>B,E%!)a-(( /4EEH<L4L.ME%%(**+
 
rf   c                 T    |                                  }t          |||dd           d S )NF)tobytesr   )r   r   r   imgbytess       rg   copy_array_to_planer      s+    mmooH%%GGGGGrf   r   uint8dtypec                 B   ddl }t          | j                  }| j        |z  }|                    | |j                  }||k    r5|                    d|          ddd|f                             d          }|                    |                    |                    S )z
    Return the useful part of the VideoPlane as a single dimensional array.

    We are simply discarding any padding which was added for alignment.
    r   Nr   )	numpyr   r   r   
frombufferr   reshapeviewr   )r   r   r   nptotal_line_sizeuseful_line_sizearrs          rg   useful_arrayr      s     %(%9%9O&+kO&C
--rx
(
(C***kk"o..qqq!4D2D/DEMMbQQ88BHHUOO$$$rf   r   okc                 :    |st          d| j         d          d S )NzUnexpected numpy array shape ``)
ValueErrorshape)r   r   s     rg   check_ndarray_shaper      s3     JH%+HHHIIIJ Jrf   c                   \   e Zd Zd'dZej        dej        dej        dej        fd            Z	ej        d             Z
d	 Zd
 Zed             Zed             Zed             Zed             Zed             Zed             Zej        d             Zed             Zej        d             Zed             Zej        d             Zd Zd Zej        defd            Zd Zd(dZd Zed             Z ed)d             Z!d! Z"ed*d"            Z#e	 	 	 d+d$e$de%de%fd%            Z&d&S ),rc   r   r#   c                 h    |t           u rd S t          |          }|                     |||           d S N)rd   r   _init)selfr   r   formatc_formats        rg   	__cinit__zVideoFrame.__cinit__   s<    ***F&1&&9&9

8UF+++++rf   r   r   r   c           	         d}t           j        5  || j        _        || j        _        || j        _        |rL|rJt                              | j        j        | j        j	        |||d          }| j        j        d         | _
        d d d            n# 1 swxY w Y   |rt          |           |                                  d S )Nr      )r   nogilptrr   r   r   rn   av_image_allocdatalinesize_bufferr   _init_user_attributes)r   r   r   r   ress        rg   r   zVideoFrame._init   s    \ 	0 	0"DHN$DHO$DHO  0 0((HM48#4eVVR   $x}Q/	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0 	0  	cNNN""$$$$$s   A3BBBc                     t          t          j        t          j        | j        j                  | j        j        | j        j                  | _        d S r   )	r	   r   castrn   AVPixelFormatr   r   r   r   r   s    rg   r   z VideoFrame._init_user_attributes   s;    &K)48?;;HNHO
 
rf   c                 v    t                               t          j        | j                             d | _        d S r   )rn   av_freepr   addressr   
_np_bufferr   s    rg   __dealloc__zVideoFrame.__dealloc__   s-     	V^DL11222rf   c                     d| j         j         d| j         d| j        j         d| j         d| j         dt          |           ddS )Nz<av.z, pts= xz at 0x>)	__class__rk   ptsr   namer   r   idr   s    rg   __repr__zVideoFrame.__repr__   su    =4>* = =$( = =T[=M = =z= = K= =/1$xx<= = =	
rf   c                 z    d}t           j        j        j                  D ])} j        j        j        |         j        dz   }||k     r|}* j        j        dk    rd}d}||k     r/ j        j        |         r|dz  }||k     r j        j        |         t           fdt          |          D                       S )z:
        A tuple of :class:`.VideoPlane` objects.
        r   r   r      c                 0    g | ]}t          |          S re   r
   ).0r   r   s     rg   
<listcomp>z%VideoFrame.planes.<locals>.<listcomp>  s#    FFFajq))FFFrf   )	r   r   r   nb_componentscompr   r   extended_datatuple)r   max_plane_countr   countplane_counts   `    rg   planeszVideoFrame.planes   s     '(t{455 	( 	(AKO(+1A5E&&"';v%%O"#O++0F{0S+1K O++0F{0S+FFFF53E3EFFFGGGrf   c                     | j         j        S )zWidth of the image, in pixels.)r   r   r   s    rg   r   zVideoFrame.width  s     x~rf   c                     | j         j        S )zHeight of the image, in pixels.)r   r   r   s    rg   r   zVideoFrame.height  s     xrf   c                      t          |           S )zThe rotation component of the `DISPLAYMATRIX` transformation matrix.

        Returns:
            int: The angle (in degrees) by which the transformation rotates the frame
                counterclockwise. The angle will be in range [-180, 180].
        r   r   s    rg   rotationzVideoFrame.rotation  s     $D)))rf   c                 N    t          | j        j        t          j        z            S )z+Is this frame an interlaced or progressive?)boolr   flagsrn   AV_FRAME_FLAG_INTERLACEDr   s    rg   interlaced_framezVideoFrame.interlaced_frame'  s     DHNS%AABBBrf   c                     | j         j        S )zReturns an integer that corresponds to the PictureType enum.

        Wraps :ffmpeg:`AVFrame.pict_type`

        :type: int
        r   	pict_typer   s    rg   r   zVideoFrame.pict_type-  s     x!!rf   c                     || j         _        d S r   r   r   values     rg   r   zVideoFrame.pict_type7  s    "rf   c                     | j         j        S )zKColorspace of frame.

        Wraps :ffmpeg:`AVFrame.colorspace`.

        r   
colorspacer   s    rg   r   zVideoFrame.colorspace;  s     x""rf   c                     || j         _        d S r   r   r   s     rg   r   zVideoFrame.colorspaceD  s    #rf   c                     | j         j        S )zMColor range of frame.

        Wraps :ffmpeg:`AVFrame.color_range`.

        r   color_ranger   s    rg   r   zVideoFrame.color_rangeH  s     x##rf   c                     || j         _        d S r   r   r   s     rg   r   zVideoFrame.color_rangeQ  s    $rf   c                 b    | j         st                      | _          | j         j        | g|R i |S )a  reformat(width=None, height=None, format=None, src_colorspace=None, dst_colorspace=None, interpolation=None)

        Create a new :class:`VideoFrame` with the given width/height/format/colorspace.

        .. seealso:: :meth:`.VideoReformatter.reformat` for arguments.

        )reformatterVideoReformatterreformat)r   argskwargss      rg   r  zVideoFrame.reformatU  sC      	2/11D(t(???????rf   c                       | j         dddi|S )a
  Get an RGB version of this frame.

        Any ``**kwargs`` are passed to :meth:`.VideoReformatter.reformat`.

        >>> frame = VideoFrame(1920, 1080)
        >>> frame.format.name
        'yuv420p'
        >>> frame.to_rgb().format.name
        'rgb24'

        r   r   re   )r  )r   r  s     rg   to_rgbzVideoFrame.to_rgba  s!     t}66G6v666rf   filepathc                 J   |                     d          rd}n<|                     d          s|                     d          rd}nt          d          |rdnd}|rd	nd
}ddlm}  ||dddi          5 }|                    ||          }| j        |_        | j        |_        |                    |                    | 	                    |                               |                    |                    d                     ddd           dS # 1 swxY w Y   dS )zPSave a VideoFrame as a JPG or PNG.

        :param filepath: str | Path
        z.pngFz.jpgz.jpegTz"filepath must end with png or jpg.mjpegpngr<   r   r   )openwupdate1)options)pix_fmt)r   N)
endswithr   av.container.corer  
add_streamr   r   muxencoder  )r   r
  is_jpgencoderr  r  outputoutput_streams           rg   savezVideoFrame.saveo  s    V$$ 	CFFv&& 	C(*;*;G*D*D 	CFFABBB"(3wwe%+8zz******T(C(C999 	3V"--gw-GGM"&*M#';M JJ}++DMMM,I,IJJKKKJJ}++D11222	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3 	3s   7BDDDc           	      `   ddl m}  | j        d	ddi|j        d         }|}d}|j        }d}|j        dz  }|j        |z  }	t          |	          }
||	k     r%||||z            |
|||z   <   ||z  }||z  }||	k     %|                    d|j        |j        ft          |
          dddd          S )
zGet an RGB ``PIL.Image`` of this frame.

        Any ``**kwargs`` are passed to :meth:`.VideoReformatter.reformat`.

        .. note:: PIL or Pillow must be installed.

        r   )Imager   r      RGBrawr   re   )
PILr  r  r   r   r   r   	bytearray	frombytesbytes)r   r  r  r   r   r   r   r   r   o_sizer   s              rg   to_imagezVideoFrame.to_image  s     	)DMCCCFCCJ1M*/ "'/ "'+/ %x 7$V,,fnn.3EEH<L4L.ME%%(**+XEXE fnn
 EK.eeUAq
 
 	
rf   Fc                     | j         dhi |ddl}j        j        dv r0j        dz  dk    s
J d            j        dz  dk    s
J d            i ddd	dd
dddddddddddddddddddddddddddddi dddddd d!d d"dd#dd$dd%dd&dd'dd(dd)dd*dd+d,d-d,d.dd/di d0dd1dd2dd3dd4dd5dd6dd7dd8dd9d,d:d,d;dd<dd=dd>dd?dd@di dAddBddCddDddEddFddGd,dHd,dIddJddKddLddMddNd dOd dPdQdRdQdSdSdTdTdddddddUdV                    j        j        dW          \  BfdXj        D             }t          |          dYk    r	|d         }n|	                    |dZ          }t          |j        j                            d[                    }|j        d         dYk    r|                    d          S j        j                            d\          r_|dddddf                                         }|dddddf         |dddddf<   |dddddYf         |dddddf<   ||dddddYf<   |s%j        j        d]v r|                    |dd          }|S j        j        d^v ry|                    t%          j        d                   t%          j        dY                   t%          j        d                   g                              d_j                  S j        j        d`k    rt%          j        d         dda                              j        j                  }t%          j        dY         dda                              j        j        dz            }t%          j        d         dda                              j        j        dz            }	|                    |ddYZ          }
|                    |	ddYZ          }|r|                    ||
|gdZ          S |                    ||
|gdZ          S j        j        dbk    rt%          j        d                                       j        j                  }|                    j        dY         dc                              dd                              d_dY                              |j                  }||fS j        j        dek    ra|                    t%          j        d                   t%          j        dY         d          g                              d_j                  S t5          dfj        j         dg          )iaI  Get a numpy array of this frame.

        Any ``**kwargs`` are passed to :meth:`.VideoReformatter.reformat`.

        The array returned is generally of dimension (height, width, channels).

        :param bool channel_last: If True, the shape of array will be
            (height, width, channels) rather than (channels, height, width) for
            the "yuv444p" and "yuvj444p" formats.

        .. note:: Numpy must be installed.

        .. note:: For formats which return an array of ``uint16``, ``float16`` or ``float32``,
            the samples will be in the system's native byte order.

        .. note:: For ``pal8``, an ``(image, palette)`` tuple will be returned,
            with the palette being in ARGB (PyAV will swap bytes if needed).

        .. note:: For ``gbrp`` formats, channels are flipped to RGB order.

        r   N>   r#   r%   r<   rT   r   z.the width has to be even for this pixel formatz/the height has to be even for this pixel formatr   )   r   r   rP   r   r   rQ   rR   rS   rZ   )r   uint16rY   r\   r[   r^   r]   r`   r_   r   )r   r   r   )   r,  r   r   r   r&   )   r,  r'   r   r>   r?   r@   rA   rB   rC   rD   rE   rN   )r*  float32rO   r   r(   r)   r*   r+   r,   r-   r.   r/   r   r   rF   rG   r   r0   r1   r2   r3   r4   r5   r6   r7   r   r   r    rH   rI   r   r!   r"   r   r   r8   r9   rJ   )r.  float16rK   )r   r/  )   r/  )r   r   )rL   rM   r:   r;   r$   rU   rV   rW   rX   r=   r%   )NNc                 p    g | ]2}t          |                              j        j        d           3S )r   )r   r   r   r   )r   planr   frameitemsizes     rg   r   z)VideoFrame.to_ndarray.<locals>.<listcomp>  sR         T8U33;;L%+r   rf   r   axisbegbr   r$   r=      r#   r<   r   rT   r,  r   i4>i4r   z'Conversion to numpy array with format `` is not yet supportedre   )r  r   r   r   r   r   getr   lenconcatenater   r  r   squeeze
startswithcopymoveaxishstackr   r   repeatstackr   astyper   r   r   )r   channel_lastr  r   layersr   bufferyuvu_fullv_fullimagepaletter   r4  r5  s                 @@@rg   
to_ndarrayzVideoFrame.to_ndarray  s   , *DM33F33 < QQQ;?a'''@ ('' <!#q(((A )((
P
LP
LP
 <P
 <	P

 <P
 <P
 mP
 mP
 mP
 mP
 mP
 mP
 mP
 mP
 \P
  }!P
" }#P
 P
$ L%P
& L'P
( )P
* +P
, \-P
. /P
0 1P
2 3P
4 5P
6 7P
8 9P
: ;P
< =P
> .?P
@ .AP
B LCP
D EP
 P
 P
F GP
H IP
J KP
L MP
N OP
P QP
R SP
T }UP
V }WP
X YP
Z [P
\ L]P
^ _P
` aP
b cP
d eP
f gP
 P
 P
h iP
j kP
l mP
n \oP
p }qP
r }sP
t uP
v wP
x \yP
z }{P
| }}P
~ LP
@ LAP
B CP
D EP
F GP
H IP
 P
J )(''#(())$#_P
 P
 P
` #el
.
.a 	%b       "L	  F 6{{aq	vA66"5%,*;*D*DT*J*JKKE{1~""}}Q'''| ++E22 (qqq!!!Qw,,..!&qqq!!!QwaaaAg!&qqq!!!QwaaaAg!'aaaAg 1EL$59P$P$PE1a00L < 77799 a11 a11 a11  gb%+&&' <--U\!_a::BBek A U\!_a::BBekQ. A U\!_a::BBekQ. A
 YYq!!Y,,FYYq!!Y,,F =xxFF 3!x<<<88Q/a8888<&& a1199%,TTEel1ot44Qbh	  '>!<&&99 a11 a!44 
 gb%+&&' _el6G___
 
 	
rf   c                 ~    |j         dk    r|                    d          }t          || j        d         d           dS )z6
        Update content from a ``PIL.Image``.
        r!  r   r   N)modeconvertr   r   )r   imgs     rg   	set_imagezVideoFrame.set_imagee  s@     8u++e$$CCQ33333rf   c                 ~    t          | j        d         | j        d         d          }|                    |            |S )z9
        Construct a frame from a ``PIL.Image``.
        r   r   r   )rc   sizerY  )rX  r4  s     rg   
from_imagezVideoFrame.from_imagen  s8    
 'sx{CHQKIIrf   r   c                 d   ddl }| j        d         }|s| j        d         }|dv rbt          | dd           t          | | j        d         dk               | j        dd         dk    rt          d	          | j        d         f}ni|d
v rbt          | dd           t          | | j        d         dk               | j        dd         dk    rt          d	          | j        d         f}n|dv rbt          | dd           t          | | j        d         dk               | j        dd         dk    rt          d	          | j        d         f}n|dv rbt          | dd           t          | | j        d         dk               | j        dd         dk    rt          d	          | j        d         f}n7|dv rbt          | dd           t          | | j        d         dk               | j        dd         dk    rt          d	          | j        d         f}n|dv rbt          | dd           t          | | j        d         dk               | j        dd         dk    rt          d	          | j        d         f}nk|dv rbt          | dd           t          | | j        d         dk               | j        dd         dk    rt          d	          | j        d         f}n|dv rAt          | dd           | j        d         dk    rt          d	          | j        d         f}n|dv rAt          | dd           | j        d         dk    rt          d	          | j        d         f}n{|dv rAt          | dd           | j        d         dk    rt          d	          | j        d         f}n6|dv rt          | dd           t          | | j        d         dk               | j        dd         dk    rt          d	          | j        d         dz  | j        d         dz  | j        d         dz  f}n|dv rt          | dd           t          | | j        d         dk               | j        dd         dk    rt          d	          | j        d         dz  | j        d         dz  | j        d         dz  f}n(|dv rt          | dd           t          | | j        d         dk               | j        dd         dk    rt          d	          | j        d         dz  | j        d         dz  | j        d         dz  f}n|dv rt          | dd           t          | | j        d         dk               | j        dd         dk    rt          d	          | j        d         dz  | j        d         dz  | j        d         dz  | j        d         dz  f}n|d v rt          | dd           t          | | j        d         dk               | j        dd         dk    rt          d	          | j        d         dz  | j        d         dz  | j        d         dz  | j        d         dz  f}nu|d!v rt          | dd           t          | | j        d         dk               | j        dd         dk    rt          d	          | j        d         dz  | j        d         dz  | j        d         dz  | j        d         dz  f}n|d"v rt          | dd           t          | | j        d         dz  dk               t          | | j        d         dz  dk               |d#z  dz  }| j        d         dk    rt          d	          |d$v r-| j        d         | j        d         dz  | j        d         dz  f}n.| j        d         | j        d         f}nt          d%| d&          |                    d'          r5|                    |                    | d(g d)f         d*d                    } nI|                    d+          r4|                    |                    | d(g d,f         d*d                    } t          t                    }|                    | ||||           |S )-a  
        Construct a frame from a numpy buffer.

        :param int width: optional width of actual image, if different from the array width.

        .. note:: For formats which expect an array of ``uint16``, ``float16`` or ``float32``,
            the samples must be in the system's native byte order.

        .. note:: for ``gbrp`` formats, channels are assumed to be given in RGB order.

        .. note:: For formats where width of the array is not the same as the width of the image,
        for example with yuv420p images the UV rows at the bottom have padding bytes in the middle of the
        row as well as at the end. To cope with these, callers need to be able to pass the actual width.
        r   Nr      r   r   r   r   r   )r   r   z.provided array does not have C_CONTIGUOUS rows   r   r   r!   r"   r,  )r-  r      r:   r;   r/  )r1  r*     r   r   r   r   r*  )r*  r      r&   r'   r8   r9   )r.  r      rJ   rK   r0     rL   rM   )r   r*  >   r   r   r   r   rP   rQ   rR   rS   >   r   r    r0   r1   r2   r3   r4   r5   r6   r7   rY   rZ   r[   r\   r]   r^   r_   r`   >   rH   rI   >   r   >
   r   r   r(   r)   r*   r+   r,   r-   r.   r/   >   rF   rG   >   r   >   r>   r?   r@   rA   rB   rC   rD   rE   >   rN   rO   >   r   r#   r<   r-  r;  )Conversion from numpy array with format `r>  r   .)r   r   r   r   r   r   )r   r   r   )r   r   r   r   stridesr   rC  ascontiguousarrayrE  rc   rd   _image_fill_pointers_numpy)r   r   r   r   r   	linesizesr4  s          rg   from_numpy_bufferzVideoFrame.from_numpy_bufferx  s	     	Q 	#KNE'''%!,,,u{1~':;;;}QRR F** !QRRRq)+IICCC%1---u{1~':;;;}QRR F** !QRRRq)+II///%A...u{1~':;;;}QRR G++ !QRRRq)+II777%!,,,u{1~':;;;}QRR F** !QRRRq)+IIGGG%1---u{1~':;;;}QRR F** !QRRRq)+II111%A...u{1~':;;;}QRR F** !QRRRq)+II111%A...u{1~':;;;}QRR G++ !QRRRq)+II 	
 	
 	
 %!,,,}Q1$$ !QRRRq)+II 
 
 
( %1---}Q1$$ !QRRRq)+II111%A...}Q1$$ !QRRRq)+IIx%!,,,u{1~':;;;}QRR F** !QRRRa A%a A%a A%II
  
 
 
 %1---u{1~':;;;}QRR F** !QRRRa A%a A%a A%II
 111%A...u{1~':;;;}QRR G++ !QRRRa A%a A%a A%II
 y  %!,,,u{1~':;;;}QRR F** !QRRRa A%a A%a A%a A%	II  	
 	
 	
 %1---u{1~':;;;}QRR F** !QRRRa A%a A%a A%a A%	II 333%A...u{1~':;;;}QRR G++ !QRRRa A%a A%a A%a A%	II 666%!,,,u{1~'9Q'>???u{1~'9Q'>???q[1_F}Q1$$ !QRRR000 M!$M!$)M!$)		 #]1-u}Q/?@		ZFZZZ   W%% 	T((U3;L5MrST)U)UVVEEv&& 	T((U3			>5JBPQ)R)RSSE122((vy&QQQrf   c                    |j         j        }t          j        t          j        t
                   |          }t          |          }t                              t          j	        | j
                             || _        || j        _        || j        _        || j        _        t!          |          D ]\  }	}
|
| j        j        |	<   t                              | j        j        t          j        t          j        | j        j                  | j        j        || j        j                  }|rt)          |           |                                  d S r   )ctypesr   r   r   pointerr   r   rn   r   r   r   r   r   r   r   r   	enumerater   av_image_fill_pointersr   r   r   )r   rL  r   r   ri  r   c_datac_ptrr   r   r   r   s               rg   rh  z%VideoFrame._image_fill_pointers_numpyU  s   * #FN73V<<v&&V^DL11222 !" $Y// 	, 	,KAx#+DHa  ((HMK)48?;;HOH
 
  	cNNN""$$$$$rf   c           	         ddl }i ddddddddd	dd
dddddddddddddddddddddddi ddddddddddddddd d!d"d#d$d#d%d#d&d#d'd#d(d#d)d#d*d#d+d#i d,d#d-d.d/d.d0dd1dd2dd3dd4dd5dd6dd7dd8dd9dd:dd;dd<d=d>d=dd!d#d#ddd!d?                    |d@          \  }}}|T| j        dAk    r| dddddf         } t          | |dB           |s|dCv r|                    | ddA          } t          | | j        dA         |k               t          | |                    dD                    } t          | j        dE         | j        d         |          }|j
        j                            dF          rG|                    | dddddEdBf         | ddddddEf         | dddddBdf         gdAG          } t          |          D ]+}t          | dddd|f         |j        |         |           ,|S |dHk    r| \  } }	t          | dIdA           t          |	dIdA           t          |	|	j        dJk               t          | j        dE         | j        d         |          }t          | |j        d         dE           |j        dE                             |	                    dK                              dL                                                     |S |dMv rt          | dIdA           t          | | j        d         dBz  dk               t          | | j        dE         dAz  dk               t          | j        dE         | j        d         dAz  dBz  |          }|j        |j        z  }
dN|
z  dOz  }|                     dP          }t          |d|
         |j        d         dE           t          ||
|         |j        dE         dE           t          ||d         |j        dA         dE           |S |dQk    rct1          | |j                  r| j        |j        k    rt9          dR          |r)| j        dA         dBk    r|                    | dAd          } n | j        d         dBk    st9          dS          | j        dEd         \  }}|dAz  dk    s	|dAz  dk    rt9          dT          t          |||          }t          | d         |j        d         dA           | dEdddddAf                                         }| dAdddddAf                                         }t          ||j        dE         dA           t          ||j        dA         dA           |S |dUk    rvt          | dIdB           t          | | j        d         dAz  dk               t          | | j        dE         dAz  dk               t          | | j        dA         dAk               nw|dVv r2t          | dIdB           t          | | j        dA         dBk               nA|dWv r2t          | dIdB           t          | | j        dA         dOk               n|dXv rt          | dYdB           t          | | j        dA         dBk               t          | j        dE         | j        d         |          }t          t          | |                    dD                    |j        d         dZ           |S |d[v rt          | d\dB           t          | | j        dA         dBk               t          | j        dE         | j        d         |          }t          t          | |                    dD                    |j        d         d]           |S |d^v rt          | dYdB           t          | | j        dA         dOk               t          | j        dE         | j        d         |          }t          t          | |                    dD                    |j        d         d_           |S |d`v rt          | dadB           t          | | j        dA         dOk               t          | j        dE         | j        d         |          }t          t          | |                    dD                    |j        d         d_           |S |dbv rt          | d\dB           t          | | j        dA         dOk               t          | j        dE         | j        d         |          }t          t          | |                    dD                    |j        d         dc           |S |ddk    rt          | dIdA           t          | | j        d         dBz  dk               t          | | j        dE         dAz  dk               t          | j        dE         | j        d         dAz  dBz  |          }|j        |j        z  }|                     dP          }t          |d|         |j        d         dE           t          ||d         |j        dE         dA           |S t9          de| df          t          | j        dE         | j        d         |          }t          | |j        d         | j        dAk    rdEn| j        dA                    |S )ga  
        Construct a frame from a numpy array.

        :param bool channel_last: If False (default), the shape for the yuv444p and yuvj444p
            is given by (channels, height, width) rather than (height, width, channels).

        .. note:: For formats which expect an array of ``uint16``, ``float16`` or ``float32``,
            the samples must be in the system's native byte order.

        .. note:: for ``pal8``, an ``(image, palette)`` pair must be passed. `palette` must
            have shape (256, 4) and is given in ARGB format (PyAV will swap bytes if needed).

        .. note:: for ``gbrp`` formats, channels are assumed to be given in RGB order.

        r   NrY   )r   r   r,  rZ   rP   )r   r   r   r[   r\   rQ   r]   r^   rR   r_   r`   rS   r   r   )r*  r   r   r>   )r*  r   r,  r?   r@   rA   rB   rC   rD   rE   rN   )r*  r*  r/  rO   r   )r   r   r   r(   )r   r   r,  r)   r*   r+   r,   r-   r.   r/   r   r   rF   )r   r*  r/  rG   r   r0   r1   r2   r3   r4   r5   r6   r7   r   r   r    rH   )r   r*  r/  rI   )r   r$   rU   rV   rW   rX   r=   )NNNr   r   r:  r8  r   r9  r6  r   r   )   r*  r=  r<  r;     r*  r   rT   zArray must be uint16 typez>Array must have shape (3, height, width) or (height, width, 3)zWidth and height must be evenr%   r^  ra  r_  r,  r-  r`  r/  r1  rb  r.  rc  r0  rd  r   r   re  r>  )r   r?  ndimr   rE  r   r   r   r  rc   r   r   rC  rA  r   r   r   r  r   rI  r   r   r   r   
isinstancendarrayr   r,  r   rD  )r   r   rJ  r   channelsr5  r   r4  r   rS  u_startv_startflatr   r   rN  rO  uv_starts                     rg   from_ndarrayzVideoFrame.from_ndarray  s?   " 	;%
.;%
.;%
 ?;%
 .	;%

 .;%
 ?;%
 .;%
 .;%
 ?;%
 .;%
 .;%
 ?;%
 O;%
 _;%
 );%
  )!;%
" )#;%
 ;%
$ )%;%
& )';%
( ));%
* )+;%
, )-;%
. +/;%
0 +1;%
2 O3;%
4 (5;%
6 (7;%
8 (9;%
: (;;%
< (=;%
> (?;%
@ (A;%
B (C;%
D 'E;%
 ;%
 ;%
F 'G;%
H *I;%
J *K;%
L OM;%
N (O;%
P (Q;%
R (S;%
T (U;%
V (W;%
X (Y;%
Z ([;%
\ (];%
^ __;%
` 'a;%
b 'c;%
d *e;%
f *g;%
 ;%
h $&++,,'u;%
 ;%
 ;%
v #f(
)
)w 	"(Ex zQaaaDj)%*** 1F.E$E$EE1a00u{1~'ABBB"5&//$*?*?@@Eu{1~u{1~vFFE| ++E22 aaaAaCi(aaaAaCi(aaaABBh
  '   8__ O O#E!!!QQQ'NELOXNNNNL V"NE7%!,,,'7A...()BCCCu{1~u{1~vFFEu|A:::LO""7<<#6#6#=#=d#C#C#K#K#M#MNNNL...%!,,,u{1~'9Q'>???u{1~'9Q'>???u{1~A0Bq/H&QQEkEL0G'kQ&G==$$DQwYa!DDDWW_ 5u|AJJJWXXQCCCL}$$eRZ00 >EK294L4L !<===  A! 3 3E1a00k!n)) T   "KOMFEqyA~~!q !@AAAuff55Ea%,q/1===aCCaCi %%''AaCCaCi %%''A5<?A6665<?A666Ly  %!,,,u{1~'9Q'>???u{1~'9Q'>???u{1~':;;;;)))%!,,,u{1~':;;;;777%!,,,u{1~':;;;;CCC%1---u{1~':;;;u{1~u{1~vFFEufood&;&;<<el1oq   L///%A...u{1~':;;;u{1~u{1~vFFEufood&;&;<<el1or   LGGG%1---u{1~':;;;u{1~u{1~vFFEufood&;&;<<el1oq   L111%A...u{1~':;;;u{1~u{1~vFFEufood&;&;<<el1oq   L111%A...u{1~':;;;u{1~u{1~vFFEufood&;&;<<el1or   Lv%!,,,u{1~'9Q'>???u{1~'9Q'>???u{1~A0Bq/H&QQE{U\1H==$$DYhYa!DDDXYYa!DDDLZFZZZ   5;q>5;q>6BB5<?qAAek!n	
 	
 	
 rf   r   r   c                    t          |||          }|dk    rt          | |j        d         d||           nM|dv r6t          | |j        d         |                    d          rdnd||           nt	          d| d	          |S )
Nr   r   r*  >   rP   rQ   rR   rS   rY   rZ   r[   r\   r]   r^   r_   r`   8r   r   zFormat 'z' is not supported.)rc   r   r   r  NotImplementedError)r   r   r   r   r   r   r4  s          rg   
from_byteszVideoFrame.from_bytesc  s     5&&11V5<?A     
 
 
  Q__S))0q    &&L&L&L&LMMMrf   N)r   r   r#   )F)r   r   )r   F)r   FF)'rk   rl   rm   r   r   cfuncrn   r   uintr   r   r   r   propertyr   r   r   r   r   r   setterr   r   r  r	  ccallobjectr  r(  rT  rY  staticmethodr\  rj  rh  r}  r&  r   r  re   rf   rg   rc   rc      s       , , , , \%C- %fk %6; % % % \%* \
 
 \
  
 
 
 H H XH(   X   X * * X* C C XC
 " " X" # # # # # X# $ $ $ $ $ X$ % % %
@ 
@ 
@7 7 7 \3V 3 3 3 \36
 
 
<z
 z
 z
 z
x4 4 4   \ Z Z Z \Zx,% ,% ,%\ ] ] ] \]~ 
 $ $$$ $ $ $ \$ $ $rf   rc   r+  )"r   enumr   r   cython.cimports.av.errorr   $cython.cimports.av.sidedata.sidedatar   cython.cimports.av.utilsr   cython.cimports.av.video.formatr   r	   cython.cimports.av.video.planer   cython.cimports.libc.stdintr   r  rd   supported_np_pix_fmtsr  rc   rh   rj   bintr   r  r   r   strr   r   cclassFramere   rf   rg   <module>r     s   



        . . . . . . E E E E E E 2 2 2 2 2 2 I I I I I I I I 5 5 5 5 5 5 / / / / / / U U U p .: . . . .         '       fk     ## [# [	#
 ;# # # #L Hj H6; H H H H
 FM% %%(.%@C% % % %$ Jv J6; J J J J
 } } } } } } } } } }rf   