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 #define MAKE_ACCESSORS(str, name, type, field) \
31  type av_##name##_get_##field(const str *s) { return s->field; } \
32  void av_##name##_set_##field(str *s, type v) { s->field = v; }
33 
34 MAKE_ACCESSORS(AVFrame, frame, int64_t, best_effort_timestamp)
35 MAKE_ACCESSORS(AVFrame, frame, int64_t, pkt_duration)
36 MAKE_ACCESSORS(AVFrame, frame, int64_t, pkt_pos)
37 MAKE_ACCESSORS(AVFrame, frame, int64_t, channel_layout)
38 MAKE_ACCESSORS(AVFrame, frame, int, channels)
39 MAKE_ACCESSORS(AVFrame, frame, int, sample_rate)
40 MAKE_ACCESSORS(AVFrame, frame, AVDictionary *, metadata)
41 MAKE_ACCESSORS(AVFrame, frame, int, decode_error_flags)
42 MAKE_ACCESSORS(AVFrame, frame, int, pkt_size)
43 
44 #define CHECK_CHANNELS_CONSISTENCY(frame) \
45  av_assert2(!(frame)->channel_layout || \
46  (frame)->channels == \
47  av_get_channel_layout_nb_channels((frame)->channel_layout))
48 
49 AVDictionary **avpriv_frame_get_metadatap(AVFrame *frame) {return &frame->metadata;};
50 
51 int av_frame_set_qp_table(AVFrame *f, AVBufferRef *buf, int stride, int qp_type)
52 {
54 
55  f->qp_table_buf = buf;
56 
57  f->qscale_table = buf->data;
58  f->qstride = stride;
59  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 {
66  *stride = f->qstride;
67  *type = f->qscale_type;
68 
69  if (!f->qp_table_buf)
70  return NULL;
71 
72  return f->qp_table_buf->data;
73 }
74 
75 static void get_frame_defaults(AVFrame *frame)
76 {
77  if (frame->extended_data != frame->data)
78  av_freep(&frame->extended_data);
79 
80  memset(frame, 0, sizeof(*frame));
81 
82  frame->pts =
83  frame->pkt_dts =
84  frame->pkt_pts = AV_NOPTS_VALUE;
86  av_frame_set_pkt_duration (frame, 0);
87  av_frame_set_pkt_pos (frame, -1);
88  av_frame_set_pkt_size (frame, -1);
89  frame->key_frame = 1;
90  frame->sample_aspect_ratio = (AVRational){ 0, 1 };
91  frame->format = -1; /* unknown */
92  frame->extended_data = frame->data;
93 }
94 
95 AVFrame *av_frame_alloc(void)
96 {
97  AVFrame *frame = av_mallocz(sizeof(*frame));
98 
99  if (!frame)
100  return NULL;
101 
102  frame->extended_data = NULL;
103  get_frame_defaults(frame);
104 
105  return frame;
106 }
107 
108 void av_frame_free(AVFrame **frame)
109 {
110  if (!frame || !*frame)
111  return;
112 
113  av_frame_unref(*frame);
114  av_freep(frame);
115 }
116 
117 static int get_video_buffer(AVFrame *frame, int align)
118 {
119  const AVPixFmtDescriptor *desc = av_pix_fmt_desc_get(frame->format);
120  int ret, i;
121 
122  if (!desc)
123  return AVERROR(EINVAL);
124 
125  if ((ret = av_image_check_size(frame->width, frame->height, 0, NULL)) < 0)
126  return ret;
127 
128  if (!frame->linesize[0]) {
129  ret = av_image_fill_linesizes(frame->linesize, frame->format,
130  frame->width);
131  if (ret < 0)
132  return ret;
133 
134  for (i = 0; i < 4 && frame->linesize[i]; i++)
135  frame->linesize[i] = FFALIGN(frame->linesize[i], align);
136  }
137 
138  for (i = 0; i < 4 && frame->linesize[i]; i++) {
139  int h = FFALIGN(frame->height, 32);
140  if (i == 1 || i == 2)
141  h = -((-h) >> desc->log2_chroma_h);
142 
143  frame->buf[i] = av_buffer_alloc(frame->linesize[i] * h + 16);
144  if (!frame->buf[i])
145  goto fail;
146 
147  frame->data[i] = frame->buf[i]->data;
148  }
149  if (desc->flags & PIX_FMT_PAL || desc->flags & PIX_FMT_PSEUDOPAL) {
150  av_buffer_unref(&frame->buf[1]);
151  frame->buf[1] = av_buffer_alloc(1024);
152  if (!frame->buf[1])
153  goto fail;
154  frame->data[1] = frame->buf[1]->data;
155  }
156 
157  frame->extended_data = frame->data;
158 
159  return 0;
160 fail:
161  av_frame_unref(frame);
162  return AVERROR(ENOMEM);
163 }
164 
165 static int get_audio_buffer(AVFrame *frame, int align)
166 {
167  int channels = frame->channels;
168  int planar = av_sample_fmt_is_planar(frame->format);
169  int planes = planar ? channels : 1;
170  int ret, i;
171 
173  if (!frame->linesize[0]) {
174  ret = av_samples_get_buffer_size(&frame->linesize[0], channels,
175  frame->nb_samples, frame->format,
176  align);
177  if (ret < 0)
178  return ret;
179  }
180 
181  if (planes > AV_NUM_DATA_POINTERS) {
182  frame->extended_data = av_mallocz(planes *
183  sizeof(*frame->extended_data));
184  frame->extended_buf = av_mallocz((planes - AV_NUM_DATA_POINTERS) *
185  sizeof(*frame->extended_buf));
186  if (!frame->extended_data || !frame->extended_buf) {
187  av_freep(&frame->extended_data);
188  av_freep(&frame->extended_buf);
189  return AVERROR(ENOMEM);
190  }
191  frame->nb_extended_buf = planes - AV_NUM_DATA_POINTERS;
192  } else
193  frame->extended_data = frame->data;
194 
195  for (i = 0; i < FFMIN(planes, AV_NUM_DATA_POINTERS); i++) {
196  frame->buf[i] = av_buffer_alloc(frame->linesize[0]);
197  if (!frame->buf[i]) {
198  av_frame_unref(frame);
199  return AVERROR(ENOMEM);
200  }
201  frame->extended_data[i] = frame->data[i] = frame->buf[i]->data;
202  }
203  for (i = 0; i < planes - AV_NUM_DATA_POINTERS; i++) {
204  frame->extended_buf[i] = av_buffer_alloc(frame->linesize[0]);
205  if (!frame->extended_buf[i]) {
206  av_frame_unref(frame);
207  return AVERROR(ENOMEM);
208  }
209  frame->extended_data[i + AV_NUM_DATA_POINTERS] = frame->extended_buf[i]->data;
210  }
211  return 0;
212 
213 }
214 
215 int av_frame_get_buffer(AVFrame *frame, int align)
216 {
217  if (frame->format < 0)
218  return AVERROR(EINVAL);
219 
220  if (frame->width > 0 && frame->height > 0)
221  return get_video_buffer(frame, align);
222  else if (frame->nb_samples > 0 && frame->channel_layout)
223  return get_audio_buffer(frame, align);
224 
225  return AVERROR(EINVAL);
226 }
227 
228 int av_frame_ref(AVFrame *dst, AVFrame *src)
229 {
230  int i, ret = 0;
231 
232  dst->format = src->format;
233  dst->width = src->width;
234  dst->height = src->height;
235  dst->channels = src->channels;
236  dst->channel_layout = src->channel_layout;
237  dst->nb_samples = src->nb_samples;
238 
239  ret = av_frame_copy_props(dst, src);
240  if (ret < 0)
241  return ret;
242 
243  /* duplicate the frame data if it's not refcounted */
244  if (!src->buf[0]) {
245  ret = av_frame_get_buffer(dst, 32);
246  if (ret < 0)
247  return ret;
248 
249  if (src->nb_samples) {
250  int ch = src->channels;
253  dst->nb_samples, ch, dst->format);
254  } else {
255  av_image_copy(dst->data, dst->linesize, src->data, src->linesize,
256  dst->format, dst->width, dst->height);
257  }
258  return 0;
259  }
260 
261  /* ref the buffers */
262  for (i = 0; i < FF_ARRAY_ELEMS(src->buf) && src->buf[i]; i++) {
263  dst->buf[i] = av_buffer_ref(src->buf[i]);
264  if (!dst->buf[i]) {
265  ret = AVERROR(ENOMEM);
266  goto fail;
267  }
268  }
269 
270  if (src->extended_buf) {
271  dst->extended_buf = av_mallocz(sizeof(*dst->extended_buf) *
272  src->nb_extended_buf);
273  if (!dst->extended_buf) {
274  ret = AVERROR(ENOMEM);
275  goto fail;
276  }
277  dst->nb_extended_buf = src->nb_extended_buf;
278 
279  for (i = 0; i < src->nb_extended_buf; i++) {
280  dst->extended_buf[i] = av_buffer_ref(src->extended_buf[i]);
281  if (!dst->extended_buf[i]) {
282  ret = AVERROR(ENOMEM);
283  goto fail;
284  }
285  }
286  }
287 
288  /* duplicate extended data */
289  if (src->extended_data != src->data) {
290  int ch = src->channels;
291 
292  if (!ch) {
293  ret = AVERROR(EINVAL);
294  goto fail;
295  }
297 
298  dst->extended_data = av_malloc(sizeof(*dst->extended_data) * ch);
299  if (!dst->extended_data) {
300  ret = AVERROR(ENOMEM);
301  goto fail;
302  }
303  memcpy(dst->extended_data, src->extended_data, sizeof(*src->extended_data) * ch);
304  } else
305  dst->extended_data = dst->data;
306 
307  memcpy(dst->data, src->data, sizeof(src->data));
308  memcpy(dst->linesize, src->linesize, sizeof(src->linesize));
309 
310  return 0;
311 
312 fail:
313  av_frame_unref(dst);
314  return ret;
315 }
316 
317 AVFrame *av_frame_clone(AVFrame *src)
318 {
319  AVFrame *ret = av_frame_alloc();
320 
321  if (!ret)
322  return NULL;
323 
324  if (av_frame_ref(ret, src) < 0)
325  av_frame_free(&ret);
326 
327  return ret;
328 }
329 
330 void av_frame_unref(AVFrame *frame)
331 {
332  int i;
333 
334  for (i = 0; i < frame->nb_side_data; i++) {
335  av_freep(&frame->side_data[i]->data);
336  av_dict_free(&frame->side_data[i]->metadata);
337  av_freep(&frame->side_data[i]);
338  }
339  av_freep(&frame->side_data);
340 
341  for (i = 0; i < FF_ARRAY_ELEMS(frame->buf); i++)
342  av_buffer_unref(&frame->buf[i]);
343  for (i = 0; i < frame->nb_extended_buf; i++)
344  av_buffer_unref(&frame->extended_buf[i]);
345  av_freep(&frame->extended_buf);
346  av_dict_free(&frame->metadata);
347  av_buffer_unref(&frame->qp_table_buf);
348 
349  get_frame_defaults(frame);
350 }
351 
352 void av_frame_move_ref(AVFrame *dst, AVFrame *src)
353 {
354  *dst = *src;
355  if (src->extended_data == src->data)
356  dst->extended_data = dst->data;
357  memset(src, 0, sizeof(*src));
358  get_frame_defaults(src);
359 }
360 
361 int av_frame_is_writable(AVFrame *frame)
362 {
363  int i, ret = 1;
364 
365  /* assume non-refcounted frames are not writable */
366  if (!frame->buf[0])
367  return 0;
368 
369  for (i = 0; i < FF_ARRAY_ELEMS(frame->buf) && frame->buf[i]; i++)
370  ret &= !!av_buffer_is_writable(frame->buf[i]);
371  for (i = 0; i < frame->nb_extended_buf; i++)
372  ret &= !!av_buffer_is_writable(frame->extended_buf[i]);
373 
374  return ret;
375 }
376 
377 int av_frame_make_writable(AVFrame *frame)
378 {
379  AVFrame tmp;
380  int ret;
381 
382  if (!frame->buf[0])
383  return AVERROR(EINVAL);
384 
385  if (av_frame_is_writable(frame))
386  return 0;
387 
388  memset(&tmp, 0, sizeof(tmp));
389  tmp.format = frame->format;
390  tmp.width = frame->width;
391  tmp.height = frame->height;
392  tmp.channels = frame->channels;
393  tmp.channel_layout = frame->channel_layout;
394  tmp.nb_samples = frame->nb_samples;
395  ret = av_frame_get_buffer(&tmp, 32);
396  if (ret < 0)
397  return ret;
398 
399  if (tmp.nb_samples) {
400  int ch = tmp.channels;
402  av_samples_copy(tmp.extended_data, frame->extended_data, 0, 0,
403  frame->nb_samples, ch, frame->format);
404  } else {
405  av_image_copy(tmp.data, tmp.linesize, frame->data, frame->linesize,
406  frame->format, frame->width, frame->height);
407  }
408 
409  ret = av_frame_copy_props(&tmp, frame);
410  if (ret < 0) {
411  av_frame_unref(&tmp);
412  return ret;
413  }
414 
415  av_frame_unref(frame);
416 
417  *frame = tmp;
418  if (tmp.data == tmp.extended_data)
419  frame->extended_data = frame->data;
420 
421  return 0;
422 }
423 
424 int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
425 {
426  int i;
427 
428  dst->key_frame = src->key_frame;
429  dst->pict_type = src->pict_type;
431  dst->pts = src->pts;
432  dst->repeat_pict = src->repeat_pict;
434  dst->top_field_first = src->top_field_first;
436  dst->sample_rate = src->sample_rate;
437  dst->opaque = src->opaque;
438 #if FF_API_AVFRAME_LAVC
439  dst->type = src->type;
440 #endif
441  dst->pkt_pts = src->pkt_pts;
442  dst->pkt_dts = src->pkt_dts;
443  dst->pkt_pos = src->pkt_pos;
444  dst->pkt_size = src->pkt_size;
445  dst->pkt_duration = src->pkt_duration;
447  dst->quality = src->quality;
452 
453  av_dict_copy(&dst->metadata, src->metadata, 0);
454 
455  memcpy(dst->error, src->error, sizeof(dst->error));
456 
457  for (i = 0; i < src->nb_side_data; i++) {
458  const AVFrameSideData *sd_src = src->side_data[i];
459  AVFrameSideData *sd_dst = av_frame_new_side_data(dst, sd_src->type,
460  sd_src->size);
461  if (!sd_dst) {
462  for (i = 0; i < dst->nb_side_data; i++) {
463  av_freep(&dst->side_data[i]->data);
464  av_freep(&dst->side_data[i]);
465  av_dict_free(&dst->side_data[i]->metadata);
466  }
467  av_freep(&dst->side_data);
468  return AVERROR(ENOMEM);
469  }
470  memcpy(sd_dst->data, sd_src->data, sd_src->size);
471  av_dict_copy(&sd_dst->metadata, sd_src->metadata, 0);
472  }
473 
474  dst->qscale_table = NULL;
475  dst->qstride = 0;
476  dst->qscale_type = 0;
477  if (src->qp_table_buf) {
479  if (dst->qp_table_buf) {
480  dst->qscale_table = dst->qp_table_buf->data;
481  dst->qstride = src->qstride;
482  dst->qscale_type = src->qscale_type;
483  }
484  }
485 
486  return 0;
487 }
488 
489 AVBufferRef *av_frame_get_plane_buffer(AVFrame *frame, int plane)
490 {
491  uint8_t *data;
492  int planes, i;
493 
494  if (frame->nb_samples) {
495  int channels = frame->channels;
496  if (!channels)
497  return NULL;
499  planes = av_sample_fmt_is_planar(frame->format) ? channels : 1;
500  } else
501  planes = 4;
502 
503  if (plane < 0 || plane >= planes || !frame->extended_data[plane])
504  return NULL;
505  data = frame->extended_data[plane];
506 
507  for (i = 0; i < FF_ARRAY_ELEMS(frame->buf) && frame->buf[i]; i++) {
508  AVBufferRef *buf = frame->buf[i];
509  if (data >= buf->data && data < buf->data + buf->size)
510  return buf;
511  }
512  for (i = 0; i < frame->nb_extended_buf; i++) {
513  AVBufferRef *buf = frame->extended_buf[i];
514  if (data >= buf->data && data < buf->data + buf->size)
515  return buf;
516  }
517  return NULL;
518 }
519 
522  int size)
523 {
524  AVFrameSideData *ret, **tmp;
525 
526  if (frame->nb_side_data > INT_MAX / sizeof(*frame->side_data) - 1)
527  return NULL;
528 
529  tmp = av_realloc(frame->side_data,
530  (frame->nb_side_data + 1) * sizeof(*frame->side_data));
531  if (!tmp)
532  return NULL;
533  frame->side_data = tmp;
534 
535  ret = av_mallocz(sizeof(*ret));
536  if (!ret)
537  return NULL;
538 
539  ret->data = av_malloc(size);
540  if (!ret->data) {
541  av_freep(&ret);
542  return NULL;
543  }
544 
545  ret->size = size;
546  ret->type = type;
547 
548  frame->side_data[frame->nb_side_data++] = ret;
549 
550  return ret;
551 }
552 
555 {
556  int i;
557 
558  for (i = 0; i < frame->nb_side_data; i++) {
559  if (frame->side_data[i]->type == type)
560  return frame->side_data[i];
561  }
562  return NULL;
563 }
void * av_mallocz(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:205
#define AV_NUM_DATA_POINTERS
Definition: frame.h:77
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:424
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it...
void av_frame_set_best_effort_timestamp(AVFrame *frame, int64_t val)
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:1778
This structure describes decoded (raw) audio or video data.
Definition: frame.h:76
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
attribute_deprecated int qscale_type
Definition: frame.h:203
int64_t pkt_pos
reordered pos from the last AVPacket that has been input into the decoder Code outside libavcodec sho...
Definition: frame.h:382
misc image utilities
memory handling functions
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:343
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:215
AVDictionary * metadata
Definition: frame.h:44
void * opaque
for some private data of the user
Definition: frame.h:249
int nb_extended_buf
Number of elements in extended_buf.
Definition: frame.h:361
int repeat_pict
When decoding, this signals how much the picture must be delayed.
Definition: frame.h:265
Sinusoidal phase f
void * av_realloc(void *ptr, size_t size)
Allocate or reallocate a block of memory.
Definition: mem.c:141
#define FF_ARRAY_ELEMS(a)
int stride
Definition: mace.c:144
attribute_deprecated int8_t * qscale_table
QP table.
Definition: frame.h:195
#define FFALIGN(x, a)
Definition: common.h:63
void av_freep(void *arg)
Free a memory block which has been allocated with av_malloc(z)() or av_realloc() and set the pointer ...
Definition: mem.c:198
void av_frame_set_pkt_duration(AVFrame *frame, int64_t val)
Public dictionary API.
uint8_t
attribute_deprecated int qstride
QP store stride.
Definition: frame.h:200
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:159
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everythnig contained in src to dst and reset src.
Definition: frame.c:352
AVDictionary * metadata
metadata.
Definition: frame.h:401
int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:270
int8_t * av_frame_get_qp_table(AVFrame *f, int *stride, int *type)
Definition: frame.c:64
int nb_side_data
Definition: frame.h:364
AVFrameSideData ** side_data
Definition: frame.h:363
frame
Definition: stft.m:14
int av_frame_make_writable(AVFrame *frame)
Ensure that the frame data is writable, avoiding data copy if possible.
Definition: frame.c:377
void av_dict_copy(AVDictionary **dst, AVDictionary *src, int flags)
Copy entries from one AVDictionary struct into another.
Definition: dict.c:176
void av_frame_set_pkt_size(AVFrame *frame, int val)
int width
width and height of the video frame
Definition: frame.h:122
AVDictionary ** avpriv_frame_get_metadatap(AVFrame *frame)
Definition: frame.c:49
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:75
void av_frame_set_pkt_pos(AVFrame *frame, int64_t val)
Spectrum Plot time data
void av_dict_free(AVDictionary **pm)
Free all the memory allocated for an AVDictionary struct and all keys and values. ...
Definition: dict.c:162
int av_frame_is_writable(AVFrame *frame)
Check if the frame data is writable.
Definition: frame.c:361
AVBufferRef * av_frame_get_plane_buffer(AVFrame *frame, int plane)
Get the buffer reference a given data plane is stored in.
Definition: frame.c:489
simple assert() macros that are a bit more flexible than ISO C assert().
#define PIX_FMT_PAL
Pixel format has a palette in data[1], values are indexes in this palette.
Definition: pixdesc.h:90
static int get_audio_buffer(AVFrame *frame, int align)
Definition: frame.c:165
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
int size
uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:331
struct AVRational AVRational
rational number numerator/denominator
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
AVFrameSideDataType
Definition: frame.h:33
int channels
number of audio channels, only used for audio.
Definition: frame.h:423
audio channel layout utility functions
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:144
#define FFMIN(a, b)
Definition: common.h:58
int display_picture_number
picture number in display order
Definition: frame.h:180
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:357
ret
Definition: avfilter.c:821
AVBufferRef * qp_table_buf
Not to be accessed directly from outside libavutil.
Definition: frame.h:438
int quality
quality (between 1 (good) and FF_LAMBDA_MAX (bad))
Definition: frame.h:185
int av_buffer_is_writable(const AVBufferRef *buf)
AVFrameSideData * av_frame_new_side_data(AVFrame *frame, enum AVFrameSideDataType type, int size)
Add a new side data to a frame.
Definition: frame.c:520
AVFrame * av_frame_clone(AVFrame *src)
Create a new frame that references the same data as src.
Definition: frame.c:317
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:134
NULL
Definition: eval.c:55
int coded_picture_number
picture number in bitstream order
Definition: frame.h:176
sample_rate
uint64_t error[AV_NUM_DATA_POINTERS]
error
Definition: frame.h:254
AVS_Value src
Definition: avisynth_c.h:523
int64_t pkt_duration
duration of the corresponding packet, expressed in AVStream->time_base units, 0 if unknown...
Definition: frame.h:392
AVBufferRef * av_buffer_alloc(int size)
Allocate an AVBuffer of the given size using av_malloc().
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:101
static int get_video_buffer(AVFrame *frame, int align)
Definition: frame.c:117
uint8_t flags
Definition: pixdesc.h:76
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:55
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:154
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
uint8_t * data
Definition: frame.h:42
void * buf
Definition: avisynth_c.h:594
void * av_malloc(size_t size)
Allocate a block of size bytes with alignment suitable for all memory accesses (including vectors if ...
Definition: mem.c:73
int64_t reordered_opaque
reordered opaque 64bit (generally an integer or a double precision float PTS but can be anything)...
Definition: frame.h:302
int sample_rate
Sample rate of the audio data.
Definition: frame.h:326
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
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:118
synthesis window for stochastic i
int palette_has_changed
Tell user application that palette has changed from previous frame.
Definition: frame.h:280
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:330
int64_t best_effort_timestamp
frame timestamp estimated using various heuristics, in stream time base Code outside libavcodec shoul...
Definition: frame.h:373
AVFrameSideData * av_frame_get_side_data(AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:553
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:412
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFilterBuffer structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Buffer references ownership and permissions
#define type
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:95
int64_t pkt_pts
PTS copied from the AVPacket that was decoded to produce this frame.
Definition: frame.h:164
int size
Size of data in bytes.
Definition: buffer.h:93
enum AVFrameSideDataType type
Definition: frame.h:41
int av_frame_ref(AVFrame *dst, AVFrame *src)
Setup a new reference to the data described by an given frame.
Definition: frame.c:228
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:87
int64_t pkt_dts
DTS copied from the AVPacket that triggered returning this frame.
Definition: frame.h:171
A reference to a data buffer.
Definition: buffer.h:81
#define MAKE_ACCESSORS(str, name, type, field)
Definition: frame.c:30
common internal and external API header
#define CHECK_CHANNELS_CONSISTENCY(frame)
Definition: frame.c:44
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:108
AVBufferRef * av_buffer_ref(AVBufferRef *buf)
Create a new reference to an AVBuffer.
int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:275
#define PIX_FMT_PSEUDOPAL
The pixel format is "pseudo-paletted".
Definition: pixdesc.h:100
else dst[i][x+y *dst_stride[i]]
Definition: vf_mcdeint.c:160
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:139
int height
Definition: frame.h:122
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:117
static void get_frame_defaults(AVFrame *frame)
Definition: frame.c:75
attribute_deprecated int type
Definition: frame.h:258
int pkt_size
size of the corresponding packet containing the compressed frame.
Definition: frame.h:433
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:127
int av_frame_set_qp_table(AVFrame *f, AVBufferRef *buf, int stride, int qp_type)
Definition: frame.c:51
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:190