
    C1iU              	          S SK r S SKJr  S SKrS SKJr  S SKJr  S SKJ	r	  S SK
JrJr  S SKJr  S SKJr  \" 5       r1 S	kr\R(                  S
\4S j5       r " S S\5      r\R(                  S\R0                  4S j5       r\R(                  S\S\R4                  S\R0                  S\R0                  4S j5       r\R(                  S\S\R4                  4S j5       r\R(                   SS\S\R4                  S\4S jj5       r\R(                  S\S\R0                  4S j5       r\R@                   " S S\!5      5       rg)    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                       [        [        5      $ )zGet a mostly uninitialized VideoFrame.

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

)
VideoFrame_cinit_bypass_sentinel     H/home/james-whalen/.local/lib/python3.13/site-packages/av/video/frame.pyalloc_video_framerg   g   s     ,--re   c                       \ rS rSr\R
                  r\R                  r\R                  r
\R                  r\R                  r\R                  r\R"                  r\R&                  rSrg)PictureTyper   rd   N)__name__
__module____qualname____firstlineno__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BI__static_attributes__rd   re   rf   ri   ri   r   sZ    ##DAAAA			B			B			Bre   ri   
big_endianc                 T    [         R                  S:H  U:w  a  U R                  5       $ U $ )Nbig)sys	byteorderbyteswap)arrayr   s     rf   byteswap_arrayr   }   s%    :-~~Lre   planebytes_per_pixelflip_horizontalflip_verticalc                    U nSnUR                   U-  nUnSn	[        UR                  5      n
[        R                  " [        R
                  5      u  pnU(       a  UR                  S-
  nSnSnOSnUR                  nSn[        XU5       HZ  nX-  nU(       a>  [        SXr5       H-  n[        U5       H  nUXg-   U-
  U-
  U-      XU-   U-   '   M     M/     O
XVXg-    XX-   & X-  n	M\     g )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ILL1$		,,Y.1h8/A+0(1,>B,E!)a-( 0 9 /4E<L.ME%*+ /re   c                 @    U R                  5       n[        X1USS5        g )NF)tobytesr   )r   r   r   imgbytess       rf   copy_array_to_planer      s    mmoH%Gre   dtypec                 &   SSK n[        U R                  5      nU R                  U-  nUR	                  XR
                  5      nXE:w  a*  UR                  SU5      SS2SU24   R                  S5      nUR                  UR                  U5      5      $ )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
--xx
(C*kk"o.q!4D2D/DEMMbQ88BHHUO$$re   r   okc                 D    U(       d  [        SU R                   S35      eg )NzUnexpected numpy array shape ``)
ValueErrorshape)r   r   s     rf   check_ndarray_shaper      s#    9%++aHII re   c                   `   \ rS rSrS$S jr\R                  S\R                  S\R                  S\R                  4S j5       r
\R                  S 5       rS rS	 r\S
 5       r\S 5       r\S 5       r\S 5       r\S 5       r\S 5       r\R*                  S 5       r\S 5       r\R*                  S 5       r\S 5       r\R*                  S 5       rS rS r\R4                  S\4S j5       rS rS%S jrS r\ S 5       r!\ S&S j5       r"S r#\ S'S j5       r$\    S(S \%S\&S\&4S! jj5       r'S"r(g#))rb      c                 R    U[         L a  g [        U5      nU R                  XAU5        g N)rc   r   _init)selfr   r   formatc_formats        rf   	__cinit__VideoFrame.__cinit__   s&    **&1&&9

8F+re   r   r   r   c           	         Sn[         R                     X R                  l        X0R                  l        XR                  l        U(       af  U(       a_  [        R                  U R                  R                  U R                  R                  X#US5      nU R                  R                  S   U l
        S S S 5        U(       a  [        U5        U R                  5         g ! , (       d  f       N1= f)Nr      )r   nogilptrr   r   r   ro   av_image_allocdatalinesize_bufferr   _init_user_attributes)r   r   r   r   ress        rf   r   VideoFrame._init   s    \\"HHN$HHO$HHO ((HHMM488#4#4eVR  $xx}}Q/  cN""$! \s   BC
C*c                     [        [        R                  " [        R                  U R
                  R                  5      U R
                  R                  U R
                  R                  5      U l        g r   )	r	   r   castro   AVPixelFormatr   r   r   r   r   s    rf   r    VideoFrame._init_user_attributes   s@    &KK))488??;HHNNHHOO
re   c                 x    [         R                  [        R                  " U R                  5      5        S U l        g r   )ro   av_freepr   addressr   
_np_bufferr   s    rf   __dealloc__VideoFrame.__dealloc__   s$     	V^^DLL12re   c                     SU R                   R                   SU R                   SU R                  R                   SU R
                   SU R                   S[        U 5      S S3$ )Nz<av.z, pts= xz at 0x>)	__class__rk   ptsr   namer   r   idr   s    rf   __repr__VideoFrame.__repr__   s\    4>>**+6$((1T[[=M=M<Nazzl!DKK=r$xl!=	
re   c           	         Sn[        U R                  R                  R                  5       H<  nU R                  R                  R                  U   R
                  S-   nX:  d  M:  UnM>     U R                  R                  S:X  a  SnSnXA:  aH  U R                  R                  U   (       a*  US-  nXA:  a   U R                  R                  U   (       a  M*  [        [        U5       Vs/ s H  n[        X5      PM     sn5      $ s  snf )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   planesVideoFrame.planes   s     '(t{{445AKKOO((+11A5E&"' 6 ;;v%O"#+0F0F{0S1K +0F0F{0S0S53EF3Eaj)3EFGGFs   )Dc                 .    U R                   R                  $ )zWidth of the image, in pixels.)r   r   r   s    rf   r   VideoFrame.width  s     xx~~re   c                 .    U R                   R                  $ )zHeight of the image, in pixels.)r   r   r   s    rf   r   VideoFrame.height  s     xxre   c                     [        U 5      $ )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   rotationVideoFrame.rotation  s     $D))re   c                 b    [        U R                  R                  [        R                  -  5      $ )z+Is this frame an interlaced or progressive?)boolr   flagsro   AV_FRAME_FLAG_INTERLACEDr   s    rf   interlaced_frameVideoFrame.interlaced_frame'  s"     DHHNNS%A%AABBre   c                 .    U R                   R                  $ )zlReturns an integer that corresponds to the PictureType enum.

Wraps :ffmpeg:`AVFrame.pict_type`

:type: int
r   	pict_typer   s    rf   r   VideoFrame.pict_type-  s     xx!!!re   c                 $    XR                   l        g r   r   r   values     rf   r   r  7  s    "re   c                 .    U R                   R                  $ )z;Colorspace of frame.

Wraps :ffmpeg:`AVFrame.colorspace`.

r   
colorspacer   s    rf   r  VideoFrame.colorspace;  s     xx"""re   c                 $    XR                   l        g r   r  r  s     rf   r  r  D  s    #re   c                 .    U R                   R                  $ )z=Color range of frame.

Wraps :ffmpeg:`AVFrame.color_range`.

r   color_ranger   s    rf   r  VideoFrame.color_rangeH  s     xx###re   c                 $    XR                   l        g r   r  r  s     rf   r  r  Q  s    $re   c                     U R                   (       d  [        5       U l         U R                   R                  " U /UQ70 UD6$ )zreformat(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  VideoFrame.reformatU  s9     /1D((????re   c                 *    U R                   " SSS0UD6$ )zGet 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_rgbVideoFrame.to_rgba  s     }}6G6v66re   filepathc           	      &   UR                  S5      (       a  SnO:UR                  S5      (       d  UR                  S5      (       a  SnO[        S5      eU(       a  SOSnU(       a  S	OS
nSSKJn  U" USSS0S9 nUR	                  X4S9nU R
                  Ul        U R                  Ul        UR                  UR                  U R                  US95      5        UR                  UR                  S5      5        SSS5        g! , (       d  f       g= f)z@Save 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   saveVideoFrame.saveo  s     V$$Fv&&(*;*;G*D*DFABB"(we%+z*(C(C9V"--g-GM"&**M#';;M JJ}++DMMM,IJKJJ}++D12 :99s   :A?D
Dc           	      n   SSK Jn  U R                  " S	SS0UD6R                  S   nUnSnUR                  nSnUR
                  S-  nUR                  U-  n	[        U	5      n
Xy:  a  XEXX-    XXx-   & XV-  nXx-  nXy:  a  M  UR                  SUR
                  UR                  4[        U
5      SSSS5      $ )
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_imageVideoFrame.to_image  s     	 MMCCFCJJ1M*/ "'// "'++/ %x 7$V,n.3E<L.ME%*+EE n
 EKK.eeUAq
 	
re   c                    U R                   " Sg0 UD6nSSKnUR                  R                  S;   a4  UR                  S-  S:X  d   S5       eUR
                  S-  S:X  d   S5       e0 SS_S	S_S
S_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_0 SS_SS_SS _S!S _S"S_S#S_S$S_S%S_S&S_S'S_S(S_S)S_S*S_S+S,_S-S,_S.S_S/S_E0 S0S_S1S_S2S_S3S_S4S_S5S_S6S_S7S_S8S_S9S,_S:S,_S;S_S<S_S=S_S>S_S?S_S@S_E0 SAS_SBS_SCS_SDS_SES_SFS_SGS,_SHS,_SIS_SJS_SKS_SLS_SMS_SNS _SOS _SPSQ_SRSQ_ESSSSSTSTSSSSSSSUSV.ER                  UR                  R                  SW5      u  pVUGbs  UR                   Vs/ s H4  n[        XuU5      R                  UR
                  UR                  SX5      PM6     nn[        U5      SY:X  a  US   n	OUR                  USSZ9n	[        XR                  R                  R                  S[5      5      n	U	R                  S   SY:X  a  U	R                  S5      $ UR                  R                  R!                  S\5      (       aQ  U	SS2SS2S4   R#                  5       n
U	SS2SS2S4   U	SS2SS2S4'   U	SS2SS2SY4   U	SS2SS2S4'   XSS2SS2SY4'   U(       d-  UR                  R                  S];   a  UR%                  U	SS5      n	U	$ UR                  R                  S^;   ap  UR'                  [        UR                  S   5      [        UR                  SY   5      [        UR                  S   5      /5      R                  SXUR                  5      $ UR                  R                  S_:X  Ga  [        UR                  S   SS`5      R                  UR
                  UR                  5      n[        UR                  SY   SS`5      R                  UR
                  UR                  S-  5      n[        UR                  S   SS`5      R                  UR
                  UR                  S-  5      nUR)                  USSYSZ9nUR)                  USSYSZ9nU(       a  UR+                  XU/SSZ9$ UR+                  XU/SSZ9$ UR                  R                  Sa:X  a  [        UR                  S   5      R                  UR
                  UR                  5      nUR-                  UR                  SY   Sb5      R/                  Sc5      R                  SXSY5      R1                  UR2                  5      nUU4$ UR                  R                  Sd:X  aZ  UR'                  [        UR                  S   5      [        UR                  SY   S5      /5      R                  SXUR                  5      $ [5        SeUR                  R                   Sf35      es  snf )ha  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   )r0  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   rA  )   rA  )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_ndarrayVideoFrame.to_ndarray  s[   , !MM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	 )D TU3;;LL%++r )	   6{aq	vA6"5,,*;*;*D*DT*JKE{{1~"}}Q''||  ++E2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F 3!x<<88Q/a888<<& a199%,,TEell1ot4Qbhh	  '>!<<&99 a1 a!4
 gb%++&' 5ell6G6G5HH^_
 	
Es   ?;Wc                 x    UR                   S:w  a  UR                  S5      n[        XR                  S   S5        g)z&
Update content from a ``PIL.Image``.
r1  r   r0  N)modeconvertr   r   )r   imgs     rf   	set_imageVideoFrame.set_imagek  s0     88u++e$CCQ3re   c                 v    [        U R                  S   U R                  S   S5      nUR                  U 5        U$ )z)
Construct a frame from a ``PIL.Image``.
r   r   r   )rb   sizerj  )ri  rX  s     rf   
from_imageVideoFrame.from_imaget  s3    
 'sxx{CHHQKIre   c                    SSK nU R                  S   nU(       d  U R                  S   nUS;   aX  [        U SS5        [        X R                  S   S:H  5        U R                  SS S:w  a  [        S	5      eU R                  S   4nGOUS
;   aX  [        U SS5        [        X R                  S   S:H  5        U R                  SS S:w  a  [        S	5      eU R                  S   4nGOUS;   aX  [        U SS5        [        X R                  S   S:H  5        U R                  SS S:w  a  [        S	5      eU R                  S   4nGOaUS;   aX  [        U SS5        [        X R                  S   S:H  5        U R                  SS S:w  a  [        S	5      eU R                  S   4nGOUS;   aX  [        U SS5        [        X R                  S   S:H  5        U R                  SS S:w  a  [        S	5      eU R                  S   4nGOUS;   aX  [        U SS5        [        X R                  S   S:H  5        U R                  SS S:w  a  [        S	5      eU R                  S   4nGOGUS;   aX  [        U SS5        [        X R                  S   S:H  5        U R                  SS S:w  a  [        S	5      eU R                  S   4nGOUS;   a=  [        U SS5        U R                  S   S:w  a  [        S	5      eU R                  S   4nGOUS;   a=  [        U SS5        U R                  S   S:w  a  [        S	5      eU R                  S   4nGOcUS;   a=  [        U SS5        U R                  S   S:w  a  [        S	5      eU R                  S   4nGO US;   a}  [        U SS5        [        X R                  S   S:H  5        U R                  SS S:w  a  [        S	5      eU R                  S   S-  U R                  S   S-  U R                  S   S-  4nGOUS;   a}  [        U SS5        [        X R                  S   S:H  5        U R                  SS S:w  a  [        S	5      eU R                  S   S-  U R                  S   S-  U R                  S   S-  4nGOUS;   a}  [        U SS5        [        X R                  S   S:H  5        U R                  SS S:w  a  [        S	5      eU R                  S   S-  U R                  S   S-  U R                  S   S-  4nGOUS;   a  [        U SS5        [        X R                  S   S:H  5        U R                  SS S:w  a  [        S	5      eU R                  S   S-  U R                  S   S-  U R                  S   S-  U R                  S   S-  4nGOUS ;   a  [        U SS5        [        X R                  S   S:H  5        U R                  SS S:w  a  [        S	5      eU R                  S   S-  U R                  S   S-  U R                  S   S-  U R                  S   S-  4nGOoUS!;   a  [        U SS5        [        X R                  S   S:H  5        U R                  SS S:w  a  [        S	5      eU R                  S   S-  U R                  S   S-  U R                  S   S-  U R                  S   S-  4nOUS";   a  [        U SS5        [        X R                  S   S-  S:H  5        [        X R                  S   S-  S:H  5        US#-  S-  nU R                  S   S:w  a  [        S	5      eUS$;   a3  U R                  S   U R                  S   S-  U R                  S   S-  4nO.U R                  S   U R                  S   4nO[        S%U S&35      eUR                  S'5      (       a*  UR                  UR                  U S(/ S)Q4   S*S5      5      n O?UR                  S+5      (       a)  UR                  UR                  U S(/ S,Q4   S*S5      5      n [        [        5      nUR                  XXEU5        U$ )-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   r0  r   )r0  r   z.provided array does not have C_CONTIGUOUS rows   r   r   r    r!   r>  )r?  r      r9   r:   rA  )rC  r<     r   r   r   r   r<  )r<  r      r%   r&   r7   r8   )r@  r      rI   rJ   rB     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 `rK  r   .)r   r   r   r0  r   r   )r   r   r   )r   r   r   r   stridesr   rP  ascontiguousarrayrR  rb   rc   _image_fill_pointers_numpy)r   r   r   r   r   	linesizesrX  s          rf   from_numpy_bufferVideoFrame.from_numpy_buffer~  sJ     	QKKNE''%!,{{1~':;}}QR F* !QRRq)+ICC%1-{{1~':;}}QR F* !QRRq)+I//%A.{{1~':;}}QR G+ !QRRq)+I77%!,{{1~':;}}QR F* !QRRq)+IGG%1-{{1~':;}}QR F* !QRRq)+I11%A.{{1~':;}}QR F* !QRRq)+I11%A.{{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%!,{{1~':;}}QR F* !QRRa A%a A%a A%I
  
 
 %1-{{1~':;}}QR F* !QRRa A%a A%a A%I
 11%A.{{1~':;}}QR G+ !QRRa A%a A%a A%I
 y %!,{{1~':;}}QR F* !QRRa A%a A%a A%a A%	I  	
 	
 %1-{{1~':;}}QR F* !QRRa A%a A%a A%a A%	I 33%A.{{1~':;}}QR G+ !QRRa A%a A%a A%a A%	I 66%!,{{1~'9Q'>?{{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((v&Qre   c                 $   UR                   R                  n[        R                  " [        R                  [
           U5      n[        U5      n[        R                  [        R                  " U R                  5      5        Xl        XR                  l        X R                  l        X0R                  l        [!        U5       H  u  pXR                  R"                  U	'   M     [        R%                  U R                  R                  [        R                  " [        R&                  U R                  R                  5      U R                  R                  UU R                  R"                  5      nU(       a  [)        U5        U R+                  5         g r   )ctypesr   r   r   pointerr   r   ro   r   r   r   r   r   r   r   r   	enumerater   av_image_fill_pointersr   r   r   )r   r\  r   r   r}  r   c_datac_ptrr   r   r   r   s               rf   r|  %VideoFrame._image_fill_pointers_numpy[  s    * ##FNN73V<v&V^^DLL12 !" $Y/KA#+HHa  0 ((HHMMKK))488??;HHOOHH
 cN""$re   c           	         SSK n0 SS_SS_SS_SS_S	S_S
S_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_SS_0 SS_SS_SS_SS_SS_SS_SS_S S!_S"S#_S$S#_S%S#_S&S#_S'S#_S(S#_S)S#_S*S#_S+S#_E0 S,S#_S-S._S/S._S0S_S1S_S2S_S3S_S4S_S5S_S6S_S7S_S8S_S9S_S:S_S;S_S<S=_S>S=_ESS!S#S#SSS!S?.ER                  US@5      u  pEnUGb=  U R                  SA:X  a  U SS2SS2S4   n [        XSB5        U(       d  USC;   a  UR	                  U SSA5      n [        X R                  SA   U:H  5        [        XR                  SD5      5      n [        U R                  SE   U R                  S   U5      nUR                  R                  R                  SF5      (       a7  UR                  U SS2SS2SESB24   U SS2SS2SSE24   U SS2SS2SBS24   /SASG9n [        U5       H'  n[        U SS2SS2U4   UR                   U   U5        M)     U$ USH:X  a  U u  p	[        U SISA5        [        U	SISA5        [        XR                  SJ:H  5        [        U R                  SE   U R                  S   U5      n[        XR                   S   SE5        UR                   SE   R#                  U	R%                  SK5      R'                  SL5      R)                  5       5        U$ USM;   a  [        U SISA5        [        X R                  S   SB-  S:H  5        [        X R                  SE   SA-  S:H  5        [        U R                  SE   U R                  S   SA-  SB-  U5      nUR*                  UR,                  -  n
SNU
-  SO-  nU R/                  SP5      n[        USU
 UR                   S   SE5        [        XU UR                   SE   SE5        [        XS UR                   SA   SE5        U$ USQ:X  a  [        U SISA5        [        X R                  S   SO-  S:H  5        [        X R                  SE   SA-  S:H  5        [        U R                  SE   U R                  S   SA-  U5      nUR*                  UR,                  -  n
XSA-  -   nU R/                  SP5      n[        USU
 UR                   S   SE5        [        XU UR                   SE   SE5        [        XS UR                   SA   SE5        U$ USR:X  GaM  [1        XR2                  5      (       a  U R4                  UR6                  :w  a  [9        SS5      eU(       a'  U R                  SA   SB:X  a  UR	                  U SAS5      n OU R                  S   SB:X  d  [9        ST5      eU R                  SES u  pUSA-  S:w  d	  USA-  S:w  a  [9        SU5      e[        XU5      n[        U S   UR                   S   SA5        U SESS2SSSA24   R;                  5       nU SASS2SSSA24   R;                  5       n[        XR                   SE   SA5        [        UUR                   SA   SA5        U$ USV:X  af  [        U SISB5        [        X R                  S   SA-  S:H  5        [        X R                  SE   SA-  S:H  5        [        X R                  SA   SA:H  5        GOUSW;   a*  [        U SISB5        [        X R                  SA   SB:H  5        GOUSX;   a*  [        U SISB5        [        X R                  SA   SO:H  5        GOUSY;   a  [        U SZSB5        [        X R                  SA   SB:H  5        [        U R                  SE   U R                  S   U5      n[        [        XR                  SD5      5      UR                   S   S[5        U$ US\;   a  [        U S]SB5        [        X R                  SA   SB:H  5        [        U R                  SE   U R                  S   U5      n[        [        XR                  SD5      5      UR                   S   S^5        U$ US_;   a  [        U SZSB5        [        X R                  SA   SO:H  5        [        U R                  SE   U R                  S   U5      n[        [        XR                  SD5      5      UR                   S   S`5        U$ USa;   a  [        U SbSB5        [        X R                  SA   SO:H  5        [        U R                  SE   U R                  S   U5      n[        [        XR                  SD5      5      UR                   S   S`5        U$ USc;   a  [        U S]SB5        [        X R                  SA   SO:H  5        [        U R                  SE   U R                  S   U5      n[        [        XR                  SD5      5      UR                   S   Sd5        U$ USe:X  a  [        U SISA5        [        X R                  S   SB-  S:H  5        [        X R                  SE   SA-  S:H  5        [        U R                  SE   U R                  S   SA-  SB-  U5      nUR*                  UR,                  -  nU R/                  SP5      n[        USU UR                   S   SE5        [        UUS UR                   SE   SA5        U$ [9        SfU Sg35      e[        U R                  SE   U R                  S   U5      n[        XR                   S   U R                  SA:X  a  SE5        U$ U R                  SA   5        U$ )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<  rA  rN   r   )r0  r   r   r'   )r0  r   r>  r(   r)   r*   r+   r,   r-   r.   r   r   rE   )r0  r<  rA  rF   r   r/   r0   r1   r2   r3   r4   r5   r6   r   r   r   rG   )r   r<  rA  rH   )r   r#   rT   rU   rV   rW   r<   )NNNr   r0  rH  rF  r   rG  rD  r   r   )   r<  rJ  rI  rx     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$   rq  rt  rr  r>  r?  rs  rA  rC  ru  r@  rv  rB  rw  r   r   ry  rK  )r   rL  ndimr   rR  r   r   r   r#  rb   r   r   rP  rN  r   r   r   r  r   rV  r   r   r   r   
isinstancendarrayr   r>  r   rQ  )r   r   rW  r   channelsrY  r   rX  r   rc  u_startv_startflatr   r   r^  r_  uv_starts                     rf   from_ndarray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 zzQaDj)%*F.E$EE1a0{{1~'AB"5//$*?@Eu{{1~u{{1~vFE||  ++E22aAaCi(aAaCi(aABh
  '  8_#E!Q'NELLOXN %L V"NE%!,'7A.()BCu{{1~u{{1~vFE||A:LLO""7<<#6#=#=d#C#K#K#MNL..%!,{{1~'9Q'>?{{1~'9Q'>?u{{1~A0Bq/H&QEkkELL0G'kQ&G==$DQwa!DW 5u||AJXQCLy %!,{{1~'9Q'>?{{1~'9Q'>?u{{1~u{{1~/BFKEkkELL0G1,G==$DQwa!DW 5u||AJXQCL}$eZZ00EKK2994L !<== A! 3E1a0kk!n) T  "KKOMFqyA~!q !@AAuf5Ea%,,q/1=aCaCi %%'AaCaCi %%'A<<?A65<<?A6Ly %!,{{1~'9Q'>?{{1~'9Q'>?{{1~':;))%!,{{1~':;77%!,{{1~':;CC%1-{{1~':;u{{1~u{{1~vFEuood&;<ell1oq L//%A.{{1~':;u{{1~u{{1~vFEuood&;<ell1or LGG%1-{{1~':;u{{1~u{{1~vFEuood&;<ell1oq L11%A.{{1~':;u{{1~u{{1~vFEuood&;<ell1oq L11%A.{{1~':;u{{1~u{{1~vFEuood&;<ell1or Lv%!,{{1~'9Q'>?{{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<<?qA	
  ?Dkk!n	
 re   r   c                     [        XU5      nUS:X  a  [        XR                  S   SXE5        U$ US;   a6  [        U UR                  S   UR                  S5      (       a  SOSUU5        U$ [	        SU S	35      e)
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   rX  s          rf   
from_bytesVideoFrame.from_bytesv  s     5&1V<<?A4 /  
 
  Q__S))q  &8K&LMMre   )r   r   r   r  N)r   r   r"   )F)r   r   )r   F)r   FF))rk   rl   rm   rn   r   r   cfuncro   r   uintr   r   r   r   propertyr   r   r   r   r   r   setterr  r  r  r  ccallobjectr,  r8  rd  rj  staticmethodrn  r~  r|  r  r6  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   