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