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 #include "libavutil/rational.h"
31 #include "libavutil/samplefmt.h"
32 
33 #include "libavcodec/codec_id.h"
35 
36 /**
37  * @addtogroup lavc_core
38  * @{
39  */
40 
41 /**
42  * Decoder can use draw_horiz_band callback.
43  */
44 #define AV_CODEC_CAP_DRAW_HORIZ_BAND (1 << 0)
45 /**
46  * Codec uses get_buffer() or get_encode_buffer() for allocating buffers and
47  * supports custom allocators.
48  * If not set, it might not use get_buffer() or get_encode_buffer() at all, or
49  * use operations that assume the buffer was allocated by
50  * avcodec_default_get_buffer2 or avcodec_default_get_encode_buffer.
51  */
52 #define AV_CODEC_CAP_DR1 (1 << 1)
53 /**
54  * Encoder or decoder requires flushing with NULL input at the end in order to
55  * give the complete and correct output.
56  *
57  * NOTE: If this flag is not set, the codec is guaranteed to never be fed with
58  * with NULL data. The user can still send NULL data to the public encode
59  * or decode function, but libavcodec will not pass it along to the codec
60  * unless this flag is set.
61  *
62  * Decoders:
63  * The decoder has a non-zero delay and needs to be fed with avpkt->data=NULL,
64  * avpkt->size=0 at the end to get the delayed data until the decoder no longer
65  * returns frames.
66  *
67  * Encoders:
68  * The encoder needs to be fed with NULL data at the end of encoding until the
69  * encoder no longer returns data.
70  *
71  * NOTE: For encoders implementing the AVCodec.encode2() function, setting this
72  * flag also means that the encoder must set the pts and duration for
73  * each output packet. If this flag is not set, the pts and duration will
74  * be determined by libavcodec from the input frame.
75  */
76 #define AV_CODEC_CAP_DELAY (1 << 5)
77 /**
78  * Codec can be fed a final frame with a smaller size.
79  * This can be used to prevent truncation of the last audio samples.
80  */
81 #define AV_CODEC_CAP_SMALL_LAST_FRAME (1 << 6)
82 
83 #if FF_API_SUBFRAMES
84 /**
85  * Codec can output multiple frames per AVPacket
86  * Normally demuxers return one frame at a time, demuxers which do not do
87  * are connected to a parser to split what they return into proper frames.
88  * This flag is reserved to the very rare category of codecs which have a
89  * bitstream that cannot be split into frames without timeconsuming
90  * operations like full decoding. Demuxers carrying such bitstreams thus
91  * may return multiple frames in a packet. This has many disadvantages like
92  * prohibiting stream copy in many cases thus it should only be considered
93  * as a last resort.
94  */
95 #define AV_CODEC_CAP_SUBFRAMES (1 << 8)
96 #endif
97 
98 /**
99  * Codec is experimental and is thus avoided in favor of non experimental
100  * encoders
101  */
102 #define AV_CODEC_CAP_EXPERIMENTAL (1 << 9)
103 /**
104  * Codec should fill in channel configuration and samplerate instead of container
105  */
106 #define AV_CODEC_CAP_CHANNEL_CONF (1 << 10)
107 /**
108  * Codec supports frame-level multithreading.
109  */
110 #define AV_CODEC_CAP_FRAME_THREADS (1 << 12)
111 /**
112  * Codec supports slice-based (or partition-based) multithreading.
113  */
114 #define AV_CODEC_CAP_SLICE_THREADS (1 << 13)
115 /**
116  * Codec supports changed parameters at any point.
117  */
118 #define AV_CODEC_CAP_PARAM_CHANGE (1 << 14)
119 /**
120  * Codec supports multithreading through a method other than slice- or
121  * frame-level multithreading. Typically this marks wrappers around
122  * multithreading-capable external libraries.
123  */
124 #define AV_CODEC_CAP_OTHER_THREADS (1 << 15)
125 /**
126  * Audio encoder supports receiving a different number of samples in each call.
127  */
128 #define AV_CODEC_CAP_VARIABLE_FRAME_SIZE (1 << 16)
129 /**
130  * Decoder is not a preferred choice for probing.
131  * This indicates that the decoder is not a good choice for probing.
132  * It could for example be an expensive to spin up hardware decoder,
133  * or it could simply not provide a lot of useful information about
134  * the stream.
135  * A decoder marked with this flag should only be used as last resort
136  * choice for probing.
137  */
138 #define AV_CODEC_CAP_AVOID_PROBING (1 << 17)
139 
140 /**
141  * Codec is backed by a hardware implementation. Typically used to
142  * identify a non-hwaccel hardware decoder. For information about hwaccels, use
143  * avcodec_get_hw_config() instead.
144  */
145 #define AV_CODEC_CAP_HARDWARE (1 << 18)
146 
147 /**
148  * Codec is potentially backed by a hardware implementation, but not
149  * necessarily. This is used instead of AV_CODEC_CAP_HARDWARE, if the
150  * implementation provides some sort of internal fallback.
151  */
152 #define AV_CODEC_CAP_HYBRID (1 << 19)
153 
154 /**
155  * This encoder can reorder user opaque values from input AVFrames and return
156  * them with corresponding output packets.
157  * @see AV_CODEC_FLAG_COPY_OPAQUE
158  */
159 #define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE (1 << 20)
160 
161 /**
162  * This encoder can be flushed using avcodec_flush_buffers(). If this flag is
163  * not set, the encoder must be closed and reopened to ensure that no frames
164  * remain pending.
165  */
166 #define AV_CODEC_CAP_ENCODER_FLUSH (1 << 21)
167 
168 /**
169  * The encoder is able to output reconstructed frame data, i.e. raw frames that
170  * would be produced by decoding the encoded bitstream.
171  *
172  * Reconstructed frame output is enabled by the AV_CODEC_FLAG_RECON_FRAME flag.
173  */
174 #define AV_CODEC_CAP_ENCODER_RECON_FRAME (1 << 22)
175 
176 /**
177  * AVProfile.
178  */
179 typedef struct AVProfile {
180  int profile;
181  const char *name; ///< short name for the profile
182 } AVProfile;
183 
184 /**
185  * AVCodec.
186  */
187 typedef struct AVCodec {
188  /**
189  * Name of the codec implementation.
190  * The name is globally unique among encoders and among decoders (but an
191  * encoder and a decoder can share the same name).
192  * This is the primary way to find a codec from the user perspective.
193  */
194  const char *name;
195  /**
196  * Descriptive name for the codec, meant to be more human readable than name.
197  * You should use the NULL_IF_CONFIG_SMALL() macro to define it.
198  */
199  const char *long_name;
201  enum AVCodecID id;
202  /**
203  * Codec capabilities.
204  * see AV_CODEC_CAP_*
205  */
207  uint8_t max_lowres; ///< maximum value for lowres supported by the decoder
208  const AVRational *supported_framerates; ///< array of supported framerates, or NULL if any, array is terminated by {0,0}
209  const enum AVPixelFormat *pix_fmts; ///< array of supported pixel formats, or NULL if unknown, array is terminated by -1
210  const int *supported_samplerates; ///< array of supported audio samplerates, or NULL if unknown, array is terminated by 0
211  const enum AVSampleFormat *sample_fmts; ///< array of supported sample formats, or NULL if unknown, array is terminated by -1
212 #if FF_API_OLD_CHANNEL_LAYOUT
213  /**
214  * @deprecated use ch_layouts instead
215  */
217  const uint64_t *channel_layouts; ///< array of support channel layouts, or NULL if unknown. array is terminated by 0
218 #endif
219  const AVClass *priv_class; ///< AVClass for the private context
220  const AVProfile *profiles; ///< array of recognized profiles, or NULL if unknown, array is terminated by {AV_PROFILE_UNKNOWN}
221 
222  /**
223  * Group name of the codec implementation.
224  * This is a short symbolic name of the wrapper backing this codec. A
225  * wrapper uses some kind of external implementation for the codec, such
226  * as an external library, or a codec implementation provided by the OS or
227  * the hardware.
228  * If this field is NULL, this is a builtin, libavcodec native codec.
229  * If non-NULL, this will be the suffix in AVCodec.name in most cases
230  * (usually AVCodec.name will be of the form "<codec_name>_<wrapper_name>").
231  */
232  const char *wrapper_name;
233 
234  /**
235  * Array of supported channel layouts, terminated with a zeroed layout.
236  */
238 } AVCodec;
239 
240 /**
241  * Iterate over all registered codecs.
242  *
243  * @param opaque a pointer where libavcodec will store the iteration state. Must
244  * point to NULL to start the iteration.
245  *
246  * @return the next registered codec or NULL when the iteration is
247  * finished
248  */
249 const AVCodec *av_codec_iterate(void **opaque);
250 
251 /**
252  * Find a registered decoder with a matching codec ID.
253  *
254  * @param id AVCodecID of the requested decoder
255  * @return A decoder if one was found, NULL otherwise.
256  */
257 const AVCodec *avcodec_find_decoder(enum AVCodecID id);
258 
259 /**
260  * Find a registered decoder with the specified name.
261  *
262  * @param name name of the requested decoder
263  * @return A decoder if one was found, NULL otherwise.
264  */
265 const AVCodec *avcodec_find_decoder_by_name(const char *name);
266 
267 /**
268  * Find a registered encoder with a matching codec ID.
269  *
270  * @param id AVCodecID of the requested encoder
271  * @return An encoder if one was found, NULL otherwise.
272  */
273 const AVCodec *avcodec_find_encoder(enum AVCodecID id);
274 
275 /**
276  * Find a registered encoder with the specified name.
277  *
278  * @param name name of the requested encoder
279  * @return An encoder if one was found, NULL otherwise.
280  */
281 const AVCodec *avcodec_find_encoder_by_name(const char *name);
282 /**
283  * @return a non-zero number if codec is an encoder, zero otherwise
284  */
285 int av_codec_is_encoder(const AVCodec *codec);
286 
287 /**
288  * @return a non-zero number if codec is a decoder, zero otherwise
289  */
290 int av_codec_is_decoder(const AVCodec *codec);
291 
292 /**
293  * Return a name for the specified profile, if available.
294  *
295  * @param codec the codec that is searched for the given profile
296  * @param profile the profile value for which a name is requested
297  * @return A name for the profile if found, NULL otherwise.
298  */
299 const char *av_get_profile_name(const AVCodec *codec, int profile);
300 
301 enum {
302  /**
303  * The codec supports this format via the hw_device_ctx interface.
304  *
305  * When selecting this format, AVCodecContext.hw_device_ctx should
306  * have been set to a device of the specified type before calling
307  * avcodec_open2().
308  */
310  /**
311  * The codec supports this format via the hw_frames_ctx interface.
312  *
313  * When selecting this format for a decoder,
314  * AVCodecContext.hw_frames_ctx should be set to a suitable frames
315  * context inside the get_format() callback. The frames context
316  * must have been created on a device of the specified type.
317  *
318  * When selecting this format for an encoder,
319  * AVCodecContext.hw_frames_ctx should be set to the context which
320  * will be used for the input frames before calling avcodec_open2().
321  */
323  /**
324  * The codec supports this format by some internal method.
325  *
326  * This format can be selected without any additional configuration -
327  * no device or frames context is required.
328  */
330  /**
331  * The codec supports this format by some ad-hoc method.
332  *
333  * Additional settings and/or function calls are required. See the
334  * codec-specific documentation for details. (Methods requiring
335  * this sort of configuration are deprecated and others should be
336  * used in preference.)
337  */
339 };
340 
341 typedef struct AVCodecHWConfig {
342  /**
343  * For decoders, a hardware pixel format which that decoder may be
344  * able to decode to if suitable hardware is available.
345  *
346  * For encoders, a pixel format which the encoder may be able to
347  * accept. If set to AV_PIX_FMT_NONE, this applies to all pixel
348  * formats supported by the codec.
349  */
351  /**
352  * Bit set of AV_CODEC_HW_CONFIG_METHOD_* flags, describing the possible
353  * setup methods which can be used with this configuration.
354  */
355  int methods;
356  /**
357  * The device type associated with the configuration.
358  *
359  * Must be set for AV_CODEC_HW_CONFIG_METHOD_HW_DEVICE_CTX and
360  * AV_CODEC_HW_CONFIG_METHOD_HW_FRAMES_CTX, otherwise unused.
361  */
364 
365 /**
366  * Retrieve supported hardware configurations for a codec.
367  *
368  * Values of index from zero to some maximum return the indexed configuration
369  * descriptor; all other values return NULL. If the codec does not support
370  * any hardware configurations then it will always return NULL.
371  */
372 const AVCodecHWConfig *avcodec_get_hw_config(const AVCodec *codec, int index);
373 
374 /**
375  * @}
376  */
377 
378 #endif /* AVCODEC_CODEC_H */
AVCodec::ch_layouts
const AVChannelLayout * ch_layouts
Array of supported channel layouts, terminated with a zeroed layout.
Definition: codec.h:237
AVCodec
AVCodec.
Definition: codec.h:187
AVPixelFormat
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
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
AVCodec::long_name
const char * long_name
Descriptive name for the codec, meant to be more human readable than name.
Definition: codec.h:199
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:355
AVCodec::priv_class
const AVClass * priv_class
AVClass for the private context.
Definition: codec.h:219
AVProfile::name
const char * name
short name for the profile
Definition: codec.h:181
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:322
rational.h
AVCodec::pix_fmts
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
Definition: codec.h:209
AVCodec::wrapper_name
const char * wrapper_name
Group name of the codec implementation.
Definition: codec.h:232
avcodec_find_encoder
const AVCodec * avcodec_find_encoder(enum AVCodecID id)
Find a registered encoder with a matching codec ID.
Definition: allcodecs.c:970
AVCodec::capabilities
int capabilities
Codec capabilities.
Definition: codec.h:206
version_major.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:309
AVProfile
AVProfile.
Definition: codec.h:179
AVCodec::max_lowres
uint8_t max_lowres
maximum value for lowres supported by the decoder
Definition: codec.h:207
AVCodec::sample_fmts
enum AVSampleFormat * sample_fmts
array of supported sample formats, or NULL if unknown, array is terminated by -1
Definition: codec.h:211
samplefmt.h
AVCodec::supported_samplerates
const int * supported_samplerates
array of supported audio samplerates, or NULL if unknown, array is terminated by 0
Definition: codec.h:210
codec_id.h
AVCodec::supported_framerates
const AVRational * supported_framerates
array of supported framerates, or NULL if any, array is terminated by {0,0}
Definition: codec.h:208
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:350
AVClass
Describe the class of an AVClass context structure.
Definition: log.h:66
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:1003
AVCodec::type
enum AVMediaType type
Definition: codec.h:200
AVRational
Rational number (pair of numerator and denominator).
Definition: rational.h:58
AVCodec::profiles
const AVProfile * profiles
array of recognized profiles, or NULL if unknown, array is terminated by {AV_PROFILE_UNKNOWN}
Definition: codec.h:220
AVProfile::profile
int profile
Definition: codec.h:180
index
int index
Definition: gxfenc.c:89
AVCodecID
AVCodecID
Identify the syntax and semantics of the bitstream.
Definition: codec_id.h:49
avcodec_find_decoder
const AVCodec * avcodec_find_decoder(enum AVCodecID id)
Find a registered decoder with a matching codec ID.
Definition: allcodecs.c:975
av_codec_is_decoder
int av_codec_is_decoder(const AVCodec *codec)
Definition: utils.c:86
AVMediaType
AVMediaType
Definition: avutil.h:199
AVChannelLayout
An AVChannelLayout holds information about the channel layout of audio data.
Definition: channel_layout.h:307
attribute_deprecated
#define attribute_deprecated
Definition: attributes.h:104
AVCodec::id
enum AVCodecID id
Definition: codec.h:201
av_codec_is_encoder
int av_codec_is_encoder(const AVCodec *codec)
Definition: utils.c:78
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:437
AVSampleFormat
AVSampleFormat
Audio sample formats.
Definition: samplefmt.h:55
AVCodec::name
const char * name
Name of the codec implementation.
Definition: codec.h:194
profile
int profile
Definition: mxfenc.c:2115
av_codec_iterate
const AVCodec * av_codec_iterate(void **opaque)
Iterate over all registered codecs.
Definition: allcodecs.c:926
pixfmt.h
AV_CODEC_HW_CONFIG_METHOD_INTERNAL
@ AV_CODEC_HW_CONFIG_METHOD_INTERNAL
The codec supports this format by some internal method.
Definition: codec.h:329
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:859
avutil.h
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:338
channel_layouts
static const uint16_t channel_layouts[7]
Definition: dca_lbr.c:111
hwcontext.h
AVCodecHWConfig
Definition: codec.h:341
AVCodecHWConfig::device_type
enum AVHWDeviceType device_type
The device type associated with the configuration.
Definition: codec.h:362
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:998