FFmpeg
codec.h
Go to the documentation of this file.
1 /*
2  * AVCodec public API
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #ifndef AVCODEC_CODEC_H
22 #define AVCODEC_CODEC_H
23 
24 #include <stdint.h>
25 
26 #include "libavutil/avutil.h"
27 #include "libavutil/hwcontext.h"
28 #include "libavutil/log.h"
29 #include "libavutil/pixfmt.h"
30 
31 #include "libavcodec/codec_id.h"
32 
33 /**
34  * @addtogroup lavc_core
35  * @{
36  */
37 
38 /**
39  * Decoder can use draw_horiz_band callback.
40  */
41 #define AV_CODEC_CAP_DRAW_HORIZ_BAND (1 << 0)
42 /**
43  * Codec uses get_buffer() or get_encode_buffer() for allocating buffers and
44  * supports custom allocators.
45  * If not set, it might not use get_buffer() or get_encode_buffer() at all, or
46  * use operations that assume the buffer was allocated by
47  * avcodec_default_get_buffer2 or avcodec_default_get_encode_buffer.
48  */
49 #define AV_CODEC_CAP_DR1 (1 << 1)
50 /**
51  * Encoder or decoder requires flushing with NULL input at the end in order to
52  * give the complete and correct output.
53  *
54  * NOTE: If this flag is not set, the codec is guaranteed to never be fed with
55  * with NULL data. The user can still send NULL data to the public encode
56  * or decode function, but libavcodec will not pass it along to the codec
57  * unless this flag is set.
58  *
59  * Decoders:
60  * The decoder has a non-zero delay and needs to be fed with avpkt->data=NULL,
61  * avpkt->size=0 at the end to get the delayed data until the decoder no longer
62  * returns frames.
63  *
64  * Encoders:
65  * The encoder needs to be fed with NULL data at the end of encoding until the
66  * encoder no longer returns data.
67  *
68  * NOTE: For encoders implementing the AVCodec.encode2() function, setting this
69  * flag also means that the encoder must set the pts and duration for
70  * each output packet. If this flag is not set, the pts and duration will
71  * be determined by libavcodec from the input frame.
72  */
73 #define AV_CODEC_CAP_DELAY (1 << 5)
74 /**
75  * Codec can be fed a final frame with a smaller size.
76  * This can be used to prevent truncation of the last audio samples.
77  */
78 #define AV_CODEC_CAP_SMALL_LAST_FRAME (1 << 6)
79 
80 /**
81  * Codec is experimental and is thus avoided in favor of non experimental
82  * encoders
83  */
84 #define AV_CODEC_CAP_EXPERIMENTAL (1 << 9)
85 /**
86  * Codec should fill in channel configuration and samplerate instead of container
87  */
88 #define AV_CODEC_CAP_CHANNEL_CONF (1 << 10)
89 /**
90  * Codec supports frame-level multithreading.
91  */
92 #define AV_CODEC_CAP_FRAME_THREADS (1 << 12)
93 /**
94  * Codec supports slice-based (or partition-based) multithreading.
95  */
96 #define AV_CODEC_CAP_SLICE_THREADS (1 << 13)
97 /**
98  * Codec supports changed parameters at any point.
99  */
100 #define AV_CODEC_CAP_PARAM_CHANGE (1 << 14)
101 /**
102  * Codec supports multithreading through a method other than slice- or
103  * frame-level multithreading. Typically this marks wrappers around
104  * multithreading-capable external libraries.
105  */
106 #define AV_CODEC_CAP_OTHER_THREADS (1 << 15)
107 /**
108  * Audio encoder supports receiving a different number of samples in each call.
109  */
110 #define AV_CODEC_CAP_VARIABLE_FRAME_SIZE (1 << 16)
111 /**
112  * Decoder is not a preferred choice for probing.
113  * This indicates that the decoder is not a good choice for probing.
114  * It could for example be an expensive to spin up hardware decoder,
115  * or it could simply not provide a lot of useful information about
116  * the stream.
117  * A decoder marked with this flag should only be used as last resort
118  * choice for probing.
119  */
120 #define AV_CODEC_CAP_AVOID_PROBING (1 << 17)
121 
122 /**
123  * Codec is backed by a hardware implementation. Typically used to
124  * identify a non-hwaccel hardware decoder. For information about hwaccels, use
125  * avcodec_get_hw_config() instead.
126  */
127 #define AV_CODEC_CAP_HARDWARE (1 << 18)
128 
129 /**
130  * Codec is potentially backed by a hardware implementation, but not
131  * necessarily. This is used instead of AV_CODEC_CAP_HARDWARE, if the
132  * implementation provides some sort of internal fallback.
133  */
134 #define AV_CODEC_CAP_HYBRID (1 << 19)
135 
136 /**
137  * This encoder can reorder user opaque values from input AVFrames and return
138  * them with corresponding output packets.
139  * @see AV_CODEC_FLAG_COPY_OPAQUE
140  */
141 #define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE (1 << 20)
142 
143 /**
144  * This encoder can be flushed using avcodec_flush_buffers(). If this flag is
145  * not set, the encoder must be closed and reopened to ensure that no frames
146  * remain pending.
147  */
148 #define AV_CODEC_CAP_ENCODER_FLUSH (1 << 21)
149 
150 /**
151  * The encoder is able to output reconstructed frame data, i.e. raw frames that
152  * would be produced by decoding the encoded bitstream.
153  *
154  * Reconstructed frame output is enabled by the AV_CODEC_FLAG_RECON_FRAME flag.
155  */
156 #define AV_CODEC_CAP_ENCODER_RECON_FRAME (1 << 22)
157 
158 /**
159  * AVProfile.
160  */
161 typedef struct AVProfile {
162  int profile;
163  const char *name; ///< short name for the profile
164 } AVProfile;
165 
166 /**
167  * AVCodec.
168  */
169 typedef struct AVCodec {
170  /**
171  * Name of the codec implementation.
172  * The name is globally unique among encoders and among decoders (but an
173  * encoder and a decoder can share the same name).
174  * This is the primary way to find a codec from the user perspective.
175  */
176  const char *name;
177  /**
178  * Descriptive name for the codec, meant to be more human readable than name.
179  * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
180  */
181  const char *long_name;
183  enum AVCodecID id;
184  /**
185  * Codec capabilities.
186  * see AV_CODEC_CAP_*
187  */
189  uint8_t max_lowres; ///< maximum value for lowres supported by the decoder
190 
191  const AVClass *priv_class; ///< AVClass for the private context
192  const AVProfile *profiles; ///< array of recognized profiles, or NULL if unknown, array is terminated by {AV_PROFILE_UNKNOWN}
193 
194  /**
195  * Group name of the codec implementation.
196  * This is a short symbolic name of the wrapper backing this codec. A
197  * wrapper uses some kind of external implementation for the codec, such
198  * as an external library, or a codec implementation provided by the OS or
199  * the hardware.
200  * If this field is NULL, this is a builtin, libavcodec native codec.
201  * If non-NULL, this will be the suffix in AVCodec.name in most cases
202  * (usually AVCodec.name will be of the form "<codec_name>_<wrapper_name>").
203  */
204  const char *wrapper_name;
205 } AVCodec;
206 
207 /**
208  * Iterate over all registered codecs.
209  *
210  * @param opaque a pointer where libavcodec will store the iteration state. Must
211  * point to NULL to start the iteration.
212  *
213  * @return the next registered codec or NULL when the iteration is
214  * finished
215  */
216 const AVCodec *av_codec_iterate(void **opaque);
217 
218 /**
219  * Find a registered decoder with a matching codec ID.
220  *
221  * @param id AVCodecID of the requested decoder
222  * @return A decoder if one was found, NULL otherwise.
223  */
224 const AVCodec *avcodec_find_decoder(enum AVCodecID id);
225 
226 /**
227  * Find a registered decoder with the specified name.
228  *
229  * @param name name of the requested decoder
230  * @return A decoder if one was found, NULL otherwise.
231  */
232 const AVCodec *avcodec_find_decoder_by_name(const char *name);
233 
234 /**
235  * Find a registered encoder with a matching codec ID.
236  *
237  * @param id AVCodecID of the requested encoder
238  * @return An encoder if one was found, NULL otherwise.
239  */
240 const AVCodec *avcodec_find_encoder(enum AVCodecID id);
241 
242 /**
243  * Find a registered encoder with the specified name.
244  *
245  * @param name name of the requested encoder
246  * @return An encoder if one was found, NULL otherwise.
247  */
248 const AVCodec *avcodec_find_encoder_by_name(const char *name);
249 /**
250  * @return a non-zero number if codec is an encoder, zero otherwise
251  */
252 int av_codec_is_encoder(const AVCodec *codec);
253 
254 /**
255  * @return a non-zero number if codec is a decoder, zero otherwise
256  */
257 int av_codec_is_decoder(const AVCodec *codec);
258 
259 /**
260  * Return a name for the specified profile, if available.
261  *
262  * @param codec the codec that is searched for the given profile
263  * @param profile the profile value for which a name is requested
264  * @return A name for the profile if found, NULL otherwise.
265  */
266 const char *av_get_profile_name(const AVCodec *codec, int profile);
267 
268 enum {
269  /**
270  * The codec supports this format via the hw_device_ctx interface.
271  *
272  * When selecting this format, AVCodecContext.hw_device_ctx should
273  * have been set to a device of the specified type before calling
274  * avcodec_open2().
275  */
277  /**
278  * The codec supports this format via the hw_frames_ctx interface.
279  *
280  * When selecting this format for a decoder,
281  * AVCodecContext.hw_frames_ctx should be set to a suitable frames
282  * context inside the get_format() callback. The frames context
283  * must have been created on a device of the specified type.
284  *
285  * When selecting this format for an encoder,
286  * AVCodecContext.hw_frames_ctx should be set to the context which
287  * will be used for the input frames before calling avcodec_open2().
288  */
290  /**
291  * The codec supports this format by some internal method.
292  *
293  * This format can be selected without any additional configuration -
294  * no device or frames context is required.
295  */
297  /**
298  * The codec supports this format by some ad-hoc method.
299  *
300  * Additional settings and/or function calls are required. See the
301  * codec-specific documentation for details. (Methods requiring
302  * this sort of configuration are deprecated and others should be
303  * used in preference.)
304  */
306 };
307 
308 typedef struct AVCodecHWConfig {
309  /**
310  * For decoders, a hardware pixel format which that decoder may be
311  * able to decode to if suitable hardware is available.
312  *
313  * For encoders, a pixel format which the encoder may be able to
314  * accept. If set to AV_PIX_FMT_NONE, this applies to all pixel
315  * formats supported by the codec.
316  */
318  /**
319  * Bit set of AV_CODEC_HW_CONFIG_METHOD_* flags, describing the possible
320  * setup methods which can be used with this configuration.
321  */
322  int methods;
323  /**
324  * The device type associated with the configuration.
325  *
326  * Must be set for AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX and
327  * AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX, otherwise unused.
328  */
331 
332 /**
333  * Retrieve supported hardware configurations for a codec.
334  *
335  * Values of index from zero to some maximum return the indexed configuration
336  * descriptor; all other values return NULL. If the codec does not support
337  * any hardware configurations then it will always return NULL.
338  */
339 const AVCodecHWConfig *avcodec_get_hw_config(const AVCodec *codec, int index);
340 
341 /**
342  * @}
343  */
344 
345 #endif /* AVCODEC_CODEC_H */
AVCodec
AVCodec.
Definition: codec.h:169
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:71
name
it s the only field you need to keep assuming you have a context There is some magic you don t need to care about around this just let it vf default minimum maximum flags name is the option name
Definition: writing_filters.txt:88
AV_CODEC_HW_CONFIG_METHOD_INTERNAL
@ AV_CODEC_HW_CONFIG_METHOD_INTERNAL
The codec supports this format by some internal method.
Definition: codec.h:296
AVCodec::long_name
const char * long_name
Descriptive name for the codec, meant to be more human readable than name.
Definition: codec.h:181
AVCodecHWConfig::methods
int methods
Bit set of AV_CODEC_HW_CONFIG_METHOD_* flags, describing the possible setup methods which can be used...
Definition: codec.h:322
AVCodec::priv_class
const AVClass * priv_class
AVClass for the private context.
Definition: codec.h:191
AVProfile::name
const char * name
short name for the profile
Definition: codec.h:163
AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX
@ AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX
The codec supports this format via the hw_frames_ctx interface.
Definition: codec.h:289
AVCodec::wrapper_name
const char * wrapper_name
Group name of the codec implementation.
Definition: codec.h:204
avcodec_find_encoder
const AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
Definition: allcodecs.c:984
AVCodec::capabilities
int capabilities
Codec capabilities.
Definition: codec.h:188
AVProfile
AVProfile.
Definition: codec.h:161
AVCodec::max_lowres
uint8_t max_lowres
maximum value for lowres supported by the decoder
Definition: codec.h:189
AV_CODEC_HW_CONFIG_METHOD_AD_HOC
@ AV_CODEC_HW_CONFIG_METHOD_AD_HOC
The codec supports this format by some ad-hoc method.
Definition: codec.h:305
codec_id.h
AVHWDeviceType
AVHWDeviceType
Definition: hwcontext.h:27
AVCodecHWConfig::pix_fmt
enum AVPixelFormat pix_fmt
For decoders, a hardware pixel format which that decoder may be able to decode to if suitable hardwar...
Definition: codec.h:317
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:76
avcodec_find_decoder_by_name
const AVCodec * avcodec_find_decoder_by_name(const char *name)
Find a registered decoder with the specified name.
Definition: allcodecs.c:1017
AVCodec::type
enum AVMediaType type
Definition: codec.h:182
AVCodec::profiles
const AVProfile * profiles
array of recognized profiles, or NULL if unknown, array is terminated by {AV_PROFILE_UNKNOWN}
Definition: codec.h:192
AVProfile::profile
int profile
Definition: codec.h:162
index
int index
Definition: gxfenc.c:90
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:47
avcodec_find_decoder
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: allcodecs.c:989
av_codec_is_decoder
int av_codec_is_decoder(const AVCodec *codec)
Definition: utils.c:85
AVMediaType
AVMediaType
Definition: avutil.h:198
AVCodec::id
enum AVCodecID id
Definition: codec.h:183
av_codec_is_encoder
int av_codec_is_encoder(const AVCodec *codec)
Definition: utils.c:79
log.h
av_get_profile_name
const char * av_get_profile_name(const AVCodec *codec, int profile)
Return a name for the specified profile, if available.
Definition: utils.c:433
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:176
profile
int profile
Definition: mxfenc.c:2299
av_codec_iterate
const AVCodec * av_codec_iterate(void **opaque)
Iterate over all registered codecs.
Definition: allcodecs.c:942
pixfmt.h
avcodec_get_hw_config
const AVCodecHWConfig * avcodec_get_hw_config(const AVCodec *codec, int index)
Retrieve supported hardware configurations for a codec.
Definition: utils.c:857
avutil.h
hwcontext.h
AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
@ AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX
The codec supports this format via the hw_device_ctx interface.
Definition: codec.h:276
AVCodecHWConfig
Definition: codec.h:308
AVCodecHWConfig::device_type
enum AVHWDeviceType device_type
The device type associated with the configuration.
Definition: codec.h:329
avcodec_find_encoder_by_name
const AVCodec * avcodec_find_encoder_by_name(const char *name)
Find a registered encoder with the specified name.
Definition: allcodecs.c:1012