@@ -6,12 +6,11 @@ from libc.string cimport memcpy
66from av.bytesource cimport ByteSource, bytesource
77from av.codec.codec cimport Codec, wrap_codec
88from av.dictionary cimport _Dictionary
9- from av.enum cimport define_enum
109from av.error cimport err_check
1110from av.packet cimport Packet
1211from av.utils cimport avrational_to_fraction, to_avrational
1312
14- from enum import Enum, Flag
13+ from enum import Flag, IntEnum
1514
1615from av.dictionary import Dictionary
1716
@@ -47,65 +46,39 @@ class ThreadType(Flag):
4746 SLICE: " Decode more than one part of a single frame at once" = lib.FF_THREAD_SLICE
4847 AUTO: " Decode using both FRAME and SLICE methods." = lib.FF_THREAD_SLICE | lib.FF_THREAD_FRAME
4948
50-
51- Flags = define_enum(" Flags" , __name__ , (
52- (" NONE" , 0 ),
53- (" UNALIGNED" , lib.AV_CODEC_FLAG_UNALIGNED,
54- " Allow decoders to produce frames with data planes that are not aligned to CPU requirements (e.g. due to cropping)."
55- ),
56- (" QSCALE" , lib.AV_CODEC_FLAG_QSCALE, " Use fixed qscale." ),
57- (" 4MV" , lib.AV_CODEC_FLAG_4MV, " 4 MV per MB allowed / advanced prediction for H.263." ),
58- (" OUTPUT_CORRUPT" , lib.AV_CODEC_FLAG_OUTPUT_CORRUPT, " Output even those frames that might be corrupted." ),
59- (" QPEL" , lib.AV_CODEC_FLAG_QPEL, " Use qpel MC." ),
60- (" DROPCHANGED" , 1 << 5 ,
61- " Don't output frames whose parameters differ from first decoded frame in stream."
62- ),
63- (" RECON_FRAME" , lib.AV_CODEC_FLAG_RECON_FRAME, " Request the encoder to output reconstructed frames, i.e. frames that would be produced by decoding the encoded bistream." ),
64- (" COPY_OPAQUE" , lib.AV_CODEC_FLAG_COPY_OPAQUE,
65- """ Request the decoder to propagate each packet's AVPacket.opaque and AVPacket.opaque_ref
66- to its corresponding output AVFrame. Request the encoder to propagate each frame's
67- AVFrame.opaque and AVFrame.opaque_ref values to its corresponding output AVPacket.""" ),
68- (" FRAME_DURATION" , lib.AV_CODEC_FLAG_FRAME_DURATION,
69- """ Signal to the encoder that the values of AVFrame.duration are valid and should be
70- used (typically for transferring them to output packets).""" ),
71- (" PASS1" , lib.AV_CODEC_FLAG_PASS1, " Use internal 2pass ratecontrol in first pass mode." ),
72- (" PASS2" , lib.AV_CODEC_FLAG_PASS2, " Use internal 2pass ratecontrol in second pass mode." ),
73- (" LOOP_FILTER" , lib.AV_CODEC_FLAG_LOOP_FILTER, " loop filter." ),
74- (" GRAY" , lib.AV_CODEC_FLAG_GRAY, " Only decode/encode grayscale." ),
75- (" PSNR" , lib.AV_CODEC_FLAG_PSNR, " error[?] variables will be set during encoding." ),
76- (" INTERLACED_DCT" , lib.AV_CODEC_FLAG_INTERLACED_DCT, " Use interlaced DCT." ),
77- (" LOW_DELAY" , lib.AV_CODEC_FLAG_LOW_DELAY, " Force low delay." ),
78- (" GLOBAL_HEADER" , lib.AV_CODEC_FLAG_GLOBAL_HEADER,
79- " Place global headers in extradata instead of every keyframe."
80- ),
81- (" BITEXACT" , lib.AV_CODEC_FLAG_BITEXACT, " Use only bitexact stuff (except (I)DCT)." ),
82- (" AC_PRED" , lib.AV_CODEC_FLAG_AC_PRED, " H.263 advanced intra coding / MPEG-4 AC prediction" ),
83- (" INTERLACED_ME" , lib.AV_CODEC_FLAG_INTERLACED_ME, " Interlaced motion estimation" ),
84- (" CLOSED_GOP" , lib.AV_CODEC_FLAG_CLOSED_GOP),
85- ), is_flags = True )
86-
87- Flags2 = define_enum(" Flags2" , __name__ , (
88- (" NONE" , 0 ),
89- (" FAST" , lib.AV_CODEC_FLAG2_FAST,
90- """ Allow non spec compliant speedup tricks.""" ),
91- (" NO_OUTPUT" , lib.AV_CODEC_FLAG2_NO_OUTPUT,
92- """ Skip bitstream encoding.""" ),
93- (" LOCAL_HEADER" , lib.AV_CODEC_FLAG2_LOCAL_HEADER,
94- """ Place global headers at every keyframe instead of in extradata.""" ),
95- (" CHUNKS" , lib.AV_CODEC_FLAG2_CHUNKS,
96- """ Input bitstream might be truncated at a packet boundaries
97- instead of only at frame boundaries.""" ),
98- (" IGNORE_CROP" , lib.AV_CODEC_FLAG2_IGNORE_CROP,
99- """ Discard cropping information from SPS.""" ),
100- (" SHOW_ALL" , lib.AV_CODEC_FLAG2_SHOW_ALL,
101- """ Show all frames before the first keyframe""" ),
102- (" EXPORT_MVS" , lib.AV_CODEC_FLAG2_EXPORT_MVS,
103- """ Export motion vectors through frame side data""" ),
104- (" SKIP_MANUAL" , lib.AV_CODEC_FLAG2_SKIP_MANUAL,
105- """ Do not skip samples and export skip information as frame side data""" ),
106- (" RO_FLUSH_NOOP" , lib.AV_CODEC_FLAG2_RO_FLUSH_NOOP,
107- """ Do not reset ASS ReadOrder field on flush (subtitles decoding)""" ),
108- ), is_flags = True )
49+ class Flags (IntEnum ):
50+ unaligned = lib.AV_CODEC_FLAG_UNALIGNED
51+ qscale = lib.AV_CODEC_FLAG_QSCALE
52+ four_mv = lib.AV_CODEC_FLAG_4MV
53+ output_corrupt = lib.AV_CODEC_FLAG_OUTPUT_CORRUPT
54+ qpel = lib.AV_CODEC_FLAG_QPEL
55+ drop_changed = 1 << 5
56+ recon_frame = lib.AV_CODEC_FLAG_RECON_FRAME
57+ copy_opaque = lib.AV_CODEC_FLAG_COPY_OPAQUE
58+ frame_duration = lib.AV_CODEC_FLAG_FRAME_DURATION
59+ pass1 = lib.AV_CODEC_FLAG_PASS1
60+ pass2 = lib.AV_CODEC_FLAG_PASS2
61+ loop_filter = lib.AV_CODEC_FLAG_LOOP_FILTER
62+ gray = lib.AV_CODEC_FLAG_GRAY
63+ psnr = lib.AV_CODEC_FLAG_PSNR
64+ interlaced_dct = lib.AV_CODEC_FLAG_INTERLACED_DCT
65+ low_delay = lib.AV_CODEC_FLAG_LOW_DELAY
66+ global_header = lib.AV_CODEC_FLAG_GLOBAL_HEADER
67+ bitexact = lib.AV_CODEC_FLAG_BITEXACT
68+ ac_pred = lib.AV_CODEC_FLAG_AC_PRED
69+ interlaced_me = lib.AV_CODEC_FLAG_INTERLACED_ME
70+ closed_gop = lib.AV_CODEC_FLAG_CLOSED_GOP
71+
72+ class Flags2 (IntEnum ):
73+ fast = lib.AV_CODEC_FLAG2_FAST
74+ no_output = lib.AV_CODEC_FLAG2_NO_OUTPUT
75+ local_header = lib.AV_CODEC_FLAG2_LOCAL_HEADER
76+ chunks = lib.AV_CODEC_FLAG2_CHUNKS
77+ ignore_crop = lib.AV_CODEC_FLAG2_IGNORE_CROP
78+ show_all = lib.AV_CODEC_FLAG2_SHOW_ALL
79+ export_mvs = lib.AV_CODEC_FLAG2_EXPORT_MVS
80+ skip_manual = lib.AV_CODEC_FLAG2_SKIP_MANUAL
81+ ro_flush_noop = lib.AV_CODEC_FLAG2_RO_FLUSH_NOOP
10982
11083
11184cdef class CodecContext:
@@ -133,53 +106,59 @@ cdef class CodecContext:
133106 self .ptr.thread_count = 0 # use as many threads as there are CPUs.
134107 self .ptr.thread_type = 0x02 # thread within a frame. Does not change the API.
135108
136- def _get_flags (self ):
109+ @property
110+ def flags (self ):
111+ """
112+ Get and set the flags bitmask of CodecContext.
113+
114+ :rtype: int
115+ """
137116 return self .ptr.flags
138117
139- def _set_flags (self , value ):
118+ @flags.setter
119+ def flags (self , int value ):
140120 self .ptr.flags = value
141121
142- flags = Flags.property(_get_flags, _set_flags, " Flag property of :class:`.Flags`." )
143-
144- unaligned = flags.flag_property(" UNALIGNED" )
145- qscale = flags.flag_property(" QSCALE" )
146- four_mv = flags.flag_property(" 4MV" )
147- output_corrupt = flags.flag_property(" OUTPUT_CORRUPT" )
148- qpel = flags.flag_property(" QPEL" )
149- drop_changed = flags.flag_property(" DROPCHANGED" )
150- recon_frame = flags.flag_property(" RECON_FRAME" )
151- copy_opaque = flags.flag_property(" COPY_OPAQUE" )
152- frame_duration = flags.flag_property(" FRAME_DURATION" )
153- pass1 = flags.flag_property(" PASS1" )
154- pass2 = flags.flag_property(" PASS2" )
155- loop_filter = flags.flag_property(" LOOP_FILTER" )
156- gray = flags.flag_property(" GRAY" )
157- psnr = flags.flag_property(" PSNR" )
158- interlaced_dct = flags.flag_property(" INTERLACED_DCT" )
159- low_delay = flags.flag_property(" LOW_DELAY" )
160- global_header = flags.flag_property(" GLOBAL_HEADER" )
161- bitexact = flags.flag_property(" BITEXACT" )
162- ac_pred = flags.flag_property(" AC_PRED" )
163- interlaced_me = flags.flag_property(" INTERLACED_ME" )
164- closed_gop = flags.flag_property(" CLOSED_GOP" )
165-
166- def _get_flags2 (self ):
122+ @property
123+ def qscale (self ):
124+ """
125+ Use fixed qscale.
126+
127+ :rtype: bool
128+ """
129+ return bool (self .ptr.flags & lib.AV_CODEC_FLAG_QSCALE)
130+
131+ @qscale.setter
132+ def qscale (self , value ):
133+ if value:
134+ self .ptr.flags |= lib.AV_CODEC_FLAG_QSCALE
135+ else :
136+ self .ptr.flags &= ~ lib.AV_CODEC_FLAG_QSCALE
137+
138+ @property
139+ def copy_opaque (self ):
140+ return bool (self .ptr.flags & lib.AV_CODEC_FLAG_COPY_OPAQUE)
141+
142+ @copy_opaque.setter
143+ def copy_opaque (self , value ):
144+ if value:
145+ self .ptr.flags |= lib.AV_CODEC_FLAG_COPY_OPAQUE
146+ else :
147+ self .ptr.flags &= ~ lib.AV_CODEC_FLAG_COPY_OPAQUE
148+
149+ @property
150+ def flags2 (self ):
151+ """
152+ Get and set the flags2 bitmask of CodecContext.
153+
154+ :rtype: int
155+ """
167156 return self .ptr.flags2
168157
169- def _set_flags2 (self , value ):
158+ @flags2.setter
159+ def flags2 (self , int value ):
170160 self .ptr.flags2 = value
171161
172- flags2 = Flags2.property(_get_flags2, _set_flags2, " Flag property of :class:`.Flags2`." )
173- fast = flags2.flag_property(" FAST" )
174- no_output = flags2.flag_property(" NO_OUTPUT" )
175- local_header = flags2.flag_property(" LOCAL_HEADER" )
176- chunks = flags2.flag_property(" CHUNKS" )
177- ignore_crop = flags2.flag_property(" IGNORE_CROP" )
178- show_all = flags2.flag_property(" SHOW_ALL" )
179- export_mvs = flags2.flag_property(" EXPORT_MVS" )
180- skip_manual = flags2.flag_property(" SKIP_MANUAL" )
181- ro_flush_noop = flags2.flag_property(" RO_FLUSH_NOOP" )
182-
183162 @property
184163 def extradata (self ):
185164 if self .ptr is NULL :
0 commit comments