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"
24 #include "libavutil/frame.h"
25 #include "libavutil/imgutils.h"
26 #include "libavutil/internal.h"
27 #include "libavutil/samplefmt.h"
28 
29 #include "avcodec.h"
30 #include "codec_internal.h"
31 #include "encode.h"
32 #include "frame_thread_encoder.h"
33 #include "internal.h"
34 
35 int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
36 {
37  if (size < 0 || size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
38  av_log(avctx, AV_LOG_ERROR, "Invalid minimum required packet size %"PRId64" (max allowed is %d)\n",
40  return AVERROR(EINVAL);
41  }
42 
43  av_assert0(!avpkt->data);
44 
46  &avctx->internal->byte_buffer_size, size);
47  avpkt->data = avctx->internal->byte_buffer;
48  if (!avpkt->data) {
49  av_log(avctx, AV_LOG_ERROR, "Failed to allocate packet of size %"PRId64"\n", size);
50  return AVERROR(ENOMEM);
51  }
52  avpkt->size = size;
53 
54  return 0;
55 }
56 
58 {
59  int ret;
60 
61  if (avpkt->size < 0 || avpkt->size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
62  return AVERROR(EINVAL);
63 
64  if (avpkt->data || avpkt->buf) {
65  av_log(avctx, AV_LOG_ERROR, "avpkt->{data,buf} != NULL in avcodec_default_get_encode_buffer()\n");
66  return AVERROR(EINVAL);
67  }
68 
70  if (ret < 0) {
71  av_log(avctx, AV_LOG_ERROR, "Failed to allocate packet of size %d\n", avpkt->size);
72  return ret;
73  }
74  avpkt->data = avpkt->buf->data;
75 
76  return 0;
77 }
78 
79 int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
80 {
81  int ret;
82 
83  if (size < 0 || size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
84  return AVERROR(EINVAL);
85 
86  av_assert0(!avpkt->data && !avpkt->buf);
87 
88  avpkt->size = size;
89  ret = avctx->get_encode_buffer(avctx, avpkt, flags);
90  if (ret < 0)
91  goto fail;
92 
93  if (!avpkt->data || !avpkt->buf) {
94  av_log(avctx, AV_LOG_ERROR, "No buffer returned by get_encode_buffer()\n");
95  ret = AVERROR(EINVAL);
96  goto fail;
97  }
98  memset(avpkt->data + avpkt->size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
99 
100  ret = 0;
101 fail:
102  if (ret < 0) {
103  av_log(avctx, AV_LOG_ERROR, "get_encode_buffer() failed\n");
104  av_packet_unref(avpkt);
105  }
106 
107  return ret;
108 }
109 
111 {
112  uint8_t *data = avpkt->data;
113  int ret;
114 
115  if (avpkt->buf)
116  return 0;
117 
118  avpkt->data = NULL;
119  ret = ff_get_encode_buffer(avctx, avpkt, avpkt->size, 0);
120  if (ret < 0)
121  return ret;
122  memcpy(avpkt->data, data, avpkt->size);
123 
124  return 0;
125 }
126 
127 /**
128  * Pad last frame with silence.
129  */
130 static int pad_last_frame(AVCodecContext *s, AVFrame *frame, const AVFrame *src, int out_samples)
131 {
132  int ret;
133 
134  frame->format = src->format;
135  frame->nb_samples = out_samples;
136  ret = av_channel_layout_copy(&frame->ch_layout, &s->ch_layout);
137  if (ret < 0)
138  goto fail;
140  if (ret < 0)
141  goto fail;
142 
144  if (ret < 0)
145  goto fail;
146 
147  if ((ret = av_samples_copy(frame->extended_data, src->extended_data, 0, 0,
148  src->nb_samples, s->ch_layout.nb_channels,
149  s->sample_fmt)) < 0)
150  goto fail;
151  if ((ret = av_samples_set_silence(frame->extended_data, src->nb_samples,
152  frame->nb_samples - src->nb_samples,
153  s->ch_layout.nb_channels, s->sample_fmt)) < 0)
154  goto fail;
155 
156  return 0;
157 
158 fail:
160  s->internal->last_audio_frame = 0;
161  return ret;
162 }
163 
164 int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
165  const AVSubtitle *sub)
166 {
167  int ret;
168  if (sub->start_display_time) {
169  av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n");
170  return -1;
171  }
172 
173  ret = ffcodec(avctx->codec)->cb.encode_sub(avctx, buf, buf_size, sub);
174  avctx->frame_number++;
175  return ret;
176 }
177 
179 {
180  AVCodecInternal *avci = avctx->internal;
181 
182  if (avci->draining)
183  return AVERROR_EOF;
184 
185  if (!avci->buffer_frame->buf[0])
186  return AVERROR(EAGAIN);
187 
189 
190  return 0;
191 }
192 
194  AVFrame *frame, int *got_packet)
195 {
196  const FFCodec *const codec = ffcodec(avctx->codec);
197  int ret;
198 
199  ret = codec->cb.encode(avctx, avpkt, frame, got_packet);
200  emms_c();
201  av_assert0(ret <= 0);
202 
203  if (!ret && *got_packet) {
204  if (avpkt->data) {
205  ret = encode_make_refcounted(avctx, avpkt);
206  if (ret < 0)
207  goto unref;
208  // Date returned by encoders must always be ref-counted
209  av_assert0(avpkt->buf);
210  }
211 
212  // set the timestamps for the simple no-delay case
213  // encoders with delay have to set the timestamps themselves
214  if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY)) {
215  if (avpkt->pts == AV_NOPTS_VALUE)
216  avpkt->pts = frame->pts;
217 
218  if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
219  if (!avpkt->duration)
220  avpkt->duration = ff_samples_to_time_base(avctx,
221  frame->nb_samples);
222  }
223  }
224 
225  // dts equals pts unless there is reordering
226  // there can be no reordering if there is no encoder delay
227  if (!(avctx->codec_descriptor->props & AV_CODEC_PROP_REORDER) ||
229  avpkt->dts = avpkt->pts;
230  } else {
231 unref:
232  av_packet_unref(avpkt);
233  }
234 #if !FF_API_THREAD_SAFE_CALLBACKS
235  if (frame)
237 #endif
238 
239  return ret;
240 }
241 
243 {
244  AVCodecInternal *avci = avctx->internal;
245  AVFrame *frame = avci->in_frame;
246  const FFCodec *const codec = ffcodec(avctx->codec);
247  int got_packet;
248  int ret;
249 
250  if (avci->draining_done)
251  return AVERROR_EOF;
252 
253  if (!frame->buf[0] && !avci->draining) {
255  ret = ff_encode_get_frame(avctx, frame);
256  if (ret < 0 && ret != AVERROR_EOF)
257  return ret;
258  }
259 
260  if (!frame->buf[0]) {
261  if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY ||
262  avci->frame_thread_encoder))
263  return AVERROR_EOF;
264 
265  // Flushing is signaled with a NULL frame
266  frame = NULL;
267  }
268 
269  got_packet = 0;
270 
272 
273  if (CONFIG_FRAME_THREAD_ENCODER && avci->frame_thread_encoder)
274  /* This will unref frame. */
275  ret = ff_thread_video_encode_frame(avctx, avpkt, frame, &got_packet);
276  else {
277  ret = ff_encode_encode_cb(avctx, avpkt, frame, &got_packet);
278 #if FF_API_THREAD_SAFE_CALLBACKS
279  if (frame)
281 #endif
282  }
283 
284  if (avci->draining && !got_packet)
285  avci->draining_done = 1;
286 
287  return ret;
288 }
289 
291 {
292  int ret;
293 
294  while (!avpkt->data && !avpkt->side_data) {
295  ret = encode_simple_internal(avctx, avpkt);
296  if (ret < 0)
297  return ret;
298  }
299 
300  return 0;
301 }
302 
304 {
305  AVCodecInternal *avci = avctx->internal;
306  int ret;
307 
308  if (avci->draining_done)
309  return AVERROR_EOF;
310 
311  av_assert0(!avpkt->data && !avpkt->side_data);
312 
313  if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
314  if ((avctx->flags & AV_CODEC_FLAG_PASS1) && avctx->stats_out)
315  avctx->stats_out[0] = '\0';
316  if (av_image_check_size2(avctx->width, avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx))
317  return AVERROR(EINVAL);
318  }
319 
321  ret = ffcodec(avctx->codec)->cb.receive_packet(avctx, avpkt);
322  if (ret < 0)
323  av_packet_unref(avpkt);
324  else
325  // Encoders must always return ref-counted buffers.
326  // Side-data only packets have no data and can be not ref-counted.
327  av_assert0(!avpkt->data || avpkt->buf);
328  } else
329  ret = encode_simple_receive_packet(avctx, avpkt);
330  if (ret >= 0)
331  avpkt->flags |= avci->intra_only_flag;
332 
333  if (ret == AVERROR_EOF)
334  avci->draining_done = 1;
335 
336  return ret;
337 }
338 
339 #if CONFIG_LCMS2
341 {
342  enum AVColorTransferCharacteristic trc = frame->color_trc;
343  enum AVColorPrimaries prim = frame->color_primaries;
344  const FFCodec *const codec = ffcodec(avctx->codec);
345  AVCodecInternal *avci = avctx->internal;
346  cmsHPROFILE profile;
347  int ret;
348 
349  /* don't generate ICC profiles if disabled or unsupported */
350  if (!(avctx->flags2 & AV_CODEC_FLAG2_ICC_PROFILES))
351  return 0;
353  return 0;
354 
355  if (trc == AVCOL_TRC_UNSPECIFIED)
356  trc = avctx->color_trc;
357  if (prim == AVCOL_PRI_UNSPECIFIED)
358  prim = avctx->color_primaries;
359  if (trc == AVCOL_TRC_UNSPECIFIED || prim == AVCOL_PRI_UNSPECIFIED)
360  return 0; /* can't generate ICC profile with missing csp tags */
361 
363  return 0; /* don't overwrite existing ICC profile */
364 
365  if (!avci->icc.avctx) {
366  ret = ff_icc_context_init(&avci->icc, avctx);
367  if (ret < 0)
368  return ret;
369  }
370 
371  ret = ff_icc_profile_generate(&avci->icc, prim, trc, &profile);
372  if (ret < 0)
373  return ret;
374 
375  ret = ff_icc_profile_attach(&avci->icc, profile, frame);
376  cmsCloseProfile(profile);
377  return ret;
378 }
379 #else /* !CONFIG_LCMS2 */
381 {
382  return 0;
383 }
384 #endif
385 
387 {
388  AVCodecInternal *avci = avctx->internal;
389  AVFrame *dst = avci->buffer_frame;
390  int ret;
391 
392  if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
393  /* extract audio service type metadata */
395  if (sd && sd->size >= sizeof(enum AVAudioServiceType))
396  avctx->audio_service_type = *(enum AVAudioServiceType*)sd->data;
397 
398  /* check for valid frame size */
400  /* if we already got an undersized frame, that must have been the last */
401  if (avctx->internal->last_audio_frame) {
402  av_log(avctx, AV_LOG_ERROR, "frame_size (%d) was not respected for a non-last frame\n", avctx->frame_size);
403  return AVERROR(EINVAL);
404  }
405  if (src->nb_samples > avctx->frame_size) {
406  av_log(avctx, AV_LOG_ERROR, "nb_samples (%d) > frame_size (%d)\n", src->nb_samples, avctx->frame_size);
407  return AVERROR(EINVAL);
408  }
409  if (src->nb_samples < avctx->frame_size) {
410  avctx->internal->last_audio_frame = 1;
412  int pad_samples = avci->pad_samples ? avci->pad_samples : avctx->frame_size;
413  int out_samples = (src->nb_samples + pad_samples - 1) / pad_samples * pad_samples;
414 
415  if (out_samples != src->nb_samples) {
416  ret = pad_last_frame(avctx, dst, src, out_samples);
417  if (ret < 0)
418  return ret;
419  goto finish;
420  }
421  }
422  }
423  }
424  }
425 
426  ret = av_frame_ref(dst, src);
427  if (ret < 0)
428  return ret;
429 
430 finish:
431 
432 #if FF_API_PKT_DURATION
434  if (dst->pkt_duration && dst->pkt_duration != dst->duration)
435  dst->duration = dst->pkt_duration;
437 #endif
438 
439  if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
440  ret = encode_generate_icc_profile(avctx, dst);
441  if (ret < 0)
442  return ret;
443  }
444 
445  return 0;
446 }
447 
448 int attribute_align_arg avcodec_send_frame(AVCodecContext *avctx, const AVFrame *frame)
449 {
450  AVCodecInternal *avci = avctx->internal;
451  int ret;
452 
453  if (!avcodec_is_open(avctx) || !av_codec_is_encoder(avctx->codec))
454  return AVERROR(EINVAL);
455 
456  if (avci->draining)
457  return AVERROR_EOF;
458 
459  if (avci->buffer_frame->buf[0])
460  return AVERROR(EAGAIN);
461 
462  if (!frame) {
463  avci->draining = 1;
464  } else {
466  if (ret < 0)
467  return ret;
468  }
469 
470  if (!avci->buffer_pkt->data && !avci->buffer_pkt->side_data) {
472  if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
473  return ret;
474  }
475 
476  avctx->frame_number++;
477 
478  return 0;
479 }
480 
481 int attribute_align_arg avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
482 {
483  AVCodecInternal *avci = avctx->internal;
484  int ret;
485 
486  av_packet_unref(avpkt);
487 
488  if (!avcodec_is_open(avctx) || !av_codec_is_encoder(avctx->codec))
489  return AVERROR(EINVAL);
490 
491  if (avci->buffer_pkt->data || avci->buffer_pkt->side_data) {
492  av_packet_move_ref(avpkt, avci->buffer_pkt);
493  } else {
494  ret = encode_receive_packet_internal(avctx, avpkt);
495  if (ret < 0)
496  return ret;
497  }
498 
499  return 0;
500 }
501 
503 {
504  const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(avctx->pix_fmt);
505  int i;
506 
507  if (avctx->codec->pix_fmts) {
508  for (i = 0; avctx->codec->pix_fmts[i] != AV_PIX_FMT_NONE; i++)
509  if (avctx->pix_fmt == avctx->codec->pix_fmts[i])
510  break;
511  if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_NONE) {
512  char buf[128];
513  snprintf(buf, sizeof(buf), "%d", avctx->pix_fmt);
514  av_log(avctx, AV_LOG_ERROR, "Specified pixel format %s is invalid or not supported\n",
515  (char *)av_x_if_null(av_get_pix_fmt_name(avctx->pix_fmt), buf));
516  return AVERROR(EINVAL);
517  }
518  if (avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ420P ||
519  avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ411P ||
520  avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ422P ||
521  avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ440P ||
522  avctx->codec->pix_fmts[i] == AV_PIX_FMT_YUVJ444P)
523  avctx->color_range = AVCOL_RANGE_JPEG;
524  }
525 
526  if ( avctx->bits_per_raw_sample < 0
527  || (avctx->bits_per_raw_sample > 8 && pixdesc->comp[0].depth <= 8)) {
528  av_log(avctx, AV_LOG_WARNING, "Specified bit depth %d not possible with the specified pixel formats depth %d\n",
529  avctx->bits_per_raw_sample, pixdesc->comp[0].depth);
530  avctx->bits_per_raw_sample = pixdesc->comp[0].depth;
531  }
532  if (avctx->width <= 0 || avctx->height <= 0) {
533  av_log(avctx, AV_LOG_ERROR, "dimensions not set\n");
534  return AVERROR(EINVAL);
535  }
536 
537  if (avctx->ticks_per_frame && avctx->time_base.num &&
538  avctx->ticks_per_frame > INT_MAX / avctx->time_base.num) {
539  av_log(avctx, AV_LOG_ERROR,
540  "ticks_per_frame %d too large for the timebase %d/%d.",
541  avctx->ticks_per_frame,
542  avctx->time_base.num,
543  avctx->time_base.den);
544  return AVERROR(EINVAL);
545  }
546 
547  if (avctx->hw_frames_ctx) {
548  AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
549  if (frames_ctx->format != avctx->pix_fmt) {
550  av_log(avctx, AV_LOG_ERROR,
551  "Mismatching AVCodecContext.pix_fmt and AVHWFramesContext.format\n");
552  return AVERROR(EINVAL);
553  }
554  if (avctx->sw_pix_fmt != AV_PIX_FMT_NONE &&
555  avctx->sw_pix_fmt != frames_ctx->sw_format) {
556  av_log(avctx, AV_LOG_ERROR,
557  "Mismatching AVCodecContext.sw_pix_fmt (%s) "
558  "and AVHWFramesContext.sw_format (%s)\n",
560  av_get_pix_fmt_name(frames_ctx->sw_format));
561  return AVERROR(EINVAL);
562  }
563  avctx->sw_pix_fmt = frames_ctx->sw_format;
564  }
565 
566  return 0;
567 }
568 
570 {
571  int i;
572 
573  if (avctx->codec->sample_fmts) {
574  for (i = 0; avctx->codec->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
575  if (avctx->sample_fmt == avctx->codec->sample_fmts[i])
576  break;
577  if (avctx->ch_layout.nb_channels == 1 &&
580  avctx->sample_fmt = avctx->codec->sample_fmts[i];
581  break;
582  }
583  }
584  if (avctx->codec->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
585  char buf[128];
586  snprintf(buf, sizeof(buf), "%d", avctx->sample_fmt);
587  av_log(avctx, AV_LOG_ERROR, "Specified sample format %s is invalid or not supported\n",
588  (char *)av_x_if_null(av_get_sample_fmt_name(avctx->sample_fmt), buf));
589  return AVERROR(EINVAL);
590  }
591  }
592  if (avctx->codec->supported_samplerates) {
593  for (i = 0; avctx->codec->supported_samplerates[i] != 0; i++)
594  if (avctx->sample_rate == avctx->codec->supported_samplerates[i])
595  break;
596  if (avctx->codec->supported_samplerates[i] == 0) {
597  av_log(avctx, AV_LOG_ERROR, "Specified sample rate %d is not supported\n",
598  avctx->sample_rate);
599  return AVERROR(EINVAL);
600  }
601  }
602  if (avctx->sample_rate < 0) {
603  av_log(avctx, AV_LOG_ERROR, "Specified sample rate %d is not supported\n",
604  avctx->sample_rate);
605  return AVERROR(EINVAL);
606  }
607  if (avctx->codec->ch_layouts) {
608  for (i = 0; avctx->codec->ch_layouts[i].nb_channels; i++) {
609  if (!av_channel_layout_compare(&avctx->ch_layout, &avctx->codec->ch_layouts[i]))
610  break;
611  }
612  if (!avctx->codec->ch_layouts[i].nb_channels) {
613  char buf[512];
614  int ret = av_channel_layout_describe(&avctx->ch_layout, buf, sizeof(buf));
615  if (ret > 0)
616  av_log(avctx, AV_LOG_ERROR, "Specified channel layout '%s' is not supported\n", buf);
617  return AVERROR(EINVAL);
618  }
619  }
620 
621  if (!avctx->bits_per_raw_sample)
623 
624  return 0;
625 }
626 
628 {
629  AVCodecInternal *avci = avctx->internal;
630  int ret = 0;
631 
632  if (avctx->time_base.num <= 0 || avctx->time_base.den <= 0) {
633  av_log(avctx, AV_LOG_ERROR, "The encoder timebase is not set.\n");
634  return AVERROR(EINVAL);
635  }
636 
637  switch (avctx->codec_type) {
638  case AVMEDIA_TYPE_VIDEO: ret = encode_preinit_video(avctx); break;
639  case AVMEDIA_TYPE_AUDIO: ret = encode_preinit_audio(avctx); break;
640  }
641  if (ret < 0)
642  return ret;
643 
644  if ( (avctx->codec_type == AVMEDIA_TYPE_VIDEO || avctx->codec_type == AVMEDIA_TYPE_AUDIO)
645  && avctx->bit_rate>0 && avctx->bit_rate<1000) {
646  av_log(avctx, AV_LOG_WARNING, "Bitrate %"PRId64" is extremely low, maybe you mean %"PRId64"k\n", avctx->bit_rate, avctx->bit_rate);
647  }
648 
649  if (!avctx->rc_initial_buffer_occupancy)
650  avctx->rc_initial_buffer_occupancy = avctx->rc_buffer_size * 3LL / 4;
651 
654 
655  if (ffcodec(avctx->codec)->cb_type == FF_CODEC_CB_TYPE_ENCODE) {
656  avci->in_frame = av_frame_alloc();
657  if (!avci->in_frame)
658  return AVERROR(ENOMEM);
659  }
660 
661  if ((avctx->flags & AV_CODEC_FLAG_RECON_FRAME)) {
663  av_log(avctx, AV_LOG_ERROR, "Reconstructed frame output requested "
664  "from an encoder not supporting it\n");
665  return AVERROR(ENOSYS);
666  }
667 
668  avci->recon_frame = av_frame_alloc();
669  if (!avci->recon_frame)
670  return AVERROR(ENOMEM);
671  }
672 
673  if (CONFIG_FRAME_THREAD_ENCODER) {
675  if (ret < 0)
676  return ret;
677  }
678 
679  return 0;
680 }
681 
683 {
684  int ret;
685 
686  switch (avctx->codec->type) {
687  case AVMEDIA_TYPE_VIDEO:
688  frame->format = avctx->pix_fmt;
689  if (frame->width <= 0 || frame->height <= 0) {
690  frame->width = FFMAX(avctx->width, avctx->coded_width);
691  frame->height = FFMAX(avctx->height, avctx->coded_height);
692  }
693 
694  break;
695  case AVMEDIA_TYPE_AUDIO:
696  frame->sample_rate = avctx->sample_rate;
697  frame->format = avctx->sample_fmt;
698  if (!frame->ch_layout.nb_channels) {
699  ret = av_channel_layout_copy(&frame->ch_layout, &avctx->ch_layout);
700  if (ret < 0)
701  return ret;
702  }
703  break;
704  }
705 
707  if (ret < 0) {
708  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
710  return ret;
711  }
712 
713  return 0;
714 }
715 
717 {
718  AVCodecInternal *avci = avctx->internal;
719 
720  if (!avci->recon_frame)
721  return AVERROR(EINVAL);
722  if (!avci->recon_frame->buf[0])
723  return avci->draining_done ? AVERROR_EOF : AVERROR(EAGAIN);
724 
726  return 0;
727 }
AVCodec::ch_layouts
const AVChannelLayout * ch_layouts
Array of supported channel layouts, terminated with a zeroed layout.
Definition: codec.h:254
AVSubtitle
Definition: avcodec.h:2308
avcodec_encode_subtitle
int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVSubtitle *sub)
Definition: encode.c:164
AVCodecContext::frame_size
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:1035
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:422
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:82
AV_LOG_WARNING
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:186
avcodec_receive_packet
int attribute_align_arg avcodec_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
Read encoded data from the encoder.
Definition: encode.c:481
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:1086
FF_CODEC_CB_TYPE_RECEIVE_PACKET
@ FF_CODEC_CB_TYPE_RECEIVE_PACKET
Definition: codec_internal.h:116
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:558
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:259
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1007
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:691
sub
static float sub(float src0, float src1)
Definition: dnn_backend_native_layer_mathbinary.c:31
AVFrame::duration
int64_t duration
Duration of the frame, in the same units as pts.
Definition: frame.h:714
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2858
AVERROR_EOF
#define AVERROR_EOF
End of file.
Definition: error.h:57
AVBufferRef::data
uint8_t * data
The data buffer.
Definition: buffer.h:90
AVHWFramesContext::format
enum AVPixelFormat format
The pixel format identifying the underlying HW surface type.
Definition: hwcontext.h:209
encode_make_refcounted
static int encode_make_refcounted(AVCodecContext *avctx, AVPacket *avpkt)
Definition: encode.c:110
AV_CODEC_CAP_ENCODER_RECON_FRAME
#define AV_CODEC_CAP_ENCODER_RECON_FRAME
The encoder is able to output reconstructed frame data, i.e.
Definition: codec.h:191
av_unused
#define av_unused
Definition: attributes.h:131
AVCodec::pix_fmts
enum AVPixelFormat * pix_fmts
array of supported pixel formats, or NULL if unknown, array is terminated by -1
Definition: codec.h:226
ff_encode_receive_frame
int ff_encode_receive_frame(AVCodecContext *avctx, AVFrame *frame)
avcodec_receive_frame() implementation for encoders.
Definition: encode.c:716
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:325
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:968
AVCodec::capabilities
int capabilities
Codec capabilities.
Definition: codec.h:223
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:661
internal.h
AVPacket::data
uint8_t * data
Definition: packet.h:374
AVComponentDescriptor::depth
int depth
Number of bits in the component.
Definition: pixdesc.h:57
AVCodecInternal::frame_thread_encoder
void * frame_thread_encoder
Definition: internal.h:105
AVCodecInternal::in_frame
AVFrame * in_frame
The input frame is stored here for encoders implementing the simple encode API.
Definition: internal.h:113
encode.h
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:561
data
const char data[16]
Definition: mxf.c:146
FFCodec
Definition: codec_internal.h:119
FFCodec::encode
int(* encode)(struct AVCodecContext *avctx, struct AVPacket *avpkt, const struct AVFrame *frame, int *got_packet_ptr)
Encode data to an AVPacket.
Definition: codec_internal.h:214
ff_encode_encode_cb
int ff_encode_encode_cb(AVCodecContext *avctx, AVPacket *avpkt, AVFrame *frame, int *got_packet)
Definition: encode.c:193
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:392
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:533
avcodec_is_open
int avcodec_is_open(AVCodecContext *s)
Definition: avcodec.c:704
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:311
ff_icc_profile_attach
int ff_icc_profile_attach(FFIccContext *s, cmsHPROFILE profile, AVFrame *frame)
Attach an ICC profile to a frame.
Definition: fflcms2.c:173
AVFrame::buf
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:525
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:429
finish
static void finish(void)
Definition: movenc.c:342
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:407
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:2059
fail
#define fail()
Definition: checkasm.h:134
AVCodec::sample_fmts
enum AVSampleFormat * sample_fmts
array of supported sample formats, or NULL if unknown, array is terminated by -1
Definition: codec.h:228
ff_icc_context_init
int ff_icc_context_init(FFIccContext *s, void *avctx)
Initializes an FFIccContext.
Definition: fflcms2.c:31
encode_receive_packet_internal
static int encode_receive_packet_internal(AVCodecContext *avctx, AVPacket *avpkt)
Definition: encode.c:303
samplefmt.h
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:478
AVCodecContext::coded_height
int coded_height
Definition: avcodec.h:586
encode_preinit_video
static int encode_preinit_video(AVCodecContext *avctx)
Definition: encode.c:502
AVRational::num
int num
Numerator.
Definition: rational.h:59
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:289
av_get_planar_sample_fmt
enum AVSampleFormat av_get_planar_sample_fmt(enum AVSampleFormat sample_fmt)
Get the planar alternative form of the given sample format.
Definition: samplefmt.c:86
av_frame_alloc
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:104
AV_PIX_FMT_YUVJ411P
@ AV_PIX_FMT_YUVJ411P
planar YUV 4:1:1, 12bpp, (1 Cr & Cb sample per 4x1 Y samples) full scale (JPEG), deprecated in favor ...
Definition: pixfmt.h:276
avassert.h
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:961
AVCodec::supported_samplerates
const int * supported_samplerates
array of supported audio samplerates, or NULL if unknown, array is terminated by 0
Definition: codec.h:227
AV_LOG_ERROR
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:180
encode_send_frame_internal
static int encode_send_frame_internal(AVCodecContext *avctx, const AVFrame *src)
Definition: encode.c:386
frame_thread_encoder.h
AVFrameSideData::size
size_t size
Definition: frame.h:234
encode_simple_internal
static int encode_simple_internal(AVCodecContext *avctx, AVPacket *avpkt)
Definition: encode.c:242
AVCodecContext::rc_initial_buffer_occupancy
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
Definition: avcodec.h:1251
av_channel_layout_describe
int av_channel_layout_describe(const AVChannelLayout *channel_layout, char *buf, size_t buf_size)
Get a human-readable string describing the channel layout properties.
Definition: channel_layout.c:778
AV_PIX_FMT_YUVJ422P
@ AV_PIX_FMT_YUVJ422P
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:79
ff_frame_thread_encoder_init
av_cold int ff_frame_thread_encoder_init(AVCodecContext *avctx)
Initialize frame thread encoder.
Definition: frame_thread_encoder.c:138
s
#define s(width, name)
Definition: cbs_vp9.c:256
AVCodecInternal::buffer_pkt
AVPacket * buffer_pkt
Temporary buffers for newly received or not yet output packets/frames.
Definition: internal.h:147
AVMEDIA_TYPE_AUDIO
@ AVMEDIA_TYPE_AUDIO
Definition: avutil.h:202
AVCodecContext::ticks_per_frame
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
Definition: avcodec.h:530
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:114
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AVCodecContext::bits_per_raw_sample
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1451
FF_CODEC_CB_TYPE_ENCODE
@ FF_CODEC_CB_TYPE_ENCODE
Definition: codec_internal.h:110
AVCodecContext::max_pixels
int64_t max_pixels
The number of pixels per image to maximally accept.
Definition: avcodec.h:1911
av_get_sample_fmt_name
const char * av_get_sample_fmt_name(enum AVSampleFormat sample_fmt)
Return the name of sample_fmt, or NULL if sample_fmt is not recognized.
Definition: samplefmt.c:51
FFCodec::encode_sub
int(* encode_sub)(struct AVCodecContext *avctx, uint8_t *buf, int buf_size, const struct AVSubtitle *sub)
Encode subtitles to a raw buffer.
Definition: codec_internal.h:220
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:536
AV_PIX_FMT_YUVJ444P
@ AV_PIX_FMT_YUVJ444P
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
ff_thread_video_encode_frame
int ff_thread_video_encode_frame(AVCodecContext *avctx, AVPacket *pkt, AVFrame *frame, int *got_packet_ptr)
Definition: frame_thread_encoder.c:287
AVCodecDescriptor::props
int props
Codec properties, a combination of AV_CODEC_PROP_* flags.
Definition: codec_desc.h:54
if
if(ret)
Definition: filter_design.txt:179
AVCodecContext::rc_buffer_size
int rc_buffer_size
decoder bitstream buffer size
Definition: avcodec.h:1208
AV_CODEC_PROP_INTRA_ONLY
#define AV_CODEC_PROP_INTRA_ONLY
Codec uses only intra compression.
Definition: codec_desc.h:72
AVPacket::buf
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: packet.h:357
NULL
#define NULL
Definition: coverity.c:32
AVHWFramesContext::sw_format
enum AVPixelFormat sw_format
The pixel format identifying the actual data layout of the hardware frames.
Definition: hwcontext.h:222
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:603
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:982
AVCodec::type
enum AVMediaType type
Definition: codec.h:217
ff_samples_to_time_base
static av_always_inline int64_t ff_samples_to_time_base(const AVCodecContext *avctx, int64_t samples)
Rescale from sample rate to AVCodecContext.time_base.
Definition: encode.h:84
AVCodecContext::internal
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:433
AV_PIX_FMT_YUVJ420P
@ AV_PIX_FMT_YUVJ420P
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:448
AV_FRAME_DATA_ICC_PROFILE
@ AV_FRAME_DATA_ICC_PROFILE
The data contains an ICC profile as an opaque octet buffer following the format described by ISO 1507...
Definition: frame.h:144
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:134
AV_CODEC_FLAG2_ICC_PROFILES
#define AV_CODEC_FLAG2_ICC_PROFILES
Generate/parse ICC profiles on encode/decode, as appropriate for the type of file.
Definition: avcodec.h:349
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:479
AVCodecInternal::draining_done
int draining_done
Definition: internal.h:149
c
Undefined Behavior In the C some operations are like signed integer dereferencing freed accessing outside allocated Undefined Behavior must not occur in a C it is not safe even if the output of undefined operations is unused The unsafety may seem nit picking but Optimizing compilers have in fact optimized code on the assumption that no undefined Behavior occurs Optimizing code based on wrong assumptions can and has in some cases lead to effects beyond the output of computations The signed integer overflow problem in speed critical code Code which is highly optimized and works with signed integers sometimes has the problem that often the output of the computation does not c
Definition: undefined.txt:32
AVAudioServiceType
AVAudioServiceType
Definition: defs.h:79
ff_icc_profile_generate
int ff_icc_profile_generate(FFIccContext *s, enum AVColorPrimaries color_prim, enum AVColorTransferCharacteristic color_trc, cmsHPROFILE *out_profile)
Generate an ICC profile for a given combination of color primaries and transfer function.
Definition: fflcms2.c:146
FFCodec::cb
union FFCodec::@50 cb
AVCodecContext::time_base
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avcodec.h:521
ff_encode_alloc_frame
int ff_encode_alloc_frame(AVCodecContext *avctx, AVFrame *frame)
Allocate buffers for a frame.
Definition: encode.c:682
AVCodecContext::stats_out
char * stats_out
pass1 encoding statistics output buffer
Definition: avcodec.h:1265
pad_last_frame
static int pad_last_frame(AVCodecContext *s, AVFrame *frame, const AVFrame *src, int out_samples)
Pad last frame with silence.
Definition: encode.c:130
f
f
Definition: af_crystalizer.c:122
AVCodecContext::flags2
int flags2
AV_CODEC_FLAG2_*.
Definition: avcodec.h:485
AVPacket::size
int size
Definition: packet.h:375
av_frame_ref
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:353
codec_internal.h
AV_CODEC_PROP_REORDER
#define AV_CODEC_PROP_REORDER
Codec supports frame reordering.
Definition: codec_desc.h:92
FFCodec::receive_packet
int(* receive_packet)(struct AVCodecContext *avctx, struct AVPacket *avpkt)
Encode API with decoupled frame/packet dataflow.
Definition: codec_internal.h:229
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1023
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
size
int size
Definition: twinvq_data.h:10344
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
AVFrameSideData::data
uint8_t * data
Definition: frame.h:233
ffcodec
static const av_always_inline FFCodec * ffcodec(const AVCodec *codec)
Definition: codec_internal.h:317
AVCodecInternal::byte_buffer
uint8_t * byte_buffer
temporary buffer used for encoders to store their bitstream
Definition: internal.h:95
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:373
attributes.h
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:380
AVCodecInternal
Definition: internal.h:52
AVCodecInternal::byte_buffer_size
unsigned int byte_buffer_size
Definition: internal.h:96
ff_encode_preinit
int ff_encode_preinit(AVCodecContext *avctx)
Definition: encode.c:627
av_channel_layout_compare
int av_channel_layout_compare(const AVChannelLayout *chl, const AVChannelLayout *chl1)
Check whether two channel layouts are semantically the same, i.e.
Definition: channel_layout.c:932
av_codec_is_encoder
int av_codec_is_encoder(const AVCodec *codec)
Definition: utils.c:75
avcodec_default_get_buffer2
int avcodec_default_get_buffer2(AVCodecContext *s, AVFrame *frame, int flags)
The default callback for AVCodecContext.get_buffer2().
Definition: get_buffer.c:282
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:222
FFCodec::caps_internal
unsigned caps_internal
Internal codec capabilities FF_CODEC_CAP_*.
Definition: codec_internal.h:128
AV_CODEC_FLAG_RECON_FRAME
#define AV_CODEC_FLAG_RECON_FRAME
Request the encoder to output reconstructed frames, i.e.
Definition: avcodec.h:243
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:269
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:367
av_get_bytes_per_sample
int av_get_bytes_per_sample(enum AVSampleFormat sample_fmt)
Return number of bytes per sample.
Definition: samplefmt.c:108
internal.h
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:49
av_frame_move_ref
void av_frame_move_ref(AVFrame *dst, AVFrame *src)
Move everything contained in src to dst and reset src.
Definition: frame.c:516
AV_PIX_FMT_YUVJ440P
@ AV_PIX_FMT_YUVJ440P
planar YUV 4:4:0 full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV440P and setting color_range
Definition: pixfmt.h:100
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:487
AVFrame::pkt_duration
attribute_deprecated int64_t pkt_duration
duration of the corresponding packet, expressed in AVStream->time_base units, 0 if unknown.
Definition: frame.h:617
profile
int profile
Definition: mxfenc.c:2006
AVCodecContext::height
int height
Definition: avcodec.h:571
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:448
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:608
AVCodecInternal::last_audio_frame
int last_audio_frame
An audio frame with less than required samples has been submitted (and potentially padded with silenc...
Definition: internal.h:63
FF_CODEC_CAP_ICC_PROFILES
#define FF_CODEC_CAP_ICC_PROFILES
Codec supports embedded ICC profiles (AV_FRAME_DATA_ICC_PROFILE).
Definition: codec_internal.h:82
AVCodecContext::hw_frames_ctx
AVBufferRef * hw_frames_ctx
A reference to the AVHWFramesContext describing the input (for encoding) or output (decoding) frames.
Definition: avcodec.h:1883
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:246
avcodec.h
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:124
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
AVPacket::side_data
AVPacketSideData * side_data
Additional packet data that can be provided by the container.
Definition: packet.h:385
AVCodecInternal::recon_frame
AVFrame * recon_frame
When the AV_CODEC_FLAG_RECON_FRAME flag is used.
Definition: internal.h:121
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
AVCodecContext
main external API structure.
Definition: avcodec.h:398
AVCodecContext::codec_descriptor
const AVCodecDescriptor * codec_descriptor
AVCodecDescriptor.
Definition: avcodec.h:1756
channel_layout.h
ff_get_encode_buffer
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
Definition: encode.c:79
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
AVCodecInternal::pad_samples
int pad_samples
Audio encoders can set this flag during init to indicate that they want the small last frame to be pa...
Definition: internal.h:69
AVCodecContext::get_encode_buffer
int(* get_encode_buffer)(struct AVCodecContext *s, AVPacket *pkt, int flags)
This callback is called at the beginning of each packet to get a data buffer for it.
Definition: avcodec.h:2051
encode_simple_receive_packet
static int encode_simple_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
Definition: encode.c:290
AVPixFmtDescriptor::comp
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:105
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:82
FFCodec::cb_type
unsigned cb_type
This field determines the type of the codec (decoder/encoder) and also the exact callback cb implemen...
Definition: codec_internal.h:135
av_buffer_realloc
int av_buffer_realloc(AVBufferRef **pbuf, size_t size)
Reallocate a given buffer.
Definition: buffer.c:183
AVCodecInternal::buffer_frame
AVFrame * buffer_frame
Definition: internal.h:148
av_channel_layout_copy
int av_channel_layout_copy(AVChannelLayout *dst, const AVChannelLayout *src)
Make a copy of a channel layout.
Definition: channel_layout.c:639
AVCodecInternal::draining
int draining
checks API usage: after codec draining, flush is required to resume operation
Definition: internal.h:142
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:81
AVCodecContext::coded_width
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:586
AVCodecContext::codec_type
enum AVMediaType codec_type
Definition: avcodec.h:406
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
AVCodecInternal::intra_only_flag
int intra_only_flag
This is set to AV_PKT_FLAG_KEY for encoders that encode intra-only formats (i.e.
Definition: internal.h:103
encode_preinit_audio
static int encode_preinit_audio(AVCodecContext *avctx)
Definition: encode.c:569
ff_encode_get_frame
int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame)
Called by encoders to get the next frame for encoding.
Definition: encode.c:178
AVCodecContext::frame_number
int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:1046
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:231
AVPixFmtDescriptor
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:69
AVPacket
This structure stores compressed data.
Definition: packet.h:351
avcodec_default_get_encode_buffer
int avcodec_default_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int flags)
The default callback for AVCodecContext.get_encode_buffer().
Definition: encode.c:57
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:571
encode_generate_icc_profile
static int encode_generate_icc_profile(av_unused AVCodecContext *c, av_unused AVFrame *f)
Definition: encode.c:380
imgutils.h
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:561
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
AVCodecContext::sw_pix_fmt
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1742
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:87
snprintf
#define snprintf
Definition: snprintf.h:34
ff_alloc_packet
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
Definition: encode.c:35
av_x_if_null
static void * av_x_if_null(const void *p, const void *x)
Return x default pointer in case p is NULL.
Definition: avutil.h:308
av_get_pix_fmt_name
const char * av_get_pix_fmt_name(enum AVPixelFormat pix_fmt)
Return the short name for a pixel format, NULL in case pix_fmt is unknown.
Definition: pixdesc.c:2778
AV_CODEC_FLAG_PASS1
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition: avcodec.h:247