
    3jT.                        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       O/home/wildlama/miniconda3/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-  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\R,                  S\4S j5       r\S 5       r\R,                  S\R2                  4S j5       r\S 5       r\R,                  S\R2                  4S j5       r\S 5       r\R,                  S\R8                  4S j5       r\S 5       r\R,                  S 5       r\S 5       r\R,                  S 5       r\S 5       r\R,                  S 5       r\S 5       r \ R,                  S\R8                  4S  j5       r \S! 5       r!\!R,                  S" 5       r!\S# 5       r"\S$ 5       r#\S% 5       r$\$R,                  S\R8                  4S& j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/ 5       r*\*R,                  S0 5       r*\S1 5       r+\+R,                  S2 5       r+\S3 5       r,\,R,                  S4 5       r,\S5 5       r-\-R,                  S6 5       r-S7r.g)8VideoCodecContext(   ptrcodechwaccelNc                    [         R                  " XX#5        UGb6   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 g ! [(         a
    S U l         g f = fN)r   _init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+   s	    	4e5(#*>>$**#= ),):):4;K;K;O;O)P&#'#3#3#:#:#>#>#F#F &4#$$++//77 ""3 LL88 "": #)..1C1C"D  ' 	( $( 	(s   D4E E'&E'inputr   c                    Ub  U(       d  S /$ Un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/$ )N)threads)formatr5   widthr*   heightreformatterr   reformatthread_countptsr    AV_NOPTS_VALUE	frame_num)r:   r<   vframes      r$   _prepare_frames_for_encode,VideoCodecContext._prepare_frames_for_encodeL   s    =6M"MM!!T\\1||txx~~-}}/###3#5 %%..-- / F ::>>S///!XX//FJJNxr&   c                     [        5       $ r.   )r   r:   s    r$   _alloc_next_frame#VideoCodecContext._alloc_next_frameg   s     ""r&   framepacketc                 V    [         R                  " XU5        UnUR                  5         g r.   )r   _setup_decoded_frame_init_user_attributes)r:   rO   rP   rH   s       r$   rR   &VideoCodecContext._setup_decoded_framek   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l        U$ Nr   )r1   r*   r?   r4   r5   is_hw_owned	device_idr   r   r   
_device_idrM   r   r    av_hwframe_transfer_datarE   )r:   rO   frame_sws      r$   _transfer_hwframe#VideoCodecContext._transfer_hwframeq   s    #L99t//66::BBB L''8<8H8H8R8RFKK
E*5L002#..x||UYYJKyyr&   c                     [        [        R                  " [        R                  U R
                  R                  5      U R
                  R                  U R
                  R                  5      $ r.   )	r   r   r   r    AVPixelFormatr*   r5   r@   rA   rL   s    r$   r?   VideoCodecContext.format   sC    KK))488+;+;<HHNNHHOO
 	
r&   r?   c                     UR                   U R                  l         UR                  U R                  l        UR                  U R                  l        g r.   )r5   r*   r@   rA   )r:   r?   s     r$   r?   r`      s0    !>> --r&   c                 j    U R                   [        R                  L a  gU R                   R                  $ rV   )r*   r   NULLr@   rL   s    r$   r@   VideoCodecContext.width   s#    88v{{"xx~~r&   valuec                 $    XR                   l        g r.   )r*   r@   r:   re   s     r$   r@   rd      s    r&   c                 j    U R                   [        R                  L a  gU R                   R                  $ rV   )r*   r   rc   rA   rL   s    r$   rA   VideoCodecContext.height   s#    88v{{"xxr&   c                 $    XR                   l        g r.   )r*   rA   rg   s     r$   rA   ri      s    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_samplerL   s    r$   rl   'VideoCodecContext.bits_per_coded_sample   s     xx---r&   c                 \    U R                   (       a  [        S5      eXR                  l        g )NzNot supported for encoders)
is_encoder
ValueErrorr*   rl   rg   s     r$   rl   rm      s    ??9::).&r&   c                     [         R                  " [        R                  " [         R                  U R
                  R                  5      5      n[        R                  " [        UR                  5      $ )z-
The pixel format's name.

:type: str | None
)	r    av_pix_fmt_desc_getr   r   r_   r*   r5   strname)r:   descs     r$   r5   VideoCodecContext.pix_fmt   sI     ##FKK0A0A488CSCS$TU 	 {{3		**r&   c                 8    [        U5      U R                  l        g r.   )r   r*   r5   rg   s     r$   r5   rv      s    &u-r&   c                 h    [        [        R                  " U R                  R                  5      5      $ )zB
The frame rate, in frames per second.

:type: fractions.Fraction
)r   r   r8   r*   	frameraterL   s    r$   ry   VideoCodecContext.framerate   s"     &fnnTXX5G5G&HIIr&   c                 l    [        U[        R                  " U R                  R                  5      5        g r.   )r	   r   r8   r*   ry   rg   s     r$   ry   rz      s    eV^^DHH,>,>?@r&   c                     U R                   $ )z#Another name for :attr:`framerate`.ry   rL   s    r$   rateVideoCodecContext.rate   s     ~~r&   c                     Xl         g r.   r}   rg   s     r$   r~   r      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_sizerL   s    r$   r   VideoCodecContext.gop_size   s'     ??FGGxx   r&   c                 \    U R                   (       a  [        S5      eXR                  l        g )Nr   r   rg   s     r$   r   r      s    ??FGG!r&   c                 h    [        [        R                  " U R                  R                  5      5      $ r.   )r   r   r8   r*   sample_aspect_ratiorL   s    r$   r   %VideoCodecContext.sample_aspect_ratio   s     %fnnTXX5Q5Q&RSSr&   c                 l    [        U[        R                  " U R                  R                  5      5        g r.   )r	   r   r8   r*   r   rg   s     r$   r   r      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   r8   numdenr*   r@   r   rA   r   )r:   dars     r$   display_aspect_ratio&VideoCodecContext.display_aspect_ratio   s     	NN377#NN377#HHNNTXX99===HHOOdhh::>>>	
 &fnnS&9::r&   c                 @    [        U R                  R                  5      $ )z
:type: bool
)boolr*   has_b_framesrL   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   rL   s    r$   reorder_depthVideoCodecContext.reorder_depth  s     xx$$$r&   c                 $    XR                   l        g r.   r   rg   s     r$   r   r          %r&   c                 .    U R                   R                  $ z
:type: int
)r*   coded_widthrL   s    r$   r   VideoCodecContext.coded_width  s    
 xx###r&   c                 .    U R                   R                  $ r   )r*   coded_heightrL   s    r$   r   VideoCodecContext.coded_height   s    
 xx$$$r&   c                 .    U R                   R                  $ )za
Describes the signal range of the colorspace.

Wraps :ffmpeg:`AVFrame.color_range`.

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

Wraps :ffmpeg:`AVFrame.color_primaries`.

:type: int
r*   color_primariesrL   s    r$   r   !VideoCodecContext.color_primaries6  s     xx'''r&   c                 $    XR                   l        g r.   r   rg   s     r$   r   r   A  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_trcrL   s    r$   r   VideoCodecContext.color_trcE  s     xx!!!r&   c                 $    XR                   l        g r.   r   rg   s     r$   r   r   P  s    "r&   c                 .    U R                   R                  $ )zq
Describes the YUV/RGB transformation matrix of the colorspace.

Wraps :ffmpeg:`AVFrame.colorspace`.

:type: int
r*   
colorspacerL   s    r$   r   VideoCodecContext.colorspaceT  s     xx"""r&   c                 $    XR                   l        g r.   r   rg   s     r$   r   r   _  s    #r&   c                 .    U R                   R                  $ )zL
The maximum run of consecutive B frames when encoding a video.

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

Wraps :ffmpeg:`AVCodecContext.qmin`.

:type: int
r*   qminrL   s    r$   r   VideoCodecContext.qminp       xx}}r&   c                 $    XR                   l        g r.   r   rg   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*   qmaxrL   s    r$   r   VideoCodecContext.qmax  r   r&   c                 $    XR                   l        g r.   r   rg   s     r$   r   r     r   r&   )ry   r1   rB   )/__name__
__module____qualname____firstlineno__r   cfuncr   r    AVCodecContextconstAVCodecr   r/   r   listrI   rM   r   rR   r\   propertyr?   setterr
   r@   uintrA   rl   intr5   ry   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	( (@ \\   4 \\#5 # # \\'% ' ' '
 \\u  $ 
 
 ]]([ ( (
  
 \\6;;    
 ]] FKK     . . !!/6:: / "/ 	+ 	+ ^^. . J J A A   
[[  ! ! __"fjj " "
 T T K  K 
; 
; + + % % &6:: & & $ $ % % $ $ % % ( ( ) ) " " # # # # $ $ % % & &   
[[    
[[ 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   r_   r%   finalcclassr(   r   r&   r$   <module>r      s     # # 9 4 . * , J V V H A / 	**	+nnV\\#*;*;<= 	  . b b  br&   