
    \jl              	          d dl mZmZ d dlZd dlmZ d dlmZm	Z	 d dl
mZm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 d dlmZ d dlmZ  ej<                  e e             Z ejB                  dejD                  ejF                     dejD                  ejH                  ejJ                        de&de'fd       Z( G d de      Z) G d de      Z* G d de      Z+ejX                   G d d             Z'y)    )FlagIntEnumN)libav)
ByteSource
bytesource)Codec
wrap_codec)
Dictionary)	err_check)Packet)avrational_to_fractionto_avrational)EAGAIN)uint8_t)memcpy)InvalidDataErrorc_ctxc_codechwaccelreturnc                 j   | j                   t        j                  k(  rddlm}  |t
              }no| j                   t        j                  k(  rddlm}  |t
              }n?| j                   t        j                  k(  rddl
m}  |t
              }nt        t
              }|j                  | ||       |S )z8Build an bv.CodecContext for an existing AVCodecContext.r   )VideoCodecContext)AudioCodecContext)SubtitleCodecContext)
codec_typelibAVMEDIA_TYPE_VIDEOav.video.codeccontextr   _cinit_sentinelAVMEDIA_TYPE_AUDIOav.audio.codeccontextr   AVMEDIA_TYPE_SUBTITLEav.subtitles.codeccontextr   CodecContext_init)r   r   r   r   py_ctxr   r   s          C/root/.hermes/venv/lib/python3.12/site-packages/av/codec/context.pywrap_codec_contextr(      s     3111;"?3			S33	3;"?3			S66	6B%o6o.
LL)M    c                       e Zd ZU dZej
                  Zded<   ej                  Z	ded<   ej                  ej
                  z  Z
ded<   y)	
ThreadTyper   z"Decode more than one frame at onceFRAMEz3Decode more than one part of a single frame at onceSLICEz*Decode using both FRAME and SLICE methods.AUTON)__name__
__module____qualname__NONEr   FF_THREAD_FRAMEr,   __annotations__FF_THREAD_SLICEr-   r.    r)   r'   r+   r+   1   sJ    D252E2EE/ECFCVCVE@Vc111 	
6 r)   r+   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ej(                  Zej,                  Zej0                  Zej4                  Zej8                  Zej<                  Zej@                  Z!ejD                  Z#ejH                  Z%ejL                  Z'ejP                  Z)ejT                  Z+y)FlagsN),r/   r0   r1   r   AV_CODEC_FLAG_UNALIGNED	unalignedAV_CODEC_FLAG_QSCALEqscaleAV_CODEC_FLAG_4MVfour_mvAV_CODEC_FLAG_OUTPUT_CORRUPToutput_corruptAV_CODEC_FLAG_QPELqpelAV_CODEC_FLAG_RECON_FRAMErecon_frameAV_CODEC_FLAG_COPY_OPAQUEcopy_opaqueAV_CODEC_FLAG_FRAME_DURATIONframe_durationAV_CODEC_FLAG_PASS1pass1AV_CODEC_FLAG_PASS2pass2AV_CODEC_FLAG_LOOP_FILTERloop_filterAV_CODEC_FLAG_GRAYgrayAV_CODEC_FLAG_PSNRpsnrAV_CODEC_FLAG_INTERLACED_DCTinterlaced_dctAV_CODEC_FLAG_LOW_DELAY	low_delayAV_CODEC_FLAG_GLOBAL_HEADERglobal_headerAV_CODEC_FLAG_BITEXACTbitexactAV_CODEC_FLAG_AC_PREDac_predAV_CODEC_FLAG_INTERLACED_MEinterlaced_meAV_CODEC_FLAG_CLOSED_GOP
closed_gopr6   r)   r'   r8   r8   :   s    ++I%%F##G55N!!D//K//K55N##E##E//K!!D!!D55N++I33M))H''G33M--Jr)   r8   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ej(                  Zy)Flags2N)r/   r0   r1   r   AV_CODEC_FLAG2_FASTfastAV_CODEC_FLAG2_NO_OUTPUT	no_outputAV_CODEC_FLAG2_LOCAL_HEADERlocal_headerAV_CODEC_FLAG2_CHUNKSchunksAV_CODEC_FLAG2_IGNORE_CROPignore_cropAV_CODEC_FLAG2_SHOW_ALLshow_allAV_CODEC_FLAG2_EXPORT_MVS
export_mvsAV_CODEC_FLAG2_SKIP_MANUALskip_manualAV_CODEC_FLAG2_RO_FLUSH_NOOPro_flush_noopr6   r)   r'   rb   rb   Q   se    ""D,,I22L&&F00K**H..J00K44Mr)   rb   c                      e Zd ZedEd       ZdFdZej                  dej                  e	j                     dej                  ej                  e	j                        defd       Zed        Zej"                  d	ej$                  fd
       Zed        Zej"                  d        Zed        Zej"                  d        Zed        Zej"                  d	ej$                  fd       Zed        Zej"                  d        Zed        Zed        Zed        Zej4                  dGdej6                  fd       Zd Zd ZdFdZed        Z de!dz  fdZ"ej                  dejF                  fd        Z$ej                  de!dz  de%fd!       Z&ej                  de!fd"       Z'ej                  d#        Z(ej                  de!fd$       Z)ej                  d%        Z*ej                  de!fd&       Z+ej4                  dFde!dz  fd'       Z,dFde!dz  fd(Z-ej                  d)e.fd*       Z/ej4                  dFd)e.dz  fd+       Z0ej4                  d,        Z1ej                  de!d)e.dz  fd-       Z2ed.        Z3ed/        Z4ed0        Z5ed1        Z6e6j"                  d2        Z6ed3        Z7e7j"                  d4        Z7ed5        Z8e8j"                  d6        Z8e ejr                  d      d7               Z:e:j"                  d	ej$                  fd8       Z:ed9        Z;e;j"                  d	ejx                  fd:       Z;ed;        Z=ed<        Z>e>j"                  d	ej$                  fd=       Z>ed>        Z?e?j"                  d	ej$                  fd?       Z?ed@        Z@e@j"                  dA        Z@edB        ZAeAj"                  dC        ZAedD        ZBy)Hr$   Nc                     t        | t              r| nt        | |      }t        j                  |j                        }t        ||j                  |      S N)
isinstancer   r   avcodec_alloc_context3ptrr(   )codecmoder   cy_codecr   s        r'   createzCodecContext.create_   sE    #-eU#;%udAS474N4NLL5
 "%w??r)   c                 T    |t         urt        d      i | _        d| _        d| _        y )NzCannot instantiate CodecContextF)r   RuntimeErroroptionsstream_indexis_open)selfsentinelargskwargss       r'   	__cinit__zCodecContext.__cinit__g   s,    ?*@AAr)   rz   r{   r   c                 N   || _         | j                   j                  r&|r$| j                   j                  |k7  rt        d      t        |t        j
                  k7  r|n| j                   j                        | _        || _        d| j                   _        d| j                   _        y )Nz,Wrapping CodecContext with mismatched codec.r      )	rz   r{   r   r	   cythonNULLr   thread_countthread_type)r   rz   r{   r   s       r'   r%   zCodecContext._inito   su     88>>e%(?MNN&++)=488>>R
 !"#r)   c                 .    | j                   j                  S )zU
        Get and set the flags bitmask of CodecContext.

        :rtype: int
        rz   flagsr   s    r'   r   zCodecContext.flags        xx~~r)   valuec                 &    || j                   _        y rw   r   r   r   s     r'   r   zCodecContext.flags   s    r)   c                 b    t        | j                  j                  t        j                  z        S )z9
        Use fixed qscale.

        :rtype: bool
        )boolrz   r   r   r;   r   s    r'   r<   zCodecContext.qscale   s"     DHHNNS%=%==>>r)   c                     |r.| j                   xj                  t        j                  z  c_        y | j                   xj                  t        j                   z  c_        y rw   )rz   r   r   r;   r   s     r'   r<   zCodecContext.qscale   s8    HHNNc666NHHNNs7777Nr)   c                 b    t        | j                  j                  t        j                  z        S rw   )r   rz   r   r   rE   r   s    r'   rF   zCodecContext.copy_opaque   s     DHHNNS%B%BBCCr)   c                     |r.| j                   xj                  t        j                  z  c_        y | j                   xj                  t        j                   z  c_        y rw   )rz   r   r   rE   r   s     r'   rF   zCodecContext.copy_opaque   s8    HHNNc;;;NHHNNs<<<<Nr)   c                 .    | j                   j                  S )zV
        Get and set the flags2 bitmask of CodecContext.

        :rtype: int
        rz   flags2r   s    r'   r   zCodecContext.flags2   s     xxr)   c                 &    || j                   _        y rw   r   r   s     r'   r   zCodecContext.flags2   s    r)   c                 L   | j                   t        j                  u ry | j                   j                  dkD  rnt        j                  t
        t        j                  t        j                  t           | j                   j                        d | j                   j                         S y Nr   )	rz   r   r   extradata_sizecastbytespointerr   	extradatar   s    r'   r   zCodecContext.extradata   su    88v{{"88""Q&;;FNN73TXX5G5GH-dhh--  r)   c                    |Nt        j                  t        j                  | j                  j
                               d| j                  _        y t        |      }t        j                  t        j                  t           t        j                  | j                  j
                  |j                  t         j                  z               | j                  _        | j                  j
                  st        d      t        | j                  j
                  |j                  |j                         t        j                  t        j                   |j                        | j                  _        y )Nr   zCannot allocate extradata)r   av_freepr   addressrz   r   r   r   r   r   r   
av_realloclengthAV_INPUT_BUFFER_PADDING_SIZEMemoryErrorr   int)r   datasources      r'   r   zCodecContext.extradata   s    <LL(:(:;<&'DHH#%F!'w'HH&&8X8X(X"DHH 88%%!"=>>488%%vzz6==A&,kk&**fmm&LDHH#r)   c                 .    | j                   j                  S rw   )rz   r   r   s    r'   r   zCodecContext.extradata_size   s    xx&&&r)   c                     | j                   t        j                  u ryt        j                  | j                   j
                        S NF)rz   r   r   r   av_codec_is_encoderr{   r   s    r'   
is_encoderzCodecContext.is_encoder   .    88v{{"&&txx~~66r)   c                     | j                   t        j                  u ryt        j                  | j                   j
                        S r   )rz   r   r   r   av_codec_is_decoderr{   r   s    r'   
is_decoderzCodecContext.is_decoder   r   r)   Tstrictc           	         | j                   r|rt        d      y t               }|j                  | j                  xs i        | j
                  j                  j                  sC| j                  r6| j                  dk(  r| j
                  j                  j                  xs d| j
                  j                  _        | j
                  j                  j                  xs t        j                  | j
                  j                  _        n| j                  dk(  rKd| j
                  j                  _        | j
                  j                  | j
                  j                  _        nDd| j
                  j                  _        t        j                  | j
                  j                  _        | j                          t!        t        j"                  | j
                  | j$                  j
                  t'        j(                  |j
                              d| j$                  j*                   d| j                   d       d| _         t-        |      | _        y )	NzCodecContext is already open.video   audiozavcodec_open2("z", )T)r   
ValueErrorr
   updater   rz   	time_basenumr   type	frameratedenr   AV_TIME_BASEsample_rate_setup_encode_hwframesr   avcodec_open2r{   r   r   namedict)r   r   r   s      r'   openzCodecContext.open   s   << !@AA(lt||)r*xx!!%%$//yyG#)-););)?)?)D1""&)-););)?)?)S3CSCS""&g%)*""&)-)=)=""&)*""&),)9)9""&##%dhh

w{{8STdjjoo.c$,,qA	
 G}r)   c                 P   | j                   rnt        j                  t        j                  | j                   j
                               t        j                  t        j                  | j                                | j                  r t        j                  | j                         y y rw   )	rz   r   r   r   r   r   avcodec_free_contextparserav_parser_closer   s    r'   __dealloc__zCodecContext.__dealloc__  sa    88LL(:(:;<$$V^^DHH%=>;;, r)   c           
          | j                   xs d}| j                  xs d}d| j                  j                   d| d| dt	        |       dd	S )	Nz<notype>z	<nocodec>z<av. /z at 0xx>)r   r   	__class__r/   id)r   _typer   s      r'   __repr__zCodecContext.__repr__	  sP    		'Zyy'Kdnn--.awavVBtHQ<qQQr)   c                 ~   | j                   sft        j                  | j                  j                  j
                        | _         | j                   s"t        d| j                  j                         t        |d      }||j                  nt        j                  }|.t        j                  t        j                  |j                        nd}d}g }	 t        j                  5  t        j                  | j                   | j                  t        j                         t        j                         ||t        j"                  t        j"                  d	      }	ddd       t%        	       r-t'        |      }t)        |j                  j*                  |       | j                   j,                  |j                  _        | j                   j.                  |j                  _        | j                   j0                  |j                  _        | j                   j2                  r%| j                   j2                  |j                  _        | j                   j4                  dk(  r-|j                  xj6                  t        j8                  z  c_        |j;                  |       |s	 |S ||	z  }||	z  }|s	 |S # 1 sw Y   [xY w)aN  Split up a byte stream into list of :class:`.Packet`.

        This is only effectively splitting up a byte stream, and does no
        actual interpretation of the data.

        It will return all packets that are fully contained within the given
        input, and will buffer partial packets until they are complete.

        Any timing information the parser is able to infer (``pts``, ``dts``,
        ``duration``, ``pos`` and the keyframe flag) is assigned onto the
        returned packets. Fields the parser cannot determine are left unset.

        :param ByteSource raw_input: A chunk of a byte-stream to process.
            Anything that can be turned into a :class:`.ByteSource` is fine.
            ``None`` or empty inputs will flush the parser's buffers.

        :return: ``list`` of :class:`.Packet` newly available.

        zNo parser for T)
allow_noneNr   r   )r   r   av_parser_initr{   rz   r   r   r   r   r   r   r   r   r   nogilav_parser_parse2r   AV_NOPTS_VALUEr   r   r   r   ptsdtsposduration	key_framer   AV_PKT_FLAG_KEYappend)
r   	raw_inputr   in_datain_sizepacketpacketsout_dataout_sizeconsumeds
             r'   parsezCodecContext.parse  s   * {{,,TZZ^^->->?DK;; >$**//1B!CDD'	dC060B&**6<6HFKK

FMM2a 	  //KKHHNN8,NN8,&&&&
 h  )vzz(; "&

!%

!%

;;''*.++*>*>FJJ';;((A-JJ$$(;(;;$v&  xGxGk  s   %A4J22J<c                     | j                   duS )zf
        Returns ``True`` if this codec context is hardware accelerated, ``False`` otherwise.
        N)hwaccel_ctxr   s    r'   
is_hwaccelzCodecContext.is_hwaccell  s    
 t++r)   framec              #   :  K   t         j                  5  t        j                  | j                  ||j                  nt         j
                        }d d d        t        d       | j                         }|r| | j                         }|ry y # 1 sw Y   @xY ww)Nzavcodec_send_frame())r   r   r   avcodec_send_framerz   r   r   _recv_packetr   r   resr   s       r'   _send_frame_and_recvz!CodecContext._send_frame_and_recvs  s      \\ 	((u'8%))fkkC	 	#-.""$L&&(F 	 	s"   B=B<BBBBr   c                    | j                   | j                  sy | j                  j                  ry | j                   j                  j                  j
                  }t        j                  t        j                  | j                  j                        }|t        j                  k(  r8t        j                  t        j                  | j                  j
                        }||k(  s|t        j                  k(  rt        j                  d      }t        j                  | j                   j                        }|t        j                  k(  rt        d      	 t        j                  t        j                   t        j"                     |j$                        }||_        ||_        | j                  j*                  |_        | j                  j,                  |_        d|_        t1        t        j2                  |             || j                  _        || j                  _
        || j                  _        y # t4        $ r* t        j6                  t        j8                  |              w xY w)Ns   nv12zav_hwframe_ctx_alloc() failed    )r   r   rz   hw_frames_ctxconfigpix_fmtr   r   r   AVPixelFormat
sw_pix_fmtAV_PIX_FMT_NONEav_get_pix_fmtav_hwframe_ctx_allocr   r   r   AVHWFramesContextr   format	sw_formatwidthheightinitial_pool_sizer   av_hwframe_ctx_init	Exceptionav_buffer_unrefr   )r   	hw_formatr	  
frames_ref
frames_ctxs        r'   r   z#CodecContext._setup_encode_hwframes  s    #4??88!!'+'7'7'>'>'B'B'J'J	'-{{txx22(
	 +++C$5$5txx7G7GHI 	!Y#2E2E%E**73I696N6N  7

 $=>>	@Fs445zAJ !*J#,J #xx~~J $J+-J(c--j9: ",'$  	z :;	s   B(H/ /3I"c                     |gS rw   r6   r   r   s     r'   _prepare_frames_for_encodez'CodecContext._prepare_frames_for_encode  s	    wr)   c                     t        d      )Nz Base CodecContext cannot decode.)NotImplementedErrorr   s    r'   _alloc_next_framezCodecContext._alloc_next_frame  s    !"DEEr)   c                    | j                   s| j                         | _         | j                   }t        j                  5  t	        j
                  | j                  |j                        }d d d        t         k(  s|t        j                  k(  ry t        |d       | j                  |      }|s	d | _         |S y # 1 sw Y   PxY w)Nzavcodec_receive_frame())_next_framer  r   r   r   avcodec_receive_framerz   r   AVERROR_EOFr   _transfer_hwframe)r   r   r   s      r'   _recv_framezCodecContext._recv_frame  s    #557D'' \\ 	A++DHHeii@C	A 6'>SCOO3#01&&u-#DL 	A 	As   +B88Cc                     |S rw   r6   r  s     r'   r  zCodecContext._transfer_hwframe  s    r)   c                    t               }t        j                  5  t        j                  | j
                  |j
                        }d d d        t         k(  s|t        j                  k(  ry t        |d       |s|S y # 1 sw Y   8xY w)Nzavcodec_receive_packet())	r   r   r   r   avcodec_receive_packetrz   r   r  r   )r   r   r   s      r'   r   zCodecContext._recv_packet  sv     \\ 	C,,TXXvzzBC	C 6'>SCOO3#12M 	C 	Cs   +A==Bc                 T   | j                   j                  t        j                  t        j                  fvrt        d      | j                  s||j                   j                  t        j                  k7  r_| j                   j                  t        j                  k(  r8t        j                  |j                   j                        | j                   _        | j                  d       | j                  |      }|D ]*  }||j                  | j                   j                         , |S )Nz/Encoding is only supported for audio and video.Fr   )rz   r   r   r   r    r  r   r   r   r   av_buffer_refr   r  _rebase_timer   )r   r   framess      r'   *_prepare_and_time_rebase_frames_for_encodez7CodecContext._prepare_and_time_rebase_frames_for_encode  s    88s'='=s?U?U&VV%&WXX !		''6;;6&&&++5%(%6%6uyy7N7N%ODHH"			007  	7E ""488#5#56	7 r)   c                     g }| j                  |      D ]:  }| j                  |      D ]$  }| j                  |       |j                  |       & < |S )zAEncode a list of :class:`.Packet` from the given :class:`.Frame`.)r'  r   _setup_encoded_packetr   r   s       r'   encodezCodecContext.encode  s^     DDUK 	#E33E: #**62

6"#	# 
r)   c              #      K   | j                  |      D ]-  }| j                  |      D ]  }| j                  |       |  / y wrw   )r'  r   r)  r   r   r   s      r'   encode_lazyzCodecContext.encode_lazy  sM     DDUK 	E33E: **62	s   AAr   c                 N    | j                   j                  |j                   _        y rw   )rz   r   )r   r   s     r'   r)  z"CodecContext._setup_encoded_packet  s      $xx11

r)   c                    | j                   j                  st        d      | j                  d       t        j
                  5  t        j                  | j                  ||j                  nt        j                        }ddd       t        d       g }	 	 | j                         }|	 |S | j                  ||       |j                  |       :# 1 sw Y   RxY w# t        $ r |rY |S  w xY w)a  Decode a list of :class:`.Frame` from the given :class:`.Packet`.

        If the packet is None, the buffers will be flushed. This is useful if
        you do not want the library to automatically re-order frames for you
        (if they are encoded with a codec that has B-frames).

        .. warning::

            This method is **not thread-safe**. Calling :meth:`decode` concurrently
            from multiple threads on the same :class:`CodecContext` will corrupt
            internal FFmpeg state and likely cause a crash (segfault). FFmpeg 8.1
            enforces this more strictly than earlier releases. If you need to decode
            from multiple threads, give each thread its own :class:`CodecContext`.

        zcannot decode unknown codecFr#  Nzavcodec_send_packet())r{   rz   r   r   r   r   r   avcodec_send_packetr   r   r  r   _setup_decoded_framer   )r   r   r   outr   s        r'   decodezCodecContext.decode  s    " zz~~:;;			 \\ 	))(:&**C	 	#./((*
 } 
 %%eV4JJu 	 	 $  
 s   =CC CC.,C.c                     | j                   r9t        j                  5  t        j                  | j
                         ddd       yy# 1 sw Y   yxY w)zReset the internal codec state and discard all internal buffers.

        Should be called before you start decoding from a new position e.g.
        when seeking or when switching to a different stream.

        N)r   r   r   r   avcodec_flush_buffersrz   r   s    r'   flush_bufferszCodecContext.flush_buffersH  sC     << 4))$((34 4 4 4s    AAc                 @    ||j                   j                  |_        y y rw   )rz   r   
_time_baser,  s      r'   r1  z!CodecContext._setup_decoded_frameT  s!     %zz33E r)   c                 .    | j                   j                  S rw   )r{   r   r   s    r'   r   zCodecContext.name^      zzr)   c                 .    | j                   j                  S rw   )r{   r   r   s    r'   r   zCodecContext.typeb  r:  r)   c                    g }| j                   j                  r6| j                  j                  r | j                  j                  j                  s|S | j                  j                  }d}|j                  |   j                  t
        j                  k7  rX|j                  |j                  |   j                         |dz  }|j                  |   j                  t
        j                  k7  rX|S )zX
        List the available profiles for this stream.

        :type: list[str]
        r   r   )	rz   r{   descprofilesprofiler   AV_PROFILE_UNKNOWNr   r   )r   retr=  is       r'   r>  zCodecContext.profilesf  s     xx~~TZZ__DJJOO<T<TJ zzmmA&&#*@*@@JJt}}Q',,-FA mmA&&#*@*@@ 
r)   c                    | j                   j                  r6| j                  j                  r | j                  j                  j                  sy | j                  j                  }d}|j                  |   j                  t
        j                  k7  rz|j                  |   j                  | j                   j                  k(  r|j                  |   j                  S |dz  }|j                  |   j                  t
        j                  k7  ryy y Nr   r   )rz   r{   r=  r>  r?  r   r@  r   )r   r=  rB  s      r'   r?  zCodecContext.profile{  s    xx~~TZZ__DJJOO<T<T zzmmA&&#*@*@@}}Q''488+;+;;}}Q',,,FA mmA&&#*@*@@r)   c                    | j                   r6| j                   j                  r | j                   j                  j                  sy | j                   j                  }d}|j                  |   j                  t        j
                  k7  rv|j                  |   j                  |k(  r)|j                  |   j                  | j                  _        y |dz  }|j                  |   j                  t        j
                  k7  ruy y rD  )r{   r=  r>  r?  r   r@  r   rz   )r   r   r=  rB  s       r'   r?  zCodecContext.profile  s    zz

8P8P zzmmA&&#*@*@@}}Q$$-#'==#3#;#; FA	 mmA&&#*@*@@r)   c                     | j                   rt        d      t        t        j                  | j
                  j                              S Nz&Cannot access 'time_base' as a decoder)r   r   r   r   r   rz   r   r   s    r'   r   zCodecContext.time_base  s3    ??GHH%fnnTXX5G5G&HIIr)   c                     | j                   rt        d      t        |t        j                  | j
                  j                               y rG  )r   r   r   r   r   rz   r   r   s     r'   r   zCodecContext.time_base  s2    ??GHHeV^^DHH,>,>?@r)   c                 r    | j                   j                  j                  ddd      j                  d      S )N   littleF	byteordersignedasciiencoding)rz   	codec_tagto_bytesr3  r   s    r'   rR  zCodecContext.codec_tag  s:    xx!!**1*OVV W 
 	
r)   c                     t        |t              rFt        |      dk(  r8t        j	                  |j                  d      dd      | j                  _        y t        d      )NrJ  rO  rP  rK  FrL  z)Codec tag should be a 4 character string.)	rx   strlenr   
from_bytesr*  rz   rR  r   r   s     r'   rR  zCodecContext.codec_tag  sP    eS!c%jAo!$g.(5 "0 "DHH HIIr)   c                 P    | j                   j                  t        j                  z  S )zGlobal quality for codecs which cannot change it per frame.

        Stored internally in lambda units; this property converts to/from
        QP units using ``FF_QP2LAMBDA``.

        Wraps :ffmpeg:`AVCodecContext.global_quality`.

        )rz   global_qualityr   FF_QP2LAMBDAr   s    r'   rY  zCodecContext.global_quality  s     xx&&#*:*:::r)   c                 H    |t         j                  z  | j                  _        y rw   )r   rZ  rz   rY  r   s     r'   rY  zCodecContext.global_quality  s    "'#*:*:":r)   c                 d    | j                   j                  dkD  r| j                   j                  S d S r   rz   bit_rater   s    r'   r^  zCodecContext.bit_rate  s(    $(HH$5$5$9txx  CtCr)   c                 &    || j                   _        y rw   r]  r   s     r'   r^  zCodecContext.bit_rate  s    !r)   c                 b    | j                   j                  dkD  r| j                   j                  S y r   )rz   rc_max_rater   s    r'   max_bit_ratezCodecContext.max_bit_rate  s'    88!#88'''r)   c                 0    | j                   j                   y rw   rz   bit_rate_tolerancer   s    r'   re  zCodecContext.bit_rate_tolerance  s    ##r)   c                 &    || j                   _        y rw   rd  r   s     r'   re  zCodecContext.bit_rate_tolerance  s    &+#r)   c                 .    | j                   j                  S )zfHow many threads to use; 0 means auto.

        Wraps :ffmpeg:`AVCodecContext.thread_count`.

        )rz   r   r   s    r'   r   zCodecContext.thread_count  s     xx$$$r)   c                 T    | j                   rt        d      || j                  _        y )Nz/Cannot change thread_count after codec is open.)r   r   rz   r   r   s     r'   r   zCodecContext.thread_count  s!    <<PQQ %r)   c                 @    t        | j                  j                        S )z[One of :class:`.ThreadType`.

        Wraps :ffmpeg:`AVCodecContext.thread_type`.

        )r+   rz   r   r   s    r'   r   zCodecContext.thread_type  s     $((..//r)   c                    | j                   rt        d      t        |      t        u r|| j                  _        y t        |      t        u r#t        |   j                  | j                  _        y |j                  | j                  _        y )Nz.Cannot change thread_type after codec is open.)	r   r   r   r   rz   r   rU  r+   r   r   s     r'   r   zCodecContext.thread_type  s`    <<OPP;##(DHH %[C#-e#4#:#:DHH #(;;DHH r)   c                 L   | j                   j                  }|t        j                  k(  ry|t        j                  k(  ry|t        j
                  k(  ry|t        j                  k(  ry|t        j                  k(  ry|t        j                  k(  ry|t        j                  k(  ry| S )a  Returns one of the following str literals:

        "NONE" Discard nothing
        "DEFAULT" Discard useless packets like 0 size packets in AVI
        "NONREF" Discard all non reference
        "BIDIR" Discard all bidirectional frames
        "NONINTRA" Discard all non intra frames
        "NONKEY Discard all frames except keyframes
        "ALL" Discard all

        Wraps :ffmpeg:`AVCodecContext.skip_frame`.
        r2   DEFAULTNONREFBIDIRNONINTRANONKEYALL)
rz   
skip_framer   AVDISCARD_NONEAVDISCARD_DEFAULTAVDISCARD_NONREFAVDISCARD_BIDIRAVDISCARD_NONINTRAAVDISCARD_NONKEYAVDISCARD_ALLr   s     r'   rr  zCodecContext.skip_frame  s     ##C&&&C)))C(((C'''C***C(((C%%%r)   c                    |dk(  r t         j                  | j                  _        y |dk(  r t         j                  | j                  _        y |dk(  r t         j
                  | j                  _        y |dk(  r t         j                  | j                  _        y |dk(  r t         j                  | j                  _        y |dk(  r t         j                  | j                  _        y |dk(  r t         j                  | j                  _        y t        d      )	Nr2   rl  rm  rn  ro  rp  rq  zInvalid skip_frame type)r   rs  rz   rr  rt  ru  rv  rw  rx  ry  r   r   s     r'   rr  zCodecContext.skip_frame  s    F?"%"4"4DHHi"%"7"7DHHh"%"6"6DHHg"%"5"5DHHj "%"8"8DHHh"%"6"6DHHe^"%"3"3DHH677r)   c                 .    | j                   j                  S )zECodec delay.

        Wraps :ffmpeg:`AVCodecContext.delay`.

        )rz   delayr   s    r'   r|  zCodecContext.delay0  r   r)   )NNrw   )T)Cr/   r0   r1   staticmethodr~   r   r   cfuncr   r   AVCodecContextconstAVCodecHWAccelr%   propertyr   setterr   r<   rF   r   r   r   r   r   ccallbintr   r   r   r   r   Framer   voidr   listr  r  r  r  r   r'  r*  r-  r   r)  r3  r6  r1  r   r   r>  r?  r   rR  	cdivisionrY  r^  longlongrb  re  r   r   rr  r|  r6   r)   r'   r$   r$   ]   s   @ @ \\$^^C../$ ~~fll3;;78$ 	$ $    \\6::   ? ? ]]8 8 D D = =   ]] FJJ     
 
 M M" ' ' 7 7
 7 7
 \\%6;; % %:-R
\| , ,)%$, ) \\2% 2% 2%h \\    \\F5 F F \\ ( \\u   \\  \\  6 \\EDL    \\2F 2 2 \\(Vd] ( (T \\	4 	4 \\4% 4$ 4 4      (   ^^  J J
 A A
 
 

 J J Vd	;  	; ;FJJ ; ; D D __"foo " "   $ $ ,

 , , % % &&** & &
 0 0 / /  < 8 8$  r)   r$   )-enumr   r   r   cython.cimportsr   r   cython.cimports.av.bufferr   r   cython.cimports.av.codec.codecr   r	   cython.cimports.av.dictionaryr
   cython.cimports.av.errorr   cython.cimports.av.packetr   cython.cimports.av.utilsr   r   cython.cimports.libc.errnor   cython.cimports.libc.stdintr   cython.cimports.libc.stringr   av.errorr   declareobjectr   r~  r   r  r  r  r  r$   r(   r+   r8   rb   cclassr6   r)   r'   <module>r     s      ( < < 4 . , J - / . % &..2 >>#,,-^^FLL56  	 8 .G ..	5W 	5 Y Y Yr)   