FFmpeg  2.1.1
frame.c
Go to the documentation of this file.
1 /*
2  *
3  * This file is part of FFmpeg.
4  *
5  * FFmpeg 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  * FFmpeg 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 FFmpeg; 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 "avassert.h"
22 #include "buffer.h"
23 #include "common.h"
24 #include "dict.h"
25 #include "frame.h"
26 #include "imgutils.h"
27 #include "mem.h"
28 #include "samplefmt.h"
29 
30 MAKE_ACCESSORS(AVFrame, frame, int64_t, best_effort_timestamp)
31 MAKE_ACCESSORS(AVFrame, frame, int64_t, pkt_duration)
32 MAKE_ACCESSORS(AVFrame, frame, int64_t, pkt_pos)
33 MAKE_ACCESSORS(AVFrame, frame, int64_t, channel_layout)
34 MAKE_ACCESSORS(AVFrame, frame, int, channels)
35 MAKE_ACCESSORS(AVFrame, frame, int, sample_rate)
36 MAKE_ACCESSORS(AVFrame, frame, AVDictionary *, metadata)
37 MAKE_ACCESSORS(AVFrame, frame, int, decode_error_flags)
38 MAKE_ACCESSORS(AVFrame, frame, int, pkt_size)
39 MAKE_ACCESSORS(AVFrame, frame, enum AVColorSpace, colorspace)
40 MAKE_ACCESSORS(AVFrame, frame, enum AVColorRange, color_range)
41 
42 #define CHECK_CHANNELS_CONSISTENCY(frame) \
43  av_assert2(!(frame)->channel_layout || \
44  (frame)->channels == \
45  av_get_channel_layout_nb_channels((frame)->channel_layout))
46 
47 AVDictionary **avpriv_frame_get_metadatap(AVFrame *frame) {return &frame->metadata;};
48 
49 int av_frame_set_qp_table(AVFrame *f, AVBufferRef *buf, int stride, int qp_type)
50 {
52 
53  f->qp_table_buf = buf;
54 
55  f->qscale_table = buf->data;
56  f->qstride = stride;
57  f->qscale_type = qp_type;
58 
59  return 0;
60 }
61 
62 int8_t *av_frame_get_qp_table(AVFrame *f, int *stride, int *type)
63 {
64  *stride = f->qstride;
65  *type = f->qscale_type;
66 
67  if (!f->qp_table_buf)
68  return NULL;
69 
70  return f->qp_table_buf->data;
71 }
72 
73 const char *av_get_colorspace_name(enum AVColorSpace val)
74 {
75  static const char *name[] = {
76  [AVCOL_SPC_RGB] = "GBR",
77  [AVCOL_SPC_BT709] = "bt709",
78  [AVCOL_SPC_FCC] = "fcc",
79  [AVCOL_SPC_BT470BG] = "bt470bg",
80  [AVCOL_SPC_SMPTE170M] = "smpte170m",
81  [AVCOL_SPC_SMPTE240M] = "smpte240m",
82  [AVCOL_SPC_YCOCG] = "YCgCo",
83  };
84  if ((unsigned)val >= FF_ARRAY_ELEMS(name))
85  return NULL;
86  return name[val];
87 }
88 
89 static void get_frame_defaults(AVFrame *frame)
90 {
91  if (frame->extended_data != frame->data)
92  av_freep(&frame->extended_data);
93 
94  memset(frame, 0, sizeof(*frame));
95 
96  frame->pts =
97  frame->pkt_dts =
98  frame->pkt_pts = AV_NOPTS_VALUE;
100  av_frame_set_pkt_duration (frame, 0);
101  av_frame_set_pkt_pos (frame, -1);
102  av_frame_set_pkt_size (frame, -1);
103  frame->key_frame = 1;
104  frame->sample_aspect_ratio = (AVRational){ 0, 1 };
105  frame->format = -1; /* unknown */
107  frame->extended_data = frame->data;
108 }
109 
110 AVFrame *av_frame_alloc(void)
111 {
112  AVFrame *frame = av_mallocz(sizeof(*frame));
113 
114  if (!frame)
115  return NULL;
116 
117  frame->extended_data = NULL;
118  get_frame_defaults(frame);
119 
120  return frame;
121 }
122 
123 void av_frame_free(AVFrame **frame)
124 {
125  if (!frame || !*frame)
126  return;
127 
128  av_frame_unref(*frame);
129  av_freep(frame);
130 }
131 
132 static int get_video_buffer(AVFrame *frame, int align)
133 {
134  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
135  int ret, i;
136 
137  if (!desc)
138  return AVERROR(EINVAL);
139 
140  if ((ret = av_image_check_size(frame->width, frame->height, 0, NULL)) < 0)
141  return ret;
142 
143  if (!frame->linesize[0]) {
144  for(i=1; i<=align; i+=i) {
145  ret = av_image_fill_linesizes(frame->linesize, frame->format,
146  FFALIGN(frame->width, i));
147  if (ret < 0)
148  return ret;
149  if (!(frame->linesize[0] & (align-1)))
150  break;
151  }
152 
153  for (i = 0; i < 4 && frame->linesize[i]; i++)
154  frame->linesize[i] = FFALIGN(frame->linesize[i], align);
155  }
156 
157  for (i = 0; i < 4 && frame->linesize[i]; i++) {
158  int h = FFALIGN(frame->height, 32);
159  if (i == 1 || i == 2)
160  h = FF_CEIL_RSHIFT(h, desc->log2_chroma_h);
161 
162  frame->buf[i] = av_buffer_alloc(frame->linesize[i] * h + 16);
163  if (!frame->buf[i])
164  goto fail;
165 
166  frame->data[i] = frame->buf[i]->data;
167  }
168  if (desc->flags & AV_PIX_FMT_FLAG_PAL || desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL) {
169  av_buffer_unref(&frame->buf[1]);
170  frame->buf[1] = av_buffer_alloc(1024);
171  if (!frame->buf[1])
172  goto fail;
173  frame->data[1] = frame->buf[1]->data;
174  }
175 
176  frame->extended_data = frame->data;
177 
178  return 0;
179 fail:
180  av_frame_unref(frame);
181  return AVERROR(ENOMEM);
182 }
183 
184 static int get_audio_buffer(AVFrame *frame, int align)
185 {
186  int channels = frame->channels;
187  int planar = av_sample_fmt_is_planar(frame->format);
188  int planes = planar ? channels : 1;
189  int ret, i;
190 
192  if (!frame->linesize[0]) {
193  ret = av_samples_get_buffer_size(&frame->linesize[0], channels,
194  frame->nb_samples, frame->format,
195  align);
196  if (ret < 0)
197  return ret;
198  }
199 
200  if (planes > AV_NUM_DATA_POINTERS) {
201  frame->extended_data = av_mallocz(planes *
202  sizeof(*frame->extended_data));
203  frame->extended_buf = av_mallocz((planes - AV_NUM_DATA_POINTERS) *
204  sizeof(*frame->extended_buf));
205  if (!frame->extended_data || !frame->extended_buf) {
206  av_freep(&frame->extended_data);
207  av_freep(&frame->extended_buf);
208  return AVERROR(ENOMEM);
209  }
210  frame->nb_extended_buf = planes - AV_NUM_DATA_POINTERS;
211  } else
212  frame->extended_data = frame->data;
213 
214  for (i = 0; i < FFMIN(planes, AV_NUM_DATA_POINTERS); i++) {
215  frame->buf[i] = av_buffer_alloc(frame->linesize[0]);
216  if (!frame->buf[i]) {
217  av_frame_unref(frame);
218  return AVERROR(ENOMEM);
219  }
220  frame->extended_data[i] = frame->data[i] = frame->buf[i]->data;
221  }
222  for (i = 0; i < planes - AV_NUM_DATA_POINTERS; i++) {
223  frame->extended_buf[i] = av_buffer_alloc(frame->linesize[0]);
224  if (!frame->extended_buf[i]) {
225  av_frame_unref(frame);
226  return AVERROR(ENOMEM);
227  }
228  frame->extended_data[i + AV_NUM_DATA_POINTERS] = frame->extended_buf[i]->data;
229  }
230  return 0;
231 
232 }
233 
234 int av_frame_get_buffer(AVFrame *frame, int align)
235 {
236  if (frame->format < 0)
237  return AVERROR(EINVAL);
238 
239  if (frame->width > 0 && frame->height > 0)
240  return get_video_buffer(frame, align);
241  else if (frame->nb_samples > 0 && (frame->channel_layout || frame->channels > 0))
242  return get_audio_buffer(frame, align);
243 
244  return AVERROR(EINVAL);
245 }
246 
247 int av_frame_ref(AVFrame *dst, AVFrame *src)
248 {
249  int i, ret = 0;
250 
251  dst->format = src->format;
252  dst->width = src->width;
253  dst->height = src->height;
254  dst->channels = src->channels;
255  dst->channel_layout = src->channel_layout;
256  dst->nb_samples = src->nb_samples;
257 
258  ret = av_frame_copy_props(dst, src);
259  if (ret < 0)
260  return ret;
261 
262  /* duplicate the frame data if it's not refcounted */
263  if (!src->buf[0]) {
264  ret = av_frame_get_buffer(dst, 32);
265  if (ret < 0)
266  return ret;
267 
268  if (src->nb_samples) {
269  int ch = src->channels;
272  dst->nb_samples, ch, dst->format);
273  } else {
274  av_image_copy(dst->data, dst->linesize, src->data, src->linesize,
275  dst->format, dst->width, dst->height);
276  }
277  return 0;
278  }
279 
280  /* ref the buffers */
281  for (i = 0; i < FF_ARRAY_ELEMS(src->buf); i++) {
282  if (!src->buf[i])
283  continue;
284  dst->buf[i] = av_buffer_ref(src->buf[i]);
285  if (!dst->buf[i]) {
286  ret = AVERROR(ENOMEM);
287  goto fail;
288  }
289  }
290 
291  if (src->extended_buf) {
292  dst->extended_buf = av_mallocz(sizeof(*dst->extended_buf) *
293  src->nb_extended_buf);
294  if (!dst->extended_buf) {
295  ret = AVERROR(ENOMEM);
296  goto fail;
297  }
298  dst->nb_extended_buf = src->nb_extended_buf;
299 
300  for (i = 0; i < src->nb_extended_buf; i++) {
301  dst->extended_buf[i] = av_buffer_ref(src->extended_buf[i]);
302  if (!dst->extended_buf[i]) {
303  ret = AVERROR(ENOMEM);
304  goto fail;
305  }
306  }
307  }
308 
309  /* duplicate extended data */
310  if (src->extended_data != src->data) {
311  int ch = src->channels;
312 
313  if (!ch) {
314  ret = AVERROR(EINVAL);
315  goto fail;
316  }
318 
319  dst->extended_data = av_malloc(sizeof(*dst->extended_data) * ch);
320  if (!dst->extended_data) {
321  ret = AVERROR(ENOMEM);
322  goto fail;
323  }
324  memcpy(dst->extended_data, src->extended_data, sizeof(*src->extended_data) * ch);
325  } else
326  dst->extended_data = dst->data;
327 
328  memcpy(dst->data, src->data, sizeof(src->data));
329  memcpy(dst->linesize, src->linesize, sizeof(src->linesize));
330 
331  return 0;
332 
333 fail:
334  av_frame_unref(dst);
335  return ret;
336 }
337 
338 AVFrame *av_frame_clone(AVFrame *src)
339 {
340  AVFrame *ret = av_frame_alloc();
341 
342  if (!ret)
343  return NULL;
344 
345  if (av_frame_ref(ret, src) < 0)
346  av_frame_free(&ret);
347 
348  return ret;
349 }
350 
351 void av_frame_unref(AVFrame *frame)
352 {
353  int i;
354 
355  for (i = 0; i < frame->nb_side_data; i++) {
356  av_freep(&frame->side_data[i]->data);
357  av_dict_free(&frame->side_data[i]->metadata);
358  av_freep(&frame->side_data[i]);
359  }
360  av_freep(&frame->side_data);
361 
362  for (i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++)
363  av_buffer_unref(&frame->buf[i]);
364  for (i = 0; i < frame->nb_extended_buf; i++)
365  av_buffer_unref(&frame->extended_buf[i]);
366  av_freep(&frame->extended_buf);
367  av_dict_free(&frame->metadata);
368  av_buffer_unref(&frame->qp_table_buf);
369 
370  get_frame_defaults(frame);
371 }
372 
373 void av_frame_move_ref(AVFrame *dst, AVFrame *src)
374 {
375  *dst = *src;
376  if (src->extended_data == src->data)
377  dst->extended_data = dst->data;
378  memset(src, 0, sizeof(*src));
379  get_frame_defaults(src);
380 }
381 
382 int av_frame_is_writable(AVFrame *frame)
383 {
384  int i, ret = 1;
385 
386  /* assume non-refcounted frames are not writable */
387  if (!frame->buf[0])
388  return 0;
389 
390  for (i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++)
391  if (frame->buf[i])
392  ret &= !!av_buffer_is_writable(frame->buf[i]);
393  for (i = 0; i < frame->nb_extended_buf; i++)
394  ret &= !!av_buffer_is_writable(frame->extended_buf[i]);
395 
396  return ret;
397 }
398 
399 int av_frame_make_writable(AVFrame *frame)
400 {
401  AVFrame tmp;
402  int ret;
403 
404  if (!frame->buf[0])
405  return AVERROR(EINVAL);
406 
407  if (av_frame_is_writable(frame))
408  return 0;
409 
410  memset(&tmp, 0, sizeof(tmp));
411  tmp.format = frame->format;
412  tmp.width = frame->width;
413  tmp.height = frame->height;
414  tmp.channels = frame->channels;
415  tmp.channel_layout = frame->channel_layout;
416  tmp.nb_samples = frame->nb_samples;
417  ret = av_frame_get_buffer(&tmp, 32);
418  if (ret < 0)
419  return ret;
420 
421  if (tmp.nb_samples) {
422  int ch = tmp.channels;
424  av_samples_copy(tmp.extended_data, frame->extended_data, 0, 0,
425  frame->nb_samples, ch, frame->format);
426  } else {
427  av_image_copy(tmp.data, tmp.linesize, frame->data, frame->linesize,
428  frame->format, frame->width, frame->height);
429  }
430 
431  ret = av_frame_copy_props(&tmp, frame);
432  if (ret < 0) {
433  av_frame_unref(&tmp);
434  return ret;
435  }
436 
437  av_frame_unref(frame);
438 
439  *frame = tmp;
440  if (tmp.data == tmp.extended_data)
441  frame->extended_data = frame->data;
442 
443  return 0;
444 }
445 
446 int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
447 {
448  int i;
449 
450  dst->key_frame = src->key_frame;
451  dst->pict_type = src->pict_type;
453  dst->pts = src->pts;
454  dst->repeat_pict = src->repeat_pict;
456  dst->top_field_first = src->top_field_first;
458  dst->sample_rate = src->sample_rate;
459  dst->opaque = src->opaque;
460 #if FF_API_AVFRAME_LAVC
461  dst->type = src->type;
462 #endif
463  dst->pkt_pts = src->pkt_pts;
464  dst->pkt_dts = src->pkt_dts;
465  dst->pkt_pos = src->pkt_pos;
466  dst->pkt_size = src->pkt_size;
467  dst->pkt_duration = src->pkt_duration;
469  dst->quality = src->quality;
474  dst->colorspace = src->colorspace;
475  dst->color_range = src->color_range;
476 
477  av_dict_copy(&dst->metadata, src->metadata, 0);
478 
479  memcpy(dst->error, src->error, sizeof(dst->error));
480 
481  for (i = 0; i < src->nb_side_data; i++) {
482  const AVFrameSideData *sd_src = src->side_data[i];
483  AVFrameSideData *sd_dst = av_frame_new_side_data(dst, sd_src->type,
484  sd_src->size);
485  if (!sd_dst) {
486  for (i = 0; i < dst->nb_side_data; i++) {
487  av_freep(&dst->side_data[i]->data);
488  av_freep(&dst->side_data[i]);
489  av_dict_free(&dst->side_data[i]->metadata);
490  }
491  av_freep(&dst->side_data);
492  return AVERROR(ENOMEM);
493  }
494  memcpy(sd_dst->data, sd_src->data, sd_src->size);
495  av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0);
496  }
497 
498  dst->qscale_table = NULL;
499  dst->qstride = 0;
500  dst->qscale_type = 0;
501  if (src->qp_table_buf) {
503  if (dst->qp_table_buf) {
504  dst->qscale_table = dst->qp_table_buf->data;
505  dst->qstride = src->qstride;
506  dst->qscale_type = src->qscale_type;
507  }
508  }
509 
510  return 0;
511 }
512 
513 AVBufferRef *av_frame_get_plane_buffer(AVFrame *frame, int plane)
514 {
515  uint8_t *data;
516  int planes, i;
517 
518  if (frame->nb_samples) {
519  int channels = frame->channels;
520  if (!channels)
521  return NULL;
523  planes = av_sample_fmt_is_planar(frame->format) ? channels : 1;
524  } else
525  planes = 4;
526 
527  if (plane < 0 || plane >= planes || !frame->extended_data[plane])
528  return NULL;
529  data = frame->extended_data[plane];
530 
531  for (i = 0; i < FF_ARRAY_ELEMS(frame->buf) && frame->buf[i]; i++) {
532  AVBufferRef *buf = frame->buf[i];
533  if (data >= buf->data && data < buf->data + buf->size)
534  return buf;
535  }
536  for (i = 0; i < frame->nb_extended_buf; i++) {
537  AVBufferRef *buf = frame->extended_buf[i];
538  if (data >= buf->data && data < buf->data + buf->size)
539  return buf;
540  }
541  return NULL;
542 }
543 
546  int size)
547 {
548  AVFrameSideData *ret, **tmp;
549 
550  if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1)
551  return NULL;
552 
553  tmp = av_realloc(frame->side_data,
554  (frame->nb_side_data + 1) * sizeof(*frame->side_data));
555  if (!tmp)
556  return NULL;
557  frame->side_data = tmp;
558 
559  ret = av_mallocz(sizeof(*ret));
560  if (!ret)
561  return NULL;
562 
563  ret->data = av_malloc(size);
564  if (!ret->data) {
565  av_freep(&ret);
566  return NULL;
567  }
568 
569  ret->size = size;
570  ret->type = type;
571 
572  frame->side_data[frame->nb_side_data++] = ret;
573 
574  return ret;
575 }
576 
579 {
580  int i;
581 
582  for (i = 0; i < frame->nb_side_data; i++) {
583  if (frame->side_data[i]->type == type)
584  return frame->side_data[i];
585  }
586  return NULL;
587 }
const char * name
Definition: avisynth_c.h:675
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:577
const char const char void * val
Definition: avisynth_c.h:671
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:105
int size
This structure describes decoded (raw) audio or video data.
Definition: frame.h:96
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:234
attribute_deprecated int qscale_type
Definition: frame.h:226
int64_t pkt_pos
reordered pos from the last AVPacket that has been input into the decoder Code outside libavcodec sho...
Definition: frame.h:405
int nb_extended_buf
Number of elements in extended_buf.
Definition: frame.h:384
int repeat_pict
When decoding, this signals how much the picture must be delayed.
Definition: frame.h:288
int av_frame_set_qp_table(AVFrame *f, AVBufferRef *buf, int stride, int type)
Definition: frame.c:49
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:140
AVDictionary * metadata
Definition: frame.h:64
misc image utilities
void av_frame_set_pkt_duration(AVFrame *frame, int64_t val)
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:382
uint8_t * data
Definition: frame.h:62
int stride
Definition: mace.c:144
AVBufferRef * av_frame_get_plane_buffer(AVFrame *frame, int plane)
Get the buffer reference a given data plane is stored in.
Definition: frame.c:513
void av_freep(void *ptr)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:234
simple assert() macros that are a bit more flexible than ISO C assert().
uint8_t
attribute_deprecated int qstride
QP store stride.
Definition: frame.h:223
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only &quot;metadata&quot; fields from src to dst.
Definition: frame.c:446
enum AVColorRange color_range
Definition: dirac.c:82
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:182
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
Definition: pixdesc.h:98
int av_frame_ref(AVFrame *dst, AVFrame *src)
Setup a new reference to the data described by a given frame.
Definition: frame.c:247
#define FF_CEIL_RSHIFT(a, b)
Definition: avcodec.h:916
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:125
const char data[16]
Definition: mxf.c:68
AVFrameSideData ** side_data
Definition: frame.h:386
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:293
#define AV_NUM_DATA_POINTERS
Definition: frame.h:97
int nb_side_data
Definition: frame.h:387
static AVFrame * frame
Definition: demuxing.c:51
#define AV_PIX_FMT_FLAG_PSEUDOPAL
The pixel format is &quot;pseudo-paletted&quot;.
Definition: pixdesc.h:120
void av_dict_copy(AVDictionary **dst, AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:176
Public dictionary API.
int width
width and height of the video frame
Definition: frame.h:145
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:77
void * opaque
for some private data of the user
Definition: frame.h:272
#define MAKE_ACCESSORS(str, name, type, field)
Definition: internal.h:88
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above ...
Definition: frame.h:39
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:110
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: frame.h:474
void av_dict_free(AVDictionary **m)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:162
enum AVColorSpace colorspace
YUV colorspace type.
Definition: frame.h:465
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:123
static int get_audio_buffer(AVFrame *frame, int align)
Definition: frame.c:184
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:225
AVColorSpace
Definition: frame.h:33
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:257
uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:354
goto fail
Definition: avfilter.c:963
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
Definition: frame.c:399
#define FF_ARRAY_ELEMS(a)
Definition: avcodec.h:929
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:231
audio channel layout utility functions
int channels
number of audio channels, only used for audio.
Definition: frame.h:446
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:167
uint8_t * data
The data buffer.
Definition: buffer.h:89
refcounted data buffer API
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:351
int display_picture_number
picture number in display order
Definition: frame.h:203
void * av_realloc(void *ptr, size_t size) 1(2)
Allocate or reallocate a block of memory.
Definition: mem.c:141
void av_frame_set_best_effort_timestamp(AVFrame *frame, int64_t val)
ret
Definition: avfilter.c:961
void * av_malloc(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:73
#define FFMIN(a, b)
Definition: avcodec.h:925
uint64_t error[AV_NUM_DATA_POINTERS]
error
Definition: frame.h:277
AVColorRange
Definition: frame.h:46
int quality
quality (between 1 (good) and FF_LAMBDA_MAX (bad))
Definition: frame.h:208
int av_buffer_is_writable(const AVBufferRef *buf)
Definition: buffer.c:120
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:380
Used by Dirac / VC-2 and H.264 FRext, see ITU-T SG16.
Definition: frame.h:41
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1938
const AVS_VideoInfo int align
Definition: avisynth_c.h:695
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:157
int coded_picture_number
picture number in bitstream order
Definition: frame.h:199
sample_rate
AVBufferRef * qp_table_buf
Not to be accessed directly from outside libavutil.
Definition: frame.h:480
AVBufferRef * av_buffer_alloc(int size)
Allocate an AVBuffer of the given size using av_malloc().
Definition: buffer.c:65
AVS_Value src
Definition: avisynth_c.h:523
int64_t pkt_duration
duration of the corresponding packet, expressed in AVStream-&gt;time_base units, 0 if unknown...
Definition: frame.h:415
memory handling functions
static int get_video_buffer(AVFrame *frame, int align)
Definition: frame.c:132
uint8_t flags
Definition: pixdesc.h:78
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:57
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everythnig contained in src to dst and reset src.
Definition: frame.c:373
AVRational sample_aspect_ratio
Sample aspect ratio for the video frame, 0/1 if unknown/unspecified.
Definition: frame.h:177
void av_frame_set_pkt_pos(AVFrame *frame, int64_t val)
void * buf
Definition: avisynth_c.h:594
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:366
int64_t reordered_opaque
reordered opaque 64bit (generally an integer or a double precision float PTS but can be anything)...
Definition: frame.h:325
int sample_rate
Sample rate of the audio data.
Definition: frame.h:349
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:86
AVFrameSideDataType
Definition: frame.h:53
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:303
int8_t * av_frame_get_qp_table(AVFrame *f, int *stride, int *type)
Definition: frame.c:62
AVDictionary ** avpriv_frame_get_metadatap(AVFrame *frame)
Definition: frame.c:47
const char * av_get_colorspace_name(enum AVColorSpace val)
Get the name of a colorspace.
Definition: frame.c:73
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:124
int64_t best_effort_timestamp
frame timestamp estimated using various heuristics, in stream time base Code outside libavcodec shoul...
Definition: frame.h:396
int decode_error_flags
decode error flags of the frame, set to a combination of FF_DECODE_ERROR_xxx flags if the decoder pro...
Definition: frame.h:435
#define type
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL &amp; SECAM / IEC 61966-2-4 xvYCC601 ...
Definition: frame.h:38
int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
Definition: frame.h:187
int size
Size of data in bytes.
Definition: buffer.h:93
enum AVFrameSideDataType type
Definition: frame.h:61
AVFrame * av_frame_clone(AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:338
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
Definition: frame.h:194
A reference to a data buffer.
Definition: buffer.h:81
#define CHECK_CHANNELS_CONSISTENCY(frame)
Definition: frame.c:42
AVDictionary * metadata
metadata.
Definition: frame.h:424
#define FFALIGN(x, a)
Definition: avcodec.h:930
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:118
attribute_deprecated int8_t * qscale_table
QP table.
Definition: frame.h:218
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:91
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:298
int key_frame
1 -&gt; keyframe, 0-&gt; not
Definition: frame.h:162
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
Definition: frame.h:35
#define AVERROR(e)
int height
Definition: frame.h:145
void av_frame_set_pkt_size(AVFrame *frame, int val)
enum AVColorSpace colorspace
Definition: dirac.c:98
common internal and external API header
static void get_frame_defaults(AVFrame *frame)
Definition: frame.c:89
attribute_deprecated int type
Definition: frame.h:281
int pkt_size
size of the corresponding packet containing the compressed frame.
Definition: frame.h:456
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:150
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:107
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, int size)
Add a new side data to a frame.
Definition: frame.c:544
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avcodec.h:2278
void * av_mallocz(size_t size) av_malloc_attrib 1(1)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:241