FFmpeg
7.1.4
Loading...
Searching...
No Matches
libavutil
frame.h
Go to the documentation of this file.
1
/*
2
* This file is part of FFmpeg.
3
*
4
* FFmpeg is free software; you can redistribute it and/or
5
* modify it under the terms of the GNU Lesser General Public
6
* License as published by the Free Software Foundation; either
7
* version 2.1 of the License, or (at your option) any later version.
8
*
9
* FFmpeg is distributed in the hope that it will be useful,
10
* but WITHOUT ANY WARRANTY; without even the implied warranty of
11
* MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
12
* Lesser General Public License for more details.
13
*
14
* You should have received a copy of the GNU Lesser General Public
15
* License along with FFmpeg; if not, write to the Free Software
16
* Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
17
*/
18
19
/**
20
* @file
21
* @ingroup lavu_frame
22
* reference-counted frame API
23
*/
24
25
#ifndef AVUTIL_FRAME_H
26
#define AVUTIL_FRAME_H
27
28
#include <stddef.h>
29
#include <stdint.h>
30
31
#include "
avutil.h
"
32
#include "
buffer.h
"
33
#include "
channel_layout.h
"
34
#include "
dict.h
"
35
#include "
rational.h
"
36
#include "
samplefmt.h
"
37
#include "
pixfmt.h
"
38
#include "
version.h
"
39
40
41
/**
42
* @defgroup lavu_frame AVFrame
43
* @ingroup lavu_data
44
*
45
* @{
46
* AVFrame is an abstraction for reference-counted raw multimedia data.
47
*/
48
49
enum
AVFrameSideDataType
{
50
/**
51
* The data is the AVPanScan struct defined in libavcodec.
52
*/
53
AV_FRAME_DATA_PANSCAN
,
54
/**
55
* ATSC A53 Part 4 Closed Captions.
56
* A53 CC bitstream is stored as uint8_t in AVFrameSideData.data.
57
* The number of bytes of CC data is AVFrameSideData.size.
58
*/
59
AV_FRAME_DATA_A53_CC
,
60
/**
61
* Stereoscopic 3d metadata.
62
* The data is the AVStereo3D struct defined in libavutil/stereo3d.h.
63
*/
64
AV_FRAME_DATA_STEREO3D
,
65
/**
66
* The data is the AVMatrixEncoding enum defined in libavutil/channel_layout.h.
67
*/
68
AV_FRAME_DATA_MATRIXENCODING
,
69
/**
70
* Metadata relevant to a downmix procedure.
71
* The data is the AVDownmixInfo struct defined in libavutil/downmix_info.h.
72
*/
73
AV_FRAME_DATA_DOWNMIX_INFO
,
74
/**
75
* ReplayGain information in the form of the AVReplayGain struct.
76
*/
77
AV_FRAME_DATA_REPLAYGAIN
,
78
/**
79
* This side data contains a 3x3 transformation matrix describing an affine
80
* transformation that needs to be applied to the frame for correct
81
* presentation.
82
*
83
* See libavutil/display.h for a detailed description of the data.
84
*/
85
AV_FRAME_DATA_DISPLAYMATRIX
,
86
/**
87
* Active Format Description data consisting of a single byte as specified
88
* in ETSI TS 101 154 using AVActiveFormatDescription enum.
89
*/
90
AV_FRAME_DATA_AFD
,
91
/**
92
* Motion vectors exported by some codecs (on demand through the export_mvs
93
* flag set in the libavcodec AVCodecContext flags2 option).
94
* The data is the AVMotionVector struct defined in
95
* libavutil/motion_vector.h.
96
*/
97
AV_FRAME_DATA_MOTION_VECTORS
,
98
/**
99
* Recommmends skipping the specified number of samples. This is exported
100
* only if the "skip_manual" AVOption is set in libavcodec.
101
* This has the same format as AV_PKT_DATA_SKIP_SAMPLES.
102
* @code
103
* u32le number of samples to skip from start of this packet
104
* u32le number of samples to skip from end of this packet
105
* u8 reason for start skip
106
* u8 reason for end skip (0=padding silence, 1=convergence)
107
* @endcode
108
*/
109
AV_FRAME_DATA_SKIP_SAMPLES
,
110
/**
111
* This side data must be associated with an audio frame and corresponds to
112
* enum AVAudioServiceType defined in avcodec.h.
113
*/
114
AV_FRAME_DATA_AUDIO_SERVICE_TYPE
,
115
/**
116
* Mastering display metadata associated with a video frame. The payload is
117
* an AVMasteringDisplayMetadata type and contains information about the
118
* mastering display color volume.
119
*/
120
AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
,
121
/**
122
* The GOP timecode in 25 bit timecode format. Data format is 64-bit integer.
123
* This is set on the first frame of a GOP that has a temporal reference of 0.
124
*/
125
AV_FRAME_DATA_GOP_TIMECODE
,
126
127
/**
128
* The data represents the AVSphericalMapping structure defined in
129
* libavutil/spherical.h.
130
*/
131
AV_FRAME_DATA_SPHERICAL
,
132
133
/**
134
* Content light level (based on CTA-861.3). This payload contains data in
135
* the form of the AVContentLightMetadata struct.
136
*/
137
AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
,
138
139
/**
140
* The data contains an ICC profile as an opaque octet buffer following the
141
* format described by ISO 15076-1 with an optional name defined in the
142
* metadata key entry "name".
143
*/
144
AV_FRAME_DATA_ICC_PROFILE
,
145
146
/**
147
* Timecode which conforms to SMPTE ST 12-1. The data is an array of 4 uint32_t
148
* where the first uint32_t describes how many (1-3) of the other timecodes are used.
149
* The timecode format is described in the documentation of av_timecode_get_smpte_from_framenum()
150
* function in libavutil/timecode.h.
151
*/
152
AV_FRAME_DATA_S12M_TIMECODE
,
153
154
/**
155
* HDR dynamic metadata associated with a video frame. The payload is
156
* an AVDynamicHDRPlus type and contains information for color
157
* volume transform - application 4 of SMPTE 2094-40:2016 standard.
158
*/
159
AV_FRAME_DATA_DYNAMIC_HDR_PLUS
,
160
161
/**
162
* Regions Of Interest, the data is an array of AVRegionOfInterest type, the number of
163
* array element is implied by AVFrameSideData.size / AVRegionOfInterest.self_size.
164
*/
165
AV_FRAME_DATA_REGIONS_OF_INTEREST
,
166
167
/**
168
* Encoding parameters for a video frame, as described by AVVideoEncParams.
169
*/
170
AV_FRAME_DATA_VIDEO_ENC_PARAMS
,
171
172
/**
173
* User data unregistered metadata associated with a video frame.
174
* This is the H.26[45] UDU SEI message, and shouldn't be used for any other purpose
175
* The data is stored as uint8_t in AVFrameSideData.data which is 16 bytes of
176
* uuid_iso_iec_11578 followed by AVFrameSideData.size - 16 bytes of user_data_payload_byte.
177
*/
178
AV_FRAME_DATA_SEI_UNREGISTERED
,
179
180
/**
181
* Film grain parameters for a frame, described by AVFilmGrainParams.
182
* Must be present for every frame which should have film grain applied.
183
*
184
* May be present multiple times, for example when there are multiple
185
* alternative parameter sets for different video signal characteristics.
186
* The user should select the most appropriate set for the application.
187
*/
188
AV_FRAME_DATA_FILM_GRAIN_PARAMS
,
189
190
/**
191
* Bounding boxes for object detection and classification,
192
* as described by AVDetectionBBoxHeader.
193
*/
194
AV_FRAME_DATA_DETECTION_BBOXES
,
195
196
/**
197
* Dolby Vision RPU raw data, suitable for passing to x265
198
* or other libraries. Array of uint8_t, with NAL emulation
199
* bytes intact.
200
*/
201
AV_FRAME_DATA_DOVI_RPU_BUFFER
,
202
203
/**
204
* Parsed Dolby Vision metadata, suitable for passing to a software
205
* implementation. The payload is the AVDOVIMetadata struct defined in
206
* libavutil/dovi_meta.h.
207
*/
208
AV_FRAME_DATA_DOVI_METADATA
,
209
210
/**
211
* HDR Vivid dynamic metadata associated with a video frame. The payload is
212
* an AVDynamicHDRVivid type and contains information for color
213
* volume transform - CUVA 005.1-2021.
214
*/
215
AV_FRAME_DATA_DYNAMIC_HDR_VIVID
,
216
217
/**
218
* Ambient viewing environment metadata, as defined by H.274.
219
*/
220
AV_FRAME_DATA_AMBIENT_VIEWING_ENVIRONMENT
,
221
222
/**
223
* Provide encoder-specific hinting information about changed/unchanged
224
* portions of a frame. It can be used to pass information about which
225
* macroblocks can be skipped because they didn't change from the
226
* corresponding ones in the previous frame. This could be useful for
227
* applications which know this information in advance to speed up
228
* encoding.
229
*/
230
AV_FRAME_DATA_VIDEO_HINT
,
231
232
/**
233
* Raw LCEVC payload data, as a uint8_t array, with NAL emulation
234
* bytes intact.
235
*/
236
AV_FRAME_DATA_LCEVC
,
237
238
/**
239
* This side data must be associated with a video frame.
240
* The presence of this side data indicates that the video stream is
241
* composed of multiple views (e.g. stereoscopic 3D content,
242
* cf. H.264 Annex H or H.265 Annex G).
243
* The data is an int storing the view ID.
244
*/
245
AV_FRAME_DATA_VIEW_ID
,
246
};
247
248
enum
AVActiveFormatDescription
{
249
AV_AFD_SAME
= 8,
250
AV_AFD_4_3
= 9,
251
AV_AFD_16_9
= 10,
252
AV_AFD_14_9
= 11,
253
AV_AFD_4_3_SP_14_9
= 13,
254
AV_AFD_16_9_SP_14_9
= 14,
255
AV_AFD_SP_4_3
= 15,
256
};
257
258
259
/**
260
* Structure to hold side data for an AVFrame.
261
*
262
* sizeof(AVFrameSideData) is not a part of the public ABI, so new fields may be added
263
* to the end with a minor bump.
264
*/
265
typedef
struct
AVFrameSideData
{
266
enum
AVFrameSideDataType
type
;
267
uint8_t *
data
;
268
size_t
size
;
269
AVDictionary
*
metadata
;
270
AVBufferRef
*
buf
;
271
}
AVFrameSideData
;
272
273
enum
AVSideDataProps
{
274
/**
275
* The side data type can be used in stream-global structures.
276
* Side data types without this property are only meaningful on per-frame
277
* basis.
278
*/
279
AV_SIDE_DATA_PROP_GLOBAL
= (1 << 0),
280
281
/**
282
* Multiple instances of this side data type can be meaningfully present in
283
* a single side data array.
284
*/
285
AV_SIDE_DATA_PROP_MULTI
= (1 << 1),
286
};
287
288
/**
289
* This struct describes the properties of a side data type. Its instance
290
* corresponding to a given type can be obtained from av_frame_side_data_desc().
291
*/
292
typedef
struct
AVSideDataDescriptor
{
293
/**
294
* Human-readable side data description.
295
*/
296
const
char
*
name
;
297
298
/**
299
* Side data property flags, a combination of AVSideDataProps values.
300
*/
301
unsigned
props
;
302
}
AVSideDataDescriptor
;
303
304
/**
305
* Structure describing a single Region Of Interest.
306
*
307
* When multiple regions are defined in a single side-data block, they
308
* should be ordered from most to least important - some encoders are only
309
* capable of supporting a limited number of distinct regions, so will have
310
* to truncate the list.
311
*
312
* When overlapping regions are defined, the first region containing a given
313
* area of the frame applies.
314
*/
315
typedef
struct
AVRegionOfInterest
{
316
/**
317
* Must be set to the size of this data structure (that is,
318
* sizeof(AVRegionOfInterest)).
319
*/
320
uint32_t
self_size
;
321
/**
322
* Distance in pixels from the top edge of the frame to the top and
323
* bottom edges and from the left edge of the frame to the left and
324
* right edges of the rectangle defining this region of interest.
325
*
326
* The constraints on a region are encoder dependent, so the region
327
* actually affected may be slightly larger for alignment or other
328
* reasons.
329
*/
330
int
top
;
331
int
bottom
;
332
int
left
;
333
int
right
;
334
/**
335
* Quantisation offset.
336
*
337
* Must be in the range -1 to +1. A value of zero indicates no quality
338
* change. A negative value asks for better quality (less quantisation),
339
* while a positive value asks for worse quality (greater quantisation).
340
*
341
* The range is calibrated so that the extreme values indicate the
342
* largest possible offset - if the rest of the frame is encoded with the
343
* worst possible quality, an offset of -1 indicates that this region
344
* should be encoded with the best possible quality anyway. Intermediate
345
* values are then interpolated in some codec-dependent way.
346
*
347
* For example, in 10-bit H.264 the quantisation parameter varies between
348
* -12 and 51. A typical qoffset value of -1/10 therefore indicates that
349
* this region should be encoded with a QP around one-tenth of the full
350
* range better than the rest of the frame. So, if most of the frame
351
* were to be encoded with a QP of around 30, this region would get a QP
352
* of around 24 (an offset of approximately -1/10 * (51 - -12) = -6.3).
353
* An extreme value of -1 would indicate that this region should be
354
* encoded with the best possible quality regardless of the treatment of
355
* the rest of the frame - that is, should be encoded at a QP of -12.
356
*/
357
AVRational
qoffset
;
358
}
AVRegionOfInterest
;
359
360
/**
361
* This structure describes decoded (raw) audio or video data.
362
*
363
* AVFrame must be allocated using av_frame_alloc(). Note that this only
364
* allocates the AVFrame itself, the buffers for the data must be managed
365
* through other means (see below).
366
* AVFrame must be freed with av_frame_free().
367
*
368
* AVFrame is typically allocated once and then reused multiple times to hold
369
* different data (e.g. a single AVFrame to hold frames received from a
370
* decoder). In such a case, av_frame_unref() will free any references held by
371
* the frame and reset it to its original clean state before it
372
* is reused again.
373
*
374
* The data described by an AVFrame is usually reference counted through the
375
* AVBuffer API. The underlying buffer references are stored in AVFrame.buf /
376
* AVFrame.extended_buf. An AVFrame is considered to be reference counted if at
377
* least one reference is set, i.e. if AVFrame.buf[0] != NULL. In such a case,
378
* every single data plane must be contained in one of the buffers in
379
* AVFrame.buf or AVFrame.extended_buf.
380
* There may be a single buffer for all the data, or one separate buffer for
381
* each plane, or anything in between.
382
*
383
* sizeof(AVFrame) is not a part of the public ABI, so new fields may be added
384
* to the end with a minor bump.
385
*
386
* Fields can be accessed through AVOptions, the name string used, matches the
387
* C structure field name for fields accessible through AVOptions.
388
*/
389
typedef
struct
AVFrame
{
390
#define AV_NUM_DATA_POINTERS 8
391
/**
392
* pointer to the picture/channel planes.
393
* This might be different from the first allocated byte. For video,
394
* it could even point to the end of the image data.
395
*
396
* All pointers in data and extended_data must point into one of the
397
* AVBufferRef in buf or extended_buf.
398
*
399
* Some decoders access areas outside 0,0 - width,height, please
400
* see avcodec_align_dimensions2(). Some filters and swscale can read
401
* up to 16 bytes beyond the planes, if these filters are to be used,
402
* then 16 extra bytes must be allocated.
403
*
404
* NOTE: Pointers not needed by the format MUST be set to NULL.
405
*
406
* @attention In case of video, the data[] pointers can point to the
407
* end of image data in order to reverse line order, when used in
408
* combination with negative values in the linesize[] array.
409
*/
410
uint8_t *
data
[
AV_NUM_DATA_POINTERS
];
411
412
/**
413
* For video, a positive or negative value, which is typically indicating
414
* the size in bytes of each picture line, but it can also be:
415
* - the negative byte size of lines for vertical flipping
416
* (with data[n] pointing to the end of the data
417
* - a positive or negative multiple of the byte size as for accessing
418
* even and odd fields of a frame (possibly flipped)
419
*
420
* For audio, only linesize[0] may be set. For planar audio, each channel
421
* plane must be the same size.
422
*
423
* For video the linesizes should be multiples of the CPUs alignment
424
* preference, this is 16 or 32 for modern desktop CPUs.
425
* Some code requires such alignment other code can be slower without
426
* correct alignment, for yet other it makes no difference.
427
*
428
* @note The linesize may be larger than the size of usable data -- there
429
* may be extra padding present for performance reasons.
430
*
431
* @attention In case of video, line size values can be negative to achieve
432
* a vertically inverted iteration over image lines.
433
*/
434
int
linesize
[
AV_NUM_DATA_POINTERS
];
435
436
/**
437
* pointers to the data planes/channels.
438
*
439
* For video, this should simply point to data[].
440
*
441
* For planar audio, each channel has a separate data pointer, and
442
* linesize[0] contains the size of each channel buffer.
443
* For packed audio, there is just one data pointer, and linesize[0]
444
* contains the total size of the buffer for all channels.
445
*
446
* Note: Both data and extended_data should always be set in a valid frame,
447
* but for planar audio with more channels that can fit in data,
448
* extended_data must be used in order to access all channels.
449
*/
450
uint8_t **
extended_data
;
451
452
/**
453
* @name Video dimensions
454
* Video frames only. The coded dimensions (in pixels) of the video frame,
455
* i.e. the size of the rectangle that contains some well-defined values.
456
*
457
* @note The part of the frame intended for display/presentation is further
458
* restricted by the @ref cropping "Cropping rectangle".
459
* @{
460
*/
461
int
width
,
height
;
462
/**
463
* @}
464
*/
465
466
/**
467
* number of audio samples (per channel) described by this frame
468
*/
469
int
nb_samples
;
470
471
/**
472
* format of the frame, -1 if unknown or unset
473
* Values correspond to enum AVPixelFormat for video frames,
474
* enum AVSampleFormat for audio)
475
*/
476
int
format
;
477
478
#if FF_API_FRAME_KEY
479
/**
480
* 1 -> keyframe, 0-> not
481
*
482
* @deprecated Use AV_FRAME_FLAG_KEY instead
483
*/
484
attribute_deprecated
485
int
key_frame;
486
#endif
487
488
/**
489
* Picture type of the frame.
490
*/
491
enum
AVPictureType
pict_type
;
492
493
/**