
    HuiU              	       t   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j0                  fd       Zej(                  dedej4                  dej0                  dej0                  fd       Zej(                  dedej4                  fd       Zej(                  	 ddedej4                  defd       Zej(                  dedej0                  fd       Zej@                   G d de!             Zy)    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     @/opt/pipecat/venv/lib/python3.12/site-packages/av/video/frame.pyalloc_video_framerg   g   s     ,--re   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y)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BIrd   re   rf   ri   ri   r   sZ    ##DAAAA			B			B			Bre   ri   
big_endianc                 R    t         j                  dk(  |k7  r| j                         S | S )Nbig)sys	byteorderbyteswap)arrayr~   s     rf   byteswap_arrayr   }   s%    :-~~Lre   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 ]Y  }||z  }|r=t        d||      D ],  }t        |      D ]  }|||z   |z
  |z
  |z      ||	|z   |z   <    . n||||z    ||	|	|z    |	|
z  }	[ y )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                    rf   copy_bytes_to_planer      s"    '0EE#kkO;HEE!%//2H%~~fjj9IwLL1$		,,Y. 
h1h8 / A+0(1,>B,E%!)a-( /4EEH<L.ME%%(*+
re   c                 B    | j                         }t        |||dd       y )NF)tobytesr   )r   r   r   imgbytess       rf   copy_array_to_planer      s    mmoH%%Gre   dtypec                 (   ddl }t        | j                        }| j                  |z  }|j	                  | |j
                        }||k7  r*|j                  d|      ddd|f   j                  d      }|j                  |j                  |            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   
frombufferuint8reshapeviewr   )r   r   r   nptotal_line_sizeuseful_line_sizearrs          rf   useful_arrayr      s     %(%9O&+kkO&C
--rxx
(C**kk"o.q!4D2D/DEMMbQ88BHHUO$$re   r   okc                 :    |st        d| j                   d      y )NzUnexpected numpy array shape ``)
ValueErrorshape)r   r   s     rf   check_ndarray_shaper      s#    9%++aHII re   c                   H   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j2                  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&y!)'rb   c                 R    |t         u ry t        |      }| j                  |||       y N)rc   r   _init)selfr   r   formatc_formats        rf   	__cinit__zVideoFrame.__cinit__   s(    **&1&&9

8UF+re   r   r   r   c           	         d}t         j                  5  || j                  _        || j                  _        || j                  _        |rb|r`t        j                  | j                  j                  | j                  j                  |||d      }| j                  j                  d   | _
        d d d        |rt        |       | j                          y # 1 sw Y   'xY w)Nr      )r   nogilptrr   r   r   rm   av_image_allocdatalinesize_bufferr   _init_user_attributes)r   r   r   r   ress        rf   r   zVideoFrame._init   s    \\ 	0"DHHN$DHHO$DHHO ((HHMM488#4#4eVVR  $xx}}Q/	0 cN""$!	0 	0s   BCCc                     t        t        j                  t        j                  | j
                  j                        | j
                  j                  | j
                  j                        | _        y r   )	r	   r   castrm   AVPixelFormatr   r   r   r   r   s    rf   r   z VideoFrame._init_user_attributes   s@    &KK))488??;HHNNHHOO
re   c                 v    t         j                  t        j                  | j                               d | _        y r   )rm   av_freepr   addressr   
_np_bufferr   s    rf   __dealloc__zVideoFrame.__dealloc__   s$     	V^^DLL12re   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__rj   ptsr   namer   r   idr   s    rf   __repr__zVideoFrame.__repr__   s\    4>>**+6$((1T[[=M=M<Nazzl!DKK=r$xl!=	
re   c           	         d}t        | j                  j                  j                        D ]:  }| j                  j                  j                  |   j
                  dz   }||k  s9|}< | j                  j                  dk(  rd}d}||k  r=| j                  j                  |   r$|dz  }||k  r| j                  j                  |   r$t        t        |      D cg c]  }t        | |       c}      S c c}w )z:
        A tuple of :class:`.VideoPlane` objects.
        r   r   r      )
r   r   r   nb_componentscompr   r   extended_datatupler
   )r   max_plane_countr   countplane_counts        rf   planeszVideoFrame.planes   s     '(t{{445 	(AKKOO((+11A5E&"'	( ;;v%O"#O+0F0F{0S1K O+0F0F{0S53EFajq)FGGFs   C4c                 .    | j                   j                  S )zWidth of the image, in pixels.)r   r   r   s    rf   r   zVideoFrame.width  s     xx~~re   c                 .    | j                   j                  S )zHeight of the image, in pixels.)r   r   r   s    rf   r   zVideoFrame.height  s     xxre   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    rf   rotationzVideoFrame.rotation  s     $D))re   c                 b    t        | j                  j                  t        j                  z        S )z+Is this frame an interlaced or progressive?)boolr   flagsrm   AV_FRAME_FLAG_INTERLACEDr   s    rf   interlaced_framezVideoFrame.interlaced_frame'  s"     DHHNNS%A%AABBre   c                 .    | j                   j                  S )zReturns an integer that corresponds to the PictureType enum.

        Wraps :ffmpeg:`AVFrame.pict_type`

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

        Wraps :ffmpeg:`AVFrame.colorspace`.

        r   
colorspacer   s    rf   r   zVideoFrame.colorspace;  s     xx"""re   c                 &    || j                   _        y r   r   r   s     rf   r   zVideoFrame.colorspaceD  s    #re   c                 .    | j                   j                  S )zMColor range of frame.

        Wraps :ffmpeg:`AVFrame.color_range`.

        r   color_ranger   s    rf   r   zVideoFrame.color_rangeH  s     xx###re   c                 &    || j                   _        y r   r   r   s     rf   r   zVideoFrame.color_rangeQ  s    $re   c                 x    | j                   st               | _          | j                   j                  | g|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      rf   r  zVideoFrame.reformatU  s;     /1D(t((????re   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   rd   )r  )r   r  s     rf   to_rgbzVideoFrame.to_rgba  s     t}}6G6v66re   filepathc                    |j                  d      rd}n0|j                  d      s|j                  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
                  |_        | j                  |_        |j                  |j                  | j                  |                   |j                  |j                  d             ddd       y# 1 sw Y   yxY w)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           rf   savezVideoFrame.saveo  s     V$Fv&(*;*;G*DFABB"(we%+z*(C(C9 	3V"--gw-GM"&**M#';;M JJ}++DMMM,IJKJJ}++D12	3 	3 	3s   $BC33C<c           	      x   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  r|j                  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   rd   )
PILr  r  r   r   r   r   	bytearray	frombytesbytes)r   r  r  r   r   r   r   r   r   o_sizer   s              rf   to_imagezVideoFrame.to_image  s     	)DMMCCFCJJ1M*/ "'// "'++/ %x 7$V,fn.3EEH<L.ME%%(*+XEXE fn
 EKK.eeUAq
 	
re   c                     | j                   dgi |}ddl}|j                  j                  dv r2|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                  j                  dW      \  }}|h|j                  D cg c]4  }t        |||      j                  |j
                  |j                  dX      6 }}t        |      dYk(  r|d   }	n|j                  |dZ      }	t        |	|j                  j                  j                  d[            }	|	j                  d   dYk(  r|	j                  d      S |j                  j                  j!                  d\      rR|	dddddf   j#                         }
|	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|j%                  |	dd      }	|	S |j                  j                  d^v rp|j'                  t        |j                  d         t        |j                  dY         t        |j                  d         g      j                  dX|j                        S |j                  j                  d_k(  rt        |j                  d   dd`      j                  |j
                  |j                        }t        |j                  dY   dd`      j                  |j
                  |j                  dz        }t        |j                  d   dd`      j                  |j
                  |j                  dz        }|j)                  |ddYZ      }|j)                  |ddYZ      }|r|j+                  |||gdZ      S |j+                  |||gdZ      S |j                  j                  dak(  rt        |j                  d         j                  |j
                  |j                        }|j-                  |j                  dY   db      j/                  dc      j                  dXdY      j1                  |j2                        }||fS |j                  j                  ddk(  rZ|j'                  t        |j                  d         t        |j                  dY   d      g      j                  dX|j                        S t5        de|j                  j                   df      c c}w )haI  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"   yuv422pr$   r;   rS   r   z.the width has to be even for this pixel formatz/the height has to be even for this pixel formatr   )   r   r   rO   r   r   rP   rQ   rR   rY   )r   uint16rX   r[   rZ   r]   r\   r_   r^   r   )r  r   r   )   r)  r   r   r   r%   )   r)  r&   r   r=   r>   r?   r@   rA   rB   rC   rD   rM   )r'  float32rN   r   r'   r(   r)   r*   r+   r,   r-   r.   r   r   rE   rF   r   r/   r0   r1   r2   r3   r4   r5   r6   r   r   r   rG   rH   r   r    r!   r   r   r7   r8   rI   )r+  float16rJ   )r   r,  )   r,  )r   r   )rK   rL   r9   r:   r#   rT   rU   rV   rW   r<   r$   )NNr   r   axisbegbr   r#   r<   >   r"   r&  r;   rS   r)  r   i4>i4r   z'Conversion to numpy array with format `` is not yet supportedrd   )r  r   r   r   r   r   getr   r   r   lenconcatenater   r  r   squeeze
startswithcopymoveaxishstackrepeatstackr   astyper   r   r   )r   channel_lastr  framer   itemsizer   planlayersr   bufferyuvu_fullv_fullimagepalettes                     rf   
to_ndarrayzVideoFrame.to_ndarray  sa   , *DMM3F3 << !
 
 ;;?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
$ 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
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
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
J )(''#(())$#_P
` #ell
.a 	%b 
 "LL	  T8U3;;LL%++rF  6{aq	vA6"5%,,*;*;*D*DT*JKE{{1~"}}Q''||  ++E2q!Qw,,.!&q!QwaAg!&q!QwaAg!'aAgELL$5$59P$PE1a0L << BB99 a1 a1 a1 gb%++&' <<-U\\!_a:BBekkA U\\!_a:BBekkQ.A U\\!_a:BBekkQ.A
 YYq!!Y,FYYq!!Y,FxxFF 3!x<<88Q/a888<<& a199%,,TEell1ot4Qbhh	  '>!<<&99 a1 a!4
 gb%++&' 5ell6G6G5HH^_
 	
Es   ;9Wc                 x    |j                   dk7  r|j                  d      }t        || j                  d   d       y)z6
        Update content from a ``PIL.Image``.
        r  r   r  N)modeconvertr   r   )r   imgs     rf   	set_imagezVideoFrame.set_imagek  s2     88u++e$CCQ3re   c                 v    t        | j                  d   | j                  d   d      }|j                  |        |S )z9
        Construct a frame from a ``PIL.Image``.
        r   r   r   )rb   sizerT  )rS  rC  s     rf   
from_imagezVideoFrame.from_imaget  s3    
 'sxx{CHHQKIre   c                 *   ddl }| j                  d   }|s| j                  d   }|dv rXt        | dd       t        | | j                  d   dk(         | j                  dd dk7  rt        d	      | j                  d   f}n|d
v rXt        | dd       t        | | j                  d   dk(         | j                  dd dk7  rt        d	      | j                  d   f}n|dv rXt        | dd       t        | | j                  d   dk(         | j                  dd dk7  rt        d	      | j                  d   f}nA|dv rXt        | dd       t        | | j                  d   dk(         | j                  dd dk7  rt        d	      | j                  d   f}n|dv rXt        | dd       t        | | j                  d   dk(         | j                  dd dk7  rt        d	      | j                  d   f}n|dv rXt        | dd       t        | | j                  d   dk(         | j                  dd dk7  rt        d	      | j                  d   f}n-|dv rXt        | dd       t        | | j                  d   dk(         | j                  dd dk7  rt        d	      | j                  d   f}n|dv r<t        | dd       | j                  d   dk7  rt        d	      | j                  d   f}n|dv r<t        | dd       | j                  d   dk7  rt        d	      | j                  d   f}nQ|dv r<t        | dd       | j                  d   dk7  rt        d	      | j                  d   f}n|dv r}t        | dd       t        | | j                  d   dk(         | j                  dd dk7  rt        d	      | j                  d   dz  | j                  d   dz  | j                  d   dz  f}n|dv r}t        | dd       t        | | j                  d   dk(         | j                  dd dk7  rt        d	      | j                  d   dz  | j                  d   dz  | j                  d   dz  f}n|dv r}t        | dd       t        | | j                  d   dk(         | j                  dd dk7  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k7  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k7  rt        d	      | j                  d   dz  | j                  d   dz  | j                  d   dz  | j                  d   dz  f}nj|d!v rt        | dd       t        | | j                  d   dk(         | j                  dd dk7  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k7  rt        d	      |d$v r3| j                  d   | j                  d   dz  | j                  d   dz  f}n.| j                  d   | j                  d   f}nt        d%| d&      |j                  d'      r*|j                  |j                  | d(g d)f   d*d            } n:|j                  d+      r)|j                  |j                  | d(g d,f   d*d            } t        t              }|j                  | ||||       |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      r9   r:   r,  )r.  r'     r   r   r   r   r'  )r'  r      r%   r&   r7   r8   )r+  r      rI   rJ   r-     rK   rL   )r   r'  >   r   r   r   r   rO   rP   rQ   rR   >   r   r   r/   r0   r1   r2   r3   r4   r5   r6   rX   rY   rZ   r[   r\   r]   r^   r_   >   rG   rH   >   r   >
   r   r   r'   r(   r)   r*   r+   r,   r-   r.   >   rE   rF   >   r   >   r=   r>   r?   r@   rA   rB   rC   rD   >   rM   rN   >   r   r"   r;   r*     r"   r;   )Conversion from numpy array with format `r6  r   .)r   r   r   r  r   r   )r   r   r   )r   r   r   r   stridesr   r;  ascontiguousarrayr=  rb   rc   _image_fill_pointers_numpy)r   r   r   r   r   	linesizesrC  s          rf   from_numpy_bufferzVideoFrame.from_numpy_buffer~  sf     	QKKNE''%!,u{{1~':;}}QR F* !QRRq)+ICC%1-u{{1~':;}}QR F* !QRRq)+I//%A.u{{1~':;}}QR G+ !QRRq)+I77%!,u{{1~':;}}QR F* !QRRq)+IGG%1-u{{1~':;}}QR F* !QRRq)+I11%A.u{{1~':;}}QR F* !QRRq)+I11%A.u{{1~':;}}QR G+ !QRRq)+I 	
 	
 %!,}}Q1$ !QRRq)+I 
 
( %1-}}Q1$ !QRRq)+I11%A.}}Q1$ !QRRq)+Ix%!,u{{1~':;}}QR F* !QRRa A%a A%a A%I
  
 
 %1-u{{1~':;}}QR F* !QRRa A%a A%a A%I
 11%A.u{{1~':;}}QR G+ !QRRa A%a A%a A%I
 y %!,u{{1~':;}}QR F* !QRRa A%a A%a A%a A%	I  	
 	
 %1-u{{1~':;}}QR F* !QRRa A%a A%a A%a A%	I 33%A.u{{1~':;}}QR G+ !QRRa A%a A%a A%a A%	I 66%!,u{{1~'9Q'>?u{{1~'9Q'>?q[1_F}}Q1$ !QRR00 MM!$MM!$)MM!$)	 #]]1-u}}Q/?@	;F8CYZ  W%((U3;L5MrST)UVEv&((U3	>5JBPQ)RSE12((vy&Qre   c                    |j                   j                  }t        j                  t        j                  t
           |      }t        |      }t        j                  t        j                  | j                               || _        || j                  _        || j                  _        || j                  _        t!        |      D ]  \  }	}
|
| j                  j"                  |	<     t        j%                  | j                  j                  t        j                  t        j&                  | j                  j                        | j                  j                  || j                  j"                        }|rt)        |       | j+                          y r   )ctypesr   r   r   pointerr   r   rm   r   r   r   r   r   r   r   r   	enumerater   av_image_fill_pointersr   r   r   )r   rG  r   r   re  r   c_datac_ptrr   r   r   r   s               rf   rd  z%VideoFrame._image_fill_pointers_numpy[  s   * ##FNN73V<v&V^^DLL12 !" $Y/ 	,KAx#+DHHa 	, ((HHMMKK))488??;HHOOHH
 cN""$re   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?j                  |d@      \  }}}|4| j                  dAk(  r| dddddf   } t        | |dB       |s|dCv r|j	                  | ddA      } t        | | j                  dA   |k(         t        | |j                  dD            } t        | j                  dE   | j                  d   |      }|j                  j                  j                  dF      r:|j                  | 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   j#                  |	j%                  dK      j'                  dL      j)                                |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  }| j/                  dP      }t        |d|
 |j                   d   dE       t        ||
| |j                   dE   dE       t        ||d |j                   dA   dE       |S |dQk(  r t        | dIdA       t        | | j                  d   dOz  dk(         t        | | j                  dE   dAz  dk(         t        | j                  dE   | j                  d   dAz  |      }|j*                  |j,                  z  }
|
|
dAz  z   }| j/                  dP      }t        |d|
 |j                   d   dE       t        ||
| |j                   dE   dE       t        ||d |j                   dA   dE       |S |dRk(  rBt1        | |j2                        r| j4                  |j6                  k7  rt9        dS      |r&| j                  dA   dBk(  r|j	                  | dAd      } n| j                  d   dBk(  st9        dT      | j                  dEd \  }}|dAz  dk7  s|dAz  dk7  rt9        dU      t        |||      }t        | d   |j                   d   dA       | dEdddddAf   j;                         }| dAdddddAf   j;                         }t        ||j                   dE   dA       t        ||j                   dA   dA       |S |dVk(  rit        | dIdB       t        | | j                  d   dAz  dk(         t        | | j                  dE   dAz  dk(         t        | | j                  dA   dAk(         n|dWv r+t        | dIdB       t        | | j                  dA   dBk(         n|dXv r+t        | dIdB       t        | | j                  dA   dOk(         n|dYv rt        | dZdB       t        | | j                  dA   dBk(         t        | j                  dE   | j                  d   |      }t        t        | |j                  dD            |j                   d   d[       |S |d\v rt        | d]dB       t        | | j                  dA   dBk(         t        | j                  dE   | j                  d   |      }t        t        | |j                  dD            |j                   d   d^       |S |d_v rt        | dZdB       t        | | j                  dA   dOk(         t        | j                  dE   | j                  d   |      }t        t        | |j                  dD            |j                   d   d`       |S |dav rt        | dbdB       t        | | j                  dA   dOk(         t        | j                  dE   | j                  d   |      }t        t        | |j                  dD            |j                   d   d`       |S |dcv rt        | d]dB       t        | | j                  dA   dOk(         t        | j                  dE   | j                  d   |      }t        t        | |j                  dD            |j                   d   dd       |S |dek(  rt        | dIdA       t        | | j                  d   dBz  dk(         t        | | j                  dE   dAz  dk(         t        | j                  dE   | j                  d   dAz  dBz  |      }|j*                  |j,                  z  }| j/                  dP      }t        |d| |j                   d   dE       t        ||d |j                   dE   dA       |S t9        df| dg      t        | j                  dE   | j                  d   |      }t        | |j                   d   | j                  dAk(  rdE       |S | j                  dA          |S )ha  
        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   NrX   )r   r   r)  rY   rO   )r   r   r   rZ   r[   rP   r\   r]   rQ   r^   r_   rR   r   r   )r'  r   r   r=   )r'  r   r)  r>   r?   r@   rA   rB   rC   rD   rM   )r'  r'  r,  rN   r   )r  r   r   r'   )r  r   r)  r(   r)   r*   r+   r,   r-   r.   r   r   rE   )r  r'  r,  rF   r   r/   r0   r1   r2   r3   r4   r5   r6   r   r   r   rG   )r   r'  r,  rH   )r   r#   rT   rU   rV   rW   r<   )NNNr   r  r3  r1  r   r2  r/  r   r   )   r'  r5  r4  r`     r'  r   r&  rS   zArray must be uint16 typez>Array must have shape (3, height, width) or (height, width, 3)zWidth and height must be evenr$   rY  r\  rZ  r)  r*  r[  r,  r.  r]  r+  r^  r-  r_  r   r   ra  r6  )r   r7  ndimr   r=  r   r   r   r  rb   r   r   r;  r9  r   r   r   r  r   rA  r   r   r   r   
isinstancendarrayr   r)  r   r<  )r   r   rB  r   channelsrD  r   rC  r   rN  u_startv_startflatr   r   rI  rJ  uv_starts                     rf   from_ndarrayzVideoFrame.from_ndarray  sW   " 	;%
.;%
.;%
 ?;%
 .	;%

 .;%
 ?;%
 .;%
 .;%
 ?;%
 .;%
 .;%
 ?;%
 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 zzQaDj)%*F.E$EE1a0u{{1~'AB"5&//$*?@Eu{{1~u{{1~vFE||  ++E2aAaCi(aAaCi(aABh
  '  8_ O#E!Q'NELLOXNOL V"NE7%!,'7A.()BCu{{1~u{{1~vFEu||A:LLO""7<<#6#=#=d#C#K#K#MNL..%!,u{{1~'9Q'>?u{{1~'9Q'>?u{{1~A0Bq/H&QEkkELL0G'kQ&G==$DQwa!DWW 5u||AJWXQCLy %!,u{{1~'9Q'>?u{{1~'9Q'>?u{{1~u{{1~/BFKEkkELL0G1,G==$DQwa!DWW 5u||AJWXQCL}$eRZZ0EKK2994L !<== A! 3E1a0kk!n) T  "KKOMFEqyA~!q !@AAuff5Ea%,,q/1=aCaCi %%'AaCaCi %%'A5<<?A65<<?A6Ly %!,u{{1~'9Q'>?u{{1~'9Q'>?u{{1~':;))%!,u{{1~':;77%!,u{{1~':;CC%1-u{{1~':;u{{1~u{{1~vFEufood&;<ell1oq L//%A.u{{1~':;u{{1~u{{1~vFEufood&;<ell1or LGG%1-u{{1~':;u{{1~u{{1~vFEufood&;<ell1oq L11%A.u{{1~':;u{{1~u{{1~vFEufood&;<ell1oq L11%A.u{{1~':;u{{1~u{{1~vFEufood&;<ell1or Lv%!,u{{1~'9Q'>?u{{1~'9Q'>?u{{1~A0Bq/H&QE{{U\\1H==$DYha!DXYa!DL;F8CYZ  5;;q>5;;q>6B5<<?qA	
  ?Dkk!n	
 re   r   c                     t        |||      }|dk(  rt        | |j                  d   d||       |S |dv r1t        | |j                  d   |j                  d      rdnd||       |S t	        d| d	      )
Nr   r   r'  >   rO   rP   rQ   rR   rX   rY   rZ   r[   r\   r]   r^   r_   8r   r   zFormat 'z' is not supported.)rb   r   r   r  NotImplementedError)r   r   r   r   r   r   rC  s          rf   
from_byteszVideoFrame.from_bytesv  s     5&&1V5<<?A4 /  
 
  Q__S)q  &8K&LMMre   N)r   r   r"   )F)r   r   )r   F)r   FF)'rj   rk   rl   r   r   cfuncrm   r   uintr   r   r   r   propertyr   r   r   r   r   r   setterr   r   r  r  ccallobjectr  r$  rO  rT  staticmethodrW  rf  rd  ry  r"  r   r}  rd   re   rf   rb   rb      s   , \\%C-- %fkk %6;; % %* \\
 

 H H(     * * C C
 " " # # # # $ $ $ $ % %
@7 \\3V 3 36
<@
D4   Z Zx,%\ j jX 
 $$$ $ $re   rb   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  rc   supported_np_pix_fmtsr~  rb   rg   ri   bintr   r  r   r   strr   r   cclassFramerd   re   rf   <module>r     s   
   . E 2 I 5 / U p .: . . '   fkk   ## [[# [[	#
 ;;# #L Hj H6;; H H
 FM%%(.%@C% %$ Jv J6;; J J
 P P Pre   