Libav
frame.c
Go to the documentation of this file.
1 /*
2  *
3  * This file is part of Libav.
4  *
5  * Libav is free software; you can redistribute it and/or
6  * modify it under the terms of the GNU Lesser General Public
7  * License as published by the Free Software Foundation; either
8  * version 2.1 of the License, or (at your option) any later version.
9  *
10  * Libav is distributed in the hope that it will be useful,
11  * but WITHOUT ANY WARRANTY; without even the implied warranty of
12  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
13  * Lesser General Public License for more details.
14  *
15  * You should have received a copy of the GNU Lesser General Public
16  * License along with Libav; if not, write to the Free Software
17  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
18  */
19 
20 #include "channel_layout.h"
21 #include "buffer.h"
22 #include "common.h"
23 #include "dict.h"
24 #include "frame.h"
25 #include "imgutils.h"
26 #include "mem.h"
27 #include "samplefmt.h"
28 
29 static void get_frame_defaults(AVFrame *frame)
30 {
31  if (frame->extended_data != frame->data)
32  av_freep(&frame->extended_data);
33 
34  memset(frame, 0, sizeof(*frame));
35 
36  frame->pts = AV_NOPTS_VALUE;
37  frame->key_frame = 1;
38  frame->sample_aspect_ratio = (AVRational){ 0, 1 };
39  frame->format = -1; /* unknown */
40  frame->extended_data = frame->data;
46 }
47 
48 static void free_side_data(AVFrameSideData **ptr_sd)
49 {
50  AVFrameSideData *sd = *ptr_sd;
51 
52  av_freep(&sd->data);
53  av_dict_free(&sd->metadata);
54  av_freep(ptr_sd);
55 }
56 
58 {
59  AVFrame *frame = av_mallocz(sizeof(*frame));
60 
61  if (!frame)
62  return NULL;
63 
64  get_frame_defaults(frame);
65 
66  return frame;
67 }
68 
69 void av_frame_free(AVFrame **frame)
70 {
71  if (!frame || !*frame)
72  return;
73 
74  av_frame_unref(*frame);
75  av_freep(frame);
76 }
77 
78 static int get_video_buffer(AVFrame *frame, int align)
79 {
80  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
81  int ret, i;
82 
83  if (!desc)
84  return AVERROR(EINVAL);
85 
86  if ((ret = av_image_check_size(frame->width, frame->height, 0, NULL)) < 0)
87  return ret;
88 
89  if (!frame->linesize[0]) {
90  ret = av_image_fill_linesizes(frame->linesize, frame->format,
91  frame->width);
92  if (ret < 0)
93  return ret;
94 
95  for (i = 0; i < 4 && frame->linesize[i]; i++)
96  frame->linesize[i] = FFALIGN(frame->linesize[i], align);
97  }
98 
99  for (i = 0; i < 4 && frame->linesize[i]; i++) {
100  int h = frame->height;
101  if (i == 1 || i == 2)
102  h = -((-h) >> desc->log2_chroma_h);
103 
104  frame->buf[i] = av_buffer_alloc(frame->linesize[i] * h);
105  if (!frame->buf[i])
106  goto fail;
107 
108  frame->data[i] = frame->buf[i]->data;
109  }
110  if (desc->flags & AV_PIX_FMT_FLAG_PAL || desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL) {
111  av_buffer_unref(&frame->buf[1]);
112  frame->buf[1] = av_buffer_alloc(1024);
113  if (!frame->buf[1])
114  goto fail;
115  frame->data[1] = frame->buf[1]->data;
116  }
117 
118  frame->extended_data = frame->data;
119 
120  return 0;
121 fail:
122  av_frame_unref(frame);
123  return AVERROR(ENOMEM);
124 }
125 
126 static int get_audio_buffer(AVFrame *frame, int align)
127 {
128  int channels = av_get_channel_layout_nb_channels(frame->channel_layout);
129  int planar = av_sample_fmt_is_planar(frame->format);
130  int planes = planar ? channels : 1;
131  int ret, i;
132 
133  if (!frame->linesize[0]) {
134  ret = av_samples_get_buffer_size(&frame->linesize[0], channels,
135  frame->nb_samples, frame->format,
136  align);
137  if (ret < 0)
138  return ret;
139  }
140 
141  if (planes > AV_NUM_DATA_POINTERS) {
142  frame->extended_data = av_mallocz(planes *
143  sizeof(*frame->extended_data));
144  frame->extended_buf = av_mallocz((planes - AV_NUM_DATA_POINTERS) *
145  sizeof(*frame->extended_buf));
146  if (!frame->extended_data || !frame->extended_buf) {
147  av_freep(&frame->extended_data);
148  av_freep(&frame->extended_buf);
149  return AVERROR(ENOMEM);
150  }
151  frame->nb_extended_buf = planes - AV_NUM_DATA_POINTERS;
152  } else
153  frame->extended_data = frame->data;
154 
155  for (i = 0; i < FFMIN(planes, AV_NUM_DATA_POINTERS); i++) {
156  frame->buf[i] = av_buffer_alloc(frame->linesize[0]);
157  if (!frame->buf[i]) {
158  av_frame_unref(frame);
159  return AVERROR(ENOMEM);
160  }
161  frame->extended_data[i] = frame->data[i] = frame->buf[i]->data;
162  }
163  for (i = 0; i < planes - AV_NUM_DATA_POINTERS; i++) {
164  frame->extended_buf[i] = av_buffer_alloc(frame->linesize[0]);
165  if (!frame->extended_buf[i]) {
166  av_frame_unref(frame);
167  return AVERROR(ENOMEM);
168  }
169  frame->extended_data[i + AV_NUM_DATA_POINTERS] = frame->extended_buf[i]->data;
170  }
171  return 0;
172 
173 }
174 
175 int av_frame_get_buffer(AVFrame *frame, int align)
176 {
177  if (frame->format < 0)
178  return AVERROR(EINVAL);
179 
180  if (frame->width > 0 && frame->height > 0)
181  return get_video_buffer(frame, align);
182  else if (frame->nb_samples > 0 && frame->channel_layout)
183  return get_audio_buffer(frame, align);
184 
185  return AVERROR(EINVAL);
186 }
187 
188 int av_frame_ref(AVFrame *dst, const AVFrame *src)
189 {
190  int i, ret = 0;
191 
192  dst->format = src->format;
193  dst->width = src->width;
194  dst->height = src->height;
195  dst->channel_layout = src->channel_layout;
196  dst->nb_samples = src->nb_samples;
197 
198  ret = av_frame_copy_props(dst, src);
199  if (ret < 0)
200  return ret;
201 
202  /* duplicate the frame data if it's not refcounted */
203  if (!src->buf[0]) {
204  ret = av_frame_get_buffer(dst, 32);
205  if (ret < 0)
206  return ret;
207 
208  ret = av_frame_copy(dst, src);
209  if (ret < 0)
210  av_frame_unref(dst);
211 
212  return ret;
213  }
214 
215  /* ref the buffers */
216  for (i = 0; i < FF_ARRAY_ELEMS(src->buf) && src->buf[i]; i++) {
217  dst->buf[i] = av_buffer_ref(src->buf[i]);
218  if (!dst->buf[i]) {
219  ret = AVERROR(ENOMEM);
220  goto fail;
221  }
222  }
223 
224  if (src->extended_buf) {
225  dst->extended_buf = av_mallocz(sizeof(*dst->extended_buf) *
226  src->nb_extended_buf);
227  if (!dst->extended_buf) {
228  ret = AVERROR(ENOMEM);
229  goto fail;
230  }
231  dst->nb_extended_buf = src->nb_extended_buf;
232 
233  for (i = 0; i < src->nb_extended_buf; i++) {
234  dst->extended_buf[i] = av_buffer_ref(src->extended_buf[i]);
235  if (!dst->extended_buf[i]) {
236  ret = AVERROR(ENOMEM);
237  goto fail;
238  }
239  }
240  }
241 
242  /* duplicate extended data */
243  if (src->extended_data != src->data) {
245 
246  if (!ch) {
247  ret = AVERROR(EINVAL);
248  goto fail;
249  }
250 
251  dst->extended_data = av_malloc(sizeof(*dst->extended_data) * ch);
252  if (!dst->extended_data) {
253  ret = AVERROR(ENOMEM);
254  goto fail;
255  }
256  memcpy(dst->extended_data, src->extended_data, sizeof(*src->extended_data) * ch);
257  } else
258  dst->extended_data = dst->data;
259 
260  memcpy(dst->data, src->data, sizeof(src->data));
261  memcpy(dst->linesize, src->linesize, sizeof(src->linesize));
262 
263  return 0;
264 
265 fail:
266  av_frame_unref(dst);
267  return ret;
268 }
269 
271 {
272  AVFrame *ret = av_frame_alloc();
273 
274  if (!ret)
275  return NULL;
276 
277  if (av_frame_ref(ret, src) < 0)
278  av_frame_free(&ret);
279 
280  return ret;
281 }
282 
284 {
285  int i;
286 
287  for (i = 0; i < frame->nb_side_data; i++) {
288  free_side_data(&frame->side_data[i]);
289  }
290  av_freep(&frame->side_data);
291 
292  for (i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++)
293  av_buffer_unref(&frame->buf[i]);
294  for (i = 0; i < frame->nb_extended_buf; i++)
295  av_buffer_unref(&frame->extended_buf[i]);
296  av_freep(&frame->extended_buf);
297  get_frame_defaults(frame);
298 }
299 
301 {
302  *dst = *src;
303  if (src->extended_data == src->data)
304  dst->extended_data = dst->data;
305  memset(src, 0, sizeof(*src));
306  get_frame_defaults(src);
307 }
308 
310 {
311  int i, ret = 1;
312 
313  /* assume non-refcounted frames are not writable */
314  if (!frame->buf[0])
315  return 0;
316 
317  for (i = 0; i < FF_ARRAY_ELEMS(frame->buf) && frame->buf[i]; i++)
318  ret &= !!av_buffer_is_writable(frame->buf[i]);
319  for (i = 0; i < frame->nb_extended_buf; i++)
320  ret &= !!av_buffer_is_writable(frame->extended_buf[i]);
321 
322  return ret;
323 }
324 
326 {
327  AVFrame tmp;
328  int ret;
329 
330  if (!frame->buf[0])
331  return AVERROR(EINVAL);
332 
333  if (av_frame_is_writable(frame))
334  return 0;
335 
336  memset(&tmp, 0, sizeof(tmp));
337  tmp.format = frame->format;
338  tmp.width = frame->width;
339  tmp.height = frame->height;
340  tmp.channel_layout = frame->channel_layout;
341  tmp.nb_samples = frame->nb_samples;
342  ret = av_frame_get_buffer(&tmp, 32);
343  if (ret < 0)
344  return ret;
345 
346  ret = av_frame_copy(&tmp, frame);
347  if (ret < 0) {
348  av_frame_unref(&tmp);
349  return ret;
350  }
351 
352  ret = av_frame_copy_props(&tmp, frame);
353  if (ret < 0) {
354  av_frame_unref(&tmp);
355  return ret;
356  }
357 
358  av_frame_unref(frame);
359 
360  *frame = tmp;
361  if (tmp.data == tmp.extended_data)
362  frame->extended_data = frame->data;
363 
364  return 0;
365 }
366 
367 int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
368 {
369  int i;
370 
371  dst->key_frame = src->key_frame;
372  dst->pict_type = src->pict_type;
374  dst->pts = src->pts;
375  dst->repeat_pict = src->repeat_pict;
377  dst->top_field_first = src->top_field_first;
379  dst->sample_rate = src->sample_rate;
380  dst->opaque = src->opaque;
381  dst->pkt_pts = src->pkt_pts;
382  dst->pkt_dts = src->pkt_dts;
384  dst->quality = src->quality;
387  dst->flags = src->flags;
388  dst->color_primaries = src->color_primaries;
389  dst->color_trc = src->color_trc;
390  dst->colorspace = src->colorspace;
391  dst->color_range = src->color_range;
392  dst->chroma_location = src->chroma_location;
393 
394  memcpy(dst->error, src->error, sizeof(dst->error));
395 
396  for (i = 0; i < src->nb_side_data; i++) {
397  const AVFrameSideData *sd_src = src->side_data[i];
398  AVFrameSideData *sd_dst = av_frame_new_side_data(dst, sd_src->type,
399  sd_src->size);
400  if (!sd_dst) {
401  for (i = 0; i < dst->nb_side_data; i++) {
402  free_side_data(&dst->side_data[i]);
403  }
404  av_freep(&dst->side_data);
405  return AVERROR(ENOMEM);
406  }
407  memcpy(sd_dst->data, sd_src->data, sd_src->size);
408  av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0);
409  }
410 
411  return 0;
412 }
413 
415 {
416  uint8_t *data;
417  int planes, i;
418 
419  if (frame->nb_samples) {
420  int channels = av_get_channel_layout_nb_channels(frame->channel_layout);
421  if (!channels)
422  return NULL;
423  planes = av_sample_fmt_is_planar(frame->format) ? channels : 1;
424  } else
425  planes = 4;
426 
427  if (plane < 0 || plane >= planes || !frame->extended_data[plane])
428  return NULL;
429  data = frame->extended_data[plane];
430 
431  for (i = 0; i < FF_ARRAY_ELEMS(frame->buf) && frame->buf[i]; i++) {
432  AVBufferRef *buf = frame->buf[i];
433  if (data >= buf->data && data < buf->data + buf->size)
434  return buf;
435  }
436  for (i = 0; i < frame->nb_extended_buf; i++) {
437  AVBufferRef *buf = frame->extended_buf[i];
438  if (data >= buf->data && data < buf->data + buf->size)
439  return buf;
440  }
441  return NULL;
442 }
443 
445  enum AVFrameSideDataType type,
446  int size)
447 {
448  AVFrameSideData *ret, **tmp;
449 
450  if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1)
451  return NULL;
452 
453  tmp = av_realloc(frame->side_data,
454  (frame->nb_side_data + 1) * sizeof(*frame->side_data));
455  if (!tmp)
456  return NULL;
457  frame->side_data = tmp;
458 
459  ret = av_mallocz(sizeof(*ret));
460  if (!ret)
461  return NULL;
462 
463  ret->data = av_malloc(size);
464  if (!ret->data) {
465  av_freep(&ret);
466  return NULL;
467  }
468 
469  ret->size = size;
470  ret->type = type;
471 
472  frame->side_data[frame->nb_side_data++] = ret;
473 
474  return ret;
475 }
476 
478  enum AVFrameSideDataType type)
479 {
480  int i;
481 
482  for (i = 0; i < frame->nb_side_data; i++) {
483  if (frame->side_data[i]->type == type)
484  return frame->side_data[i];
485  }
486  return NULL;
487 }
488 
489 static int frame_copy_video(AVFrame *dst, const AVFrame *src)
490 {
491  const uint8_t *src_data[4];
492  int i, planes;
493 
494  if (dst->width != src->width ||
495  dst->height != src->height)
496  return AVERROR(EINVAL);
497 
498  planes = av_pix_fmt_count_planes(dst->format);
499  for (i = 0; i < planes; i++)
500  if (!dst->data[i] || !src->data[i])
501  return AVERROR(EINVAL);
502 
503  memcpy(src_data, src->data, sizeof(src_data));
504  av_image_copy(dst->data, dst->linesize,
505  src_data, src->linesize,
506  dst->format, dst->width, dst->height);
507 
508  return 0;
509 }
510 
511 static int frame_copy_audio(AVFrame *dst, const AVFrame *src)
512 {
513  int planar = av_sample_fmt_is_planar(dst->format);
515  int planes = planar ? channels : 1;
516  int i;
517 
518  if (dst->nb_samples != src->nb_samples ||
519  dst->channel_layout != src->channel_layout)
520  return AVERROR(EINVAL);
521 
522  for (i = 0; i < planes; i++)
523  if (!dst->extended_data[i] || !src->extended_data[i])
524  return AVERROR(EINVAL);
525 
527  dst->nb_samples, channels, dst->format);
528 
529  return 0;
530 }
531 
532 int av_frame_copy(AVFrame *dst, const AVFrame *src)
533 {
534  if (dst->format != src->format || dst->format < 0)
535  return AVERROR(EINVAL);
536 
537  if (dst->width > 0 && dst->height > 0)
538  return frame_copy_video(dst, src);
539  else if (dst->nb_samples > 0 && dst->channel_layout)
540  return frame_copy_audio(dst, src);
541 
542  return AVERROR(EINVAL);
543 }
544 
546 {
547  int i;
548 
549  for (i = 0; i < frame->nb_side_data; i++) {
550  AVFrameSideData *sd = frame->side_data[i];
551  if (sd->type == type) {
552  free_side_data(&frame->side_data[i]);
553  frame->side_data[i] = frame->side_data[frame->nb_side_data - 1];
554  frame->nb_side_data--;
555  }
556  }
557 }
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
Definition: pixdesc.h:112
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:62
#define AV_NUM_DATA_POINTERS
Definition: frame.h:136
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
Definition: buffer.c:106
int size
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1599
This structure describes decoded (raw) audio or video data.
Definition: frame.h:135
misc image utilities
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1637
memory handling functions
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:393
AVDictionary * metadata
Definition: frame.h:106
void * opaque
for some private data of the user
Definition: frame.h:299
int nb_extended_buf
Number of elements in extended_buf.
Definition: frame.h:411
int repeat_pict
When decoding, this signals how much the picture must be delayed.
Definition: frame.h:315
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everythnig contained in src to dst and reset src.
Definition: frame.c:300
#define FF_ARRAY_ELEMS(a)
#define FFALIGN(x, a)
Definition: common.h:62
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:477
Public dictionary API.
uint8_t
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:57
static int frame_copy_video(AVFrame *dst, const AVFrame *src)
Definition: frame.c:489
int av_frame_ref(AVFrame *dst, const AVFrame *src)
Set up a new reference to the data described by the source frame.
Definition: frame.c:188
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:211
const char data[16]
Definition: mxf.c:70
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:320
int nb_side_data
Definition: frame.h:414
void av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:184
AVFrameSideData ** side_data
Definition: frame.h:413
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:101
int width
width and height of the video frame
Definition: frame.h:174
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:89
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:69
enum AVColorRange color_range
Definition: frame.h:436
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:170
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
enum AVColorSpace colorspace
Definition: frame.h:442
static int get_audio_buffer(AVFrame *frame, int align)
Definition: frame.c:126
void av_image_copy(uint8_t *dst_data[4], int dst_linesizes[4], const uint8_t *src_data[4], const int src_linesizes[4], enum AVPixelFormat pix_fmt, int width, int height)
Copy image in src_data to dst_data.
Definition: imgutils.c:267
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:532
reference-counted frame API
uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:381
int av_image_check_size(unsigned int w, unsigned int h, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of the image can be address...
Definition: imgutils.c:222
audio channel layout utility functions
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:196
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition: frame.h:434
#define FFMIN(a, b)
Definition: common.h:57
int display_picture_number
picture number in display order
Definition: frame.h:230
AVBufferRef ** extended_buf
For planar audio which requires more than AV_NUM_DATA_POINTERS AVBufferRef pointers, this array will hold all the references which cannot fit into AVFrame.buf.
Definition: frame.h:407
#define AV_PIX_FMT_FLAG_PSEUDOPAL
The pixel format is "pseudo-paletted".
Definition: pixdesc.h:134
AVBufferRef * av_frame_get_plane_buffer(AVFrame *frame, int plane)
Get the buffer reference a given data plane is stored in.
Definition: frame.c:414
AVFrameSideDataType
Definition: frame.h:48
int quality
quality (between 1 (good) and FF_LAMBDA_MAX (bad))
Definition: frame.h:235
int av_buffer_is_writable(const AVBufferRef *buf)
Definition: buffer.c:121
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:270
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:186
NULL
Definition: eval.c:55
int coded_picture_number
picture number in bitstream order
Definition: frame.h:226
uint64_t error[AV_NUM_DATA_POINTERS]
error
Definition: frame.h:304
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:309
AVBufferRef * av_buffer_alloc(int size)
Allocate an AVBuffer of the given size using av_malloc().
Definition: buffer.c:66
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:153
static int get_video_buffer(AVFrame *frame, int align)
Definition: frame.c:78
uint8_t flags
Definition: pixdesc.h:90
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
uint8_t * data
The data buffer.
Definition: buffer.h:89
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:206
uint8_t * data
Definition: frame.h:104
int av_samples_copy(uint8_t **dst, uint8_t *const *src, int dst_offset, int src_offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Copy samples from src to dst.
Definition: samplefmt.c:187
void av_frame_remove_side_data(AVFrame *frame, enum AVFrameSideDataType type)
If side data of the supplied type exists in the frame, free it and remove it from the frame...
Definition: frame.c:545
int64_t reordered_opaque
reordered opaque 64bit (generally an integer or a double precision float PTS but can be anything)...
Definition: frame.h:352
int sample_rate
Sample rate of the audio data.
Definition: frame.h:376
int av_image_fill_linesizes(int linesizes[4], enum AVPixelFormat pix_fmt, int width)
Fill plane linesizes for an image with pixel format pix_fmt and width width.
Definition: imgutils.c:68
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, int size)
Add a new side data to a frame.
Definition: frame.c:444
int av_samples_get_buffer_size(int *linesize, int nb_channels, int nb_samples, enum AVSampleFormat sample_fmt, int align)
Get the required buffer size for the given audio parameters.
Definition: samplefmt.c:108
rational number numerator/denominator
Definition: rational.h:43
int palette_has_changed
Tell user application that palette has changed from previous frame.
Definition: frame.h:330
refcounted data buffer API
enum AVChromaLocation chroma_location
Definition: frame.h:444
static int frame_copy_audio(AVFrame *dst, const AVFrame *src)
Definition: frame.c:511
int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
Definition: frame.h:216
int size
Size of data in bytes.
Definition: buffer.h:93
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:175
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:283
enum AVFrameSideDataType type
Definition: frame.h:103
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
Definition: frame.c:325
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:141
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
Definition: frame.h:221
A reference to a data buffer.
Definition: buffer.h:81
common internal and external API header
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
Definition: mem.c:117
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:92
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:325
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:191
enum AVColorPrimaries color_primaries
Definition: frame.h:438
int height
Definition: frame.h:174
static void free_side_data(AVFrameSideData **ptr_sd)
Definition: frame.c:48
enum AVColorTransferCharacteristic color_trc
Definition: frame.h:440
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:169
static void get_frame_defaults(AVFrame *frame)
Definition: frame.c:29
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:179
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:367
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:228