FFmpeg
encode.c
Go to the documentation of this file.
1 /*
2  * generic encoding-related code
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 #include "libavutil/attributes.h"
22 #include "libavutil/avassert.h"
23 #include "libavutil/frame.h"
24 #include "libavutil/imgutils.h"
25 #include "libavutil/internal.h"
26 #include "libavutil/samplefmt.h"
27 
28 #include "avcodec.h"
29 #include "encode.h"
30 #include "frame_thread_encoder.h"
31 #include "internal.h"
32 
33 int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
34 {
36  av_log(avctx, AV_LOG_ERROR, "Invalid minimum required packet size %"PRId64" (max allowed is %d)\n",
37  size, INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE);
38  return AVERROR(EINVAL);
39  }
40 
41  av_assert0(!avpkt->data);
42 
43  if (avctx && 2*min_size < size) { // FIXME The factor needs to be finetuned
45  avpkt->data = avctx->internal->byte_buffer;
46  avpkt->size = size;
47  }
48 
49  if (!avpkt->data) {
50  int ret = av_new_packet(avpkt, size);
51  if (ret < 0)
52  av_log(avctx, AV_LOG_ERROR, "Failed to allocate packet of size %"PRId64"\n", size);
53  return ret;
54  }
55 
56  return 0;
57 }
58 
59 /**
60  * Pad last frame with silence.
61  */
63 {
64  int ret;
65 
66  frame->format = src->format;
67  frame->channel_layout = src->channel_layout;
68  frame->channels = src->channels;
69  frame->nb_samples = s->frame_size;
70  ret = av_frame_get_buffer(frame, 0);
71  if (ret < 0)
72  goto fail;
73 
74  ret = av_frame_copy_props(frame, src);
75  if (ret < 0)
76  goto fail;
77 
78  if ((ret = av_samples_copy(frame->extended_data, src->extended_data, 0, 0,
79  src->nb_samples, s->channels, s->sample_fmt)) < 0)
80  goto fail;
81  if ((ret = av_samples_set_silence(frame->extended_data, src->nb_samples,
82  frame->nb_samples - src->nb_samples,
83  s->channels, s->sample_fmt)) < 0)
84  goto fail;
85 
86  return 0;
87 
88 fail:
89  av_frame_unref(frame);
90  return ret;
91 }
92 
93 int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
94  const AVSubtitle *sub)
95 {
96  int ret;
97  if (sub->start_display_time) {
98  av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n");
99  return -1;
100  }
101 
102  ret = avctx->codec->encode_sub(avctx, buf, buf_size, sub);
103  avctx->frame_number++;
104  return ret;
105 }
106 
108 {
109  AVCodecInternal *avci = avctx->internal;
110 
111  if (avci->draining)
112  return AVERROR_EOF;
113 
114  if (!avci->buffer_frame->buf[0])
115  return AVERROR(EAGAIN);
116 
117  av_frame_move_ref(frame, avci->buffer_frame);
118 
119  return 0;
120 }
121 
123 {
124  AVCodecInternal *avci = avctx->internal;
125  EncodeSimpleContext *es = &avci->es;
126  AVFrame *frame = es->in_frame;
127  int got_packet;
128  int ret;
129 
130  if (avci->draining_done)
131  return AVERROR_EOF;
132 
133  if (!frame->buf[0] && !avci->draining) {
134  av_frame_unref(frame);
135  ret = ff_encode_get_frame(avctx, frame);
136  if (ret < 0 && ret != AVERROR_EOF)
137  return ret;
138  }
139 
140  if (!frame->buf[0]) {
141  if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY ||
143  return AVERROR_EOF;
144 
145  // Flushing is signaled with a NULL frame
146  frame = NULL;
147  }
148 
149  got_packet = 0;
150 
151  av_assert0(avctx->codec->encode2);
152 
153  if (CONFIG_FRAME_THREAD_ENCODER &&
155  /* This might modify frame, but it doesn't matter, because
156  * the frame properties used below are not used for video
157  * (due to the delay inherent in frame threaded encoding, it makes
158  * no sense to use the properties of the current frame anyway). */
159  ret = ff_thread_video_encode_frame(avctx, avpkt, frame, &got_packet);
160  else {
161  ret = avctx->codec->encode2(avctx, avpkt, frame, &got_packet);
162  if (avctx->codec->type == AVMEDIA_TYPE_VIDEO && !ret && got_packet &&
164  avpkt->pts = avpkt->dts = frame->pts;
165  }
166 
167  av_assert0(ret <= 0);
168 
169  emms_c();
170 
171  if (!ret && got_packet) {
172  if (avpkt->data) {
173  ret = av_packet_make_refcounted(avpkt);
174  if (ret < 0)
175  goto end;
176  }
177 
178  if (frame && !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY)) {
179  if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
180  if (avpkt->pts == AV_NOPTS_VALUE)
181  avpkt->pts = frame->pts;
182  if (!avpkt->duration)
183  avpkt->duration = ff_samples_to_time_base(avctx,
184  frame->nb_samples);
185  }
186  }
187  if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
188  /* NOTE: if we add any audio encoders which output non-keyframe packets,
189  * this needs to be moved to the encoders, but for now we can do it
190  * here to simplify things */
191  avpkt->flags |= AV_PKT_FLAG_KEY;
192  avpkt->dts = avpkt->pts;
193  }
194  }
195 
196  if (avci->draining && !got_packet)
197  avci->draining_done = 1;
198 
199 end:
200  if (ret < 0 || !got_packet)
201  av_packet_unref(avpkt);
202 
203  if (frame) {
204  if (!ret)
205  avctx->frame_number++;
206  av_frame_unref(frame);
207  }
208 
209  if (got_packet)
210  // Encoders must always return ref-counted buffers.
211  // Side-data only packets have no data and can be not ref-counted.
212  av_assert0(!avpkt->data || avpkt->buf);
213 
214  return ret;
215 }
216 
218 {
219  int ret;
220 
221  while (!avpkt->data && !avpkt->side_data) {
222  ret = encode_simple_internal(avctx, avpkt);
223  if (ret < 0)
224  return ret;
225  }
226 
227  return 0;
228 }
229 
231 {
232  AVCodecInternal *avci = avctx->internal;
233  int ret;
234 
235  if (avci->draining_done)
236  return AVERROR_EOF;
237 
238  av_assert0(!avpkt->data && !avpkt->side_data);
239 
240  if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
241  if ((avctx->flags & AV_CODEC_FLAG_PASS1) && avctx->stats_out)
242  avctx->stats_out[0] = '\0';
243  if (av_image_check_size2(avctx->width, avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx))
244  return AVERROR(EINVAL);
245  }
246 
247  if (avctx->codec->receive_packet) {
248  ret = avctx->codec->receive_packet(avctx, avpkt);
249  if (ret < 0)
250  av_packet_unref(avpkt);
251  else
252  // Encoders must always return ref-counted buffers.
253  // Side-data only packets have no data and can be not ref-counted.
254  av_assert0(!avpkt->data || avpkt->buf);
255  } else
256  ret = encode_simple_receive_packet(avctx, avpkt);
257 
258  if (ret == AVERROR_EOF)
259  avci->draining_done = 1;
260 
261  return ret;
262 }
263 
265 {
266  AVCodecInternal *avci = avctx->internal;
267  AVFrame *dst = avci->buffer_frame;
268  int ret;
269 
270  if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
271  /* extract audio service type metadata */
273  if (sd && sd->size >= sizeof(enum AVAudioServiceType))
274  avctx->audio_service_type = *(enum AVAudioServiceType*)sd->data;
275 
276  /* check for valid frame size */
278  if (src->nb_samples > avctx->frame_size) {
279  av_log(avctx, AV_LOG_ERROR, "more samples than frame size\n");
280  return AVERROR(EINVAL);
281  }
282  } else if (!(avctx->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)) {
283  /* if we already got an undersized frame, that must have been the last */
284  if (avctx->internal->last_audio_frame) {
285  av_log(avctx, AV_LOG_ERROR, "frame_size (%d) was not respected for a non-last frame\n", avctx->frame_size);
286  return AVERROR(EINVAL);
287  }
288 
289  if (src->nb_samples < avctx->frame_size) {
290  ret = pad_last_frame(avctx, dst, src);
291  if (ret < 0)
292  return ret;
293 
294  avctx->internal->last_audio_frame = 1;
295  } else if (src->nb_samples > avctx->frame_size) {
296  av_log(avctx, AV_LOG_ERROR, "nb_samples (%d) != frame_size (%d)\n", src->nb_samples, avctx->frame_size);
297  return AVERROR(EINVAL);
298  }
299  }
300  }
301 
302  if (!dst->data[0]) {
303  ret = av_frame_ref(dst, src);
304  if (ret < 0)
305  return ret;
306  }
307 
308  return 0;
309 }
310 
311 int attribute_align_arg avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame)
312 {
313  AVCodecInternal *avci = avctx->internal;
314  int ret;
315 
316  if (!avcodec_is_open(avctx) || !av_codec_is_encoder(avctx->codec))
317  return AVERROR(EINVAL);
318 
319  if (avci->draining)
320  return AVERROR_EOF;
321 
322  if (avci->buffer_frame->data[0])
323  return AVERROR(EAGAIN);
324 
325  if (!frame) {
326  avci->draining = 1;
327  } else {
328  ret = encode_send_frame_internal(avctx, frame);
329  if (ret < 0)
330  return ret;
331  }
332 
333  if (!avci->buffer_pkt->data && !avci->buffer_pkt->side_data) {
334  ret = encode_receive_packet_internal(avctx, avci->buffer_pkt);
335  if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
336  return ret;
337  }
338 
339  return 0;
340 }
341 
342 int attribute_align_arg avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
343 {
344  AVCodecInternal *avci = avctx->internal;
345  int ret;
346 
347  av_packet_unref(avpkt);
348 
349  if (!avcodec_is_open(avctx) || !av_codec_is_encoder(avctx->codec))
350  return AVERROR(EINVAL);
351 
352  if (avci->buffer_pkt->data || avci->buffer_pkt->side_data) {
353  av_packet_move_ref(avpkt, avci->buffer_pkt);
354  } else {
355  ret = encode_receive_packet_internal(avctx, avpkt);
356  if (ret < 0)
357  return ret;
358  }
359 
360  return 0;
361 }
362 
363 #if FF_API_OLD_ENCDEC
364 static int compat_encode(AVCodecContext *avctx, AVPacket *avpkt,
365  int *got_packet, const AVFrame *frame)
366 {
367  AVCodecInternal *avci = avctx->internal;
368  AVPacket user_pkt;
369  int ret;
370 
371  *got_packet = 0;
372 
373  if (frame && avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
374  if (frame->format == AV_PIX_FMT_NONE)
375  av_log(avctx, AV_LOG_WARNING, "AVFrame.format is not set\n");
376  if (frame->width == 0 || frame->height == 0)
377  av_log(avctx, AV_LOG_WARNING, "AVFrame.width or height is not set\n");
378  }
379 
380  ret = avcodec_send_frame(avctx, frame);
381  if (ret == AVERROR_EOF)
382  ret = 0;
383  else if (ret == AVERROR(EAGAIN)) {
384  /* we fully drain all the output in each encode call, so this should not
385  * ever happen */
386  return AVERROR_BUG;
387  } else if (ret < 0)
388  return ret;
389 
390  av_packet_move_ref(&user_pkt, avpkt);
391  while (ret >= 0) {
392  ret = avcodec_receive_packet(avctx, avpkt);
393  if (ret < 0) {
394  if (ret == AVERROR(EAGAIN) || ret == AVERROR_EOF)
395  ret = 0;
396  goto finish;
397  }
398 
399  if (avpkt != avci->compat_encode_packet) {
400  if (avpkt->data && user_pkt.data) {
401  if (user_pkt.size >= avpkt->size) {
402  memcpy(user_pkt.data, avpkt->data, avpkt->size);
403  av_buffer_unref(&avpkt->buf);
404  avpkt->buf = user_pkt.buf;
405  avpkt->data = user_pkt.data;
406  av_init_packet(&user_pkt);
407  } else {
408  av_log(avctx, AV_LOG_ERROR, "Provided packet is too small, needs to be %d\n", avpkt->size);
409  av_packet_unref(avpkt);
410  ret = AVERROR(EINVAL);
411  goto finish;
412  }
413  }
414 
415  *got_packet = 1;
416  avpkt = avci->compat_encode_packet;
417  } else {
418  if (!avci->compat_decode_warned) {
419  av_log(avctx, AV_LOG_WARNING, "The deprecated avcodec_encode_* "
420  "API cannot return all the packets for this encoder. "
421  "Some packets will be dropped. Update your code to the "
422  "new encoding API to fix this.\n");
423  avci->compat_decode_warned = 1;
424  av_packet_unref(avpkt);
425  }
426  }
427 
428  if (avci->draining)
429  break;
430  }
431 
432 finish:
433  if (ret < 0)
434  av_packet_unref(&user_pkt);
435 
436  return ret;
437 }
438 
439 int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
440  AVPacket *avpkt,
441  const AVFrame *frame,
442  int *got_packet_ptr)
443 {
444  int ret = compat_encode(avctx, avpkt, got_packet_ptr, frame);
445 
446  if (ret < 0)
447  av_packet_unref(avpkt);
448 
449  return ret;
450 }
451 
452 int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx,
453  AVPacket *avpkt,
454  const AVFrame *frame,
455  int *got_packet_ptr)
456 {
457  int ret = compat_encode(avctx, avpkt, got_packet_ptr, frame);
458 
459  if (ret < 0)
460  av_packet_unref(avpkt);
461 
462  return ret;
463 }
464 #endif
static int compat_encode(AVCodecContext *avctx, AVPacket *avpkt, int *got_packet, const AVFrame *frame)
Definition: encode.c:364
#define NULL
Definition: coverity.c:32
const struct AVCodec * codec
Definition: avcodec.h:540
int(* receive_packet)(struct AVCodecContext *avctx, struct AVPacket *avpkt)
Encode API with decoupled frame/packet dataflow.
Definition: codec.h:291
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:125
This structure describes decoded (raw) audio or video data.
Definition: frame.h:314
int av_codec_is_encoder(const AVCodec *codec)
Definition: utils.c:96
This side data must be associated with an audio frame and corresponds to enum AVAudioServiceType defi...
Definition: frame.h:113
misc image utilities
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:505
int attribute_align_arg avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
Read encoded data from the encoder.
Definition: encode.c:342
int size
Definition: packet.h:364
int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode a frame of audio.
Definition: encode.c:439
void av_fast_padded_malloc(void *ptr, unsigned int *size, size_t min_size)
Same behaviour av_fast_malloc but the buffer has additional AV_INPUT_BUFFER_PADDING_SIZE at the end w...
Definition: utils.c:72
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:582
enum AVMediaType type
Definition: codec.h:203
Macro definitions for various function/variable attributes.
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:738
enum AVAudioServiceType audio_service_type
Type of service that the audio stream conveys.
Definition: avcodec.h:1256
#define AV_CODEC_CAP_DELAY
Encoder or decoder requires flushing with NULL input at the end in order to give the complete and cor...
Definition: codec.h:75
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
Definition: encode.c:33
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1199
uint8_t
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:381
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:443
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:407
int(* encode2)(struct AVCodecContext *avctx, struct AVPacket *avpkt, const struct AVFrame *frame, int *got_packet_ptr)
Encode data to an AVPacket.
Definition: codec.h:282
static int encode_send_frame_internal(AVCodecContext *avctx, const AVFrame *src)
Definition: encode.c:264
void * frame_thread_encoder
Definition: internal.h:159
Structure to hold side data for an AVFrame.
Definition: frame.h:220
static void finish(void)
Definition: movenc.c:345
uint8_t * data
Definition: packet.h:363
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
Definition: avpacket.c:664
int ff_thread_video_encode_frame(AVCodecContext *avctx, AVPacket *pkt, AVFrame *frame, int *got_packet_ptr)
#define AVERROR_EOF
End of file.
Definition: error.h:55
ptrdiff_t size
Definition: opengl_enc.c:100
char * stats_out
pass1 encoding statistics output buffer
Definition: avcodec.h:1552
#define av_log(a,...)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:401
static int encode_simple_internal(AVCodecContext *avctx, AVPacket *avpkt)
Definition: encode.c:122
#define src
Definition: vp8dsp.c:255
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:88
int width
Definition: frame.h:372
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
int av_samples_set_silence(uint8_t **audio_data, int offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Fill an audio buffer with silence.
Definition: samplefmt.c:237
AVAudioServiceType
Definition: avcodec.h:239
AVFrame * in_frame
Definition: internal.h:116
int active_thread_type
Which multithreading methods are in use by the codec.
Definition: avcodec.h:1787
int avcodec_is_open(AVCodecContext *s)
Definition: utils.c:1984
AVFrame * buffer_frame
Definition: internal.h:182
int capabilities
Codec capabilities.
Definition: codec.h:209
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: packet.h:346
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:611
simple assert() macros that are a bit more flexible than ISO C assert().
int64_t max_pixels
The number of pixels per image to maximally accept.
Definition: avcodec.h:2239
#define fail()
Definition: checkasm.h:133
#define AV_CODEC_CAP_VARIABLE_FRAME_SIZE
Audio encoder supports receiving a different number of samples in each call.
Definition: codec.h:122
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:369
reference-counted frame API
uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:491
common internal API header
int channels
number of audio channels, only used for audio.
Definition: frame.h:620
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:1779
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
Definition: codec.h:80
int width
picture width / height.
Definition: avcodec.h:704
int av_packet_make_refcounted(AVPacket *pkt)
Ensure the data described by a given packet is reference counted.
Definition: avpacket.c:672
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition: avcodec.h:296
these buffered frames must be flushed immediately if a new input produces new the filter must not call request_frame to get more It must just process the frame or queue it The task of requesting more frames is left to the filter s request_frame method or the application If a filter has several the filter must be ready for frames arriving randomly on any input any filter with several inputs will most likely require some kind of queuing mechanism It is perfectly acceptable to have a limited queue and to drop frames when the inputs are too unbalanced request_frame For filters that do not use the this method is called when a frame is wanted on an output For a it should directly call filter_frame on the corresponding output For a if there are queued frames already one of these frames should be pushed If the filter should request a frame on one of its repeatedly until at least one frame has been pushed Return or at least make progress towards producing a frame
#define s(width, name)
Definition: cbs_vp9.c:257
int draining
checks API usage: after codec draining, flush is required to resume operation
Definition: internal.h:176
if(ret)
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:387
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:1211
static int encode_receive_packet_internal(AVCodecContext *avctx, AVPacket *avpkt)
Definition: encode.c:230
Libavcodec external API header.
int compat_decode_warned
Definition: internal.h:186
EncodeSimpleContext es
Definition: internal.h:161
main external API structure.
Definition: avcodec.h:531
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:606
uint8_t * data
Definition: frame.h:222
int attribute_align_arg avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame)
Supply a raw video or audio frame to the encoder.
Definition: encode.c:311
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:213
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:50
AVPacket * compat_encode_packet
Definition: internal.h:194
int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode a frame of video.
Definition: encode.c:452
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:337
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:553
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:328
AVPacket * buffer_pkt
buffers for using new encode/decode API through legacy API
Definition: internal.h:181
AVPacketSideData * side_data
Additional packet data that can be provided by the container.
Definition: packet.h:374
common internal api header.
int(* encode_sub)(struct AVCodecContext *, uint8_t *buf, int buf_size, const struct AVSubtitle *sub)
Definition: codec.h:270
uint32_t start_display_time
Definition: avcodec.h:2677
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:35
int av_image_check_size2(unsigned int w, unsigned int h, int64_t max_pixels, enum AVPixelFormat pix_fmt, int log_offset, void *log_ctx)
Check if the given dimension of an image is valid, meaning that all bytes of a plane of an image with...
Definition: imgutils.c:288
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:215
static int pad_last_frame(AVCodecContext *s, AVFrame *frame, const AVFrame *src)
Pad last frame with silence.
Definition: encode.c:62
int channels
number of audio channels
Definition: avcodec.h:1192
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:566
unsigned int byte_buffer_size
Definition: internal.h:157
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: packet.h:362
int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:1222
int height
Definition: frame.h:372
static float sub(float src0, float src1)
static av_always_inline int64_t ff_samples_to_time_base(AVCodecContext *avctx, int64_t samples)
Rescale from sample rate to AVCodecContext.time_base.
Definition: internal.h:268
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame 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.Frame references ownership and permissions
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:361
static int encode_simple_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
Definition: encode.c:217
This structure stores compressed data.
Definition: packet.h:340
uint8_t * byte_buffer
temporary buffer used for encoders to store their bitstream
Definition: internal.h:156
int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVSubtitle *sub)
Definition: encode.c:93
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:380
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:356
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:658
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame)
Called by encoders to get the next frame for encoding.
Definition: encode.c:107
int last_audio_frame
An audio frame with less than required samples has been submitted and padded with silence...
Definition: internal.h:132