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/emms.h"
25 #include "libavutil/frame.h"
26 #include "libavutil/imgutils.h"
27 #include "libavutil/internal.h"
28 #include "libavutil/pixdesc.h"
29 #include "libavutil/samplefmt.h"
30 
31 #include "avcodec.h"
32 #include "avcodec_internal.h"
33 #include "codec_desc.h"
34 #include "codec_internal.h"
35 #include "encode.h"
36 #include "frame_thread_encoder.h"
37 #include "internal.h"
38 
39 typedef struct EncodeContext {
41 
42  /**
43  * This is set to AV_PKT_FLAG_KEY for encoders that encode intra-only
44  * formats (i.e. whose codec descriptor has AV_CODEC_PROP_INTRA_ONLY set).
45  * This is used to set said flag generically for said encoders.
46  */
48 
49  /**
50  * An audio frame with less than required samples has been submitted (and
51  * potentially padded with silence). Reject all subsequent frames.
52  */
55 
57 {
58  return (EncodeContext*)avci;
59 }
60 
61 int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
62 {
63  if (size < 0 || size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE) {
64  av_log(avctx, AV_LOG_ERROR, "Invalid minimum required packet size %"PRId64" (max allowed is %d)\n",
66  return AVERROR(EINVAL);
67  }
68 
69  av_assert0(!avpkt->data);
70 
72  &avctx->internal->byte_buffer_size, size);
73  avpkt->data = avctx->internal->byte_buffer;
74  if (!avpkt->data) {
75  av_log(avctx, AV_LOG_ERROR, "Failed to allocate packet of size %"PRId64"\n", size);
76  return AVERROR(ENOMEM);
77  }
78  avpkt->size = size;
79 
80  return 0;
81 }
82 
84 {
85  int ret;
86 
87  if (avpkt->size < 0 || avpkt->size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
88  return AVERROR(EINVAL);
89 
90  if (avpkt->data || avpkt->buf) {
91  av_log(avctx, AV_LOG_ERROR, "avpkt->{data,buf} != NULL in avcodec_default_get_encode_buffer()\n");
92  return AVERROR(EINVAL);
93  }
94 
96  if (ret < 0) {
97  av_log(avctx, AV_LOG_ERROR, "Failed to allocate packet of size %d\n", avpkt->size);
98  return ret;
99  }
100  avpkt->data = avpkt->buf->data;
101 
102  return 0;
103 }
104 
105 int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
106 {
107  int ret;
108 
109  if (size < 0 || size > INT_MAX - AV_INPUT_BUFFER_PADDING_SIZE)
110  return AVERROR(EINVAL);
111 
112  av_assert0(!avpkt->data && !avpkt->buf);
113 
114  avpkt->size = size;
115  ret = avctx->get_encode_buffer(avctx, avpkt, flags);
116  if (ret < 0)
117  goto fail;
118 
119  if (!avpkt->data || !avpkt->buf) {
120  av_log(avctx, AV_LOG_ERROR, "No buffer returned by get_encode_buffer()\n");
121  ret = AVERROR(EINVAL);
122  goto fail;
123  }
124  memset(avpkt->data + avpkt->size, 0, AV_INPUT_BUFFER_PADDING_SIZE);
125 
126  ret = 0;
127 fail:
128  if (ret < 0) {
129  av_log(avctx, AV_LOG_ERROR, "get_encode_buffer() failed\n");
130  av_packet_unref(avpkt);
131  }
132 
133  return ret;
134 }
135 
137 {
138  uint8_t *data = avpkt->data;
139  int ret;
140 
141  if (avpkt->buf)
142  return 0;
143 
144  avpkt->data = NULL;
145  ret = ff_get_encode_buffer(avctx, avpkt, avpkt->size, 0);
146  if (ret < 0)
147  return ret;
148  memcpy(avpkt->data, data, avpkt->size);
149 
150  return 0;
151 }
152 
153 /**
154  * Pad last frame with silence.
155  */
156 static int pad_last_frame(AVCodecContext *s, AVFrame *frame, const AVFrame *src, int out_samples)
157 {
158  int ret;
159 
160  frame->format = src->format;
161  frame->nb_samples = out_samples;
162  ret = av_channel_layout_copy(&frame->ch_layout, &s->ch_layout);
163  if (ret < 0)
164  goto fail;
166  if (ret < 0)
167  goto fail;
168 
170  if (ret < 0)
171  goto fail;
172 
173  if ((ret = av_samples_copy(frame->extended_data, src->extended_data, 0, 0,
174  src->nb_samples, s->ch_layout.nb_channels,
175  s->sample_fmt)) < 0)
176  goto fail;
177  if ((ret = av_samples_set_silence(frame->extended_data, src->nb_samples,
178  frame->nb_samples - src->nb_samples,
179  s->ch_layout.nb_channels, s->sample_fmt)) < 0)
180  goto fail;
181 
182  return 0;
183 
184 fail:
186  encode_ctx(s->internal)->last_audio_frame = 0;
187  return ret;
188 }
189 
190 int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size,
191  const AVSubtitle *sub)
192 {
193  int ret;
194  if (sub->start_display_time) {
195  av_log(avctx, AV_LOG_ERROR, "start_display_time must be 0.\n");
196  return -1;
197  }
198 
199  ret = ffcodec(avctx->codec)->cb.encode_sub(avctx, buf, buf_size, sub);
200  avctx->frame_num++;
201 #if FF_API_AVCTX_FRAME_NUMBER
203  avctx->frame_number = avctx->frame_num;
205 #endif
206  return ret;
207 }
208 
210 {
211  AVCodecInternal *avci = avctx->internal;
212 
213  if (avci->draining)
214  return AVERROR_EOF;
215 
216  if (!avci->buffer_frame->buf[0])
217  return AVERROR(EAGAIN);
218 
220 
221 #if FF_API_FRAME_KEY
223  if (frame->key_frame)
226 #endif
227 #if FF_API_INTERLACED_FRAME
229  if (frame->interlaced_frame)
231  if (frame->top_field_first)
234 #endif
235 
236  return 0;
237 }
238 
240  AVPacket *pkt, const AVFrame *frame)
241 {
242 #if FF_API_REORDERED_OPAQUE
244  avctx->reordered_opaque = frame->reordered_opaque;
246 #endif
247 
248  if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
250  if (ret < 0)
251  return ret;
252  pkt->opaque = frame->opaque;
253  }
254 
255  return 0;
256 }
257 
259  AVFrame *frame, int *got_packet)
260 {
261  const FFCodec *const codec = ffcodec(avctx->codec);
262  int ret;
263 
264  ret = codec->cb.encode(avctx, avpkt, frame, got_packet);
265  emms_c();
266  av_assert0(ret <= 0);
267 
268  if (!ret && *got_packet) {
269  if (avpkt->data) {
270  ret = encode_make_refcounted(avctx, avpkt);
271  if (ret < 0)
272  goto unref;
273  // Date returned by encoders must always be ref-counted
274  av_assert0(avpkt->buf);
275  }
276 
277  // set the timestamps for the simple no-delay case
278  // encoders with delay have to set the timestamps themselves
279  if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY) ||
280  (frame && (codec->caps_internal & FF_CODEC_CAP_EOF_FLUSH))) {
281  if (avpkt->pts == AV_NOPTS_VALUE)
282  avpkt->pts = frame->pts;
283 
284  if (!avpkt->duration) {
285  if (frame->duration)
286  avpkt->duration = frame->duration;
287  else if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
288  avpkt->duration = ff_samples_to_time_base(avctx,
289  frame->nb_samples);
290  }
291  }
292 
293  ret = ff_encode_reordered_opaque(avctx, avpkt, frame);
294  if (ret < 0)
295  goto unref;
296  }
297 
298  // dts equals pts unless there is reordering
299  // there can be no reordering if there is no encoder delay
300  if (!(avctx->codec_descriptor->props & AV_CODEC_PROP_REORDER) ||
301  !(avctx->codec->capabilities & AV_CODEC_CAP_DELAY) ||
303  avpkt->dts = avpkt->pts;
304  } else {
305 unref:
306  av_packet_unref(avpkt);
307  }
308 
309  if (frame)
311 
312  return ret;
313 }
314 
316 {
317  AVCodecInternal *avci = avctx->internal;
318  AVFrame *frame = avci->in_frame;
319  const FFCodec *const codec = ffcodec(avctx->codec);
320  int got_packet;
321  int ret;
322 
323  if (avci->draining_done)
324  return AVERROR_EOF;
325 
326  if (!frame->buf[0] && !avci->draining) {
328  ret = ff_encode_get_frame(avctx, frame);
329  if (ret < 0 && ret != AVERROR_EOF)
330  return ret;
331  }
332 
333  if (!frame->buf[0]) {
334  if (!(avctx->codec->capabilities & AV_CODEC_CAP_DELAY ||
335  avci->frame_thread_encoder))
336  return AVERROR_EOF;
337 
338  // Flushing is signaled with a NULL frame
339  frame = NULL;
340  }
341 
342  got_packet = 0;
343 
345 
346  if (CONFIG_FRAME_THREAD_ENCODER && avci->frame_thread_encoder)
347  /* This will unref frame. */
348  ret = ff_thread_video_encode_frame(avctx, avpkt, frame, &got_packet);
349  else {
350  ret = ff_encode_encode_cb(avctx, avpkt, frame, &got_packet);
351  }
352 
353  if (avci->draining && !got_packet)
354  avci->draining_done = 1;
355 
356  return ret;
357 }
358 
360 {
361  int ret;
362 
363  while (!avpkt->data && !avpkt->side_data) {
364  ret = encode_simple_internal(avctx, avpkt);
365  if (ret < 0)
366  return ret;
367  }
368 
369  return 0;
370 }
371 
373 {
374  AVCodecInternal *avci = avctx->internal;
375  int ret;
376 
377  if (avci->draining_done)
378  return AVERROR_EOF;
379 
380  av_assert0(!avpkt->data && !avpkt->side_data);
381 
382  if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
383  if ((avctx->flags & AV_CODEC_FLAG_PASS1) && avctx->stats_out)
384  avctx->stats_out[0] = '\0';
385  if (av_image_check_size2(avctx->width, avctx->height, avctx->max_pixels, AV_PIX_FMT_NONE, 0, avctx))
386  return AVERROR(EINVAL);
387  }
388 
390  ret = ffcodec(avctx->codec)->cb.receive_packet(avctx, avpkt);
391  if (ret < 0)
392  av_packet_unref(avpkt);
393  else
394  // Encoders must always return ref-counted buffers.
395  // Side-data only packets have no data and can be not ref-counted.
396  av_assert0(!avpkt->data || avpkt->buf);
397  } else
398  ret = encode_simple_receive_packet(avctx, avpkt);
399  if (ret >= 0)
400  avpkt->flags |= encode_ctx(avci)->intra_only_flag;
401 
402  if (ret == AVERROR_EOF)
403  avci->draining_done = 1;
404 
405  return ret;
406 }
407 
408 #if CONFIG_LCMS2
410 {
413  const FFCodec *const codec = ffcodec(avctx->codec);
414  AVCodecInternal *avci = avctx->internal;
415  cmsHPROFILE profile;
416  int ret;
417 
418  /* don't generate ICC profiles if disabled or unsupported */
419  if (!(avctx->flags2 & AV_CODEC_FLAG2_ICC_PROFILES))
420  return 0;
422  return 0;
423 
424  if (trc == AVCOL_TRC_UNSPECIFIED)
425  trc = avctx->color_trc;
426  if (prim == AVCOL_PRI_UNSPECIFIED)
427  prim = avctx->color_primaries;
428  if (trc == AVCOL_TRC_UNSPECIFIED || prim == AVCOL_PRI_UNSPECIFIED)
429  return 0; /* can't generate ICC profile with missing csp tags */
430 
432  return 0; /* don't overwrite existing ICC profile */
433 
434  if (!avci->icc.avctx) {
435  ret = ff_icc_context_init(&avci->icc, avctx);
436  if (ret < 0)
437  return ret;
438  }
439 
440  ret = ff_icc_profile_generate(&avci->icc, prim, trc, &profile);
441  if (ret < 0)
442  return ret;
443 
444  ret = ff_icc_profile_attach(&avci->icc, profile, frame);
445  cmsCloseProfile(profile);
446  return ret;
447 }
448 #else /* !CONFIG_LCMS2 */
450 {
451  return 0;
452 }
453 #endif
454 
456 {
457  AVCodecInternal *avci = avctx->internal;
458  EncodeContext *ec = encode_ctx(avci);
459  AVFrame *dst = avci->buffer_frame;
460  int ret;
461 
462  if (avctx->codec->type == AVMEDIA_TYPE_AUDIO) {
463  /* extract audio service type metadata */
465  if (sd && sd->size >= sizeof(enum AVAudioServiceType))
466  avctx->audio_service_type = *(enum AVAudioServiceType*)sd->data;
467 
468  /* check for valid frame size */
470  /* if we already got an undersized frame, that must have been the last */
471  if (ec->last_audio_frame) {
472  av_log(avctx, AV_LOG_ERROR, "frame_size (%d) was not respected for a non-last frame\n", avctx->frame_size);
473  return AVERROR(EINVAL);
474  }
475  if (src->nb_samples > avctx->frame_size) {
476  av_log(avctx, AV_LOG_ERROR, "nb_samples (%d) > frame_size (%d)\n", src->nb_samples, avctx->frame_size);
477  return AVERROR(EINVAL);
478  }
479  if (src->nb_samples < avctx->frame_size) {
480  ec->last_audio_frame = 1;
482  int pad_samples = avci->pad_samples ? avci->pad_samples : avctx->frame_size;
483  int out_samples = (src->nb_samples + pad_samples - 1) / pad_samples * pad_samples;
484 
485  if (out_samples != src->nb_samples) {
486  ret = pad_last_frame(avctx, dst, src, out_samples);
487  if (ret < 0)
488  return ret;
489  goto finish;
490  }
491  }
492  }
493  }
494  }
495 
496  ret = av_frame_ref(dst, src);
497  if (ret < 0)
498  return ret;
499 
500 finish:
501 
502  if (avctx->codec->type == AVMEDIA_TYPE_VIDEO) {
503  ret = encode_generate_icc_profile(avctx, dst);
504  if (ret < 0)
505  return ret;
506  }
507 
508  // unset frame duration unless AV_CODEC_FLAG_FRAME_DURATION is set,
509  // since otherwise we cannot be sure that whatever value it has is in the
510  // right timebase, so we would produce an incorrect value, which is worse
511  // than none at all
512  if (!(avctx->flags & AV_CODEC_FLAG_FRAME_DURATION))
513  dst->duration = 0;
514 
515  return 0;
516 }
517 
519 {
520  AVCodecInternal *avci = avctx->internal;
521  int ret;
522 
523  if (!avcodec_is_open(avctx) || !av_codec_is_encoder(avctx->codec))
524  return AVERROR(EINVAL);
525 
526  if (avci->draining)
527  return AVERROR_EOF;
528 
529  if (avci->buffer_frame->buf[0])
530  return AVERROR(EAGAIN);
531 
532  if (!frame) {
533  avci->draining = 1;
534  } else {
536  if (ret < 0)
537  return ret;
538  }
539 
540  if (!avci->buffer_pkt->data && !avci->buffer_pkt->side_data) {
542  if (ret < 0 && ret != AVERROR(EAGAIN) && ret != AVERROR_EOF)
543  return ret;
544  }
545 
546  avctx->frame_num++;
547 #if FF_API_AVCTX_FRAME_NUMBER
549  avctx->frame_number = avctx->frame_num;
551 #endif
552 
553  return 0;
554 }
555 
557 {
558  AVCodecInternal *avci = avctx->internal;
559  int ret;
560 
561  av_packet_unref(avpkt);
562 
563  if (!avcodec_is_open(avctx) || !av_codec_is_encoder(avctx->codec))
564  return AVERROR(EINVAL);
565 
566  if (avci->buffer_pkt->data || avci->buffer_pkt->side_data) {
567  av_packet_move_ref(avpkt, avci->buffer_pkt);
568  } else {
569  ret = encode_receive_packet_internal(avctx, avpkt);
570  if (ret < 0)
571  return ret;
572  }
573 
574  return 0;
575 }
576 
578 {
579  const AVCodec *c = avctx->codec;
580  const AVPixFmtDescriptor *pixdesc = av_pix_fmt_desc_get(avctx->pix_fmt);
581  int i;
582 
583  if (!av_get_pix_fmt_name(avctx->pix_fmt)) {
584  av_log(avctx, AV_LOG_ERROR, "Invalid video pixel format: %d\n",
585  avctx->pix_fmt);
586  return AVERROR(EINVAL);
587  }
588 
589  if (c->pix_fmts) {
590  for (i = 0; c->pix_fmts[i] != AV_PIX_FMT_NONE; i++)
591  if (avctx->pix_fmt == c->pix_fmts[i])
592  break;
593  if (c->pix_fmts[i] == AV_PIX_FMT_NONE) {
594  av_log(avctx, AV_LOG_ERROR,
595  "Specified pixel format %s is not supported by the %s encoder.\n",
596  av_get_pix_fmt_name(avctx->pix_fmt), c->name);
597 
598  av_log(avctx, AV_LOG_ERROR, "Supported pixel formats:\n");
599  for (int p = 0; c->pix_fmts[p] != AV_PIX_FMT_NONE; p++) {
600  av_log(avctx, AV_LOG_ERROR, " %s\n",
601  av_get_pix_fmt_name(c->pix_fmts[p]));
602  }
603 
604  return AVERROR(EINVAL);
605  }
606  if (c->pix_fmts[i] == AV_PIX_FMT_YUVJ420P ||
607  c->pix_fmts[i] == AV_PIX_FMT_YUVJ411P ||
608  c->pix_fmts[i] == AV_PIX_FMT_YUVJ422P ||
609  c->pix_fmts[i] == AV_PIX_FMT_YUVJ440P ||
610  c->pix_fmts[i] == AV_PIX_FMT_YUVJ444P)
611  avctx->color_range = AVCOL_RANGE_JPEG;
612  }
613 
614  if ( avctx->bits_per_raw_sample < 0
615  || (avctx->bits_per_raw_sample > 8 && pixdesc->comp[0].depth <= 8)) {
616  av_log(avctx, AV_LOG_WARNING, "Specified bit depth %d not possible with the specified pixel formats depth %d\n",
617  avctx->bits_per_raw_sample, pixdesc->comp[0].depth);
618  avctx->bits_per_raw_sample = pixdesc->comp[0].depth;
619  }
620  if (avctx->width <= 0 || avctx->height <= 0) {
621  av_log(avctx, AV_LOG_ERROR, "dimensions not set\n");
622  return AVERROR(EINVAL);
623  }
624 
625 #if FF_API_TICKS_PER_FRAME
627  if (avctx->ticks_per_frame && avctx->time_base.num &&
628  avctx->ticks_per_frame > INT_MAX / avctx->time_base.num) {
629  av_log(avctx, AV_LOG_ERROR,
630  "ticks_per_frame %d too large for the timebase %d/%d.",
631  avctx->ticks_per_frame,
632  avctx->time_base.num,
633  avctx->time_base.den);
634  return AVERROR(EINVAL);
635  }
637 #endif
638 
639  if (avctx->hw_frames_ctx) {
640  AVHWFramesContext *frames_ctx = (AVHWFramesContext*)avctx->hw_frames_ctx->data;
641  if (frames_ctx->format != avctx->pix_fmt) {
642  av_log(avctx, AV_LOG_ERROR,
643  "Mismatching AVCodecContext.pix_fmt and AVHWFramesContext.format\n");
644  return AVERROR(EINVAL);
645  }
646  if (avctx->sw_pix_fmt != AV_PIX_FMT_NONE &&
647  avctx->sw_pix_fmt != frames_ctx->sw_format) {
648  av_log(avctx, AV_LOG_ERROR,
649  "Mismatching AVCodecContext.sw_pix_fmt (%s) "
650  "and AVHWFramesContext.sw_format (%s)\n",
652  av_get_pix_fmt_name(frames_ctx->sw_format));
653  return AVERROR(EINVAL);
654  }
655  avctx->sw_pix_fmt = frames_ctx->sw_format;
656  }
657 
658  return 0;
659 }
660 
662 {
663  const AVCodec *c = avctx->codec;
664  int i;
665 
666  if (!av_get_sample_fmt_name(avctx->sample_fmt)) {
667  av_log(avctx, AV_LOG_ERROR, "Invalid audio sample format: %d\n",
668  avctx->sample_fmt);
669  return AVERROR(EINVAL);
670  }
671  if (avctx->sample_rate <= 0) {
672  av_log(avctx, AV_LOG_ERROR, "Invalid audio sample rate: %d\n",
673  avctx->sample_rate);
674  return AVERROR(EINVAL);
675  }
676 
677  if (c->sample_fmts) {
678  for (i = 0; c->sample_fmts[i] != AV_SAMPLE_FMT_NONE; i++) {
679  if (avctx->sample_fmt == c->sample_fmts[i])
680  break;
681  if (avctx->ch_layout.nb_channels == 1 &&
683  av_get_planar_sample_fmt(c->sample_fmts[i])) {
684  avctx->sample_fmt = c->sample_fmts[i];
685  break;
686  }
687  }
688  if (c->sample_fmts[i] == AV_SAMPLE_FMT_NONE) {
689  av_log(avctx, AV_LOG_ERROR,
690  "Specified sample format %s is not supported by the %s encoder\n",
691  av_get_sample_fmt_name(avctx->sample_fmt), c->name);
692 
693  av_log(avctx, AV_LOG_ERROR, "Supported sample formats:\n");
694  for (int p = 0; c->sample_fmts[p] != AV_SAMPLE_FMT_NONE; p++) {
695  av_log(avctx, AV_LOG_ERROR, " %s\n",
696  av_get_sample_fmt_name(c->sample_fmts[p]));
697  }
698 
699  return AVERROR(EINVAL);
700  }
701  }
702  if (c->supported_samplerates) {
703  for (i = 0; c->supported_samplerates[i] != 0; i++)
704  if (avctx->sample_rate == c->supported_samplerates[i])
705  break;
706  if (c->supported_samplerates[i] == 0) {
707  av_log(avctx, AV_LOG_ERROR,
708  "Specified sample rate %d is not supported by the %s encoder\n",
709  avctx->sample_rate, c->name);
710 
711  av_log(avctx, AV_LOG_ERROR, "Supported sample rates:\n");
712  for (int p = 0; c->supported_samplerates[p]; p++)
713  av_log(avctx, AV_LOG_ERROR, " %d\n", c->supported_samplerates[p]);
714 
715  return AVERROR(EINVAL);
716  }
717  }
718  if (c->ch_layouts) {
719  for (i = 0; c->ch_layouts[i].nb_channels; i++) {
720  if (!av_channel_layout_compare(&avctx->ch_layout, &c->ch_layouts[i]))
721  break;
722  }
723  if (!c->ch_layouts[i].nb_channels) {
724  char buf[512];
725  int ret = av_channel_layout_describe(&avctx->ch_layout, buf, sizeof(buf));
726  av_log(avctx, AV_LOG_ERROR,
727  "Specified channel layout '%s' is not supported by the %s encoder\n",
728  ret > 0 ? buf : "?", c->name);
729 
730  av_log(avctx, AV_LOG_ERROR, "Supported channel layouts:\n");
731  for (int p = 0; c->ch_layouts[p].nb_channels; p++) {
732  ret = av_channel_layout_describe(&c->ch_layouts[p], buf, sizeof(buf));
733  av_log(avctx, AV_LOG_ERROR, " %s\n", ret > 0 ? buf : "?");
734  }
735  return AVERROR(EINVAL);
736  }
737  }
738 
739  if (!avctx->bits_per_raw_sample)
741 
742  return 0;
743 }
744 
746 {
747  AVCodecInternal *avci = avctx->internal;
748  EncodeContext *ec = encode_ctx(avci);
749  int ret = 0;
750 
751  if (avctx->time_base.num <= 0 || avctx->time_base.den <= 0) {
752  av_log(avctx, AV_LOG_ERROR, "The encoder timebase is not set.\n");
753  return AVERROR(EINVAL);
754  }
755 
756  if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE &&
758  av_log(avctx, AV_LOG_ERROR, "The copy_opaque flag is set, but the "
759  "encoder does not support it.\n");
760  return AVERROR(EINVAL);
761  }
762 
763  switch (avctx->codec_type) {
764  case AVMEDIA_TYPE_VIDEO: ret = encode_preinit_video(avctx); break;
765  case AVMEDIA_TYPE_AUDIO: ret = encode_preinit_audio(avctx); break;
766  }
767  if (ret < 0)
768  return ret;
769 
770  if ( (avctx->codec_type == AVMEDIA_TYPE_VIDEO || avctx->codec_type == AVMEDIA_TYPE_AUDIO)
771  && avctx->bit_rate>0 && avctx->bit_rate<1000) {
772  av_log(avctx, AV_LOG_WARNING, "Bitrate %"PRId64" is extremely low, maybe you mean %"PRId64"k\n", avctx->bit_rate, avctx->bit_rate);
773  }
774 
775  if (!avctx->rc_initial_buffer_occupancy)
776  avctx->rc_initial_buffer_occupancy = avctx->rc_buffer_size * 3LL / 4;
777 
780 
781  if (ffcodec(avctx->codec)->cb_type == FF_CODEC_CB_TYPE_ENCODE) {
782  avci->in_frame = av_frame_alloc();
783  if (!avci->in_frame)
784  return AVERROR(ENOMEM);
785  }
786 
787  if ((avctx->flags & AV_CODEC_FLAG_RECON_FRAME)) {
789  av_log(avctx, AV_LOG_ERROR, "Reconstructed frame output requested "
790  "from an encoder not supporting it\n");
791  return AVERROR(ENOSYS);
792  }
793 
794  avci->recon_frame = av_frame_alloc();
795  if (!avci->recon_frame)
796  return AVERROR(ENOMEM);
797  }
798 
799  if (CONFIG_FRAME_THREAD_ENCODER) {
801  if (ret < 0)
802  return ret;
803  }
804 
805  return 0;
806 }
807 
809 {
810  int ret;
811 
812  switch (avctx->codec->type) {
813  case AVMEDIA_TYPE_VIDEO:
814  frame->format = avctx->pix_fmt;
815  if (frame->width <= 0 || frame->height <= 0) {
816  frame->width = FFMAX(avctx->width, avctx->coded_width);
817  frame->height = FFMAX(avctx->height, avctx->coded_height);
818  }
819 
820  break;
821  case AVMEDIA_TYPE_AUDIO:
822  frame->sample_rate = avctx->sample_rate;
823  frame->format = avctx->sample_fmt;
824  if (!frame->ch_layout.nb_channels) {
826  if (ret < 0)
827  return ret;
828  }
829  break;
830  }
831 
833  if (ret < 0) {
834  av_log(avctx, AV_LOG_ERROR, "get_buffer() failed\n");
836  return ret;
837  }
838 
839  return 0;
840 }
841 
843 {
844  AVCodecInternal *avci = avctx->internal;
845 
846  if (!avci->recon_frame)
847  return AVERROR(EINVAL);
848  if (!avci->recon_frame->buf[0])
849  return avci->draining_done ? AVERROR_EOF : AVERROR(EAGAIN);
850 
852  return 0;
853 }
854 
856 {
857  AVCodecInternal *avci = avctx->internal;
858 
859  if (avci->in_frame)
860  av_frame_unref(avci->in_frame);
861  if (avci->recon_frame)
863 }
864 
866 {
867  return av_mallocz(sizeof(EncodeContext));
868 }
869 
871 {
873  AVCPBProperties *props;
874  size_t size;
875  int i;
876 
877  for (i = 0; i < avctx->nb_coded_side_data; i++)
879  return (AVCPBProperties *)avctx->coded_side_data[i].data;
880 
881  props = av_cpb_properties_alloc(&size);
882  if (!props)
883  return NULL;
884 
885  tmp = av_realloc_array(avctx->coded_side_data, avctx->nb_coded_side_data + 1, sizeof(*tmp));
886  if (!tmp) {
887  av_freep(&props);
888  return NULL;
889  }
890 
891  avctx->coded_side_data = tmp;
892  avctx->nb_coded_side_data++;
893 
895  avctx->coded_side_data[avctx->nb_coded_side_data - 1].data = (uint8_t*)props;
896  avctx->coded_side_data[avctx->nb_coded_side_data - 1].size = size;
897 
898  return props;
899 }
AVSubtitle
Definition: avcodec.h:2273
AVFrame::color_trc
enum AVColorTransferCharacteristic color_trc
Definition: frame.h:660
avcodec_encode_subtitle
int avcodec_encode_subtitle(AVCodecContext *avctx, uint8_t *buf, int buf_size, const AVSubtitle *sub)
Definition: encode.c:190
ff_encode_reordered_opaque
int ff_encode_reordered_opaque(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame)
Propagate user opaque values from the frame to avctx/pkt as needed.
Definition: encode.c:239
av_samples_copy
int av_samples_copy(uint8_t *const *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
AVCodecContext::frame_size
int frame_size
Number of samples per channel in an audio frame.
Definition: avcodec.h:1096
av_packet_unref
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:427
AVCodec
AVCodec.
Definition: codec.h:187
FF_ENABLE_DEPRECATION_WARNINGS
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:73
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:556
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:1151
FF_CODEC_CB_TYPE_RECEIVE_PACKET
@ FF_CODEC_CB_TYPE_RECEIVE_PACKET
Definition: codec_internal.h:124
AVColorTransferCharacteristic
AVColorTransferCharacteristic
Color Transfer Characteristic.
Definition: pixfmt.h:584
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:243
AVCodecContext::sample_rate
int sample_rate
samples per second
Definition: avcodec.h:1068
av_frame_get_side_data
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition: frame.c:824
AVFrame::duration
int64_t duration
Duration of the frame, in the same units as pts.
Definition: frame.h:807
av_pix_fmt_desc_get
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2968
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:210
FF_CODEC_CAP_EOF_FLUSH
#define FF_CODEC_CAP_EOF_FLUSH
The encoder has AV_CODEC_CAP_DELAY set, but does not actually have delay - it only wants to be flushe...
Definition: codec_internal.h:90
AVCodecContext::codec_descriptor
const struct AVCodecDescriptor * codec_descriptor
AVCodecDescriptor.
Definition: avcodec.h:1828
AVCodecContext::coded_side_data
AVPacketSideData * coded_side_data
Additional data associated with the entire coded stream.
Definition: avcodec.h:1919
encode_make_refcounted
static int encode_make_refcounted(AVCodecContext *avctx, AVPacket *avpkt)
Definition: encode.c:136
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:174
AVFrame::color_primaries
enum AVColorPrimaries color_primaries
Definition: frame.h:658
av_unused
#define av_unused
Definition: attributes.h:131
AVFrame::opaque
void * opaque
Frame owner's private data.
Definition: frame.h:501
ff_encode_receive_frame
int ff_encode_receive_frame(AVCodecContext *avctx, AVFrame *frame)
avcodec_receive_frame() implementation for encoders.
Definition: encode.c:842
AVFrame
This structure describes decoded (raw) audio or video data.
Definition: frame.h:340
tmp
static uint8_t tmp[11]
Definition: aes_ctr.c:28
pixdesc.h
AVFrame::pts
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:452
AVCodecContext::color_trc
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:1026
AVFrame::width
int width
Definition: frame.h:412
AVPacketSideData
This structure stores auxiliary information for decoding, presenting, or otherwise processing the cod...
Definition: packet.h:373
AVCodec::capabilities
int capabilities
Codec capabilities.
Definition: codec.h:206
AVCOL_RANGE_JPEG
@ AVCOL_RANGE_JPEG
Full range content.
Definition: pixfmt.h:687
internal.h
av_samples_set_silence
int av_samples_set_silence(uint8_t *const *audio_data, int offset, int nb_samples, int nb_channels, enum AVSampleFormat sample_fmt)
Fill an audio buffer with silence.
Definition: samplefmt.c:246
AVPacket::data
uint8_t * data
Definition: packet.h:522
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:89
AVCodecInternal::in_frame
AVFrame * in_frame
The input frame is stored here for encoders implementing the simple encode API.
Definition: internal.h:97
encode.h
AVCOL_TRC_UNSPECIFIED
@ AVCOL_TRC_UNSPECIFIED
Definition: pixfmt.h:587
data
const char data[16]
Definition: mxf.c:148
FFCodec
Definition: codec_internal.h:127
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:222
ff_encode_encode_cb
int ff_encode_encode_cb(AVCodecContext *avctx, AVPacket *avpkt, AVFrame *frame, int *got_packet)
Definition: encode.c:258
AVPacket::duration
int64_t duration
Duration of this packet in AVStream->time_base units, 0 if unknown.
Definition: packet.h:540
AVFrame::flags
int flags
Frame flags, a combination of AV_FRAME_FLAGS.
Definition: frame.h:649
FFMAX
#define FFMAX(a, b)
Definition: macros.h:47
AVColorPrimaries
AVColorPrimaries
Chromaticity coordinates of the source primaries.
Definition: pixfmt.h:559
avcodec_is_open
int avcodec_is_open(AVCodecContext *s)
Definition: avcodec.c:710
AVChannelLayout::nb_channels
int nb_channels
Number of channels in this layout.
Definition: channel_layout.h:323
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:172
AVFrame::buf
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:590
AV_PKT_FLAG_KEY
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:577
AV_FRAME_FLAG_TOP_FIELD_FIRST
#define AV_FRAME_FLAG_TOP_FIELD_FIRST
A flag to mark frames where the top field is displayed first if the content is interlaced.
Definition: frame.h:641
AVFrame::opaque_ref
AVBufferRef * opaque_ref
Frame owner's private data.
Definition: frame.h:768
AVPacketSideData::size
size_t size
Definition: packet.h:375
FFCodec::cb
union FFCodec::@63 cb
AV_CODEC_FLAG_COPY_OPAQUE
#define AV_CODEC_FLAG_COPY_OPAQUE
Definition: avcodec.h:299
finish
static void finish(void)
Definition: movenc.c:342
AVCodecContext::codec
const struct AVCodec * codec
Definition: avcodec.h:454
AVPacket::opaque_ref
AVBufferRef * opaque_ref
AVBufferRef for free use by the API user.
Definition: packet.h:558
AV_CODEC_FLAG_FRAME_DURATION
#define AV_CODEC_FLAG_FRAME_DURATION
Signal to the encoder that the values of AVFrame.duration are valid and should be used (typically for...
Definition: avcodec.h:306
AVCodecContext::ch_layout
AVChannelLayout ch_layout
Audio channel layout.
Definition: avcodec.h:2111
fail
#define fail()
Definition: checkasm.h:179
ff_icc_context_init
int ff_icc_context_init(FFIccContext *s, void *avctx)
Initializes an FFIccContext.
Definition: fflcms2.c:30
encode_receive_packet_internal
static int encode_receive_packet_internal(AVCodecContext *avctx, AVPacket *avpkt)
Definition: encode.c:372
samplefmt.h
AVCodecContext::flags
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:525
AVFrame::ch_layout
AVChannelLayout ch_layout
Channel layout of the audio data.
Definition: frame.h:802
AVCodecContext::coded_height
int coded_height
Definition: avcodec.h:640
encode_preinit_video
static int encode_preinit_video(AVCodecContext *avctx)
Definition: encode.c:577
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:88
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:283
AVFrame::interlaced_frame
attribute_deprecated int interlaced_frame
The content of the picture is interlaced.
Definition: frame.h:530
avassert.h
AVCodecContext::color_primaries
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:1019
pkt
AVPacket * pkt
Definition: movenc.c:59
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:455
frame_thread_encoder.h
AVFrameSideData::size
size_t size
Definition: frame.h:249
encode_simple_internal
static int encode_simple_internal(AVCodecContext *avctx, AVPacket *avpkt)
Definition: encode.c:315
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:1316
AV_FRAME_FLAG_KEY
#define AV_FRAME_FLAG_KEY
A flag to mark frames that are keyframes.
Definition: frame.h:628
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:847
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:86
emms_c
#define emms_c()
Definition: emms.h:63
ff_frame_thread_encoder_init
av_cold int ff_frame_thread_encoder_init(AVCodecContext *avctx)
Initialize frame thread encoder.
Definition: frame_thread_encoder.c:119
AVFrame::reordered_opaque
attribute_deprecated int64_t reordered_opaque
reordered opaque 64 bits (generally an integer or a double precision float PTS but can be anything).
Definition: frame.h:561
s
#define s(width, name)
Definition: cbs_vp9.c:198
AVCodecInternal::buffer_pkt
AVPacket * buffer_pkt
Temporary buffers for newly received or not yet output packets/frames.
Definition: internal.h:131
av_realloc_array
void * av_realloc_array(void *ptr, size_t nmemb, size_t size)
Definition: mem.c:215
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:114
AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
#define AV_CODEC_CAP_ENCODER_REORDERED_OPAQUE
This encoder can reorder user opaque values from input AVFrames and return them with corresponding ou...
Definition: codec.h:159
av_assert0
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:40
AVCodecContext::bits_per_raw_sample
int bits_per_raw_sample
Bits per sample/pixel of internal libavcodec pixel/sample format.
Definition: avcodec.h:1521
EncodeContext::avci
AVCodecInternal avci
Definition: encode.c:40
AVPacketSideData::data
uint8_t * data
Definition: packet.h:374
FF_CODEC_CB_TYPE_ENCODE
@ FF_CODEC_CB_TYPE_ENCODE
Definition: codec_internal.h:118
AVCodecContext::max_pixels
int64_t max_pixels
The number of pixels per image to maximally accept.
Definition: avcodec.h:1963
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:228
AVPacket::opaque
void * opaque
for some private data of the user
Definition: packet.h:547
AVCOL_PRI_UNSPECIFIED
@ AVCOL_PRI_UNSPECIFIED
Definition: pixfmt.h:562
AVCPBProperties
This structure describes the bitrate properties of an encoded bitstream.
Definition: defs.h:269
AVFrame::key_frame
attribute_deprecated int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:436
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:87
frame
static AVFrame * frame
Definition: demux_decode.c:54
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:268
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:1273
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:505
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:223
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:736
AVCodecContext::color_range
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:1043
AVCodec::type
enum AVMediaType type
Definition: codec.h:200
AVCodecContext::nb_coded_side_data
int nb_coded_side_data
Definition: avcodec.h:1920
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:90
AVCodecContext::internal
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:480
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:85
AVCodecContext::bit_rate
int64_t bit_rate
the average bitrate
Definition: avcodec.h:495
AVPacketSideData::type
enum AVPacketSideDataType type
Definition: packet.h:376
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
ff_encode_internal_alloc
AVCodecInternal * ff_encode_internal_alloc(void)
Definition: encode.c:865
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:128
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:398
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:484
AVCodecInternal::draining_done
int draining_done
Definition: internal.h:133
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:222
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:145
attribute_align_arg
#define attribute_align_arg
Definition: internal.h:50
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:567
ff_encode_alloc_frame
int ff_encode_alloc_frame(AVCodecContext *avctx, AVFrame *frame)
Allocate buffers for a frame.
Definition: encode.c:808
AVCodecContext::stats_out
char * stats_out
pass1 encoding statistics output buffer
Definition: avcodec.h:1330
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:156
f
f
Definition: af_crystalizer.c:121
AVCodecContext::flags2
int flags2
AV_CODEC_FLAG2_*.
Definition: avcodec.h:532
AVPacket::size
int size
Definition: packet.h:523
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:361
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:237
AVFrame::sample_rate
int sample_rate
Sample rate of the audio data.
Definition: frame.h:567
EncodeContext
Definition: encode.c:39
AVCodecContext::sample_fmt
enum AVSampleFormat sample_fmt
audio sample format
Definition: avcodec.h:1084
AV_SAMPLE_FMT_NONE
@ AV_SAMPLE_FMT_NONE
Definition: samplefmt.h:56
size
int size
Definition: twinvq_data.h:10344
EncodeContext::last_audio_frame
int last_audio_frame
An audio frame with less than required samples has been submitted (and potentially padded with silenc...
Definition: encode.c:53
AV_NOPTS_VALUE
#define AV_NOPTS_VALUE
Undefined timestamp value.
Definition: avutil.h:248
AVFrameSideData::data
uint8_t * data
Definition: frame.h:248
ffcodec
static const av_always_inline FFCodec * ffcodec(const AVCodec *codec)
Definition: codec_internal.h:325
AVCodecInternal::byte_buffer
uint8_t * byte_buffer
temporary buffer used for encoders to store their bitstream
Definition: internal.h:86
AVFrame::format
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:427
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:521
attributes.h
AVPacket::flags
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:528
AVCodecInternal
Definition: internal.h:49
AVCodecInternal::byte_buffer_size
unsigned int byte_buffer_size
Definition: internal.h:87
encode_ctx
static EncodeContext * encode_ctx(AVCodecInternal *avci)
Definition: encode.c:56
ff_encode_preinit
int ff_encode_preinit(AVCodecContext *avctx)
Definition: encode.c:745
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:1003
av_codec_is_encoder
int av_codec_is_encoder(const AVCodec *codec)
Definition: utils.c:78
emms.h
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:260
FFCodec::caps_internal
unsigned caps_internal
Internal codec capabilities FF_CODEC_CAP_*.
Definition: codec_internal.h:136
AV_PKT_DATA_CPB_PROPERTIES
@ AV_PKT_DATA_CPB_PROPERTIES
This side data corresponds to the AVCPBProperties struct.
Definition: packet.h:146
AVFrame::nb_samples
int nb_samples
number of audio samples (per channel) described by this frame
Definition: frame.h:420
AV_CODEC_FLAG_RECON_FRAME
#define AV_CODEC_FLAG_RECON_FRAME
Request the encoder to output reconstructed frames, i.e. frames that would be produced by decoding th...
Definition: avcodec.h:264
i
#define i(width, name, range_min, range_max)
Definition: cbs_h2645.c:255
AVPacket::pts
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:515
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
AVFrame::top_field_first
attribute_deprecated int top_field_first
If the content is interlaced, is top field displayed first.
Definition: frame.h:538
internal.h
AVFrame::extended_data
uint8_t ** extended_data
pointers to the data planes/channels.
Definition: frame.h:401
EncodeContext::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: encode.c:47
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:52
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:649
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:107
av_frame_unref
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:622
av_mallocz
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:254
av_buffer_replace
int av_buffer_replace(AVBufferRef **pdst, const AVBufferRef *src)
Ensure dst refers to the same data as src.
Definition: buffer.c:233
profile
int profile
Definition: mxfenc.c:2226
AVCodecContext::height
int height
Definition: avcodec.h:625
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:518
AVCodecContext::pix_fmt
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:662
AV_FRAME_FLAG_INTERLACED
#define AV_FRAME_FLAG_INTERLACED
A flag to mark frames whose content is interlaced.
Definition: frame.h:636
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:1944
avcodec.h
AVHWFramesContext
This struct describes a set or pool of "hardware" frames (i.e.
Definition: hwcontext.h:125
AVCodecContext::frame_num
int64_t frame_num
Frame counter, set by libavcodec.
Definition: avcodec.h:2122
ret
ret
Definition: filter_design.txt:187
ff_encode_flush_buffers
void ff_encode_flush_buffers(AVCodecContext *avctx)
Definition: encode.c:855
AVPacket::side_data
AVPacketSideData * side_data
Additional packet data that can be provided by the container.
Definition: packet.h:533
AVCodecInternal::recon_frame
AVFrame * recon_frame
When the AV_CODEC_FLAG_RECON_FRAME flag is used.
Definition: internal.h:105
AV_INPUT_BUFFER_PADDING_SIZE
#define AV_INPUT_BUFFER_PADDING_SIZE
Definition: defs.h:40
AVCodecContext
main external API structure.
Definition: avcodec.h:445
AVFrame::height
int height
Definition: frame.h:412
channel_layout.h
avcodec_internal.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:105
AVRational::den
int den
Denominator.
Definition: rational.h:60
AV_PIX_FMT_NONE
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:72
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:60
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:2103
encode_simple_receive_packet
static int encode_simple_receive_packet(AVCodecContext *avctx, AVPacket *avpkt)
Definition: encode.c:359
AVPixFmtDescriptor::comp
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:105
AVCodecContext::ticks_per_frame
attribute_deprecated int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
Definition: avcodec.h:583
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:76
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:143
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:132
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:669
AVCodecInternal::draining
int draining
checks API usage: after codec draining, flush is required to resume operation
Definition: internal.h:126
FF_DISABLE_DEPRECATION_WARNINGS
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:72
AVCodecContext::coded_width
int coded_width
Bitstream width / height, may be different from width/height e.g.
Definition: avcodec.h:640
AVCodecContext::codec_type
enum AVMediaType codec_type
Definition: avcodec.h:453
AVMEDIA_TYPE_VIDEO
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
encode_preinit_audio
static int encode_preinit_audio(AVCodecContext *avctx)
Definition: encode.c:661
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:209
AVFrameSideData
Structure to hold side data for an AVFrame.
Definition: frame.h:246
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:499
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:83
av_freep
#define av_freep(p)
Definition: tableprint_vlc.h:34
src
INIT_CLIP pixel * src
Definition: h264pred_template.c:418
AVCodecContext::width
int width
picture width / height.
Definition: avcodec.h:625
encode_generate_icc_profile
static int encode_generate_icc_profile(av_unused AVCodecContext *c, av_unused AVFrame *f)
Definition: encode.c:449
imgutils.h
AVCodecContext::frame_number
attribute_deprecated int frame_number
Frame counter, set by libavcodec.
Definition: avcodec.h:1110
flags
#define flags(name, subs,...)
Definition: cbs_av1.c:474
av_log
#define av_log(a,...)
Definition: tableprint_vlc.h:27
ff_encode_add_cpb_side_data
AVCPBProperties * ff_encode_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
Definition: encode.c:870
AVCodecContext::sw_pix_fmt
enum AVPixelFormat sw_pix_fmt
Nominal unaccelerated pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1814
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:81
codec_desc.h
ff_alloc_packet
int ff_alloc_packet(AVCodecContext *avctx, AVPacket *avpkt, int64_t size)
Check AVPacket size and allocate data.
Definition: encode.c:61
AVSubtitle::start_display_time
uint32_t start_display_time
Definition: avcodec.h:2275
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:2888
av_cpb_properties_alloc
AVCPBProperties * av_cpb_properties_alloc(size_t *size)
Allocate a CPB properties structure and initialize its fields to default values.
Definition: utils.c:996
AV_CODEC_FLAG_PASS1
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition: avcodec.h:310