FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
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 "frame_thread_encoder.h"
30 #include "internal.h"
31 
32 int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
33 {
34  if (avpkt->size < 0) {
35  av_log(avctx, AV_LOG_ERROR, "Invalid negative user packet size %d\n", avpkt->size);
36  return AVERROR(EINVAL);
37  }
39  av_log(avctx, AV_LOG_ERROR, "Invalid minimum required packet size %"PRId64" (max allowed is %d)\n",
40  size, INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE);
41  return AVERROR(EINVAL);
42  }
43 
44  if (avctx && 2*min_size < size) { // FIXME The factor needs to be finetuned
45  av_assert0(!avpkt->data || avpkt->data != avctx->internal->byte_buffer);
46  if (!avpkt->data || avpkt->size < size) {
48  avpkt->data = avctx->internal->byte_buffer;
49  avpkt->size = avctx->internal->byte_buffer_size;
50  }
51  }
52 
53  if (avpkt->data) {
54  AVBufferRef *buf = avpkt->buf;
55 
56  if (avpkt->size < size) {
57  av_log(avctx, AV_LOG_ERROR, "User packet is too small (%d < %"PRId64")\n", avpkt->size, size);
58  return AVERROR(EINVAL);
59  }
60 
61  av_init_packet(avpkt);
62  avpkt->buf = buf;
63  avpkt->size = size;
64  return 0;
65  } else {
66  int ret = av_new_packet(avpkt, size);
67  if (ret < 0)
68  av_log(avctx, AV_LOG_ERROR, "Failed to allocate packet of size %"PRId64"\n", size);
69  return ret;
70  }
71 }
72 
73 int ff_alloc_packet(AVPacket *avpkt, int size)
74 {
75  return ff_alloc_packet2(NULL, avpkt, size, 0);
76 }
77 
78 /**
79  * Pad last frame with silence.
80  */
81 static int pad_last_frame(AVCodecContext *s, AVFrame **dst, const AVFrame *src)
82 {
83  AVFrame *frame = NULL;
84  int ret;
85 
86  if (!(frame = av_frame_alloc()))
87  return AVERROR(ENOMEM);
88 
89  frame->format = src->format;
90  frame->channel_layout = src->channel_layout;
91  frame->channels = src->channels;
92  frame->nb_samples = s->frame_size;
93  ret = av_frame_get_buffer(frame, 32);
94  if (ret < 0)
95  goto fail;
96 
97  ret = av_frame_copy_props(frame, src);
98  if (ret < 0)
99  goto fail;
100 
101  if ((ret = av_samples_copy(frame->extended_data, src->extended_data, 0, 0,
102  src->nb_samples, s->channels, s->sample_fmt)) < 0)
103  goto fail;
104  if ((ret = av_samples_set_silence(frame->extended_data, src->nb_samples,
105  frame->nb_samples - src->nb_samples,
106  s->channels, s->sample_fmt)) < 0)
107  goto fail;
108 
109  *dst = frame;
110 
111  return 0;
112 
113 fail:
114  av_frame_free(&frame);
115  return ret;
116 }
117 
119  AVPacket *avpkt,
120  const AVFrame *frame,
121  int *got_packet_ptr)
122 {
123  AVFrame *extended_frame = NULL;
124  AVFrame *padded_frame = NULL;
125  int ret;
126  AVPacket user_pkt = *avpkt;
127  int needs_realloc = !user_pkt.data;
128 
129  *got_packet_ptr = 0;
130 
131  if (!avctx->codec->encode2) {
132  av_log(avctx, AV_LOG_ERROR, "This encoder requires using the avcodec_send_frame() API.\n");
133  return AVERROR(ENOSYS);
134  }
135 
136  if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY) && !frame) {
137  av_packet_unref(avpkt);
138  av_init_packet(avpkt);
139  return 0;
140  }
141 
142  /* ensure that extended_data is properly set */
143  if (frame && !frame->extended_data) {
144  if (av_sample_fmt_is_planar(avctx->sample_fmt) &&
145  avctx->channels > AV_NUM_DATA_POINTERS) {
146  av_log(avctx, AV_LOG_ERROR, "Encoding to a planar sample format, "
147  "with more than %d channels, but extended_data is not set.\n",
149  return AVERROR(EINVAL);
150  }
151  av_log(avctx, AV_LOG_WARNING, "extended_data is not set.\n");
152 
153  extended_frame = av_frame_alloc();
154  if (!extended_frame)
155  return AVERROR(ENOMEM);
156 
157  memcpy(extended_frame, frame, sizeof(AVFrame));
158  extended_frame->extended_data = extended_frame->data;
159  frame = extended_frame;
160  }
161 
162  /* extract audio service type metadata */
163  if (frame) {
165  if (sd && sd->size >= sizeof(enum AVAudioServiceType))
166  avctx->audio_service_type = *(enum AVAudioServiceType*)sd->data;
167  }
168 
169  /* check for valid frame size */
170  if (frame) {
172  if (frame->nb_samples > avctx->frame_size) {
173  av_log(avctx, AV_LOG_ERROR, "more samples than frame size (avcodec_encode_audio2)\n");
174  ret = AVERROR(EINVAL);
175  goto end;
176  }
177  } else if (!(avctx->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)) {
178  if (frame->nb_samples < avctx->frame_size &&
179  !avctx->internal->last_audio_frame) {
180  ret = pad_last_frame(avctx, &padded_frame, frame);
181  if (ret < 0)
182  goto end;
183 
184  frame = padded_frame;
185  avctx->internal->last_audio_frame = 1;
186  }
187 
188  if (frame->nb_samples != avctx->frame_size) {
189  av_log(avctx, AV_LOG_ERROR, "nb_samples (%d) != frame_size (%d) (avcodec_encode_audio2)\n", frame->nb_samples, avctx->frame_size);
190  ret = AVERROR(EINVAL);
191  goto end;
192  }
193  }
194  }
195 
196  av_assert0(avctx->codec->encode2);
197 
198  ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);
199  if (!ret) {
200  if (*got_packet_ptr) {
201  if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY)) {
202  if (avpkt->pts == AV_NOPTS_VALUE)
203  avpkt->pts = frame->pts;
204  if (!avpkt->duration)
205  avpkt->duration = ff_samples_to_time_base(avctx,
206  frame->nb_samples);
207  }
208  avpkt->dts = avpkt->pts;
209  } else {
210  avpkt->size = 0;
211  }
212  }
213  if (avpkt->data && avpkt->data == avctx->internal->byte_buffer) {
214  needs_realloc = 0;
215  if (user_pkt.data) {
216  if (user_pkt.size >= avpkt->size) {
217  memcpy(user_pkt.data, avpkt->data, avpkt->size);
218  } else {
219  av_log(avctx, AV_LOG_ERROR, "Provided packet is too small, needs to be %d\n", avpkt->size);
220  avpkt->size = user_pkt.size;
221  ret = -1;
222  }
223  avpkt->buf = user_pkt.buf;
224  avpkt->data = user_pkt.data;
225  } else if (!avpkt->buf) {
226  AVPacket tmp = { 0 };
227  ret = av_packet_ref(&tmp, avpkt);
228  av_packet_unref(avpkt);
229  if (ret < 0)
230  goto end;
231  *avpkt = tmp;
232  }
233  }
234 
235  if (!ret) {
236  if (needs_realloc && avpkt->data) {
237  ret = av_buffer_realloc(&avpkt->buf, avpkt->size + AV_INPUT_BUFFER_PADDING_SIZE);
238  if (ret >= 0)
239  avpkt->data = avpkt->buf->data;
240  }
241 
242  avctx->frame_number++;
243  }
244 
245  if (ret < 0 || !*got_packet_ptr) {
246  av_packet_unref(avpkt);
247  av_init_packet(avpkt);
248  goto end;
249  }
250 
251  /* NOTE: if we add any audio encoders which output non-keyframe packets,
252  * this needs to be moved to the encoders, but for now we can do it
253  * here to simplify things */
254  avpkt->flags |= AV_PKT_FLAG_KEY;
255 
256 end:
257  av_frame_free(&padded_frame);
258  av_free(extended_frame);
259 
260 #if FF_API_AUDIOENC_DELAY
261  avctx->delay = avctx->initial_padding;
262 #endif
263 
264  return ret;
265 }
266 
268  AVPacket *avpkt,
269  const AVFrame *frame,
270  int *got_packet_ptr)
271 {
272  int ret;
273  AVPacket user_pkt = *avpkt;
274  int needs_realloc = !user_pkt.data;
275 
276  *got_packet_ptr = 0;
277 
278  if (!avctx->codec->encode2) {
279  av_log(avctx, AV_LOG_ERROR, "This encoder requires using the avcodec_send_frame() API.\n");
280  return AVERROR(ENOSYS);
281  }
282 
283  if(CONFIG_FRAME_THREAD_ENCODER &&
285  return ff_thread_video_encode_frame(avctx, avpkt, frame, got_packet_ptr);
286 
287  if ((avctx->flags&AV_CODEC_FLAG_PASS1) && avctx->stats_out)
288  avctx->stats_out[0] = '\0';
289 
290  if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY) && !frame) {
291  av_packet_unref(avpkt);
292  av_init_packet(avpkt);
293  avpkt->size = 0;
294  return 0;
295  }
296 
297  if (av_image_check_size2(avctx->width, avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx))
298  return AVERROR(EINVAL);
299 
300  if (frame && frame->format == AV_PIX_FMT_NONE)
301  av_log(avctx, AV_LOG_WARNING, "AVFrame.format is not set\n");
302  if (frame && (frame->width == 0 || frame->height == 0))
303  av_log(avctx, AV_LOG_WARNING, "AVFrame.width or height is not set\n");
304 
305  av_assert0(avctx->codec->encode2);
306 
307  ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);
308  av_assert0(ret <= 0);
309 
310  emms_c();
311 
312  if (avpkt->data && avpkt->data == avctx->internal->byte_buffer) {
313  needs_realloc = 0;
314  if (user_pkt.data) {
315  if (user_pkt.size >= avpkt->size) {
316  memcpy(user_pkt.data, avpkt->data, avpkt->size);
317  } else {
318  av_log(avctx, AV_LOG_ERROR, "Provided packet is too small, needs to be %d\n", avpkt->size);
319  avpkt->size = user_pkt.size;
320  ret = -1;
321  }
322  avpkt->buf = user_pkt.buf;
323  avpkt->data = user_pkt.data;
324  } else if (!avpkt->buf) {
325  AVPacket tmp = { 0 };
326  ret = av_packet_ref(&tmp, avpkt);
327  av_packet_unref(avpkt);
328  if (ret < 0)
329  return ret;
330  *avpkt = tmp;
331  }
332  }
333 
334  if (!ret) {
335  if (!*got_packet_ptr)
336  avpkt->size = 0;
337  else if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
338  avpkt->pts = avpkt->dts = frame->pts;
339 
340  if (needs_realloc && avpkt->data) {
341  ret = av_buffer_realloc(&avpkt->buf, avpkt->size + AV_INPUT_BUFFER_PADDING_SIZE);
342  if (ret >= 0)
343  avpkt->data = avpkt->buf->data;
344  }
345 
346  avctx->frame_number++;
347  }
348 
349  if (ret < 0 || !*got_packet_ptr)
350  av_packet_unref(avpkt);
351 
352  return ret;
353 }
354 
356  const AVSubtitle *sub)
357 {
358  int ret;
359  if (sub->start_display_time) {
360  av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n");
361  return -1;
362  }
363 
364  ret = avctx->codec->encode_sub(avctx, buf, buf_size, sub);
365  avctx->frame_number++;
366  return ret;
367 }
368 
369 static int do_encode(AVCodecContext *avctx, const AVFrame *frame, int *got_packet)
370 {
371  int ret;
372  *got_packet = 0;
373 
375  avctx->internal->buffer_pkt_valid = 0;
376 
377  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
378  ret = avcodec_encode_video2(avctx, avctx->internal->buffer_pkt,
379  frame, got_packet);
380  } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
381  ret = avcodec_encode_audio2(avctx, avctx->internal->buffer_pkt,
382  frame, got_packet);
383  } else {
384  ret = AVERROR(EINVAL);
385  }
386 
387  if (ret >= 0 && *got_packet) {
388  // Encoders must always return ref-counted buffers.
389  // Side-data only packets have no data and can be not ref-counted.
390  av_assert0(!avctx->internal->buffer_pkt->data || avctx->internal->buffer_pkt->buf);
391  avctx->internal->buffer_pkt_valid = 1;
392  ret = 0;
393  } else {
395  }
396 
397  return ret;
398 }
399 
401 {
402  if (!avcodec_is_open(avctx) || !av_codec_is_encoder(avctx->codec))
403  return AVERROR(EINVAL);
404 
405  if (avctx->internal->draining)
406  return AVERROR_EOF;
407 
408  if (!frame) {
409  avctx->internal->draining = 1;
410 
411  if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
412  return 0;
413  }
414 
415  if (avctx->codec->send_frame)
416  return avctx->codec->send_frame(avctx, frame);
417 
418  // Emulation via old API. Do it here instead of avcodec_receive_packet, because:
419  // 1. if the AVFrame is not refcounted, the copying will be much more
420  // expensive than copying the packet data
421  // 2. assume few users use non-refcounted AVPackets, so usually no copy is
422  // needed
423 
424  if (avctx->internal->buffer_pkt_valid)
425  return AVERROR(EAGAIN);
426 
427  return do_encode(avctx, frame, &(int){0});
428 }
429 
431 {
432  av_packet_unref(avpkt);
433 
434  if (!avcodec_is_open(avctx) || !av_codec_is_encoder(avctx->codec))
435  return AVERROR(EINVAL);
436 
437  if (avctx->codec->receive_packet) {
438  if (avctx->internal->draining && !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
439  return AVERROR_EOF;
440  return avctx->codec->receive_packet(avctx, avpkt);
441  }
442 
443  // Emulation via old API.
444 
445  if (!avctx->internal->buffer_pkt_valid) {
446  int got_packet;
447  int ret;
448  if (!avctx->internal->draining)
449  return AVERROR(EAGAIN);
450  ret = do_encode(avctx, NULL, &got_packet);
451  if (ret < 0)
452  return ret;
453  if (ret >= 0 && !got_packet)
454  return AVERROR_EOF;
455  }
456 
457  av_packet_move_ref(avpkt, avctx->internal->buffer_pkt);
458  avctx->internal->buffer_pkt_valid = 0;
459  return 0;
460 }
#define NULL
Definition: coverity.c:32
const struct AVCodec * codec
Definition: avcodec.h:1770
const char * s
Definition: avisynth_c.h:768
#define AV_NUM_DATA_POINTERS
Definition: frame.h:202
int ff_thread_video_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet_ptr)
This structure describes decoded (raw) audio or video data.
Definition: frame.h:201
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:182
int attribute_align_arg avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
Read encoded data from the encoder.
Definition: encode.c:430
int size
Definition: avcodec.h:1680
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:118
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:121
#define src
Definition: vp8dsp.c:254
static int pad_last_frame(AVCodecContext *s, AVFrame **dst, const AVFrame *src)
Pad last frame with silence.
Definition: encode.c:81
Macro definitions for various function/variable attributes.
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:682
enum AVAudioServiceType audio_service_type
Type of service that the audio stream conveys.
Definition: avcodec.h:2588
int av_codec_is_encoder(const AVCodec *codec)
Definition: utils.c:169
#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: avcodec.h:1027
#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:32
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:2531
uint8_t
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:150
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: avcodec.h:1697
#define emms_c()
Definition: internal.h:54
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:294
static AVFrame * frame
void * frame_thread_encoder
Definition: internal.h:182
Structure to hold side data for an AVFrame.
Definition: frame.h:163
uint8_t * data
Definition: avcodec.h:1679
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
Definition: avpacket.c:673
#define AVERROR_EOF
End of file.
Definition: error.h:55
ptrdiff_t size
Definition: opengl_enc.c:101
char * stats_out
pass1 encoding statistics output buffer
Definition: avcodec.h:2931
#define av_log(a,...)
int av_packet_ref(AVPacket *dst, const AVPacket *src)
Setup a new reference to the data described by a given packet.
Definition: avpacket.c:627
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:112
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1711
int(* send_frame)(AVCodecContext *avctx, const AVFrame *frame)
Encode API with decoupled packet/frame dataflow.
Definition: avcodec.h:3832
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:86
int width
Definition: frame.h:259
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
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:833
#define AVERROR(e)
Definition: error.h:43
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:163
int active_thread_type
Which multithreading methods are in use by the codec.
Definition: avcodec.h:3211
int avcodec_is_open(AVCodecContext *s)
Definition: utils.c:2137
int capabilities
Codec capabilities.
Definition: avcodec.h:3758
int initial_padding
Audio only.
Definition: avcodec.h:3451
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: avcodec.h:1662
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:1856
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:3646
int av_buffer_realloc(AVBufferRef **pbuf, int size)
Reallocate a given buffer.
Definition: buffer.c:169
#define fail()
Definition: checkasm.h:109
int ff_alloc_packet(AVPacket *avpkt, int size)
Definition: encode.c:73
#define AV_CODEC_CAP_VARIABLE_FRAME_SIZE
Audio encoder supports receiving a different number of samples in each call.
Definition: avcodec.h:1081
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1685
reference-counted frame API
uint64_t channel_layout
Channel layout of the audio data.
Definition: frame.h:379
int(* encode_sub)(AVCodecContext *, uint8_t *buf, int buf_size, const struct AVSubtitle *sub)
Definition: avcodec.h:3808
common internal API header
int channels
number of audio channels, only used for audio.
Definition: frame.h:506
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:3203
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
Definition: avcodec.h:1032
int width
picture width / height.
Definition: avcodec.h:1948
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition: avcodec.h:892
int draining
checks API usage: after codec draining, flush is required to resume operation
Definition: internal.h:197
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:274
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:2543
#define attribute_align_arg
Definition: internal.h:61
Libavcodec external API header.
enum AVMediaType codec_type
Definition: avcodec.h:1769
main external API structure.
Definition: avcodec.h:1761
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:618
uint8_t * data
The data buffer.
Definition: buffer.h:89
uint8_t * data
Definition: frame.h:165
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:400
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
void * buf
Definition: avisynth_c.h:690
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:267
int buffer_pkt_valid
Definition: internal.h:203
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:283
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:215
AVPacket * buffer_pkt
buffers for using new encode/decode API through legacy API
Definition: internal.h:202
A reference to a data buffer.
Definition: buffer.h:81
common internal api header.
uint32_t start_display_time
Definition: avcodec.h:4130
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:33
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:252
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding...
Definition: avcodec.h:777
#define av_free(p)
int channels
number of audio channels
Definition: avcodec.h:2524
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:1811
unsigned int byte_buffer_size
Definition: internal.h:180
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1678
int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:2554
int height
Definition: frame.h:259
int(* receive_packet)(AVCodecContext *avctx, AVPacket *avpkt)
Definition: avcodec.h:3833
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:295
static int do_encode(AVCodecContext *avctx, const AVFrame *frame, int *got_packet)
Definition: encode.c:369
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:248
This structure stores compressed data.
Definition: avcodec.h:1656
uint8_t * byte_buffer
temporary buffer used for encoders to store their bitstream
Definition: internal.h:179
int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVSubtitle *sub)
Definition: encode.c:355
int(* encode2)(AVCodecContext *avctx, AVPacket *avpkt, const AVFrame *frame, int *got_packet_ptr)
Encode data to an AVPacket.
Definition: avcodec.h:3820
int delay
Codec delay.
Definition: avcodec.h:1931
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:267
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1672
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:603
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
int last_audio_frame
An audio frame with less than required samples has been submitted and padded with silence...
Definition: internal.h:159
static uint8_t tmp[11]
Definition: aes_ctr.c:26