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 "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  }
38  if (size < 0 || size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
39  av_log(avctx, AV_LOG_ERROR, "Invalid minimum required packet size %"PRId64" (max allowed is %d)\n",
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 /**
74  * Pad last frame with silence.
75  */
76 static int pad_last_frame(AVCodecContext *s, AVFrame **dst, const AVFrame *src)
77 {
78  AVFrame *frame = NULL;
79  int ret;
80 
81  if (!(frame = av_frame_alloc()))
82  return AVERROR(ENOMEM);
83 
84  frame->format = src->format;
85  frame->channel_layout = src->channel_layout;
86  frame->channels = src->channels;
87  frame->nb_samples = s->frame_size;
89  if (ret < 0)
90  goto fail;
91 
93  if (ret < 0)
94  goto fail;
95 
96  if ((ret = av_samples_copy(frame->extended_data, src->extended_data, 0, 0,
97  src->nb_samples, s->channels, s->sample_fmt)) < 0)
98  goto fail;
99  if ((ret = av_samples_set_silence(frame->extended_data, src->nb_samples,
100  frame->nb_samples - src->nb_samples,
101  s->channels, s->sample_fmt)) < 0)
102  goto fail;
103 
104  *dst = frame;
105 
106  return 0;
107 
108 fail:
110  return ret;
111 }
112 
113 int attribute_align_arg avcodec_encode_audio2(AVCodecContext *avctx,
114  AVPacket *avpkt,
115  const AVFrame *frame,
116  int *got_packet_ptr)
117 {
118  AVFrame *extended_frame = NULL;
119  AVFrame *padded_frame = NULL;
120  int ret;
121  AVPacket user_pkt = *avpkt;
122  int needs_realloc = !user_pkt.data;
123 
124  *got_packet_ptr = 0;
125 
126  if (!avctx->codec->encode2) {
127  av_log(avctx, AV_LOG_ERROR, "This encoder requires using the avcodec_send_frame() API.\n");
128  return AVERROR(ENOSYS);
129  }
130 
131  if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY) && !frame) {
132  av_packet_unref(avpkt);
133  return 0;
134  }
135 
136  /* ensure that extended_data is properly set */
137  if (frame && !frame->extended_data) {
138  if (av_sample_fmt_is_planar(avctx->sample_fmt) &&
139  avctx->channels > AV_NUM_DATA_POINTERS) {
140  av_log(avctx, AV_LOG_ERROR, "Encoding to a planar sample format, "
141  "with more than %d channels, but extended_data is not set.\n",
143  return AVERROR(EINVAL);
144  }
145  av_log(avctx, AV_LOG_WARNING, "extended_data is not set.\n");
146 
147  extended_frame = av_frame_alloc();
148  if (!extended_frame)
149  return AVERROR(ENOMEM);
150 
151  memcpy(extended_frame, frame, sizeof(AVFrame));
152  extended_frame->extended_data = extended_frame->data;
153  frame = extended_frame;
154  }
155 
156  /* extract audio service type metadata */
157  if (frame) {
159  if (sd && sd->size >= sizeof(enum AVAudioServiceType))
160  avctx->audio_service_type = *(enum AVAudioServiceType*)sd->data;
161  }
162 
163  /* check for valid frame size */
164  if (frame) {
166  if (frame->nb_samples > avctx->frame_size) {
167  av_log(avctx, AV_LOG_ERROR, "more samples than frame size (avcodec_encode_audio2)\n");
168  ret = AVERROR(EINVAL);
169  goto end;
170  }
171  } else if (!(avctx->codec->capabilities & AV_CODEC_CAP_VARIABLE_FRAME_SIZE)) {
172  /* if we already got an undersized frame, that must have been the last */
173  if (avctx->internal->last_audio_frame) {
174  av_log(avctx, AV_LOG_ERROR, "frame_size (%d) was not respected for a non-last frame (avcodec_encode_audio2)\n", avctx->frame_size);
175  ret = AVERROR(EINVAL);
176  goto end;
177  }
178 
179  if (frame->nb_samples < avctx->frame_size) {
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) {
227  if (ret < 0)
228  goto end;
229  }
230  }
231 
232  if (!ret) {
233  if (needs_realloc && avpkt->data) {
235  if (ret >= 0)
236  avpkt->data = avpkt->buf->data;
237  }
238  if (frame)
239  avctx->frame_number++;
240  }
241 
242  if (ret < 0 || !*got_packet_ptr) {
243  av_packet_unref(avpkt);
244  goto end;
245  }
246 
247  /* NOTE: if we add any audio encoders which output non-keyframe packets,
248  * this needs to be moved to the encoders, but for now we can do it
249  * here to simplify things */
250  avpkt->flags |= AV_PKT_FLAG_KEY;
251 
252 end:
253  av_frame_free(&padded_frame);
254  av_free(extended_frame);
255 
256  return ret;
257 }
258 
259 int attribute_align_arg avcodec_encode_video2(AVCodecContext *avctx,
260  AVPacket *avpkt,
261  const AVFrame *frame,
262  int *got_packet_ptr)
263 {
264  int ret;
265  AVPacket user_pkt = *avpkt;
266  int needs_realloc = !user_pkt.data;
267 
268  *got_packet_ptr = 0;
269 
270  if (!avctx->codec->encode2) {
271  av_log(avctx, AV_LOG_ERROR, "This encoder requires using the avcodec_send_frame() API.\n");
272  return AVERROR(ENOSYS);
273  }
274 
275  if ((avctx->flags&AV_CODEC_FLAG_PASS1) && avctx->stats_out)
276  avctx->stats_out[0] = '\0';
277 
278  if (!frame &&
279  !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY ||
281  av_packet_unref(avpkt);
282  return 0;
283  }
284 
285  if (av_image_check_size2(avctx->width, avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx))
286  return AVERROR(EINVAL);
287 
288  if (frame && frame->format == AV_PIX_FMT_NONE)
289  av_log(avctx, AV_LOG_WARNING, "AVFrame.format is not set\n");
290  if (frame && (frame->width == 0 || frame->height == 0))
291  av_log(avctx, AV_LOG_WARNING, "AVFrame.width or height is not set\n");
292 
293  av_assert0(avctx->codec->encode2);
294 
295 
296  if (CONFIG_FRAME_THREAD_ENCODER &&
298  ret = ff_thread_video_encode_frame(avctx, avpkt, frame, got_packet_ptr);
299  else {
300  ret = avctx->codec->encode2(avctx, avpkt, frame, got_packet_ptr);
301  if (*got_packet_ptr && !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
302  avpkt->pts = avpkt->dts = frame->pts;
303  }
304  av_assert0(ret <= 0);
305 
306  emms_c();
307 
308  if (avpkt->data && avpkt->data == avctx->internal->byte_buffer) {
309  needs_realloc = 0;
310  if (user_pkt.data) {
311  if (user_pkt.size >= avpkt->size) {
312  memcpy(user_pkt.data, avpkt->data, avpkt->size);
313  } else {
314  av_log(avctx, AV_LOG_ERROR, "Provided packet is too small, needs to be %d\n", avpkt->size);
315  avpkt->size = user_pkt.size;
316  ret = -1;
317  }
318  avpkt->buf = user_pkt.buf;
319  avpkt->data = user_pkt.data;
320  } else if (!avpkt->buf) {
322  if (ret < 0)
323  return ret;
324  }
325  }
326 
327  if (!ret) {
328  if (!*got_packet_ptr)
329  avpkt->size = 0;
330 
331  if (needs_realloc && avpkt->data) {
333  if (ret >= 0)
334  avpkt->data = avpkt->buf->data;
335  }
336 
337  if (frame)
338  avctx->frame_number++;
339  }
340 
341  if (ret < 0 || !*got_packet_ptr)
342  av_packet_unref(avpkt);
343 
344  return ret;
345 }
346 
347 int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
348  const AVSubtitle *sub)
349 {
350  int ret;
351  if (sub->start_display_time) {
352  av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n");
353  return -1;
354  }
355 
356  ret = avctx->codec->encode_sub(avctx, buf, buf_size, sub);
357  avctx->frame_number++;
358  return ret;
359 }
360 
361 static int do_encode(AVCodecContext *avctx, const AVFrame *frame, int *got_packet)
362 {
363  int ret;
364  *got_packet = 0;
365 
367  avctx->internal->buffer_pkt_valid = 0;
368 
369  if (avctx->codec_type == AVMEDIA_TYPE_VIDEO) {
370  ret = avcodec_encode_video2(avctx, avctx->internal->buffer_pkt,
371  frame, got_packet);
372  } else if (avctx->codec_type == AVMEDIA_TYPE_AUDIO) {
373  ret = avcodec_encode_audio2(avctx, avctx->internal->buffer_pkt,
374  frame, got_packet);
375  } else {
376  ret = AVERROR(EINVAL);
377  }
378 
379  if (ret >= 0 && *got_packet) {
380  // Encoders must always return ref-counted buffers.
381  // Side-data only packets have no data and can be not ref-counted.
382  av_assert0(!avctx->internal->buffer_pkt->data || avctx->internal->buffer_pkt->buf);
383  avctx->internal->buffer_pkt_valid = 1;
384  ret = 0;
385  } else {
387  }
388 
389  return ret;
390 }
391 
392 int attribute_align_arg avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame)
393 {
394  if (!avcodec_is_open(avctx) || !av_codec_is_encoder(avctx->codec))
395  return AVERROR(EINVAL);
396 
397  if (avctx->internal->draining)
398  return AVERROR_EOF;
399 
400  if (!frame) {
401  avctx->internal->draining = 1;
402 
403  if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
404  return 0;
405  }
406 
407  if (avctx->codec->send_frame)
408  return avctx->codec->send_frame(avctx, frame);
409 
410  // Emulation via old API. Do it here instead of avcodec_receive_packet, because:
411  // 1. if the AVFrame is not refcounted, the copying will be much more
412  // expensive than copying the packet data
413  // 2. assume few users use non-refcounted AVPackets, so usually no copy is
414  // needed
415 
416  if (avctx->internal->buffer_pkt_valid)
417  return AVERROR(EAGAIN);
418 
419  return do_encode(avctx, frame, &(int){0});
420 }
421 
422 int attribute_align_arg avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
423 {
424  av_packet_unref(avpkt);
425 
426  if (!avcodec_is_open(avctx) || !av_codec_is_encoder(avctx->codec))
427  return AVERROR(EINVAL);
428 
429  if (avctx->codec->receive_packet) {
430  int ret;
431  if (avctx->internal->draining && !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY))
432  return AVERROR_EOF;
433  ret = avctx->codec->receive_packet(avctx, avpkt);
434  if (!ret)
435  // Encoders must always return ref-counted buffers.
436  // Side-data only packets have no data and can be not ref-counted.
437  av_assert0(!avpkt->data || avpkt->buf);
438  return ret;
439  }
440 
441  // Emulation via old API.
442 
443  if (!avctx->internal->buffer_pkt_valid) {
444  int got_packet;
445  int ret;
446  if (!avctx->internal->draining)
447  return AVERROR(EAGAIN);
448  ret = do_encode(avctx, NULL, &got_packet);
449  if (ret < 0)
450  return ret;
451  if (ret >= 0 && !got_packet)
452  return AVERROR_EOF;
453  }
454 
455  av_packet_move_ref(avpkt, avctx->internal->buffer_pkt);
456  avctx->internal->buffer_pkt_valid = 0;
457  return 0;
458 }
AVSubtitle
Definition: avcodec.h:2694
avcodec_encode_subtitle
int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVSubtitle *sub)
Definition: encode.c:347
AVCodecContext::frame_size
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:1206
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:605
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
avcodec_receive_packet
int attribute_align_arg avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
Read encoded data from the encoder.
Definition: encode.c:422
AVERROR
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
AVCodecContext::audio_service_type
enum AVAudioServiceType audio_service_type
Type of service that the audio stream conveys.
Definition: avcodec.h:1251
av_buffer_realloc
int av_buffer_realloc(AVBufferRef **pbuf, int size)
Reallocate a given buffer.
Definition: buffer.c:169
av_frame_get_buffer
int av_frame_get_buffer(AVFrame *frame, int align)
Allocate new buffer(s) for audio or video data.
Definition: frame.c:325
avcodec_encode_audio2
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:113
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:739
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:55
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:89
av_frame_free
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
end
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:92
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:300
AVCodec::capabilities
int capabilities
Codec capabilities.
Definition: codec.h:209
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:355
AVCodecInternal::frame_thread_encoder
void * frame_thread_encoder
Definition: internal.h:152
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:373
avcodec_is_open
int avcodec_is_open(AVCodecContext *s)
Definition: utils.c:1962
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:388
AVFrame::data
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:314
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:535
fail
#define fail()
Definition: checkasm.h:123
AVCodec::encode_sub
int(* encode_sub)(struct AVCodecContext *, uint8_t *buf, int buf_size, const struct AVSubtitle *sub)
Definition: codec.h:268
samplefmt.h
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:606
av_image_check_size2
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:253
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:190
avassert.h
ff_samples_to_time_base
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:256
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
frame_thread_encoder.h
s
#define s(width, name)
Definition: cbs_vp9.c:257
av_new_packet
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
AVCodecInternal::buffer_pkt
AVPacket * buffer_pkt
buffers for using new encode/decode API through legacy API
Definition: internal.h:172
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AV_FRAME_DATA_AUDIO_SERVICE_TYPE
@ AV_FRAME_DATA_AUDIO_SERVICE_TYPE
This side data must be associated with an audio frame and corresponds to enum AVAudioServiceType defi...
Definition: frame.h:113
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
av_sample_fmt_is_planar
int av_sample_fmt_is_planar(enum AVSampleFormat sample_fmt)
Check if the sample format is planar.
Definition: samplefmt.c:112
AVAudioServiceType
AVAudioServiceType
Definition: avcodec.h:239
AVCodecContext::max_pixels
int64_t max_pixels
The number of pixels per image to maximally accept.
Definition: avcodec.h:2256
pad_last_frame
static int pad_last_frame(AVCodecContext *s, AVFrame **dst, const AVFrame *src)
Pad last frame with silence.
Definition: encode.c:76
AVPacket::buf
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: packet.h:338
NULL
#define NULL
Definition: coverity.c:32
av_frame_copy_props
int av_frame_copy_props(AVFrame *dst, const AVFrame *src)
Copy only "metadata" fields from src to dst.
Definition: frame.c:659
AVCodecContext::internal
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:561
src
#define src
Definition: vp8dsp.c:254
AV_CODEC_CAP_VARIABLE_FRAME_SIZE
#define AV_CODEC_CAP_VARIABLE_FRAME_SIZE
Audio encoder supports receiving a different number of samples in each call.
Definition: codec.h:122
av_packet_move_ref
void av_packet_move_ref(AVPacket *dst, AVPacket *src)
Move every field in src to dst and reset src.
Definition: avpacket.c:663
AVCodecContext::stats_out
char * stats_out
pass1 encoding statistics output buffer
Definition: avcodec.h:1545
AVPacket::size
int size
Definition: packet.h:356
AVCodec::send_frame
int(* send_frame)(struct AVCodecContext *avctx, const struct AVFrame *frame)
Encode API with decoupled packet/frame dataflow.
Definition: codec.h:292
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1194
size
int size
Definition: twinvq_data.h:11134
AVCodec::encode2
int(* encode2)(struct AVCodecContext *avctx, struct AVPacket *avpkt, const struct AVFrame *frame, int *got_packet_ptr)
Encode data to an AVPacket.
Definition: codec.h:280
AV_NUM_DATA_POINTERS
#define AV_NUM_DATA_POINTERS
Definition: frame.h:301
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
AVCodec::receive_packet
int(* receive_packet)(struct AVCodecContext *avctx, struct AVPacket *avpkt)
Definition: codec.h:293
AVFrameSideData::data
uint8_t * data
Definition: frame.h:208
AVCodecInternal::byte_buffer
uint8_t * byte_buffer
temporary buffer used for encoders to store their bitstream
Definition: internal.h:149
frame.h
AVPacket::dts
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:354
avcodec_encode_video2
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:259
attributes.h
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:361
av_packet_make_refcounted
int av_packet_make_refcounted(AVPacket *pkt)
Ensure the data described by a given packet is reference counted.
Definition: avpacket.c:671
AVCodecInternal::byte_buffer_size
unsigned int byte_buffer_size
Definition: internal.h:150
FF_THREAD_FRAME
#define FF_THREAD_FRAME
Decode more than one frame at once.
Definition: avcodec.h:1796
AVCodecContext::channels
int channels
number of audio channels
Definition: avcodec.h:1187
av_codec_is_encoder
int av_codec_is_encoder(const AVCodec *codec)
Definition: utils.c:94
av_samples_copy
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
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:348
internal.h
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:347
av_fast_padded_malloc
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:70
ff_thread_video_encode_frame
int ff_thread_video_encode_frame(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet_ptr)
Definition: frame_thread_encoder.c:287
uint8_t
uint8_t
Definition: audio_convert.c:194
AVCodecContext::height
int height
Definition: avcodec.h:699
avcodec_send_frame
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:392
AVCodecInternal::last_audio_frame
int last_audio_frame
An audio frame with less than required samples has been submitted and padded with silence.
Definition: internal.h:129
av_samples_set_silence
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
avcodec.h
ret
ret
Definition: filter_design.txt:187
frame
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
Definition: filter_design.txt:264
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: avcodec.h:215
AVCodecContext
main external API structure.
Definition: avcodec.h:526
AVCodecContext::active_thread_type
int active_thread_type
Which multithreading methods are in use by the codec.
Definition: avcodec.h:1804
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AV_CODEC_CAP_DELAY
#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
AVCodecInternal::draining
int draining
checks API usage: after codec draining, flush is required to resume operation
Definition: internal.h:167
AVCodecContext::codec_type
enum AVMediaType codec_type
Definition: avcodec.h:534
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVBufferRef
A reference to a data buffer.
Definition: buffer.h:81
AVCodecInternal::buffer_pkt_valid
int buffer_pkt_valid
Definition: internal.h:173
AVCodecContext::frame_number
int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:1217
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:206
av_free
#define av_free(p)
Definition: tableprint_vlc.h:34
AVPacket
This structure stores compressed data.
Definition: packet.h:332
AVFrameSideData::size
int size
Definition: frame.h:209
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:699
imgutils.h
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:28
AV_CODEC_CAP_SMALL_LAST_FRAME
#define AV_CODEC_CAP_SMALL_LAST_FRAME
Codec can be fed a final frame with a smaller size.
Definition: codec.h:80
ff_alloc_packet2
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
AVSubtitle::start_display_time
uint32_t start_display_time
Definition: avcodec.h:2696
do_encode
static int do_encode(AVCodecContext *avctx, const AVFrame *frame, int *got_packet)
Definition: encode.c:361
AV_CODEC_FLAG_PASS1
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition: avcodec.h:296
av_init_packet
void av_init_packet(AVPacket *pkt)
Initialize optional fields of a packet with default values.
Definition: avpacket.c:35