FFmpeg
Loading...
Searching...
No Matches
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 <inttypes.h>
25#include <EbSvtAv1ErrorCodes.h>
26#include <EbSvtAv1Enc.h>
27#include <EbSvtAv1Metadata.h>
28
30#include "libavutil/common.h"
31#include "libavutil/frame.h"
32#include "libavutil/imgutils.h"
33#include "libavutil/base64.h"
36#include "libavutil/mem.h"
37#include "libavutil/opt.h"
38#include "libavutil/pixdesc.h"
39#include "libavutil/avassert.h"
40
41#include "codec_internal.h"
42#include "dovi_rpu.h"
43#include "encode.h"
44#include "avcodec.h"
45#include "profiles.h"
46
47typedef enum eos_status {
52
53typedef struct SvtContext {
54 const AVClass *class;
55
56 EbSvtAv1EncConfiguration enc_params;
57 EbComponentType *svt_handle;
58
59 EbBufferHeaderType *in_buf;
62
64
66
68
70
71 uint8_t *stats_buf;
72
73 // User options.
76 int crf;
77 int qp;
79
80static 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
99static int svt_map_error(EbErrorType eb_err, const char **desc)
100{
101 int i;
102
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
114static 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
125static 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
149static void handle_mdcv(struct EbSvtAv1MasteringDisplayInfo *dst,
150 const AVMasteringDisplayMetadata *mdcv)
151{
152 if (mdcv->has_primaries) {
153 const struct EbSvtAv1ChromaPoints *const points[] = {
154 &dst->r,
155 &dst->g,
156 &dst->b,
157 };
158
159 for (int i = 0; i < 3; i++) {
160 const struct EbSvtAv1ChromaPoints *dst = points[i];
161 const AVRational *src = mdcv->display_primaries[i];
162
163 AV_WB16(&dst->x,
164 av_rescale_q(1, src[0], (AVRational){ 1, (1 << 16) }));
165 AV_WB16(&dst->y,
166 av_rescale_q(1, src[1], (AVRational){ 1, (1 << 16) }));
167 }
168
169 AV_WB16(&dst->white_point.x,
170 av_rescale_q(1, mdcv->white_point[0],
171 (AVRational){ 1, (1 << 16) }));
172 AV_WB16(&dst->white_point.y,
173 av_rescale_q(1, mdcv->white_point[1],
174 (AVRational){ 1, (1 << 16) }));
175 }
176
177 if (mdcv->has_luminance) {
178 AV_WB32(&dst->max_luma,
180 (AVRational){ 1, (1 << 8) }));
181 AV_WB32(&dst->min_luma,
183 (AVRational){ 1, (1 << 14) }));
184 }
185}
186
188 EbSvtAv1EncConfiguration *param)
189{
190 const AVFrameSideData *cll_sd =
193 const AVFrameSideData *mdcv_sd =
197
198 if (cll_sd) {
199 const AVContentLightMetadata *cll =
200 (AVContentLightMetadata *)cll_sd->data;
201
202 AV_WB16(&param->content_light_level.max_cll, cll->MaxCLL);
203 AV_WB16(&param->content_light_level.max_fall, cll->MaxFALL);
204 }
205
206 if (mdcv_sd) {
207 handle_mdcv(&param->mastering_display,
208 (AVMasteringDisplayMetadata *)mdcv_sd->data);
209 }
210}
211
212static int config_enc_params(EbSvtAv1EncConfiguration *param,
213 AVCodecContext *avctx)
214{
215 SvtContext *svt_enc = avctx->priv_data;
217 av_unused const AVDictionaryEntry *en = NULL;
218
219#if !SVT_AV1_CHECK_VERSION(3, 0, 0)
220 // SVT-AV1 < 3.0.0 requires input dimensions of at least 64x64. Reject
221 // smaller inputs explicitly here to produce a clear error rather than
222 // relying on the library's internal validation, which may silently fail
223 // to produce output and cause the caller to hang.
224 // Sub-64px inputs were enabled upstream in MR !2356 (first released in
225 // v3.0.0); for those versions the library validates the dimensions
226 // itself.
227 if (avctx->width < 64 || avctx->height < 64) {
228 av_log(avctx, AV_LOG_ERROR,
229 "Input dimensions %dx%d are smaller than the minimum 64x64 "
230 "supported by SVT-AV1 < 3.0.0.\n",
231 avctx->width, avctx->height);
232 return AVERROR(EINVAL);
233 }
234#endif
235
236 // Update param from options
237 if (svt_enc->enc_mode >= -1)
238 param->enc_mode = svt_enc->enc_mode;
239
240 if (avctx->bit_rate) {
241 param->target_bit_rate = avctx->bit_rate;
242 if (avctx->rc_max_rate != avctx->bit_rate)
243 param->rate_control_mode = 1;
244 else
245 param->rate_control_mode = 2;
246
247 param->max_qp_allowed = avctx->qmax;
248 param->min_qp_allowed = avctx->qmin;
249 }
250 param->max_bit_rate = avctx->rc_max_rate;
251 if ((avctx->bit_rate > 0 || avctx->rc_max_rate > 0) && avctx->rc_buffer_size)
252 param->maximum_buffer_size_ms =
253 avctx->rc_buffer_size * 1000LL /
254 FFMAX(avctx->bit_rate, avctx->rc_max_rate);
255
256 if (svt_enc->crf > 0) {
257 param->qp = svt_enc->crf;
258 param->rate_control_mode = 0;
259 } else if (svt_enc->qp > 0) {
260 param->qp = svt_enc->qp;
261 param->rate_control_mode = 0;
262#if SVT_AV1_CHECK_VERSION(4, 0, 0)
263 param->aq_mode = 0;
264#else
265 param->enable_adaptive_quantization = 0;
266#endif
267 }
268
270 param->color_primaries = (enum EbColorPrimaries)avctx->color_primaries;
271 param->matrix_coefficients = (enum EbMatrixCoefficients)((desc->flags & AV_PIX_FMT_FLAG_RGB) ?
272 AVCOL_SPC_RGB : avctx->colorspace);
273 param->transfer_characteristics = (enum EbTransferCharacteristics)avctx->color_trc;
274
276 param->color_range = avctx->color_range == AVCOL_RANGE_JPEG;
277 else
278 param->color_range = !!(desc->flags & AV_PIX_FMT_FLAG_RGB);
279
280#if SVT_AV1_CHECK_VERSION(1, 0, 0)
282 const char *name =
284
285 switch (avctx->chroma_sample_location) {
287 param->chroma_sample_position = EB_CSP_VERTICAL;
288 break;
290 param->chroma_sample_position = EB_CSP_COLOCATED;
291 break;
292 default:
293 if (!name)
294 break;
295
296 av_log(avctx, AV_LOG_WARNING,
297 "Specified chroma sample location %s is unsupported "
298 "on the AV1 bit stream level. Usage of a container that "
299 "allows passing this information - such as Matroska - "
300 "is recommended.\n",
301 name);
302 break;
303 }
304 }
305#endif
306
307 if (avctx->profile != AV_PROFILE_UNKNOWN)
308 param->profile = avctx->profile;
309
310 if (avctx->level != AV_LEVEL_UNKNOWN)
311 param->level = avctx->level;
312
313 // gop_size == 1 case is handled when encoding each frame by setting
314 // pic_type to EB_AV1_KEY_PICTURE. For gop_size > 1, set the
315 // intra_period_length. Even though setting intra_period_length to 0 should
316 // work in this case, it does not.
317 // See: https://gitlab.com/AOMediaCodec/SVT-AV1/-/issues/2076
318 if (avctx->gop_size > 1)
319 param->intra_period_length = avctx->gop_size - 1;
320
321#if SVT_AV1_CHECK_VERSION(1, 1, 0)
322 // In order for SVT-AV1 to force keyframes by setting pic_type to
323 // EB_AV1_KEY_PICTURE on any frame, force_key_frames has to be set. Note
324 // that this does not force all frames to be keyframes (it only forces a
325 // keyframe with pic_type is set to EB_AV1_KEY_PICTURE). As of now, SVT-AV1
326 // does not support arbitrary keyframe requests by setting pic_type to
327 // EB_AV1_KEY_PICTURE, so it is done only when gop_size == 1.
328 // FIXME: When SVT-AV1 supports arbitrary keyframe requests, this code needs
329 // to be updated to set force_key_frames accordingly.
330 if (avctx->gop_size == 1)
331 param->force_key_frames = 1;
332#endif
333
334 if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
335 param->frame_rate_numerator = avctx->framerate.num;
336 param->frame_rate_denominator = avctx->framerate.den;
337 } else {
338 param->frame_rate_numerator = avctx->time_base.den;
339 param->frame_rate_denominator = avctx->time_base.num;
340 }
341
342 /* 2 = IDR, closed GOP, 1 = CRA, open GOP */
343 param->intra_refresh_type = avctx->flags & AV_CODEC_FLAG_CLOSED_GOP ? 2 : 1;
344
345 handle_side_data(avctx, param);
346
347#if SVT_AV1_CHECK_VERSION(0, 9, 1)
348 while ((en = av_dict_iterate(svt_enc->svtav1_opts, en))) {
349 EbErrorType ret = svt_av1_enc_parse_parameter(param, en->key, en->value);
350 if (ret != EB_ErrorNone) {
352 av_log(avctx, level, "Error parsing option %s: %s.\n", en->key, en->value);
353 if (avctx->err_recognition & AV_EF_EXPLODE)
354 return AVERROR(EINVAL);
355 }
356 }
357#else
358 if (av_dict_count(svt_enc->svtav1_opts)) {
360 av_log(avctx, level, "svt-params needs libavcodec to be compiled with SVT-AV1 "
361 "headers >= 0.9.1.\n");
362 if (avctx->err_recognition & AV_EF_EXPLODE)
363 return AVERROR(ENOSYS);
364 }
365#endif
366 if (avctx->flags & AV_CODEC_FLAG_PASS2) {
367 int stats_sz;
368
369 if (!avctx->stats_in) {
370 av_log(avctx, AV_LOG_ERROR, "No stats file for second pass\n");
371 return AVERROR(EINVAL);
372 }
373
374 stats_sz = AV_BASE64_DECODE_SIZE(strlen(avctx->stats_in));
375 if (stats_sz <= 0) {
376 av_log(avctx, AV_LOG_ERROR, "Invalid stats file size\n");
377 return AVERROR(EINVAL);
378 }
379
380 svt_enc->stats_buf = av_malloc(stats_sz);
381 if (!svt_enc->stats_buf) {
382 av_log(avctx, AV_LOG_ERROR, "Failed to allocate stats buffer\n");
383 return AVERROR(ENOMEM);
384 }
385
386 stats_sz = av_base64_decode(svt_enc->stats_buf, avctx->stats_in, stats_sz);
387 if (stats_sz < 0) {
388 av_log(avctx, AV_LOG_ERROR, "Failed to decode stats file\n");
389 av_freep(&svt_enc->stats_buf);
390 return AVERROR(EINVAL);
391 }
392
393 param->rc_stats_buffer.buf = svt_enc->stats_buf;
394 param->rc_stats_buffer.sz = stats_sz;
395 param->pass = 2;
396
397 av_log(avctx, AV_LOG_VERBOSE, "Using %d bytes of 2-pass stats\n", stats_sz);
398 } else if (avctx->flags & AV_CODEC_FLAG_PASS1) {
399 param->pass = 1;
400 av_log(avctx, AV_LOG_VERBOSE, "Starting first pass\n");
401 }
402
403 param->source_width = avctx->width;
404 param->source_height = avctx->height;
405
406 param->encoder_bit_depth = desc->comp[0].depth;
407
408 if (desc->log2_chroma_w == 1 && desc->log2_chroma_h == 1)
409 param->encoder_color_format = EB_YUV420;
410 else if (desc->log2_chroma_w == 1 && desc->log2_chroma_h == 0)
411 param->encoder_color_format = EB_YUV422;
412 else if (!desc->log2_chroma_w && !desc->log2_chroma_h)
413 param->encoder_color_format = EB_YUV444;
414 else {
415 av_log(avctx, AV_LOG_ERROR , "Unsupported pixel format\n");
416 return AVERROR(EINVAL);
417 }
418
419 if ((param->encoder_color_format == EB_YUV422 || param->encoder_bit_depth > 10)
420 && param->profile != AV_PROFILE_AV1_PROFESSIONAL ) {
421 av_log(avctx, AV_LOG_WARNING, "Forcing Professional profile\n");
422 param->profile = AV_PROFILE_AV1_PROFESSIONAL;
423 } else if (param->encoder_color_format == EB_YUV444 && param->profile != AV_PROFILE_AV1_HIGH) {
424 av_log(avctx, AV_LOG_WARNING, "Forcing High profile\n");
425 param->profile = AV_PROFILE_AV1_HIGH;
426 }
427
428 avctx->bit_rate = param->rate_control_mode > 0 ?
429 param->target_bit_rate : 0;
430 avctx->rc_max_rate = param->max_bit_rate;
431 avctx->rc_buffer_size = param->maximum_buffer_size_ms *
432 FFMAX(avctx->bit_rate, avctx->rc_max_rate) / 1000LL;
433
434 if (avctx->bit_rate || avctx->rc_max_rate || avctx->rc_buffer_size) {
436 if (!cpb_props)
437 return AVERROR(ENOMEM);
438
439 cpb_props->buffer_size = avctx->rc_buffer_size;
440 cpb_props->max_bitrate = avctx->rc_max_rate;
441 cpb_props->avg_bitrate = avctx->bit_rate;
442 }
443
444 return 0;
445}
446
447static int read_in_data(EbSvtAv1EncConfiguration *param, const AVFrame *frame,
448 EbBufferHeaderType *header_ptr)
449{
450 EbSvtIOFormat *in_data = (EbSvtIOFormat *)header_ptr->p_buffer;
451 ptrdiff_t linesizes[4];
452 size_t sizes[4];
453 int bytes_shift = param->encoder_bit_depth > 8 ? 1 : 0;
454 int ret, frame_size;
455
456 for (int i = 0; i < 4; i++)
457 linesizes[i] = frame->linesize[i];
458
459 ret = av_image_fill_plane_sizes(sizes, frame->format, frame->height,
460 linesizes);
461 if (ret < 0)
462 return ret;
463
464 frame_size = 0;
465 for (int i = 0; i < 4; i++) {
466 if (sizes[i] > INT_MAX - frame_size)
467 return AVERROR(EINVAL);
468 frame_size += sizes[i];
469 }
470
471 in_data->luma = frame->data[0];
472 in_data->cb = frame->data[1];
473 in_data->cr = frame->data[2];
474
475 in_data->y_stride = AV_CEIL_RSHIFT(frame->linesize[0], bytes_shift);
476 in_data->cb_stride = AV_CEIL_RSHIFT(frame->linesize[1], bytes_shift);
477 in_data->cr_stride = AV_CEIL_RSHIFT(frame->linesize[2], bytes_shift);
478
479 header_ptr->n_filled_len = frame_size;
480 svt_metadata_array_free(&header_ptr->metadata);
481
482 return 0;
483}
484
486{
487 SvtContext *svt_enc = avctx->priv_data;
488 EbErrorType svt_ret;
489 int ret;
490
491 svt_enc->eos_flag = EOS_NOT_REACHED;
492
493#if SVT_AV1_CHECK_VERSION(3, 0, 0)
494 svt_ret = svt_av1_enc_init_handle(&svt_enc->svt_handle, &svt_enc->enc_params);
495#else
496 svt_ret = svt_av1_enc_init_handle(&svt_enc->svt_handle, svt_enc, &svt_enc->enc_params);
497#endif
498 if (svt_ret != EB_ErrorNone) {
499 return svt_print_error(avctx, svt_ret, "Error initializing encoder handle");
500 }
501
502 ret = config_enc_params(&svt_enc->enc_params, avctx);
503 if (ret < 0) {
504 av_log(avctx, AV_LOG_ERROR, "Error configuring encoder parameters\n");
505 return ret;
506 }
507
508 svt_ret = svt_av1_enc_set_parameter(svt_enc->svt_handle, &svt_enc->enc_params);
509 if (svt_ret != EB_ErrorNone) {
510 return svt_print_error(avctx, svt_ret, "Error setting encoder parameters");
511 }
512
513 svt_ret = svt_av1_enc_init(svt_enc->svt_handle);
514 if (svt_ret != EB_ErrorNone) {
515 return svt_print_error(avctx, svt_ret, "Error initializing encoder");
516 }
517
518 svt_enc->dovi.logctx = avctx;
519 ret = ff_dovi_configure(&svt_enc->dovi, avctx);
520 if (ret < 0)
521 return ret;
522
523 if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
524 EbBufferHeaderType *headerPtr = NULL;
525
526 svt_ret = svt_av1_enc_stream_header(svt_enc->svt_handle, &headerPtr);
527 if (svt_ret != EB_ErrorNone) {
528 return svt_print_error(avctx, svt_ret, "Error building stream header");
529 }
530
531 avctx->extradata_size = headerPtr->n_filled_len;
533 if (!avctx->extradata) {
534 av_log(avctx, AV_LOG_ERROR,
535 "Cannot allocate AV1 header of size %d.\n", avctx->extradata_size);
536 return AVERROR(ENOMEM);
537 }
538
539 memcpy(avctx->extradata, headerPtr->p_buffer, avctx->extradata_size);
540
541 svt_ret = svt_av1_enc_stream_header_release(headerPtr);
542 if (svt_ret != EB_ErrorNone) {
543 return svt_print_error(avctx, svt_ret, "Error freeing stream header");
544 }
545 }
546
547 svt_enc->frame = av_frame_alloc();
548 if (!svt_enc->frame)
549 return AVERROR(ENOMEM);
550
551 return alloc_buffer(&svt_enc->enc_params, svt_enc);
552}
553
554static int eb_send_frame(AVCodecContext *avctx, const AVFrame *frame)
555{
556 SvtContext *svt_enc = avctx->priv_data;
557 EbBufferHeaderType *headerPtr = svt_enc->in_buf;
558 AVFrameSideData *sd;
559 EbErrorType svt_ret;
560 int ret;
561
562 if (!frame) {
563 EbBufferHeaderType headerPtrLast;
564
565 if (svt_enc->eos_flag == EOS_SENT)
566 return 0;
567
568 memset(&headerPtrLast, 0, sizeof(headerPtrLast));
569 headerPtrLast.pic_type = EB_AV1_INVALID_PICTURE;
570 headerPtrLast.flags = EB_BUFFERFLAG_EOS;
571
572 svt_av1_enc_send_picture(svt_enc->svt_handle, &headerPtrLast);
573 svt_enc->eos_flag = EOS_SENT;
574 return 0;
575 }
576
577 ret = read_in_data(&svt_enc->enc_params, frame, headerPtr);
578 if (ret < 0)
579 return ret;
580
581 headerPtr->flags = 0;
582 headerPtr->p_app_private = NULL;
583 headerPtr->pts = frame->pts;
584
585 switch (frame->pict_type) {
587 headerPtr->pic_type = EB_AV1_KEY_PICTURE;
588 break;
589 default:
590 // Actually means auto, or default.
591 headerPtr->pic_type = EB_AV1_INVALID_PICTURE;
592 break;
593 }
594
595 if (avctx->gop_size == 1)
596 headerPtr->pic_type = EB_AV1_KEY_PICTURE;
597
599 if (svt_enc->dovi.cfg.dv_profile && sd) {
600 const AVDOVIMetadata *metadata = (const AVDOVIMetadata *)sd->data;
601 uint8_t *t35;
602 int size;
603 if ((ret = ff_dovi_rpu_generate(&svt_enc->dovi, metadata, FF_DOVI_WRAP_T35,
604 &t35, &size)) < 0)
605 return ret;
606 ret = svt_add_metadata(headerPtr, EB_AV1_METADATA_TYPE_ITUT_T35, t35, size);
607 av_free(t35);
608 if (ret < 0)
609 return AVERROR(ENOMEM);
610 } else if (svt_enc->dovi.cfg.dv_profile) {
611 av_log(avctx, AV_LOG_ERROR, "Dolby Vision enabled, but received frame "
612 "without AV_FRAME_DATA_DOVI_METADATA\n");
613 return AVERROR_INVALIDDATA;
614 }
615
616
617 svt_ret = svt_av1_enc_send_picture(svt_enc->svt_handle, headerPtr);
618 if (svt_ret != EB_ErrorNone)
619 return svt_print_error(avctx, svt_ret, "Error sending a frame to encoder");
620
621 return 0;
622}
623
624static AVBufferRef *get_output_ref(AVCodecContext *avctx, SvtContext *svt_enc, int filled_len)
625{
626 if (filled_len > svt_enc->max_tu_size) {
627 const int max_frames = 8;
628 int max_tu_size;
629
630 if (filled_len > svt_enc->raw_size * max_frames) {
631 av_log(avctx, AV_LOG_ERROR, "TU size > %d raw frame size.\n", max_frames);
632 return NULL;
633 }
634
635 max_tu_size = 1 << av_ceil_log2(filled_len);
636 av_buffer_pool_uninit(&svt_enc->pool);
638 if (!svt_enc->pool)
639 return NULL;
640
641 svt_enc->max_tu_size = max_tu_size;
642 }
643 av_assert0(svt_enc->pool);
644
645 return av_buffer_pool_get(svt_enc->pool);
646}
647
649{
650 SvtContext *svt_enc = avctx->priv_data;
651 EbBufferHeaderType *headerPtr;
652 AVFrame *frame = svt_enc->frame;
653 EbErrorType svt_ret;
655 int ret = 0;
656
657 if (svt_enc->eos_flag == EOS_RECEIVED)
658 return AVERROR_EOF;
659
660 ret = ff_encode_get_frame(avctx, frame);
661 if (ret < 0 && ret != AVERROR_EOF)
662 return ret;
663 if (ret == AVERROR_EOF)
664 frame = NULL;
665
666 ret = eb_send_frame(avctx, frame);
667 if (ret < 0)
668 return ret;
669 av_frame_unref(svt_enc->frame);
670
671 svt_ret = svt_av1_enc_get_packet(svt_enc->svt_handle, &headerPtr, svt_enc->eos_flag);
672 if (svt_ret == EB_NoErrorEmptyQueue)
673 return AVERROR(EAGAIN);
674 else if (svt_ret != EB_ErrorNone)
675 return svt_print_error(avctx, svt_ret, "Error getting an output packet from encoder");
676
677#if SVT_AV1_CHECK_VERSION(2, 0, 0)
678 if (headerPtr->flags & EB_BUFFERFLAG_EOS) {
679 if (avctx->flags & AV_CODEC_FLAG_PASS1) {
680 SvtAv1FixedBuf first_pass_stats = { 0 };
681 EbErrorType svt_ret_stats;
682 int b64_size;
683
684 svt_ret_stats = svt_av1_enc_get_stream_info(
685 svt_enc->svt_handle,
686 SVT_AV1_STREAM_INFO_FIRST_PASS_STATS_OUT,
687 &first_pass_stats);
688
689 if (svt_ret_stats != EB_ErrorNone) {
690 av_log(avctx, AV_LOG_ERROR,
691 "Failed to get first pass stats\n");
692 svt_av1_enc_release_out_buffer(&headerPtr);
693 return AVERROR_EXTERNAL;
694 }
695
696 if (first_pass_stats.sz > 0 && first_pass_stats.buf) {
697 b64_size = AV_BASE64_SIZE(first_pass_stats.sz);
698 avctx->stats_out = av_malloc(b64_size);
699 if (!avctx->stats_out) {
700 av_log(avctx, AV_LOG_ERROR,
701 "Failed to allocate stats output buffer\n");
702 svt_av1_enc_release_out_buffer(&headerPtr);
703 return AVERROR(ENOMEM);
704 }
705
706 av_base64_encode(avctx->stats_out, b64_size,
707 first_pass_stats.buf, first_pass_stats.sz);
708
709 av_log(avctx, AV_LOG_VERBOSE,
710 "First pass stats: %"PRIu64" bytes, encoded to %d bytes\n",
711 first_pass_stats.sz, b64_size);
712 }
713 }
714
715 svt_enc->eos_flag = EOS_RECEIVED;
716 svt_av1_enc_release_out_buffer(&headerPtr);
717 return AVERROR_EOF;
718 }
719#endif
720
721 ref = get_output_ref(avctx, svt_enc, headerPtr->n_filled_len);
722 if (!ref) {
723 av_log(avctx, AV_LOG_ERROR, "Failed to allocate output packet.\n");
724 svt_av1_enc_release_out_buffer(&headerPtr);
725 return AVERROR(ENOMEM);
726 }
727 pkt->buf = ref;
728 pkt->data = ref->data;
729
730 memcpy(pkt->data, headerPtr->p_buffer, headerPtr->n_filled_len);
731 memset(pkt->data + headerPtr->n_filled_len, 0, AV_INPUT_BUFFER_PADDING_SIZE);
732
733 pkt->size = headerPtr->n_filled_len;
734 pkt->pts = headerPtr->pts;
735 pkt->dts = headerPtr->dts;
736
737 enum AVPictureType pict_type;
738 switch (headerPtr->pic_type) {
739 case EB_AV1_KEY_PICTURE:
740 pkt->flags |= AV_PKT_FLAG_KEY;
742 case EB_AV1_INTRA_ONLY_PICTURE:
743 pict_type = AV_PICTURE_TYPE_I;
744 break;
745 case EB_AV1_INVALID_PICTURE:
746 pict_type = AV_PICTURE_TYPE_NONE;
747 break;
748 default:
749 pict_type = AV_PICTURE_TYPE_P;
750 break;
751 }
752
753 if (headerPtr->pic_type == EB_AV1_NON_REF_PICTURE)
754 pkt->flags |= AV_PKT_FLAG_DISPOSABLE;
755
756#if !(SVT_AV1_CHECK_VERSION(2, 0, 0))
757 if (headerPtr->flags & EB_BUFFERFLAG_EOS)
758 svt_enc->eos_flag = EOS_RECEIVED;
759#endif
760
761 ff_encode_add_stats_side_data(pkt, headerPtr->qp * FF_QP2LAMBDA, NULL, 0, pict_type);
762
763 svt_av1_enc_release_out_buffer(&headerPtr);
764
765 return 0;
766}
767
769{
770 SvtContext *svt_enc = avctx->priv_data;
771
772 if (svt_enc->svt_handle) {
773 svt_av1_enc_deinit(svt_enc->svt_handle);
774 svt_av1_enc_deinit_handle(svt_enc->svt_handle);
775 }
776 if (svt_enc->in_buf) {
777 av_free(svt_enc->in_buf->p_buffer);
778 svt_metadata_array_free(&svt_enc->in_buf->metadata);
779 av_freep(&svt_enc->in_buf);
780 }
781
782 av_buffer_pool_uninit(&svt_enc->pool);
783 av_frame_free(&svt_enc->frame);
784 ff_dovi_ctx_unref(&svt_enc->dovi);
785 av_freep(&svt_enc->stats_buf);
786
787 return 0;
788}
789
790#define OFFSET(x) offsetof(SvtContext, x)
791#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
792static const AVOption options[] = {
793 { "preset", "Encoding preset",
794 OFFSET(enc_mode), AV_OPT_TYPE_INT, { .i64 = -2 }, -2, MAX_ENC_PRESET, VE },
795
797
798#define LEVEL(name, value) name, NULL, 0, AV_OPT_TYPE_CONST, \
799 { .i64 = value }, 0, 0, VE, .unit = "avctx.level"
800 { LEVEL("2.0", 20) },
801 { LEVEL("2.1", 21) },
802 { LEVEL("2.2", 22) },
803 { LEVEL("2.3", 23) },
804 { LEVEL("3.0", 30) },
805 { LEVEL("3.1", 31) },
806 { LEVEL("3.2", 32) },
807 { LEVEL("3.3", 33) },
808 { LEVEL("4.0", 40) },
809 { LEVEL("4.1", 41) },
810 { LEVEL("4.2", 42) },
811 { LEVEL("4.3", 43) },
812 { LEVEL("5.0", 50) },
813 { LEVEL("5.1", 51) },
814 { LEVEL("5.2", 52) },
815 { LEVEL("5.3", 53) },
816 { LEVEL("6.0", 60) },
817 { LEVEL("6.1", 61) },
818 { LEVEL("6.2", 62) },
819 { LEVEL("6.3", 63) },
820 { LEVEL("7.0", 70) },
821 { LEVEL("7.1", 71) },
822 { LEVEL("7.2", 72) },
823 { LEVEL("7.3", 73) },
824#undef LEVEL
825
826 { "crf", "Constant Rate Factor value", OFFSET(crf),
827 AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 63, VE },
828 { "qp", "Initial Quantizer level value", OFFSET(qp),
829 AV_OPT_TYPE_INT, { .i64 = 0 }, 0, 63, VE },
830 { "svtav1-params", "Set the SVT-AV1 configuration using a :-separated list of key=value parameters", OFFSET(svtav1_opts), AV_OPT_TYPE_DICT, { 0 }, 0, 0, VE },
831
832 { "dolbyvision", "Enable Dolby Vision RPU coding", OFFSET(dovi.enable), AV_OPT_TYPE_BOOL, {.i64 = FF_DOVI_AUTOMATIC }, -1, 1, VE, .unit = "dovi" },
833 { "auto", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = FF_DOVI_AUTOMATIC}, .flags = VE, .unit = "dovi" },
834
835 {NULL},
836};
837
838static const AVClass class = {
839 .class_name = "libsvtav1",
841 .option = options,
843};
844
846 { "b", "0" },
847 { "flags", "+cgop" },
848 { "g", "-1" },
849 { "qmin", "1" },
850 { "qmax", "63" },
851 { NULL },
852};
853
855 .p.name = "libsvtav1",
856 CODEC_LONG_NAME("SVT-AV1(Scalable Video Technology for AV1) encoder"),
857 .priv_data_size = sizeof(SvtContext),
858 .p.type = AVMEDIA_TYPE_VIDEO,
859 .p.id = AV_CODEC_ID_AV1,
860 .init = eb_enc_init,
862 .close = eb_enc_close,
864 .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
867 .color_ranges = AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG,
868 .p.priv_class = &class,
869 .defaults = eb_enc_defaults,
870 .p.wrapper_name = "libsvtav1",
871};
uint8_t ptrdiff_t const uint8_t ptrdiff_t int intptr_t intptr_t int int16_t * dst
Definition dsp.h:87
const FFCodec ff_libsvtav1_encoder
Definition libsvtav1.c:854
#define VE
Definition amfenc_av1.c:30
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:42
Libavcodec external API header.
static int FUNC metadata(CodedBitstreamContext *ctx, RWContext *rw, APVRawMetadata *current)
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define CODEC_PIXFMTS(...)
#define FF_CODEC_CAP_NOT_INIT_THREADSAFE
The codec is not known to be init-threadsafe (i.e.
#define FF_CODEC_RECEIVE_PACKET_CB(func)
#define CODEC_LONG_NAME(str)
#define FF_CODEC_CAP_INIT_CLEANUP
The codec allows calling the close function for deallocation even if the init function returned a fai...
#define FF_CODEC_CAP_AUTO_THREADS
Codec handles avctx->thread_count == 0 (auto) internally.
common internal and external API header
#define AV_CEIL_RSHIFT(a, b)
Definition common.h:60
#define av_ceil_log2
Definition common.h:97
#define NULL
Definition coverity.c:32
#define AV_PROFILE_AV1_HIGH
Definition defs.h:170
#define AV_PROFILE_UNKNOWN
Definition defs.h:65
#define AV_LEVEL_UNKNOWN
Definition defs.h:209
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition defs.h:51
#define AV_PROFILE_AV1_PROFESSIONAL
Definition defs.h:171
static AVPacket * pkt
static AVFrame * frame
void ff_dovi_ctx_unref(DOVIContext *s)
Completely reset a DOVIContext, preserving only logctx.
Definition dovi_rpu.c:30
#define FF_DOVI_AUTOMATIC
Enable tri-state.
Definition dovi_rpu.h:49
int ff_dovi_rpu_generate(DOVIContext *s, const AVDOVIMetadata *metadata, int flags, uint8_t **out_rpu, int *out_size)
Synthesize a Dolby Vision RPU reflecting the current state.
@ FF_DOVI_WRAP_T35
wrap inside T.35+EMDF
Definition dovi_rpu.h:160
int ff_dovi_configure(DOVIContext *s, AVCodecContext *avctx)
Variant of ff_dovi_configure_from_codedpar which infers the codec parameters from an AVCodecContext.
int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame)
Called by encoders to get the next frame for encoding.
Definition encode.c:218
AVCPBProperties * ff_encode_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
Definition encode.c:1039
int ff_encode_add_stats_side_data(AVPacket *pkt, int quality, const int64_t error[], int error_count, enum AVPictureType pict_type)
Definition encode.c:1070
reference-counted frame API
static const uint8_t frame_size[4]
Definition g723_1.h:222
@ AV_OPT_TYPE_CONST
Special option type for declaring named constants.
Definition opt.h:298
@ AV_OPT_TYPE_INT
Underlying C type is int.
Definition opt.h:258
@ AV_OPT_TYPE_DICT
Underlying C type is AVDictionary*.
Definition opt.h:289
@ AV_OPT_TYPE_BOOL
Underlying C type is int.
Definition opt.h:326
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
Definition avcodec.h:294
#define AV_CODEC_CAP_OTHER_THREADS
Codec supports multithreading through a method other than slice- or frame-level multithreading.
Definition codec.h:112
#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:79
#define AV_CODEC_FLAG_CLOSED_GOP
Definition avcodec.h:332
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition avcodec.h:290
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
Definition avcodec.h:318
@ AV_CODEC_ID_AV1
Definition codec_id.h:275
#define AV_INPUT_BUFFER_PADDING_SIZE
Required number of additionally allocated bytes at the end of the input bitstream for decoding.
Definition defs.h:40
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition packet.h:650
#define AV_PKT_FLAG_DISPOSABLE
Flag is used to indicate packets that contain frames that can be discarded by the decoder.
Definition packet.h:669
char * av_base64_encode(char *out, int out_size, const uint8_t *in, int in_size)
Encode data to base64 and null-terminate.
Definition base64.c:147
#define AV_BASE64_DECODE_SIZE(x)
Calculate the output size in bytes needed to decode a base64 string with length x to a data buffer.
Definition base64.h:48
#define AV_BASE64_SIZE(x)
Calculate the output size needed to base64-encode x bytes to a null-terminated string.
Definition base64.h:66
int av_base64_decode(uint8_t *out, const char *in_str, int out_size)
Decode a base64-encoded string.
Definition base64.c:81
void av_buffer_pool_uninit(AVBufferPool **ppool)
Mark the pool as being available for freeing.
Definition buffer.c:328
AVBufferPool * av_buffer_pool_init(size_t size, AVBufferRef *(*alloc)(size_t size))
Allocate and initialize a buffer pool.
Definition buffer.c:283
AVBufferRef * av_buffer_pool_get(AVBufferPool *pool)
Allocate a new AVBuffer, reusing an old buffer from the pool when available.
Definition buffer.c:390
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
Definition dict.c:42
int av_dict_count(const AVDictionary *m)
Get number of entries in dictionary.
Definition dict.c:37
#define FF_QP2LAMBDA
factor to convert from H.263 QP to lambda
Definition avutil.h:226
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition error.h:73
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition error.h:59
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition error.h:61
#define AVERROR_EOF
End of file.
Definition error.h:57
#define AVERROR(e)
Definition error.h:45
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition frame.c:496
AVFrameSideData * av_frame_get_side_data(const AVFrame *frame, enum AVFrameSideDataType type)
Definition frame.c:659
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition frame.c:64
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition frame.c:52
static const AVFrameSideData * av_frame_side_data_get(AVFrameSideData *const *sd, const int nb_sd, enum AVFrameSideDataType type)
Wrapper around av_frame_side_data_get_c() to workaround the limitation that for any type T the conver...
Definition frame.h:1196
@ AV_FRAME_DATA_DOVI_METADATA
Parsed Dolby Vision metadata, suitable for passing to a software implementation.
Definition frame.h:208
@ AV_FRAME_DATA_CONTENT_LIGHT_LEVEL
Content light level (based on CTA-861.3).
Definition frame.h:137
@ AV_FRAME_DATA_MASTERING_DISPLAY_METADATA
Mastering display metadata associated with a video frame.
Definition frame.h:120
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#define AV_LOG_VERBOSE
Detailed information.
Definition log.h:226
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition log.h:210
const char * av_default_item_name(void *ptr)
Return the context name.
Definition log.c:241
int64_t av_rescale_q(int64_t a, AVRational bq, AVRational cq)
Rescale a 64-bit integer by 2 rational numbers.
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
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
AVPictureType
Definition avutil.h:276
@ AV_PICTURE_TYPE_I
Intra.
Definition avutil.h:278
@ AV_PICTURE_TYPE_NONE
Undefined.
Definition avutil.h:277
@ AV_PICTURE_TYPE_P
Predicted.
Definition avutil.h:279
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
static const int sizes[][2]
Definition img2dec.c:62
misc image utilities
#define AV_WB32(p, v)
#define AV_WB16(p, v)
Macro definitions for various function/variable attributes.
#define av_fallthrough
Definition attributes.h:67
#define av_unused
Definition attributes.h:164
#define av_cold
Definition attributes.h:117
static const FFCodecDefault eb_enc_defaults[]
Definition libsvtav1.c:845
static int config_enc_params(EbSvtAv1EncConfiguration *param, AVCodecContext *avctx)
Definition libsvtav1.c:212
static int eb_send_frame(AVCodecContext *avctx, const AVFrame *frame)
Definition libsvtav1.c:554
EOS_STATUS
Definition libsvtav1.c:47
@ EOS_SENT
Definition libsvtav1.c:49
@ EOS_NOT_REACHED
Definition libsvtav1.c:48
@ EOS_RECEIVED
Definition libsvtav1.c:50
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 AVBufferRef * get_output_ref(AVCodecContext *avctx, SvtContext *svt_enc, int filled_len)
Definition libsvtav1.c:624
static void handle_mdcv(struct EbSvtAv1MasteringDisplayInfo *dst, const AVMasteringDisplayMetadata *mdcv)
Definition libsvtav1.c:149
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:648
static av_cold int eb_enc_init(AVCodecContext *avctx)
Definition libsvtav1.c:485
const char * desc
Definition libsvtav1.c:83
#define LEVEL(name, value)
static void handle_side_data(AVCodecContext *avctx, EbSvtAv1EncConfiguration *param)
Definition libsvtav1.c:187
int av_err
Definition libsvtav1.c:82
static int read_in_data(EbSvtAv1EncConfiguration *param, const AVFrame *frame, EbBufferHeaderType *header_ptr)
Definition libsvtav1.c:447
#define OFFSET(x)
Definition libsvtav1.c:790
static av_cold int eb_enc_close(AVCodecContext *avctx)
Definition libsvtav1.c:768
static const struct @322326316233131355250374050203261141371005313331 svt_errors[]
#define FFMAX(a, b)
Definition macros.h:47
Memory handling functions.
#define av_malloc(s)
Definition ops_static.c:52
AVOptions.
const char * av_chroma_location_name(enum AVChromaLocation location)
Definition pixdesc.c:3881
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3460
#define AV_PIX_FMT_FLAG_RGB
The pixel format contains RGB-like data (as opposed to YUV/grayscale).
Definition pixdesc.h:136
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
Definition pixfmt.h:806
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Definition pixfmt.h:804
@ AVCHROMA_LOC_UNSPECIFIED
Definition pixfmt.h:803
#define AV_PIX_FMT_YUV420P10
Definition pixfmt.h:545
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition pixfmt.h:766
@ AVCOL_RANGE_UNSPECIFIED
Definition pixfmt.h:749
@ AVCOL_RANGE_JPEG
Full range content.
Definition pixfmt.h:783
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AVCOL_SPC_RGB
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB), YZX and ST 428-1
Definition pixfmt.h:707
#define FF_AV1_PROFILE_OPTS
Definition profiles.h:56
const char * name
Definition qsvenc.c:142
#define FF_ARRAY_ELEMS(a)
The buffer pool.
A reference to a data buffer.
Definition buffer.h:82
This structure describes the bitrate properties of an encoded bitstream.
Definition defs.h:282
int64_t avg_bitrate
Average bitrate of the stream, in bits per second.
Definition defs.h:297
int64_t max_bitrate
Maximum bitrate of the stream, in bits per second.
Definition defs.h:287
int64_t buffer_size
The size of the buffer to which the ratecontrol is applied, in bits.
Definition defs.h:303
Describe the class of an AVClass context structure.
Definition log.h:76
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:81
main external API structure.
Definition avcodec.h:443
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition avcodec.h:643
int width
picture width / height.
Definition avcodec.h:604
char * stats_out
pass1 encoding statistics output buffer
Definition avcodec.h:1330
int rc_buffer_size
decoder bitstream buffer size
Definition avcodec.h:1273
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition avcodec.h:681
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition avcodec.h:657
int qmin
minimum quantizer
Definition avcodec.h:1252
AVRational framerate
Definition avcodec.h:563
char * stats_in
pass2 encoding statistics input buffer Concatenated stuff from stats_out of pass1 should be placed he...
Definition avcodec.h:1338
int level
Encoding level descriptor.
Definition avcodec.h:1646
int64_t bit_rate
the average bitrate
Definition avcodec.h:493
int profile
profile
Definition avcodec.h:1636
int nb_decoded_side_data
Definition avcodec.h:1930
enum AVColorSpace colorspace
YUV colorspace type.
Definition avcodec.h:671
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition avcodec.h:1021
int64_t rc_max_rate
maximum bitrate
Definition avcodec.h:1288
int qmax
maximum quantizer
Definition avcodec.h:1259
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition avcodec.h:664
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented.
Definition avcodec.h:547
int flags
AV_CODEC_FLAG_*.
Definition avcodec.h:500
AVFrameSideData ** decoded_side_data
Array containing static side data, such as HDR10 CLL / MDCV structures.
Definition avcodec.h:1929
uint8_t * extradata
Out-of-band global headers that may be used by some codecs.
Definition avcodec.h:526
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition avcodec.h:688
int extradata_size
Definition avcodec.h:527
void * priv_data
Definition avcodec.h:470
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition avcodec.h:1416
Content light level needed by to transmit HDR over HDMI (CTA-861.3).
unsigned MaxFALL
Max average light level per frame (cd/m^2).
unsigned MaxCLL
Max content light level (cd/m^2).
Combined struct representing a combination of header, mapping and color metadata, for attaching to fr...
Definition dovi_meta.h:345
Structure to hold side data for an AVFrame.
Definition frame.h:327
uint8_t * data
Definition frame.h:329
This structure describes decoded (raw) audio or video data.
Definition frame.h:472
Mastering display metadata capable of representing the color volume of the display used to master the...
int has_primaries
Flag indicating whether the display primaries (and white point) are set.
AVRational max_luminance
Max luminance of mastering display (cd/m^2).
AVRational min_luminance
Min luminance of mastering display (cd/m^2).
AVRational display_primaries[3][2]
CIE 1931 xy chromaticity coords of color primaries (r, g, b order).
AVRational white_point[2]
CIE 1931 xy chromaticity coords of white point.
int has_luminance
Flag indicating whether the luminance (min_ and max_) have been set.
AVOption.
Definition opt.h:428
This structure stores compressed data.
Definition packet.h:580
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition pixdesc.h:69
Rational number (pair of numerator and denominator).
Definition rational.h:58
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
AVDOVIDecoderConfigurationRecord cfg
Currently active dolby vision configuration, or {0} for none.
Definition dovi_rpu.h:61
void * logctx
Definition dovi_rpu.h:43
AVBufferPool * pool
Definition libsvtav1.c:65
EbComponentType * svt_handle
Definition libsvtav1.c:57
EbBufferHeaderType * in_buf
Definition libsvtav1.c:59
DOVIContext dovi
Definition libsvtav1.c:69
AVFrame * frame
Definition libsvtav1.c:63
int raw_size
Definition libsvtav1.c:60
EOS_STATUS eos_flag
Definition libsvtav1.c:67
EbSvtAv1EncConfiguration enc_params
Definition libsvtav1.c:56
AVDictionary * svtav1_opts
Definition libsvtav1.c:74
int enc_mode
Definition libsvtav1.c:75
uint8_t * stats_buf
Definition libsvtav1.c:71
int max_tu_size
Definition libsvtav1.c:61
uint8_t level
Definition svq3.c:208
#define av_free(p)
#define av_mallocz(s)
#define av_freep(p)
#define av_log(a,...)
#define src
Definition vp8dsp.c:248
static int ref[MAX_W *MAX_W]
int size