FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 #if FF_API_FRAME_QP
50 int av_frame_set_qp_table(AVFrame *f, AVBufferRef *buf, int stride, int qp_type)
51 {
53 
54  f->qp_table_buf = buf;
55 
57  f->qscale_table = buf->data;
58  f->qstride = stride;
59  f->qscale_type = qp_type;
61 
62  return 0;
63 }
64 
65 int8_t *av_frame_get_qp_table(AVFrame *f, int *stride, int *type)
66 {
68  *stride = f->qstride;
69  *type = f->qscale_type;
71 
72  if (!f->qp_table_buf)
73  return NULL;
74 
75  return f->qp_table_buf->data;
76 }
77 #endif
78 
79 const char *av_get_colorspace_name(enum AVColorSpace val)
80 {
81  static const char * const name[] = {
82  [AVCOL_SPC_RGB] = "GBR",
83  [AVCOL_SPC_BT709] = "bt709",
84  [AVCOL_SPC_FCC] = "fcc",
85  [AVCOL_SPC_BT470BG] = "bt470bg",
86  [AVCOL_SPC_SMPTE170M] = "smpte170m",
87  [AVCOL_SPC_SMPTE240M] = "smpte240m",
88  [AVCOL_SPC_YCOCG] = "YCgCo",
89  };
90  if ((unsigned)val >= FF_ARRAY_ELEMS(name))
91  return NULL;
92  return name[val];
93 }
94 
95 static void get_frame_defaults(AVFrame *frame)
96 {
97  if (frame->extended_data != frame->data)
98  av_freep(&frame->extended_data);
99 
100  memset(frame, 0, sizeof(*frame));
101 
102  frame->pts =
103  frame->pkt_dts =
104  frame->pkt_pts = AV_NOPTS_VALUE;
106  av_frame_set_pkt_duration (frame, 0);
107  av_frame_set_pkt_pos (frame, -1);
108  av_frame_set_pkt_size (frame, -1);
109  frame->key_frame = 1;
110  frame->sample_aspect_ratio = (AVRational){ 0, 1 };
111  frame->format = -1; /* unknown */
112  frame->extended_data = frame->data;
118 }
119 
120 static void free_side_data(AVFrameSideData **ptr_sd)
121 {
122  AVFrameSideData *sd = *ptr_sd;
123 
124  av_buffer_unref(&sd->buf);
125  av_dict_free(&sd->metadata);
126  av_freep(ptr_sd);
127 }
128 
129 static void wipe_side_data(AVFrame *frame)
130 {
131  int i;
132 
133  for (i = 0; i < frame->nb_side_data; i++) {
134  free_side_data(&frame->side_data[i]);
135  }
136  frame->nb_side_data = 0;
137 
138  av_freep(&frame->side_data);
139 }
140 
141 AVFrame *av_frame_alloc(void)
142 {
143  AVFrame *frame = av_mallocz(sizeof(*frame));
144 
145  if (!frame)
146  return NULL;
147 
148  frame->extended_data = NULL;
149  get_frame_defaults(frame);
150 
151  return frame;
152 }
153 
154 void av_frame_free(AVFrame **frame)
155 {
156  if (!frame || !*frame)
157  return;
158 
159  av_frame_unref(*frame);
160  av_freep(frame);
161 }
162 
163 static int get_video_buffer(AVFrame *frame, int align)
164 {
165  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
166  int ret, i;
167 
168  if (!desc)
169  return AVERROR(EINVAL);
170 
171  if ((ret = av_image_check_size(frame->width, frame->height, 0, NULL)) < 0)
172  return ret;
173 
174  if (!frame->linesize[0]) {
175  for(i=1; i<=align; i+=i) {
176  ret = av_image_fill_linesizes(frame->linesize, frame->format,
177  FFALIGN(frame->width, i));
178  if (ret < 0)
179  return ret;
180  if (!(frame->linesize[0] & (align-1)))
181  break;
182  }
183 
184  for (i = 0; i < 4 && frame->linesize[i]; i++)
185  frame->linesize[i] = FFALIGN(frame->linesize[i], align);
186  }
187 
188  for (i = 0; i < 4 && frame->linesize[i]; i++) {
189  int h = FFALIGN(frame->height, 32);
190  if (i == 1 || i == 2)
191  h = AV_CEIL_RSHIFT(h, desc->log2_chroma_h);
192 
193  frame->buf[i] = av_buffer_alloc(frame->linesize[i] * h + 16 + 16/*STRIDE_ALIGN*/ - 1);
194  if (!frame->buf[i])
195  goto fail;
196 
197  frame->data[i] = frame->buf[i]->data;
198  }
199  if (desc->flags & AV_PIX_FMT_FLAG_PAL || desc->flags & AV_PIX_FMT_FLAG_PSEUDOPAL) {
200  av_buffer_unref(&frame->buf[1]);
201  frame->buf[1] = av_buffer_alloc(AVPALETTE_SIZE);
202  if (!frame->buf[1])
203  goto fail;
204  frame->data[1] = frame->buf[1]->data;
205  }
206 
207  frame->extended_data = frame->data;
208 
209  return 0;
210 fail:
211  av_frame_unref(frame);
212  return AVERROR(ENOMEM);
213 }
214 
215 static int get_audio_buffer(AVFrame *frame, int align)
216 {
217  int channels;
218  int planar = av_sample_fmt_is_planar(frame->format);
219  int planes;
220  int ret, i;
221 
222  if (!frame->channels)
224 
225  channels = frame->channels;
226  planes = planar ? channels : 1;
227 
229  if (!frame->linesize[0]) {
230  ret = av_samples_get_buffer_size(&frame->linesize[0], channels,
231  frame->nb_samples, frame->format,
232  align);
233  if (ret < 0)
234  return ret;
235  }
236 
237  if (planes > AV_NUM_DATA_POINTERS) {
238  frame->extended_data = av_mallocz_array(planes,
239  sizeof(*frame->extended_data));
241  sizeof(*frame->extended_buf));
242  if (!frame->extended_data || !frame->extended_buf) {
243  av_freep(&frame->extended_data);
244  av_freep(&frame->extended_buf);
245  return AVERROR(ENOMEM);
246  }
247  frame->nb_extended_buf = planes - AV_NUM_DATA_POINTERS;
248  } else
249  frame->extended_data = frame->data;
250 
251  for (i = 0; i < FFMIN(planes, AV_NUM_DATA_POINTERS); i++) {
252  frame->buf[i] = av_buffer_alloc(frame->linesize[0]);
253  if (!frame->buf[i]) {
254  av_frame_unref(frame);
255  return AVERROR(ENOMEM);
256  }
257  frame->extended_data[i] = frame->data[i] = frame->buf[i]->data;
258  }
259  for (i = 0; i < planes - AV_NUM_DATA_POINTERS; i++) {
260  frame->extended_buf[i] = av_buffer_alloc(frame->linesize[0]);
261  if (!frame->extended_buf[i]) {
262  av_frame_unref(frame);
263  return AVERROR(ENOMEM);
264  }
265  frame->extended_data[i + AV_NUM_DATA_POINTERS] = frame->extended_buf[i]->data;
266  }
267  return 0;
268 
269 }
270 
271 int av_frame_get_buffer(AVFrame *frame, int align)
272 {
273  if (frame->format < 0)
274  return AVERROR(EINVAL);
275 
276  if (frame->width > 0 && frame->height > 0)
277  return get_video_buffer(frame, align);
278  else if (frame->nb_samples > 0 && (frame->channel_layout || frame->channels > 0))
279  return get_audio_buffer(frame, align);
280 
281  return AVERROR(EINVAL);
282 }
283 
284 static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy)
285 {
286  int i;
287 
288  dst->key_frame = src->key_frame;
289  dst->pict_type = src->pict_type;
291  dst->pts = src->pts;
292  dst->repeat_pict = src->repeat_pict;
294  dst->top_field_first = src->top_field_first;
296  dst->sample_rate = src->sample_rate;
297  dst->opaque = src->opaque;
298  dst->pkt_pts = src->pkt_pts;
299  dst->pkt_dts = src->pkt_dts;
300  dst->pkt_pos = src->pkt_pos;
301  dst->pkt_size = src->pkt_size;
302  dst->pkt_duration = src->pkt_duration;
304  dst->quality = src->quality;
308  dst->flags = src->flags;
310  dst->color_primaries = src->color_primaries;
311  dst->color_trc = src->color_trc;
312  dst->colorspace = src->colorspace;
313  dst->color_range = src->color_range;
314  dst->chroma_location = src->chroma_location;
315 
316  av_dict_copy(&dst->metadata, src->metadata, 0);
317 
318 #if FF_API_ERROR_FRAME
320  memcpy(dst->error, src->error, sizeof(dst->error));
322 #endif
323 
324  for (i = 0; i < src->nb_side_data; i++) {
325  const AVFrameSideData *sd_src = src->side_data[i];
326  AVFrameSideData *sd_dst;
327  if ( sd_src->type == AV_FRAME_DATA_PANSCAN
328  && (src->width != dst->width || src->height != dst->height))
329  continue;
330  if (force_copy) {
331  sd_dst = av_frame_new_side_data(dst, sd_src->type,
332  sd_src->size);
333  if (!sd_dst) {
334  wipe_side_data(dst);
335  return AVERROR(ENOMEM);
336  }
337  memcpy(sd_dst->data, sd_src->data, sd_src->size);
338  } else {
339  sd_dst = av_frame_new_side_data(dst, sd_src->type, 0);
340  if (!sd_dst) {
341  wipe_side_data(dst);
342  return AVERROR(ENOMEM);
343  }
344  sd_dst->buf = av_buffer_ref(sd_src->buf);
345  if (!sd_dst->buf) {
346  wipe_side_data(dst);
347  return AVERROR(ENOMEM);
348  }
349  sd_dst->data = sd_dst->buf->data;
350  sd_dst->size = sd_dst->buf->size;
351  }
352  av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0);
353  }
354 
355 #if FF_API_FRAME_QP
357  dst->qscale_table = NULL;
358  dst->qstride = 0;
359  dst->qscale_type = 0;
361  if (src->qp_table_buf) {
363  if (dst->qp_table_buf) {
364  dst->qscale_table = dst->qp_table_buf->data;
365  dst->qstride = src->qstride;
366  dst->qscale_type = src->qscale_type;
367  }
368  }
370 #endif
371 
372  return 0;
373 }
374 
375 int av_frame_ref(AVFrame *dst, const AVFrame *src)
376 {
377  int i, ret = 0;
378 
379  dst->format = src->format;
380  dst->width = src->width;
381  dst->height = src->height;
382  dst->channels = src->channels;
383  dst->channel_layout = src->channel_layout;
384  dst->nb_samples = src->nb_samples;
385 
386  ret = frame_copy_props(dst, src, 0);
387  if (ret < 0)
388  return ret;
389 
390  /* duplicate the frame data if it's not refcounted */
391  if (!src->buf[0]) {
392  ret = av_frame_get_buffer(dst, 32);
393  if (ret < 0)
394  return ret;
395 
396  ret = av_frame_copy(dst, src);
397  if (ret < 0)
398  av_frame_unref(dst);
399 
400  return ret;
401  }
402 
403  /* ref the buffers */
404  for (i = 0; i < FF_ARRAY_ELEMS(src->buf); i++) {
405  if (!src->buf[i])
406  continue;
407  dst->buf[i] = av_buffer_ref(src->buf[i]);
408  if (!dst->buf[i]) {
409  ret = AVERROR(ENOMEM);
410  goto fail;
411  }
412  }
413 
414  if (src->extended_buf) {
415  dst->extended_buf = av_mallocz_array(sizeof(*dst->extended_buf),
416  src->nb_extended_buf);
417  if (!dst->extended_buf) {
418  ret = AVERROR(ENOMEM);
419  goto fail;
420  }
421  dst->nb_extended_buf = src->nb_extended_buf;
422 
423  for (i = 0; i < src->nb_extended_buf; i++) {
424  dst->extended_buf[i] = av_buffer_ref(src->extended_buf[i]);
425  if (!dst->extended_buf[i]) {
426  ret = AVERROR(ENOMEM);
427  goto fail;
428  }
429  }
430  }
431 
432  /* duplicate extended data */
433  if (src->extended_data != src->data) {
434  int ch = src->channels;
435 
436  if (!ch) {
437  ret = AVERROR(EINVAL);
438  goto fail;
439  }
441 
442  dst->extended_data = av_malloc_array(sizeof(*dst->extended_data), ch);
443  if (!dst->extended_data) {
444  ret = AVERROR(ENOMEM);
445  goto fail;
446  }
447  memcpy(dst->extended_data, src->extended_data, sizeof(*src->extended_data) * ch);
448  } else
449  dst->extended_data = dst->data;
450 
451  memcpy(dst->data, src->data, sizeof(src->data));
452  memcpy(dst->linesize, src->linesize, sizeof(src->linesize));
453 
454  return 0;
455 
456 fail:
457  av_frame_unref(dst);
458  return ret;
459 }
460 
461 AVFrame *av_frame_clone(const AVFrame *src)
462 {
463  AVFrame *ret = av_frame_alloc();
464 
465  if (!ret)
466  return NULL;
467 
468  if (av_frame_ref(ret, src) < 0)
469  av_frame_free(&ret);
470 
471  return ret;
472 }
473 
474 void av_frame_unref(AVFrame *frame)
475 {
476  int i;
477 
478  if (!frame)
479  return;
480 
481  wipe_side_data(frame);
482 
483  for (i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++)
484  av_buffer_unref(&frame->buf[i]);
485  for (i = 0; i < frame->nb_extended_buf; i++)
486  av_buffer_unref(&frame->extended_buf[i]);
487  av_freep(&frame->extended_buf);
488  av_dict_free(&frame->metadata);
489 #if FF_API_FRAME_QP
490  av_buffer_unref(&frame->qp_table_buf);
491 #endif
492 
493  get_frame_defaults(frame);
494 }
495 
496 void av_frame_move_ref(AVFrame *dst, AVFrame *src)
497 {
498  *dst = *src;
499  if (src->extended_data == src->data)
500  dst->extended_data = dst->data;
501  memset(src, 0, sizeof(*src));
502  get_frame_defaults(src);
503 }
504 
505 int av_frame_is_writable(AVFrame *frame)
506 {
507  int i, ret = 1;
508 
509  /* assume non-refcounted frames are not writable */
510  if (!frame->buf[0])
511  return 0;
512 
513  for (i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++)
514  if (frame->buf[i])
515  ret &= !!av_buffer_is_writable(frame->buf[i]);
516  for (i = 0; i < frame->nb_extended_buf; i++)
517  ret &= !!av_buffer_is_writable(frame->extended_buf[i]);
518 
519  return ret;
520 }
521 
522 int av_frame_make_writable(AVFrame *frame)
523 {
524  AVFrame tmp;
525  int ret;
526 
527  if (!frame->buf[0])
528  return AVERROR(EINVAL);
529 
530  if (av_frame_is_writable(frame))
531  return 0;
532 
533  memset(&tmp, 0, sizeof(tmp));
534  tmp.format = frame->format;
535  tmp.width = frame->width;
536  tmp.height = frame->height;
537  tmp.channels = frame->channels;
538  tmp.channel_layout = frame->channel_layout;
539  tmp.nb_samples = frame->nb_samples;
540  ret = av_frame_get_buffer(&tmp, 32);
541  if (ret < 0)
542  return ret;
543 
544  ret = av_frame_copy(&tmp, frame);
545  if (ret < 0) {
546  av_frame_unref(&tmp);
547  return ret;
548  }
549 
550  ret = av_frame_copy_props(&tmp, frame);
551  if (ret < 0) {
552  av_frame_unref(&tmp);
553  return ret;
554  }
555 
556  av_frame_unref(frame);
557 
558  *frame = tmp;
559  if (tmp.data == tmp.extended_data)
560  frame->extended_data = frame->data;
561 
562  return 0;
563 }
564 
565 int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
566 {
567  return frame_copy_props(dst, src, 1);
568 }
569 
571 {
572  uint8_t *data;
573  int planes, i;
574 
575  if (frame->nb_samples) {
576  int channels = frame->channels;
577  if (!channels)
578  return NULL;
580  planes = av_sample_fmt_is_planar(frame->format) ? channels : 1;
581  } else
582  planes = 4;
583 
584  if (plane < 0 || plane >= planes || !frame->extended_data[plane])
585  return NULL;
586  data = frame->extended_data[plane];
587 
588  for (i = 0; i < FF_ARRAY_ELEMS(frame->buf) && frame->buf[i]; i++) {
589  AVBufferRef *buf = frame->buf[i];
590  if (data >= buf->data && data < buf->data + buf->size)
591  return buf;
592  }
593  for (i = 0; i < frame->nb_extended_buf; i++) {
594  AVBufferRef *buf = frame->extended_buf[i];
595  if (data >= buf->data && data < buf->data + buf->size)
596  return buf;
597  }
598  return NULL;
599 }
600 
603  int size)
604 {
605  AVFrameSideData *ret, **tmp;
606 
607  if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1)
608  return NULL;
609 
610  tmp = av_realloc(frame->side_data,
611  (frame->nb_side_data + 1) * sizeof(*frame->side_data));
612  if (!tmp)
613  return NULL;
614  frame->side_data = tmp;
615 
616  ret = av_mallocz(sizeof(*ret));
617  if (!ret)
618  return NULL;
619 
620  if (size > 0) {
621  ret->buf = av_buffer_alloc(size);
622  if (!ret->buf) {
623  av_freep(&ret);
624  return NULL;
625  }
626 
627  ret->data = ret->buf->data;
628  ret->size = size;
629  }
630  ret->type = type;
631 
632  frame->side_data[frame->nb_side_data++] = ret;
633 
634  return ret;
635 }
636 
639 {
640  int i;
641 
642  for (i = 0; i < frame->nb_side_data; i++) {
643  if (frame->side_data[i]->type == type)
644  return frame->side_data[i];
645  }
646  return NULL;
647 }
648 
649 static int frame_copy_video(AVFrame *dst, const AVFrame *src)
650 {
651  const uint8_t *src_data[4];
652  int i, planes;
653 
654  if (dst->width < src->width ||
655  dst->height < src->height)
656  return AVERROR(EINVAL);
657 
658  planes = av_pix_fmt_count_planes(dst->format);
659  for (i = 0; i < planes; i++)
660  if (!dst->data[i] || !src->data[i])
661  return AVERROR(EINVAL);
662 
663  memcpy(src_data, src->data, sizeof(src_data));
664  av_image_copy(dst->data, dst->linesize,
665  src_data, src->linesize,
666  dst->format, src->width, src->height);
667 
668  return 0;
669 }
670 
671 static int frame_copy_audio(AVFrame *dst, const AVFrame *src)
672 {
673  int planar = av_sample_fmt_is_planar(dst->format);
674  int channels = dst->channels;
675  int planes = planar ? channels : 1;
676  int i;
677 
678  if (dst->nb_samples != src->nb_samples ||
679  dst->channels != src->channels ||
680  dst->channel_layout != src->channel_layout)
681  return AVERROR(EINVAL);
682 
684 
685  for (i = 0; i < planes; i++)
686  if (!dst->extended_data[i] || !src->extended_data[i])
687  return AVERROR(EINVAL);
688 
690  dst->nb_samples, channels, dst->format);
691 
692  return 0;
693 }
694 
695 int av_frame_copy(AVFrame *dst, const AVFrame *src)
696 {
697  if (dst->format != src->format || dst->format < 0)
698  return AVERROR(EINVAL);
699 
700  if (dst->width > 0 && dst->height > 0)
701  return frame_copy_video(dst, src);
702  else if (dst->nb_samples > 0 && dst->channel_layout)
703  return frame_copy_audio(dst, src);
704 
705  return AVERROR(EINVAL);
706 }
707 
709 {
710  int i;
711 
712  for (i = 0; i < frame->nb_side_data; i++) {
713  AVFrameSideData *sd = frame->side_data[i];
714  if (sd->type == type) {
715  free_side_data(&frame->side_data[i]);
716  frame->side_data[i] = frame->side_data[frame->nb_side_data - 1];
717  frame->nb_side_data--;
718  }
719  }
720 }
721 
723 {
724  switch(type) {
725  case AV_FRAME_DATA_PANSCAN: return "AVPanScan";
726  case AV_FRAME_DATA_A53_CC: return "ATSC A53 Part 4 Closed Captions";
727  case AV_FRAME_DATA_STEREO3D: return "Stereoscopic 3d metadata";
728  case AV_FRAME_DATA_MATRIXENCODING: return "AVMatrixEncoding";
729  case AV_FRAME_DATA_DOWNMIX_INFO: return "Metadata relevant to a downmix procedure";
730  case AV_FRAME_DATA_REPLAYGAIN: return "AVReplayGain";
731  case AV_FRAME_DATA_DISPLAYMATRIX: return "3x3 displaymatrix";
732  case AV_FRAME_DATA_AFD: return "Active format description";
733  case AV_FRAME_DATA_MOTION_VECTORS: return "Motion vectors";
734  case AV_FRAME_DATA_SKIP_SAMPLES: return "Skip samples";
735  case AV_FRAME_DATA_AUDIO_SERVICE_TYPE: return "Audio service type";
736  case AV_FRAME_DATA_MASTERING_DISPLAY_METADATA: return "Mastering display metadata";
737  case AV_FRAME_DATA_GOP_TIMECODE: return "GOP timecode";
738  }
739  return NULL;
740 }
#define AV_PIX_FMT_FLAG_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
Definition: pixdesc.h:132
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
Definition: pixfmt.h:422
int plane
Definition: avisynth_c.h:291
#define NULL
Definition: coverity.c:32
const char const char void * val
Definition: avisynth_c.h:634
#define AV_NUM_DATA_POINTERS
Definition: frame.h:182
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:124
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2157
This structure describes decoded (raw) audio or video data.
Definition: frame.h:181
ptrdiff_t const GLvoid * data
Definition: opengl_enc.c:101
This side data must be associated with an audio frame and corresponds to enum AVAudioServiceType defi...
Definition: frame.h:113
attribute_deprecated int qscale_type
Definition: frame.h:508
int64_t pkt_pos
reordered pos from the last AVPacket that has been input into the decoder Code outside libavutil shou...
Definition: frame.h:440
misc image utilities
int av_pix_fmt_count_planes(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2197
memory handling functions
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:357
AVDictionary * metadata
Definition: frame.h:148
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
Definition: pixfmt.h:426
void * opaque
for some private data of the user
Definition: frame.h:293
int nb_extended_buf
Number of elements in extended_buf.
Definition: frame.h:375
int repeat_pict
When decoding, this signals how much the picture must be delayed.
Definition: frame.h:307
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC / functionally identical to above ...
Definition: pixfmt.h:427
int av_frame_set_qp_table(AVFrame *f, AVBufferRef *buf, int stride, int qp_type)
Definition: frame.c:50
void av_frame_set_pkt_duration(AVFrame *frame, int64_t val)
int av_dict_copy(AVDictionary **dst, const AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:213
Mastering display metadata associated with a video frame.
Definition: frame.h:119
static void wipe_side_data(AVFrame *frame)
Definition: frame.c:129
color_range
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:496
void av_frame_set_pkt_size(AVFrame *frame, int val)
int8_t * av_frame_get_qp_table(AVFrame *f, int *stride, int *type)
Definition: frame.c:65
Used by Dirac / VC-2 and H.264 FRext, see ITU-T SG16.
Definition: pixfmt.h:429
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
Definition: pixfmt.h:421
attribute_deprecated int8_t * qscale_table
QP table Not to be accessed directly from outside libavutil.
Definition: frame.h:499
int av_get_channel_layout_nb_channels(uint64_t channel_layout)
Return the number of channels in the channel layout.
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:637
Public dictionary API.
uint8_t
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:141
static int frame_copy_video(AVFrame *dst, const AVFrame *src)
Definition: frame.c:649
AVColorSpace
YUV colorspace type.
Definition: pixfmt.h:420
#define AVPALETTE_SIZE
Definition: pixfmt.h:33
attribute_deprecated int qstride
QP store stride Not to be accessed directly from outside libavutil.
Definition: frame.h:505
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:375
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:262
AVBufferRef * buf
Definition: frame.h:149
The data is the AVPanScan struct defined in libavcodec.
Definition: frame.h:52
static AVFrame * frame
Structure to hold side data for an AVFrame.
Definition: frame.h:144
AVDictionary * metadata
metadata.
Definition: frame.h:459
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:312
void av_frame_set_best_effort_timestamp(AVFrame *frame, int64_t val)
AVColorRange
MPEG vs JPEG YUV range.
Definition: pixfmt.h:440
ptrdiff_t size
Definition: opengl_enc.c:101
Active Format Description data consisting of a single byte as specified in ETSI TS 101 154 using AVAc...
Definition: frame.h:89
Metadata relevant to a downmix procedure.
Definition: frame.h:72
int nb_side_data
Definition: frame.h:378
#define FFALIGN(x, a)
Definition: macros.h:48
attribute_deprecated uint64_t error[AV_NUM_DATA_POINTERS]
Definition: frame.h:300
AVFrameSideData ** side_data
Definition: frame.h:377
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:110
int width
width and height of the video frame
Definition: frame.h:230
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
#define MAKE_ACCESSORS(str, name, type, field)
Definition: internal.h:87
#define AVERROR(e)
Definition: error.h:43
static int frame_copy_props(AVFrame *dst, const AVFrame *src, int force_copy)
Definition: frame.c:284
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:154
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: frame.h:407
ATSC A53 Part 4 Closed Captions.
Definition: frame.h:58
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:199
enum AVColorSpace colorspace
YUV colorspace type.
Definition: frame.h:420
simple assert() macros that are a bit more flexible than ISO C assert().
The GOP timecode in 25 bit timecode format.
Definition: frame.h:124
static int get_audio_buffer(AVFrame *frame, int align)
Definition: frame.c:215
#define fail()
Definition: checkasm.h:80
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:302
int av_frame_copy(AVFrame *dst, const AVFrame *src)
Copy the frame data from src to dst.
Definition: frame.c:695
reference-counted frame API
uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:343
uint64_t flags
Combination of AV_PIX_FMT_FLAG_...
Definition: pixdesc.h:106
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:251
int channels
number of audio channels, only used for audio.
Definition: frame.h:481
audio channel layout utility functions
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:252
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition: frame.h:398
#define FFMIN(a, b)
Definition: common.h:96
int display_picture_number
picture number in display order
Definition: frame.h:283
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:371
#define AV_PIX_FMT_FLAG_PSEUDOPAL
The pixel format is "pseudo-paletted".
Definition: pixdesc.h:158
Motion vectors exported by some codecs (on demand through the export_mvs flag set in the libavcodec A...
Definition: frame.h:96
AVBufferRef * av_frame_get_plane_buffer(AVFrame *frame, int plane)
Get the buffer reference a given data plane is stored in.
Definition: frame.c:570
void av_frame_set_pkt_pos(AVFrame *frame, int64_t val)
AVFrameSideDataType
Definition: frame.h:48
AVBufferRef * qp_table_buf
Not to be accessed directly from outside libavutil.
Definition: frame.h:513
int quality
quality (between 1 (good) and FF_LAMBDA_MAX (bad))
Definition: frame.h:288
int av_buffer_is_writable(const AVBufferRef *buf)
Definition: buffer.c:132
const char * av_get_colorspace_name(enum AVColorSpace val)
Get the name of a colorspace.
Definition: frame.c:79
#define src
Definition: vp9dsp.c:530
FCC Title 47 Code of Federal Regulations 73.682 (a)(20)
Definition: pixfmt.h:425
AVFrame * av_frame_clone(const AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:461
#define FF_ARRAY_ELEMS(a)
const AVS_VideoInfo int align
Definition: avisynth_c.h:658
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:242
int coded_picture_number
picture number in bitstream order
Definition: frame.h:279
sample_rate
int64_t pkt_duration
duration of the corresponding packet, expressed in AVStream->time_base units, 0 if unknown...
Definition: frame.h:450
This side data contains a 3x3 transformation matrix describing an affine transformation that needs to...
Definition: frame.h:84
AVDictionary ** avpriv_frame_get_metadatap(AVFrame *frame)
Definition: frame.c:47
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:505
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:209
static int get_video_buffer(AVFrame *frame, int align)
Definition: frame.c:163
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
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:257
uint8_t * data
Definition: frame.h:146
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:211
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:708
void * buf
Definition: avisynth_c.h:553
GLint GLenum type
Definition: opengl_enc.c:105
int64_t reordered_opaque
reordered opaque 64bit (generally an integer or a double precision float PTS but can be anything)...
Definition: frame.h:333
int sample_rate
Sample rate of the audio data.
Definition: frame.h:338
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:88
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, int size)
Add a new side data to a frame.
Definition: frame.c:601
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:117
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:322
refcounted data buffer API
enum AVChromaLocation chroma_location
Definition: frame.h:422
int64_t best_effort_timestamp
frame timestamp estimated using various heuristics, in stream time base Code outside libavutil should...
Definition: frame.h:431
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:470
static int frame_copy_audio(AVFrame *dst, const AVFrame *src)
Definition: frame.c:671
const char * av_frame_side_data_name(enum AVFrameSideDataType type)
Definition: frame.c:722
int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
Definition: frame.h:267
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:271
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:474
enum AVFrameSideDataType type
Definition: frame.h:145
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
Definition: frame.c:522
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:192
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
Definition: frame.h:274
A reference to a data buffer.
Definition: buffer.h:81
GLint GLenum GLboolean GLsizei stride
Definition: opengl_enc.c:105
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:80
common internal and external API header
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
Definition: mem.c:145
#define CHECK_CHANNELS_CONSISTENCY(frame)
Definition: frame.c:42
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
Definition: buffer.c:92
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:81
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:317
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:247
enum AVColorPrimaries color_primaries
Definition: frame.h:409
static void * av_mallocz_array(size_t nmemb, size_t size)
Definition: mem.h:229
int height
Definition: frame.h:230
#define av_freep(p)
static void free_side_data(AVFrameSideData **ptr_sd)
Definition: frame.c:120
enum AVColorTransferCharacteristic color_trc
Definition: frame.h:411
Recommmends skipping the specified number of samples.
Definition: frame.h:108
#define av_malloc_array(a, b)
#define stride
ReplayGain information in the form of the AVReplayGain struct.
Definition: frame.h:76
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:225
static void get_frame_defaults(AVFrame *frame)
Definition: frame.c:95
int pkt_size
size of the corresponding packet containing the compressed frame.
Definition: frame.h:491
Stereoscopic 3d metadata.
Definition: frame.h:63
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:235
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:252
The data is the AVMatrixEncoding enum defined in libavutil/channel_layout.h.
Definition: frame.h:67
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:565
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:240
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
const char * name
Definition: opengl_enc.c:103