FFmpeg  4.4.9
libsvtav1.c
Go to the documentation of this file.
1 /*
2  * Scalable Video Technology for AV1 encoder library plugin
3  *
4  * Copyright (c) 2018 Intel Corporation
5  *
6  * This file is part of FFmpeg.
7  *
8  * FFmpeg is free software; you can redistribute it and/or
9  * modify it under the terms of the GNU Lesser General Public
10  * License as published by the Free Software Foundation; either
11  * version 2.1 of the License, or (at your option) any later version.
12  *
13  * FFmpeg is distributed in the hope that it will be useful,
14  * but WITHOUT ANY WARRANTY; without even the implied warranty of
15  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
16  * Lesser General Public License for more details.
17  *
18  * You should have received a copy of the GNU Lesser General Public
19  * License along with this program; if not, write to the Free Software
20  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21  */
22 
23 #include <stdint.h>
24 #include <EbSvtAv1ErrorCodes.h>
25 #include <EbSvtAv1Enc.h>
26 
27 #include "libavutil/common.h"
28 #include "libavutil/frame.h"
29 #include "libavutil/imgutils.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/pixdesc.h"
32 #include "libavutil/avassert.h"
33 
34 #include "internal.h"
35 #include "encode.h"
36 #include "packet_internal.h"
37 #include "avcodec.h"
38 #include "profiles.h"
39 
40 #ifndef SVT_AV1_CHECK_VERSION
41 #define SVT_AV1_CHECK_VERSION(major, minor, patch) 0
42 #endif
43 
44 typedef enum eos_status {
49 
50 typedef struct SvtContext {
51  const AVClass *class;
52 
53  EbSvtAv1EncConfiguration enc_params;
54  EbComponentType *svt_handle;
55 
56  EbBufferHeaderType *in_buf;
57  int raw_size;
59 
61 
63 
65 
66  // User options.
68  int la_depth;
69  int enc_mode;
70  int rc_mode;
71  int scd;
72  int qp;
73 
74  int tier;
75 
77  int tile_rows;
78 } SvtContext;
79 
80 static const struct {
81  EbErrorType eb_err;
82  int av_err;
83  const char *desc;
84 } svt_errors[] = {
85  { EB_ErrorNone, 0, "success" },
86  { EB_ErrorInsufficientResources, AVERROR(ENOMEM), "insufficient resources" },
87  { EB_ErrorUndefined, AVERROR(EINVAL), "undefined error" },
88  { EB_ErrorInvalidComponent, AVERROR(EINVAL), "invalid component" },
89  { EB_ErrorBadParameter, AVERROR(EINVAL), "bad parameter" },
90  { EB_ErrorDestroyThreadFailed, AVERROR_EXTERNAL, "failed to destroy thread" },
91  { EB_ErrorSemaphoreUnresponsive, AVERROR_EXTERNAL, "semaphore unresponsive" },
92  { EB_ErrorDestroySemaphoreFailed, AVERROR_EXTERNAL, "failed to destroy semaphore"},
93  { EB_ErrorCreateMutexFailed, AVERROR_EXTERNAL, "failed to create mutex" },
94  { EB_ErrorMutexUnresponsive, AVERROR_EXTERNAL, "mutex unresponsive" },
95  { EB_ErrorDestroyMutexFailed, AVERROR_EXTERNAL, "failed to destroy mutex" },
96  { EB_NoErrorEmptyQueue, AVERROR(EAGAIN), "empty queue" },
97 };
98 
99 static int svt_map_error(EbErrorType eb_err, const char **desc)
100 {
101  int i;
102 
103  av_assert0(desc);
104  for (i = 0; i < FF_ARRAY_ELEMS(svt_errors); i++) {
105  if (svt_errors[i].eb_err == eb_err) {
106  *desc = svt_errors[i].desc;
107  return svt_errors[i].av_err;
108  }
109  }
110  *desc = "unknown error";
111  return AVERROR_UNKNOWN;
112 }
113 
114 static int svt_print_error(void *log_ctx, EbErrorType err,
115  const char *error_string)
116 {
117  const char *desc;
118  int ret = svt_map_error(err, &desc);
119 
120  av_log(log_ctx, AV_LOG_ERROR, "%s: %s (0x%x)\n", error_string, desc, err);
121 
122  return ret;
123 }
124 
125 static int alloc_buffer(EbSvtAv1EncConfiguration *config, SvtContext *svt_enc)
126 {
127  const size_t luma_size = config->source_width * config->source_height *
128  (config->encoder_bit_depth > 8 ? 2 : 1);
129 
130  EbSvtIOFormat *in_data;
131 
132  svt_enc->raw_size = luma_size * 3 / 2;
133 
134  // allocate buffer for in and out
135  svt_enc->in_buf = av_mallocz(sizeof(*svt_enc->in_buf));
136  if (!svt_enc->in_buf)
137  return AVERROR(ENOMEM);
138 
139  svt_enc->in_buf->p_buffer = av_mallocz(sizeof(*in_data));
140  if (!svt_enc->in_buf->p_buffer)
141  return AVERROR(ENOMEM);
142 
143  svt_enc->in_buf->size = sizeof(*svt_enc->in_buf);
144 
145  return 0;
146 
147 }
148 
149 static int config_enc_params(EbSvtAv1EncConfiguration *param,
150  AVCodecContext *avctx)
151 {
152  SvtContext *svt_enc = avctx->priv_data;
153  const AVPixFmtDescriptor *desc;
154 
155  param->source_width = avctx->width;
156  param->source_height = avctx->height;
157 
158  desc = av_pix_fmt_desc_get(avctx->pix_fmt);
159  param->encoder_bit_depth = desc->comp[0].depth;
160 
161  if (desc->log2_chroma_w == 1 && desc->log2_chroma_h == 1)
162  param->encoder_color_format = EB_YUV420;
163  else if (desc->log2_chroma_w == 1 && desc->log2_chroma_h == 0)
164  param->encoder_color_format = EB_YUV422;
165  else if (!desc->log2_chroma_w && !desc->log2_chroma_h)
166  param->encoder_color_format = EB_YUV444;
167  else {
168  av_log(avctx, AV_LOG_ERROR , "Unsupported pixel format\n");
169  return AVERROR(EINVAL);
170  }
171 
172  if (avctx->profile != FF_PROFILE_UNKNOWN)
173  param->profile = avctx->profile;
174 
175  if (avctx->level != FF_LEVEL_UNKNOWN)
176  param->level = avctx->level;
177 
178  if ((param->encoder_color_format == EB_YUV422 || param->encoder_bit_depth > 10)
179  && param->profile != FF_PROFILE_AV1_PROFESSIONAL ) {
180  av_log(avctx, AV_LOG_WARNING, "Forcing Professional profile\n");
181  param->profile = FF_PROFILE_AV1_PROFESSIONAL;
182  } else if (param->encoder_color_format == EB_YUV444 && param->profile != FF_PROFILE_AV1_HIGH) {
183  av_log(avctx, AV_LOG_WARNING, "Forcing High profile\n");
184  param->profile = FF_PROFILE_AV1_HIGH;
185  }
186 
187  // Update param from options
188  param->hierarchical_levels = svt_enc->hierarchical_level;
189  param->enc_mode = svt_enc->enc_mode;
190  param->tier = svt_enc->tier;
191  param->rate_control_mode = svt_enc->rc_mode;
192  param->scene_change_detection = svt_enc->scd;
193  param->qp = svt_enc->qp;
194 
195  param->target_bit_rate = avctx->bit_rate;
196 
197  if (avctx->gop_size > 0)
198  param->intra_period_length = avctx->gop_size - 1;
199 
200  if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
201  param->frame_rate_numerator = avctx->framerate.num;
202  param->frame_rate_denominator = avctx->framerate.den;
203  } else {
204  param->frame_rate_numerator = avctx->time_base.den;
205  param->frame_rate_denominator = avctx->time_base.num * avctx->ticks_per_frame;
206  }
207 
208  if (param->rate_control_mode) {
209  param->max_qp_allowed = avctx->qmax;
210  param->min_qp_allowed = avctx->qmin;
211  }
212 
213  param->intra_refresh_type = 2; /* Real keyframes only */
214 
215  if (svt_enc->la_depth >= 0)
216  param->look_ahead_distance = svt_enc->la_depth;
217 
218  param->tile_columns = svt_enc->tile_columns;
219  param->tile_rows = svt_enc->tile_rows;
220 
221  return 0;
222 }
223 
224 static int read_in_data(EbSvtAv1EncConfiguration *param, const AVFrame *frame,
225  EbBufferHeaderType *header_ptr)
226 {
227  EbSvtIOFormat *in_data = (EbSvtIOFormat *)header_ptr->p_buffer;
228  ptrdiff_t linesizes[4];
229  size_t sizes[4];
230  int bytes_shift = param->encoder_bit_depth > 8 ? 1 : 0;
231  int ret, frame_size;
232 
233  for (int i = 0; i < 4; i++)
234  linesizes[i] = frame->linesize[i];
235 
237  linesizes);
238  if (ret < 0)
239  return ret;
240 
241  frame_size = 0;
242  for (int i = 0; i < 4; i++) {
243  if (sizes[i] > INT_MAX - frame_size)
244  return AVERROR(EINVAL);
245  frame_size += sizes[i];
246  }
247 
248  in_data->luma = frame->data[0];
249  in_data->cb = frame->data[1];
250  in_data->cr = frame->data[2];
251 
252  in_data->y_stride = AV_CEIL_RSHIFT(frame->linesize[0], bytes_shift);
253  in_data->cb_stride = AV_CEIL_RSHIFT(frame->linesize[1], bytes_shift);
254  in_data->cr_stride = AV_CEIL_RSHIFT(frame->linesize[2], bytes_shift);
255 
256  header_ptr->n_filled_len = frame_size;
257 
258  return 0;
259 }
260 
262 {
263  SvtContext *svt_enc = avctx->priv_data;
264  EbErrorType svt_ret;
265  int ret;
266 
267  svt_enc->eos_flag = EOS_NOT_REACHED;
268 
269 #if SVT_AV1_CHECK_VERSION(3, 0, 0)
270  svt_ret = svt_av1_enc_init_handle(&svt_enc->svt_handle, &svt_enc->enc_params);
271 #else
272  svt_ret = svt_av1_enc_init_handle(&svt_enc->svt_handle, svt_enc, &svt_enc->enc_params);
273 #endif
274  if (svt_ret != EB_ErrorNone) {
275  return svt_print_error(avctx, svt_ret, "Error initializing encoder handle");
276  }
277 
278  ret = config_enc_params(&svt_enc->enc_params, avctx);
279  if (ret < 0) {
280  av_log(avctx, AV_LOG_ERROR, "Error configuring encoder parameters\n");
281  return ret;
282  }
283 
284  svt_ret = svt_av1_enc_set_parameter(svt_enc->svt_handle, &svt_enc->enc_params);
285  if (svt_ret != EB_ErrorNone) {
286  return svt_print_error(avctx, svt_ret, "Error setting encoder parameters");
287  }
288 
289  svt_ret = svt_av1_enc_init(svt_enc->svt_handle);
290  if (svt_ret != EB_ErrorNone) {
291  return svt_print_error(avctx, svt_ret, "Error initializing encoder");
292  }
293 
294  if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
295  EbBufferHeaderType *headerPtr = NULL;
296 
297  svt_ret = svt_av1_enc_stream_header(svt_enc->svt_handle, &headerPtr);
298  if (svt_ret != EB_ErrorNone) {
299  return svt_print_error(avctx, svt_ret, "Error building stream header");
300  }
301 
302  avctx->extradata_size = headerPtr->n_filled_len;
304  if (!avctx->extradata) {
305  av_log(avctx, AV_LOG_ERROR,
306  "Cannot allocate AV1 header of size %d.\n", avctx->extradata_size);
307  return AVERROR(ENOMEM);
308  }
309 
310  memcpy(avctx->extradata, headerPtr->p_buffer, avctx->extradata_size);
311 
312  svt_ret = svt_av1_enc_stream_header_release(headerPtr);
313  if (svt_ret != EB_ErrorNone) {
314  return svt_print_error(avctx, svt_ret, "Error freeing stream header");
315  }
316  }
317 
318  svt_enc->frame = av_frame_alloc();
319  if (!svt_enc->frame)
320  return AVERROR(ENOMEM);
321 
322  return alloc_buffer(&svt_enc->enc_params, svt_enc);
323 }
324 
325 static int eb_send_frame(AVCodecContext *avctx, const AVFrame *frame)
326 {
327  SvtContext *svt_enc = avctx->priv_data;
328  EbBufferHeaderType *headerPtr = svt_enc->in_buf;
329  EbErrorType svt_ret;
330  int ret;
331 
332  if (!frame) {
333  EbBufferHeaderType headerPtrLast;
334 
335  if (svt_enc->eos_flag == EOS_SENT)
336  return 0;
337 
338  memset(&headerPtrLast, 0, sizeof(headerPtrLast));
339  headerPtrLast.pic_type = EB_AV1_INVALID_PICTURE;
340  headerPtrLast.flags = EB_BUFFERFLAG_EOS;
341 
342  svt_av1_enc_send_picture(svt_enc->svt_handle, &headerPtrLast);
343  svt_enc->eos_flag = EOS_SENT;
344  return 0;
345  }
346 
347  ret = read_in_data(&svt_enc->enc_params, frame, headerPtr);
348  if (ret < 0)
349  return ret;
350 
351  headerPtr->flags = 0;
352  headerPtr->p_app_private = NULL;
353  headerPtr->pts = frame->pts;
354 
355  svt_ret = svt_av1_enc_send_picture(svt_enc->svt_handle, headerPtr);
356  if (svt_ret != EB_ErrorNone)
357  return svt_print_error(avctx, svt_ret, "Error sending a frame to encoder");
358 
359  return 0;
360 }
361 
362 static AVBufferRef *get_output_ref(AVCodecContext *avctx, SvtContext *svt_enc, int filled_len)
363 {
364  if (filled_len > svt_enc->max_tu_size) {
365  const int max_frames = 8;
366  int max_tu_size;
367 
368  if (filled_len > svt_enc->raw_size * max_frames) {
369  av_log(avctx, AV_LOG_ERROR, "TU size > %d raw frame size.\n", max_frames);
370  return NULL;
371  }
372 
373  max_tu_size = 1 << av_ceil_log2(filled_len);
374  av_buffer_pool_uninit(&svt_enc->pool);
375  svt_enc->pool = av_buffer_pool_init(max_tu_size + AV_INPUT_BUFFER_PADDING_SIZE, NULL);
376  if (!svt_enc->pool)
377  return NULL;
378 
379  svt_enc->max_tu_size = max_tu_size;
380  }
381  av_assert0(svt_enc->pool);
382 
383  return av_buffer_pool_get(svt_enc->pool);
384 }
385 
387 {
388  SvtContext *svt_enc = avctx->priv_data;
389  EbBufferHeaderType *headerPtr;
390  AVFrame *frame = svt_enc->frame;
391  EbErrorType svt_ret;
392  AVBufferRef *ref;
393  int ret = 0, pict_type;
394 
395  if (svt_enc->eos_flag == EOS_RECEIVED)
396  return AVERROR_EOF;
397 
398  ret = ff_encode_get_frame(avctx, frame);
399  if (ret < 0 && ret != AVERROR_EOF)
400  return ret;
401  if (ret == AVERROR_EOF)
402  frame = NULL;
403 
404  ret = eb_send_frame(avctx, frame);
405  av_frame_unref(svt_enc->frame);
406  if (ret < 0)
407  return ret;
408 
409  svt_ret = svt_av1_enc_get_packet(svt_enc->svt_handle, &headerPtr, svt_enc->eos_flag);
410  if (svt_ret == EB_NoErrorEmptyQueue)
411  return AVERROR(EAGAIN);
412  else if (svt_ret != EB_ErrorNone)
413  return svt_print_error(avctx, svt_ret, "Error getting an output packet from encoder");
414 
415  ref = get_output_ref(avctx, svt_enc, headerPtr->n_filled_len);
416  if (!ref) {
417  av_log(avctx, AV_LOG_ERROR, "Failed to allocate output packet.\n");
418  svt_av1_enc_release_out_buffer(&headerPtr);
419  return AVERROR(ENOMEM);
420  }
421  pkt->buf = ref;
422  pkt->data = ref->data;
423 
424  memcpy(pkt->data, headerPtr->p_buffer, headerPtr->n_filled_len);
425  memset(pkt->data + headerPtr->n_filled_len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
426 
427  pkt->size = headerPtr->n_filled_len;
428  pkt->pts = headerPtr->pts;
429  pkt->dts = headerPtr->dts;
430 
431  switch (headerPtr->pic_type) {
432  case EB_AV1_KEY_PICTURE:
434  // fall-through
435  case EB_AV1_INTRA_ONLY_PICTURE:
436  pict_type = AV_PICTURE_TYPE_I;
437  break;
438  case EB_AV1_INVALID_PICTURE:
439  pict_type = AV_PICTURE_TYPE_NONE;
440  break;
441  default:
442  pict_type = AV_PICTURE_TYPE_P;
443  break;
444  }
445 
446  if (headerPtr->pic_type == EB_AV1_NON_REF_PICTURE)
448 
449  if (headerPtr->flags & EB_BUFFERFLAG_EOS)
450  svt_enc->eos_flag = EOS_RECEIVED;
451 
452  ff_side_data_set_encoder_stats(pkt, headerPtr->qp * FF_QP2LAMBDA, NULL, 0, pict_type);
453 
454  svt_av1_enc_release_out_buffer(&headerPtr);
455 
456  return 0;
457 }
458 
460 {
461  SvtContext *svt_enc = avctx->priv_data;
462 
463  if (svt_enc->svt_handle) {
464  svt_av1_enc_deinit(svt_enc->svt_handle);
465  svt_av1_enc_deinit_handle(svt_enc->svt_handle);
466  }
467  if (svt_enc->in_buf) {
468  av_free(svt_enc->in_buf->p_buffer);
469  av_freep(&svt_enc->in_buf);
470  }
471 
472  av_buffer_pool_uninit(&svt_enc->pool);
473  av_frame_free(&svt_enc->frame);
474 
475  return 0;
476 }
477 
478 #define OFFSET(x) offsetof(SvtContext, x)
479 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
480 static const AVOption options[] = {
481  { "hielevel", "Hierarchical prediction levels setting", OFFSET(hierarchical_level),
482  AV_OPT_TYPE_INT, { .i64 = 4 }, 3, 4, VE , "hielevel"},
483  { "3level", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 3 }, INT_MIN, INT_MAX, VE, "hielevel" },
484  { "4level", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 4 }, INT_MIN, INT_MAX, VE, "hielevel" },
485 
486  { "la_depth", "Look ahead distance [0, 120]", OFFSET(la_depth),
487  AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 120, VE },
488 
489  { "preset", "Encoding preset [0, 8]",
490  OFFSET(enc_mode), AV_OPT_TYPE_INT, { .i64 = MAX_ENC_PRESET }, 0, MAX_ENC_PRESET, VE },
491 
492  { "tier", "Set operating point tier", OFFSET(tier),
493  AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 1, VE, "tier" },
494  { "main", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, 0, 0, VE, "tier" },
495  { "high", NULL, 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, 0, 0, VE, "tier" },
496 
498 
499 #define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
500  { .i64 = value }, 0, 0, VE, "avctx.level"
501  { LEVEL("2.0", 20) },
502  { LEVEL("2.1", 21) },
503  { LEVEL("2.2", 22) },
504  { LEVEL("2.3", 23) },
505  { LEVEL("3.0", 30) },
506  { LEVEL("3.1", 31) },
507  { LEVEL("3.2", 32) },
508  { LEVEL("3.3", 33) },
509  { LEVEL("4.0", 40) },
510  { LEVEL("4.1", 41) },
511  { LEVEL("4.2", 42) },
512  { LEVEL("4.3", 43) },
513  { LEVEL("5.0", 50) },
514  { LEVEL("5.1", 51) },
515  { LEVEL("5.2", 52) },
516  { LEVEL("5.3", 53) },
517  { LEVEL("6.0", 60) },
518  { LEVEL("6.1", 61) },
519  { LEVEL("6.2", 62) },
520  { LEVEL("6.3", 63) },
521  { LEVEL("7.0", 70) },
522  { LEVEL("7.1", 71) },
523  { LEVEL("7.2", 72) },
524  { LEVEL("7.3", 73) },
525 #undef LEVEL
526 
527  { "rc", "Bit rate control mode", OFFSET(rc_mode),
528  AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 2, VE , "rc"},
529  { "cqp", "Constant quantizer", 0, AV_OPT_TYPE_CONST, { .i64 = 0 }, INT_MIN, INT_MAX, VE, "rc" },
530  { "vbr", "Variable Bit Rate, use a target bitrate for the entire stream", 0, AV_OPT_TYPE_CONST, { .i64 = 1 }, INT_MIN, INT_MAX, VE, "rc" },
531  { "cvbr", "Constrained Variable Bit Rate, use a target bitrate for each GOP", 0, AV_OPT_TYPE_CONST,{ .i64 = 2 }, INT_MIN, INT_MAX, VE, "rc" },
532 
533  { "qp", "Quantizer to use with cqp rate control mode", OFFSET(qp),
534  AV_OPT_TYPE_INT, { .i64 = 50 }, 0, 63, VE },
535 
536  { "sc_detection", "Scene change detection", OFFSET(scd),
537  AV_OPT_TYPE_BOOL, { .i64 = 0 }, 0, 1, VE },
538 
539  { "tile_columns", "Log2 of number of tile columns to use", OFFSET(tile_columns), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 4, VE},
540  { "tile_rows", "Log2 of number of tile rows to use", OFFSET(tile_rows), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 6, VE},
541 
542  {NULL},
543 };
544 
545 static const AVClass class = {
546  .class_name = "libsvtav1",
547  .item_name = av_default_item_name,
548  .option = options,
550 };
551 
552 static const AVCodecDefault eb_enc_defaults[] = {
553  { "b", "7M" },
554  { "g", "-1" },
555  { "qmin", "0" },
556  { "qmax", "63" },
557  { NULL },
558 };
559 
561  .name = "libsvtav1",
562  .long_name = NULL_IF_CONFIG_SMALL("SVT-AV1(Scalable Video Technology for AV1) encoder"),
563  .priv_data_size = sizeof(SvtContext),
565  .id = AV_CODEC_ID_AV1,
566  .init = eb_enc_init,
567  .receive_packet = eb_receive_packet,
568  .close = eb_enc_close,
571  .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P,
573  AV_PIX_FMT_NONE },
574  .priv_class = &class,
575  .defaults = eb_enc_defaults,
576  .wrapper_name = "libsvtav1",
577 };
#define av_cold
Definition: attributes.h:88
simple assert() macros that are a bit more flexible than ISO C assert().
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
Libavcodec external API header.
#define FF_PROFILE_UNKNOWN
Definition: avcodec.h:1863
#define FF_LEVEL_UNKNOWN
Definition: avcodec.h:1989
#define FF_PROFILE_AV1_HIGH
Definition: avcodec.h:1959
#define FF_PROFILE_AV1_PROFESSIONAL
Definition: avcodec.h:1960
int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type)
Definition: avpacket.c:820
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:31
common internal and external API header
#define AV_CEIL_RSHIFT(a, b)
Definition: common.h:58
#define av_ceil_log2
Definition: common.h:119
#define NULL
Definition: coverity.c:32
static AVFrame * frame
int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame)
Called by encoders to get the next frame for encoding.
Definition: encode.c:162
reference-counted frame API
@ AV_OPT_TYPE_CONST
Definition: opt.h:234
@ AV_OPT_TYPE_INT
Definition: opt.h:225
@ AV_OPT_TYPE_BOOL
Definition: opt.h:242
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
Definition: codec.h:122
#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:77
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
Definition: avcodec.h:329
@ AV_CODEC_ID_AV1
Definition: codec_id.h:279
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Definition: avcodec.h:215
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:410
#define AV_PKT_FLAG_DISPOSABLE
Flag is used to indicate packets that contain frames that can be discarded by the decoder.
Definition: packet.h:429
AVBufferPool * av_buffer_pool_init(buffer_size_t size, AVBufferRef *(*alloc)(buffer_size_t size))
Allocate and initialize a buffer pool.
Definition: buffer.c:269
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
Definition: buffer.c:379
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
Definition: buffer.c:314
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
Definition: avutil.h:227
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:57
#define AVERROR_EOF
End of file.
Definition: error.h:55
#define AVERROR(e)
Definition: error.h:43
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:553
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:190
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
void * av_mallocz(size_t size)
Allocate a memory block with alignment suitable for all memory accesses (including vectors if availab...
Definition: mem.c:237
@ AVMEDIA_TYPE_VIDEO
Definition: avutil.h:201
int av_image_fill_plane_sizes(size_t sizes[4], enum AVPixelFormat pix_fmt, int height, const ptrdiff_t linesizes[4])
Fill plane sizes for an image with pixel format pix_fmt and height height.
Definition: imgutils.c:111
@ AV_PICTURE_TYPE_I
Intra.
Definition: avutil.h:274
@ AV_PICTURE_TYPE_NONE
Undefined.
Definition: avutil.h:273
@ AV_PICTURE_TYPE_P
Predicted.
Definition: avutil.h:275
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
for(j=16;j >0;--j)
int tile_rows
Definition: h265_levels.c:217
cl_device_type type
static const int sizes[][2]
Definition: img2dec.c:54
misc image utilities
int i
Definition: input.c:407
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
Definition: internal.h:49
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
Definition: internal.h:80
common internal API header
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification.
Definition: internal.h:117
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:309
static int config_enc_params(EbSvtAv1EncConfiguration *param, AVCodecContext *avctx)
Definition: libsvtav1.c:149
static int eb_send_frame(AVCodecContext *avctx, const AVFrame *frame)
Definition: libsvtav1.c:325
EOS_STATUS
Definition: libsvtav1.c:44
@ EOS_SENT
Definition: libsvtav1.c:46
@ EOS_NOT_REACHED
Definition: libsvtav1.c:45
@ EOS_RECEIVED
Definition: libsvtav1.c:47
EbErrorType eb_err
Definition: libsvtav1.c:81
static int svt_print_error(void *log_ctx, EbErrorType err, const char *error_string)
Definition: libsvtav1.c:114
static int alloc_buffer(EbSvtAv1EncConfiguration *config, SvtContext *svt_enc)
Definition: libsvtav1.c:125
static const AVCodecDefault eb_enc_defaults[]
Definition: libsvtav1.c:552
static const AVOption options[]
Definition: libsvtav1.c:480
#define VE
Definition: libsvtav1.c:479
static int svt_map_error(EbErrorType eb_err, const char **desc)
Definition: libsvtav1.c:99
static int eb_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
Definition: libsvtav1.c:386
static av_cold int eb_enc_init(AVCodecContext *avctx)
Definition: libsvtav1.c:261
static const struct @85 svt_errors[]
const char * desc
Definition: libsvtav1.c:83
#define LEVEL(name, value)
int av_err
Definition: libsvtav1.c:82
static int read_in_data(EbSvtAv1EncConfiguration *param, const AVFrame *frame, EbBufferHeaderType *header_ptr)
Definition: libsvtav1.c:224
#define OFFSET(x)
Definition: libsvtav1.c:478
static av_cold int eb_enc_close(AVCodecContext *avctx)
Definition: libsvtav1.c:459
AVCodec ff_libsvtav1_encoder
Definition: libsvtav1.c:560
static AVBufferRef * get_output_ref(AVCodecContext *avctx, SvtContext *svt_enc, int filled_len)
Definition: libsvtav1.c:362
int frame_size
Definition: mxfenc.c:2206
AVOptions.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2573
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:399
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
@ AV_PIX_FMT_NONE
Definition: pixfmt.h:65
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
#define FF_AV1_PROFILE_OPTS
Definition: profiles.h:54
mfxU16 rc_mode
Definition: qsvenc.c:84
#define FF_ARRAY_ELEMS(a)
The buffer pool.
A reference to a data buffer.
Definition: buffer.h:84
Describe the class of an AVClass context structure.
Definition: log.h:67
const char * class_name
The name of the class; usually it is the same name as the context structure type to which the AVClass...
Definition: log.h:72
main external API structure.
Definition: avcodec.h:536
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:746
int width
picture width / height.
Definition: avcodec.h:709
int qmin
minimum quantizer
Definition: avcodec.h:1384
AVRational framerate
Definition: avcodec.h:2075
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
Definition: avcodec.h:668
int level
level
Definition: avcodec.h:1988
int64_t bit_rate
the average bitrate
Definition: avcodec.h:586
int profile
profile
Definition: avcodec.h:1862
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition: avcodec.h:731
int qmax
maximum quantizer
Definition: avcodec.h:1391
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition: avcodec.h:659
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:616
uint8_t * extradata
some codecs need / can use extradata like Huffman tables.
Definition: avcodec.h:637
int extradata_size
Definition: avcodec.h:638
void * priv_data
Definition: avcodec.h:563
AVCodec.
Definition: codec.h:197
const char * name
Name of the codec implementation.
Definition: codec.h:204
This structure describes decoded (raw) audio or video data.
Definition: frame.h:318
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:411
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:332
int height
Definition: frame.h:376
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:349
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames,...
Definition: frame.h:391
AVOption.
Definition: opt.h:248
This structure stores compressed data.
Definition: packet.h:346
AVBufferRef * buf
A reference to the reference-counted buffer where the packet data is stored.
Definition: packet.h:352
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:375
int size
Definition: packet.h:370
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:362
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed.
Definition: packet.h:368
uint8_t * data
Definition: packet.h:369
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
int num
Numerator.
Definition: rational.h:59
int den
Denominator.
Definition: rational.h:60
AVBufferPool * pool
Definition: libsvtav1.c:62
EbComponentType * svt_handle
Definition: libsvtav1.c:54
EbBufferHeaderType * in_buf
Definition: libsvtav1.c:56
AVFrame * frame
Definition: libsvtav1.c:60
int tile_columns
Definition: libsvtav1.c:76
int la_depth
Definition: libsvtav1.c:68
int raw_size
Definition: libsvtav1.c:57
EOS_STATUS eos_flag
Definition: libsvtav1.c:64
int hierarchical_level
Definition: libsvtav1.c:67
EbSvtAv1EncConfiguration enc_params
Definition: libsvtav1.c:53
int tile_rows
Definition: libsvtav1.c:77
int enc_mode
Definition: libsvtav1.c:69
int tier
Definition: libsvtav1.c:74
int rc_mode
Definition: libsvtav1.c:70
int max_tu_size
Definition: libsvtav1.c:58
#define av_free(p)
#define av_freep(p)
#define av_log(a,...)
static int ref[MAX_W *MAX_W]
Definition: jpeg2000dwt.c:107
AVPacket * pkt
Definition: movenc.c:59