
    ybj=                        S SK r S SKJs  Jr  S SKJr  S SKJ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JrJr  S S	KJrJr  S S
KJr  S SKJr  \ R:                  \ R<                  " SS9S\ R>                  \R@                     S\ R>                  \ RB                  \RD                        S\RD                  4S j5       5       r#\ RH                  \ RJ                   " S S\5      5       5       r&g)    N)CodecContext)HWAccel)	err_check)Frame)Packet)avrational_to_fractionto_avrational)VideoFormatget_pix_fmtget_video_format)
VideoFramealloc_video_frame)VideoReformatter)int64_tF)checkctxpix_fmtsreturnc                 &   [         R                  " [         R                  [           U R                  5      nSnX   S:w  a%  X   UR
                  :X  a  X   $ US-  nX   S:w  a  M%  UR                  (       a  U R                  $ [        R                  $ )Nr      )
cythoncastpointerAVCodecPrivateDataopaquehardware_pix_fmtallow_software_fallback
sw_pix_fmtlibAV_PIX_FMT_NONE)r   r   private_datais       ڑ/tmp/claude-0/-home-danvics-docker-quiz/c1e0577a-e42c-4a3d-b1ea-3edd61103a4e/scratchpad/stt/lib/python3.13/site-packages/av/video/codeccontext.py_get_hw_formatr%      s     8>{{)*CJJ8L A
+
;,777;	Q +

 '>>DGDWDW    c                   ~   \ rS rSr\R
                  S\R                  \R                     S\R                  \R                  \R                        S\S-  4S j5       r\R
                  S\S\4S	 j5       r\R
                  S
\S-  S\4S j5       r\R
                  S\4S j5       r\R
                  S\S\4S j5       r\R
                  S\4S j5       r\S 5       r\R0                  S\4S j5       r\S 5       r\R0                  S\R6                  4S j5       r\S 5       r\R0                  S\R6                  4S j5       r\S 5       r\R0                  S\R<                  4S j5       r\S 5       r\R0                  S 5       r\S 5       r \ R0                  S 5       r \S 5       r!\!R0                  S  5       r!\S! 5       r"\"R0                  S" 5       r"\S# 5       r#\#R0                  S\R<                  4S$ j5       r#\S% 5       r$\$R0                  S& 5       r$\S' 5       r%\S( 5       r&\S) 5       r'\'R0                  S\R<                  4S* j5       r'\S+ 5       r(\S, 5       r)\S- 5       r*\*R0                  S. 5       r*\S/ 5       r+\+R0                  S0 5       r+\S1 5       r,\,R0                  S2 5       r,\S3 5       r-\-R0                  S4 5       r-\S5 5       r.\.R0                  S\R<                  4S6 j5       r.\S7 5       r/\/R0                  S8 5       r/\S9 5       r0\0R0                  S: 5       r0\S; 5       r1\1R0                  S< 5       r1S=r2g)>VideoCodecContext(   ptrcodechwaccelNc                    [         R                  " XX#5        Uc  g U R                  (       aY  UR                  U R                  SS9U l        [        R                  " U R
                  R                  5      U R                  l	        g  UR                  U R                  5      U l        [        R                  " U R
                  R                  5      U R                  l	        U R
                  R                  R                  R                  U R                  l        [        U R                  l        U R
                  R                  R                  R                  U R                  l        U R                   R"                  U R                  l        [$        R&                  " U R                  5      U R                  l        g ! [*         a
    S U l         g f = f)NT)for_encoding)r   _init
is_encodercreater+   hwaccel_ctxr    av_buffer_refr*   hw_device_ctxconfigpix_fmtr%   
get_format_private_datar   r,   r   r   addressr   NotImplementedError)selfr*   r+   r,   s       r$   r/   VideoCodecContext._init+   sG    	4e5???
  '~~djjt~LD%(%6%6t7G7G7K7K%LDHH"	$&~~djj9D%(%6%6t7G7G7K7K%LDHH"#//66::BBDHH"0DHH262B2B2I2I2M2M2U2UD/44 6 %nnT-?-?@DHHO" 		$  $D		$s   D4F< <GGvframer   c           
         [         R                  " [         R                  [        R                     U R
                  R                  R                  5      nUR
                  R                  UR                  :X  a  U$ UR
                  R                  UR                  :w  dH  UR
                  R                  UR                  :w  d$  UR
                  R                  UR                  :w  a  U R                  (       d  [        5       U l        U R                  R                  UUR                  UR                  [        UR                  UR                  UR                  5      U R
                  R                   S9n[#        5       n[%        [        R&                  " U R
                  R                  UR
                  S5      5        [%        [        R(                  " UR
                  UR
                  S5      5        UR+                  USS9  UR-                  5         UR
                  R.                  [        R0                  :X  a%  U R
                  R2                  UR
                  l        U$ )Nthreadsr   Fdata_layout)r   r   r   r    AVHWFramesContextr*   hw_frames_ctxdataformat	sw_formatwidthheightreformatterr   reformatr   thread_countr   r   av_hwframe_get_bufferav_hwframe_transfer_data_copy_internal_attributes_init_user_attributesptsAV_NOPTS_VALUE	frame_num)r;   r=   
frames_ctxhwframes       r$   _encode_upload_frame&VideoCodecContext._encode_upload_frameU   s    =CKKNN30014883I3I3N3N=


 ::
 1 11M
 JJ!5!55zz:#3#33zz  J$5$55###3#5 %%..  !! ((**:*:J<M<M -- / F 01#++DHH,B,BGKKQRST#..w{{FJJJK))&e)D%%';;??c000"hh00GKKOr&   inputc                    Ub  U(       d  S /$ UnU R                   R                  [        R                  :w  a  U R	                  U5      /$ UR
                  R                  U R                  :w  dH  UR                  U R                   R                  :w  d$  UR                  U R                   R                  :w  a  U R                  (       d  [        5       U l	        U R                  R                  UU R                   R                  U R                   R                  U R
                  U R                   R                  S9nUR                   R                  [        R                  :X  a%  U R                   R                   UR                   l        U/$ )Nr?   )r*   rD   r   NULLrV   rF   r6   rH   rI   rJ   r   rK   rL   rQ   r    rR   rS   )r;   rX   r=   s      r$   _prepare_frames_for_encode,VideoCodecContext._prepare_frames_for_encode~   s   =6M" 88!!V[[0--f566 MM!!T\\1||txx~~-}}/###3#5 %%..-- / F ::>>S///!XX//FJJNxr&   c                     [        5       $ N)r   r;   s    r$   _alloc_next_frame#VideoCodecContext._alloc_next_frame   s     ""r&   framepacketc                 V    [         R                  " XU5        UnUR                  5         g r^   )r   _setup_decoded_framerP   )r;   rb   rc   r=   s       r$   re   &VideoCodecContext._setup_decoded_frame   s#    ))$v>"$$&r&   c                    U R                   c  U$ UR                  R                  U R                   R                  R                  R                  :w  a  U$ U R                   R
                  (       a6  U R                   R                  [        R                  " [        U5      l
        U$ U R                  5       n[        [        R                  " UR                  UR                  S5      5        UR                  USS9  U$ )Nr   FrA   )r2   r*   rF   r5   r6   is_hw_owned	device_idr   r   r   
_device_idr`   r   r    rN   rO   )r;   rb   frame_sws      r$   _transfer_hwframe#VideoCodecContext._transfer_hwframe   s    #L99t//66::BBB L''8<8H8H8R8RFKK
E*5L002#..x||UYYJK**5e*Dr&   c                     [        [        R                  " [        R                  U R
                  R                  5      U R
                  R                  U R
                  R                  5      $ r^   )	r   r   r   r    AVPixelFormatr*   r6   rH   rI   r_   s    r$   rF   VideoCodecContext.format   sC    KK))488+;+;<HHNNHHOO
 	
r&   rF   c                     U R                  S5        UR                  U R                  l        UR                  U R                  l        UR                  U R                  l        g )NrF   )_assert_not_openr6   r*   rH   rI   )r;   rF   s     r$   rF   rp      s>    h'!>> --r&   c                 j    U R                   [        R                  L a  gU R                   R                  $ Nr   )r*   r   rZ   rH   r_   s    r$   rH   VideoCodecContext.width   s#    88v{{"xx~~r&   valuec                 F    U R                  S5        XR                  l        g )NrH   )rr   r*   rH   r;   rv   s     r$   rH   ru      s    g&r&   c                 j    U R                   [        R                  L a  gU R                   R                  $ rt   )r*   r   rZ   rI   r_   s    r$   rI   VideoCodecContext.height   s#    88v{{"xxr&   c                 F    U R                  S5        XR                  l        g )NrI   )rr   r*   rI   rx   s     r$   rI   rz      s    h'r&   c                 .    U R                   R                  $ )z
The number of bits per sample in the codedwords. It's mandatory for this to be set for some formats to decode properly.

Wraps :ffmpeg:`AVCodecContext.bits_per_coded_sample`.

:type: int
)r*   bits_per_coded_sampler_   s    r$   r}   'VideoCodecContext.bits_per_coded_sample   s     xx---r&   c                 \    U R                   (       a  [        S5      eXR                  l        g )NzNot supported for encoders)r0   
ValueErrorr*   r}   rx   s     r$   r}   r~      s    ??9::).&r&   c                    [         R                  " [        R                  " [         R                  U R
                  R                  5      5      nU[        R                  :X  a  g[        R                  " [        UR                  5      $ )z-
The pixel format's name.

:type: str | None
N)
r    av_pix_fmt_desc_getr   r   ro   r*   r6   rZ   strname)r;   descs     r$   r6   VideoCodecContext.pix_fmt   sX     ##FKK0A0A488CSCS$TU 	 6;;{{3		**r&   c                 Z    U R                  S5        [        U5      U R                  l        g )Nr6   )rr   r   r*   r6   rx   s     r$   r6   r      s!    i(&u-r&   c                    U R                   R                  (       d  U R                   R                  [        R                  :w  al  [        [        R                  " [        R                  U R                   R                  5      U R                   R                  U R                   R                  5      $ g[        R                  " [        R                  [        R                     U R                   R                  R                  5      n[        UR                  U R                   R                  U R                   R                  5      $ )z
For a hardware context (e.g. ``format.name == "cuda"``), the underlying
software pixel format (``nv12``, ``p010le``, ...). ``None`` for a regular
software context.

:type: VideoFormat | None
N)r*   rD   r   r    r!   r   r   r   ro   rH   rI   r   rC   rE   rG   )r;   rT   s     r$   rG   VideoCodecContext.sw_format  s     xx%%xx""c&9&99'KK 1 14883F3FGHHNNHHOO 
 <BKKNN30014883I3I3N3N=

  
 4 4dhhnndhhooVVr&   c                 Z    U R                  S5        [        U5      U R                  l        g )NrG   )rr   r   r*   r   rx   s     r$   rG   r     s!    k*)%0r&   c                 h    [        [        R                  " U R                  R                  5      5      $ )zB
The frame rate, in frames per second.

:type: fractions.Fraction
)r   r   r9   r*   	framerater_   s    r$   r   VideoCodecContext.framerate  s"     &fnnTXX5G5G&HIIr&   c                     U R                  S5        [        U[        R                  " U R                  R
                  5      5        g )Nr   )rr   r	   r   r9   r*   r   rx   s     r$   r   r   (  s-    k*eV^^DHH,>,>?@r&   c                     U R                   $ )z#Another name for :attr:`framerate`.r   r_   s    r$   rateVideoCodecContext.rate-  s     ~~r&   c                     Xl         g r^   r   rx   s     r$   r   r   2  s    r&   c                 f    U R                   (       a  [        S5      eU R                  R                  $ )zR
Sets the number of frames between keyframes. Used only for encoding.

:type: int
%Cannot access 'gop_size' as a decoder
is_decoderRuntimeErrorr*   gop_sizer_   s    r$   r   VideoCodecContext.gop_size6  s'     ??FGGxx   r&   c                 \    U R                   (       a  [        S5      eXR                  l        g )Nr   r   rx   s     r$   r   r   A  s    ??FGG!r&   c                 h    [        [        R                  " U R                  R                  5      5      $ r^   )r   r   r9   r*   sample_aspect_ratior_   s    r$   r   %VideoCodecContext.sample_aspect_ratioG  s     %fnnTXX5Q5Q&RSSr&   c                 l    [        U[        R                  " U R                  R                  5      5        g r^   )r	   r   r9   r*   r   rx   s     r$   r   r   K  s    eV^^DHH,H,HIJr&   c                    [         R                  " [        R                  " WR                  5      [        R                  " UR
                  5      U R                  R                  U R                  R                  R                  -  U R                  R                  U R                  R                  R
                  -  S5        [        [        R                  " U5      5      $ )Ni   )r    	av_reducer   r9   numdenr*   rH   r   rI   r   )r;   dars     r$   display_aspect_ratio&VideoCodecContext.display_aspect_ratioO  s     	NN377#NN377#HHNNTXX99===HHOOdhh::>>>	
 &fnnS&9::r&   c                 @    [        U R                  R                  5      $ )z
:type: bool
)boolr*   has_b_framesr_   s    r$   r   VideoCodecContext.has_b_frames\  s    
 DHH))**r&   c                 .    U R                   R                  $ )zRaw ``has_b_frames`` value from FFmpeg (int, not bool).

After :meth:`flush_buffers`, FFmpeg may reset the internal reorder
heuristic. Set this to the known reorder depth *after* seeking to
avoid dropped hierarchical B-frames.
r*   r   r_   s    r$   reorder_depthVideoCodecContext.reorder_depthc  s     xx$$$r&   c                 $    XR                   l        g r^   r   rx   s     r$   r   r   m       %r&   c                 .    U R                   R                  $ z
:type: int
)r*   coded_widthr_   s    r$   r   VideoCodecContext.coded_widthq  s    
 xx###r&   c                 .    U R                   R                  $ r   )r*   coded_heightr_   s    r$   r   VideoCodecContext.coded_heightx  s    
 xx$$$r&   c                 .    U R                   R                  $ )za
Describes the signal range of the colorspace.

Wraps :ffmpeg:`AVFrame.color_range`.

:type: int
r*   color_ranger_   s    r$   r   VideoCodecContext.color_range  s     xx###r&   c                 $    XR                   l        g r^   r   rx   s     r$   r   r     s    $r&   c                 .    U R                   R                  $ )zg
Describes the RGB/XYZ matrix of the colorspace.

Wraps :ffmpeg:`AVFrame.color_primaries`.

:type: int
r*   color_primariesr_   s    r$   r   !VideoCodecContext.color_primaries  s     xx'''r&   c                 $    XR                   l        g r^   r   rx   s     r$   r   r     s    #( r&   c                 .    U R                   R                  $ )z
Describes the linearization function (a.k.a. transformation characteristics) of the colorspace.

Wraps :ffmpeg:`AVFrame.color_trc`.

:type: int
r*   	color_trcr_   s    r$   r   VideoCodecContext.color_trc  s     xx!!!r&   c                 $    XR                   l        g r^   r   rx   s     r$   r   r     s    "r&   c                 .    U R                   R                  $ )zq
Describes the YUV/RGB transformation matrix of the colorspace.

Wraps :ffmpeg:`AVFrame.colorspace`.

:type: int
r*   
colorspacer_   s    r$   r   VideoCodecContext.colorspace  s     xx"""r&   c                 $    XR                   l        g r^   r   rx   s     r$   r   r     s    #r&   c                 .    U R                   R                  $ )zcThe video field order as FFmpeg's raw integer value.

Wraps :ffmpeg:`AVCodecContext.field_order`.

)r*   field_orderr_   s    r$   r   VideoCodecContext.field_order  s     xx###r&   c                 l    [         R                  " [        R                  U5      U R                  l        g r^   )r   r   r    AVFieldOrderr*   r   rx   s     r$   r   r     s    %{{3+;+;UCr&   c                 .    U R                   R                  $ )zL
The maximum run of consecutive B frames when encoding a video.

:type: int
r*   max_b_framesr_   s    r$   r   VideoCodecContext.max_b_frames  s     xx$$$r&   c                 $    XR                   l        g r^   r   rx   s     r$   r   r     r   r&   c                 .    U R                   R                  $ )ze
The minimum quantiser value of an encoded stream.

Wraps :ffmpeg:`AVCodecContext.qmin`.

:type: int
r*   qminr_   s    r$   r   VideoCodecContext.qmin       xx}}r&   c                 $    XR                   l        g r^   r   rx   s     r$   r   r         r&   c                 .    U R                   R                  $ )ze
The maximum quantiser value of an encoded stream.

Wraps :ffmpeg:`AVCodecContext.qmax`.

:type: int
r*   qmaxr_   s    r$   r   VideoCodecContext.qmax  r   r&   c                 $    XR                   l        g r^   r   rx   s     r$   r   r     r   r&   )r   r2   rJ   )3__name__
__module____qualname____firstlineno__r   cfuncr   r    AVCodecContextconstAVCodecr   r/   r   rV   r   listr[   r`   r   re   rl   propertyrF   setterr
   rH   uintrI   r}   intr6   rG   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   r   __static_attributes__ r&   r$   r(   r(   (   s    \\'$^^C../'$ ~~fll3;;78'$ 4	'$ '$R \\&: &* & &P \\   > \\#5 # # \\'% ' ' '
 \\u  " 
 
 ]]([ ( (  
 \\6;;    
 ]] FKK     . . !!/6:: / "/ + + ^^. . W W* 1 1 J J A A   
[[  ! ! __"fjj " "
 T T K  K 
; 
; + + % % &6:: & & $ $ % % $ $ % % ( ( ) ) " " # # # # $ $ $ $ D D D % % & &   
[[    
[[ r&   r(   )'r   cython.cimports.libavcimportslibavr     cython.cimports.av.codec.contextr    cython.cimports.av.codec.hwaccelr   cython.cimports.av.errorr   cython.cimports.av.framer   cython.cimports.av.packetr   cython.cimports.av.utilsr   r	   cython.cimports.av.video.formatr
   r   r   cython.cimports.av.video.framer   r   $cython.cimports.av.video.reformatterr   cython.cimports.libc.stdintr   r   	exceptvalr   r   r   ro   r%   finalcclassr(   r   r&   r$   <module>r     s     # # 9 4 . * , J V V H A / 	**	+nnV\\#*;*;<= 	  . G G  Gr&   