FFmpeg
Loading...
Searching...
No Matches
librav1e.c
Go to the documentation of this file.
1/*
2 * librav1e encoder
3 *
4 * Copyright (c) 2019 Derek Buitenhuis
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 FFmpeg; if not, write to the Free Software
20 * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
21 */
22
23#include <rav1e.h>
24
25#include "libavutil/buffer.h"
26#include "libavutil/internal.h"
27#include "libavutil/avassert.h"
28#include "libavutil/base64.h"
29#include "libavutil/common.h"
31#include "libavutil/mem.h"
32#include "libavutil/opt.h"
33#include "libavutil/pixdesc.h"
34#include "avcodec.h"
35#include "codec_internal.h"
36#include "encode.h"
37#include "internal.h"
38
39typedef struct librav1eContext {
40 const AVClass *class;
41
42 RaContext *ctx;
44 RaFrame *rframe;
45
46 uint8_t *pass_data;
47 size_t pass_pos;
49
52 int speed;
53 int tiles;
57
58typedef struct FrameData {
61
64} FrameData;
65
66static inline RaPixelRange range_map(enum AVPixelFormat pix_fmt, enum AVColorRange range)
67{
68 switch (pix_fmt) {
72 return RA_PIXEL_RANGE_FULL;
73 }
74
75 switch (range) {
77 return RA_PIXEL_RANGE_FULL;
79 default:
80 return RA_PIXEL_RANGE_LIMITED;
81 }
82}
83
84static inline RaChromaSampling pix_fmt_map(enum AVPixelFormat pix_fmt)
85{
86 switch (pix_fmt) {
91 return RA_CHROMA_SAMPLING_CS420;
96 return RA_CHROMA_SAMPLING_CS422;
101 return RA_CHROMA_SAMPLING_CS444;
102 default:
103 av_assert0(0);
104 }
105}
106
107static inline RaChromaSamplePosition chroma_loc_map(enum AVChromaLocation chroma_loc)
108{
109 switch (chroma_loc) {
111 return RA_CHROMA_SAMPLE_POSITION_VERTICAL;
113 return RA_CHROMA_SAMPLE_POSITION_COLOCATED;
114 default:
115 return RA_CHROMA_SAMPLE_POSITION_UNKNOWN;
116 }
117}
118
119static int get_stats(AVCodecContext *avctx, int eos)
120{
121 librav1eContext *ctx = avctx->priv_data;
122 RaData* buf = rav1e_twopass_out(ctx->ctx);
123 if (!buf)
124 return 0;
125
126 if (!eos) {
127 uint8_t *tmp = av_fast_realloc(ctx->pass_data, &ctx->pass_size,
128 ctx->pass_pos + buf->len);
129 if (!tmp) {
130 rav1e_data_unref(buf);
131 return AVERROR(ENOMEM);
132 }
133
134 ctx->pass_data = tmp;
135 memcpy(ctx->pass_data + ctx->pass_pos, buf->data, buf->len);
136 ctx->pass_pos += buf->len;
137 } else {
138 size_t b64_size = AV_BASE64_SIZE(ctx->pass_pos);
139
140 memcpy(ctx->pass_data, buf->data, buf->len);
141
142 avctx->stats_out = av_malloc(b64_size);
143 if (!avctx->stats_out) {
144 rav1e_data_unref(buf);
145 return AVERROR(ENOMEM);
146 }
147
148 av_base64_encode(avctx->stats_out, b64_size, ctx->pass_data, ctx->pass_pos);
149
150 av_freep(&ctx->pass_data);
151 }
152
153 rav1e_data_unref(buf);
154
155 return 0;
156}
157
158static int set_stats(AVCodecContext *avctx)
159{
160 librav1eContext *ctx = avctx->priv_data;
161 int ret = 1;
162
163 while (ret > 0 && ctx->pass_size - ctx->pass_pos > 0) {
164 ret = rav1e_twopass_in(ctx->ctx, ctx->pass_data + ctx->pass_pos,
165 ctx->pass_size - ctx->pass_pos);
166 if (ret < 0)
167 return AVERROR_EXTERNAL;
168 ctx->pass_pos += ret;
169 }
170
171 return 0;
172}
173
175{
176 librav1eContext *ctx = avctx->priv_data;
177
178 if (ctx->ctx) {
179 rav1e_context_unref(ctx->ctx);
180 ctx->ctx = NULL;
181 }
182 if (ctx->rframe) {
183 rav1e_frame_unref(ctx->rframe);
184 ctx->rframe = NULL;
185 }
186
187 av_frame_free(&ctx->frame);
188 av_freep(&ctx->pass_data);
189
190 return 0;
191}
192
194{
195 librav1eContext *ctx = avctx->priv_data;
197 RaConfig *cfg = NULL;
198 int rret;
199 int ret = 0;
200
201 ctx->frame = av_frame_alloc();
202 if (!ctx->frame)
203 return AVERROR(ENOMEM);
204
205 cfg = rav1e_config_default();
206 if (!cfg) {
207 av_log(avctx, AV_LOG_ERROR, "Could not allocate rav1e config.\n");
208 return AVERROR_EXTERNAL;
209 }
210
211 /*
212 * Rav1e currently uses the time base given to it only for ratecontrol... where
213 * the inverse is taken and used as a framerate. So, do what we do in other wrappers
214 * and use the framerate if we can.
215 */
216 if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
217 rav1e_config_set_time_base(cfg, (RaRational) {
218 avctx->framerate.den, avctx->framerate.num
219 });
220 } else {
221 rav1e_config_set_time_base(cfg, (RaRational) {
222 avctx->time_base.num, avctx->time_base.den
223 });
224 }
225
226 if ((avctx->flags & AV_CODEC_FLAG_PASS1 || avctx->flags & AV_CODEC_FLAG_PASS2) && !avctx->bit_rate) {
227 av_log(avctx, AV_LOG_ERROR, "A bitrate must be set to use two pass mode.\n");
229 goto end;
230 }
231
232 if (avctx->flags & AV_CODEC_FLAG_PASS2) {
233 if (!avctx->stats_in) {
234 av_log(avctx, AV_LOG_ERROR, "No stats file provided for second pass.\n");
235 ret = AVERROR(EINVAL);
236 goto end;
237 }
238
239 ctx->pass_size = (strlen(avctx->stats_in) * 3) / 4;
240 ctx->pass_data = av_malloc(ctx->pass_size);
241 if (!ctx->pass_data) {
242 av_log(avctx, AV_LOG_ERROR, "Could not allocate stats buffer.\n");
243 ret = AVERROR(ENOMEM);
244 goto end;
245 }
246
247 ctx->pass_size = av_base64_decode(ctx->pass_data, avctx->stats_in, ctx->pass_size);
248 if (ctx->pass_size < 0) {
249 av_log(avctx, AV_LOG_ERROR, "Invalid pass file.\n");
250 ret = AVERROR(EINVAL);
251 goto end;
252 }
253 }
254
255 {
256 const AVDictionaryEntry *en = NULL;
257 while ((en = av_dict_iterate(ctx->rav1e_opts, en))) {
258 if (rav1e_config_parse(cfg, en->key, en->value) < 0)
259 av_log(avctx, AV_LOG_WARNING, "Invalid value for %s: %s.\n", en->key, en->value);
260 }
261 }
262
263 rret = rav1e_config_parse_int(cfg, "width", avctx->width);
264 if (rret < 0) {
265 av_log(avctx, AV_LOG_ERROR, "Invalid width passed to rav1e.\n");
267 goto end;
268 }
269
270 rret = rav1e_config_parse_int(cfg, "height", avctx->height);
271 if (rret < 0) {
272 av_log(avctx, AV_LOG_ERROR, "Invalid height passed to rav1e.\n");
274 goto end;
275 }
276
277 if (avctx->sample_aspect_ratio.num > 0 && avctx->sample_aspect_ratio.den > 0)
278 rav1e_config_set_sample_aspect_ratio(cfg, (RaRational) {
281 });
282
283 rret = rav1e_config_parse_int(cfg, "threads", avctx->thread_count);
284 if (rret < 0)
285 av_log(avctx, AV_LOG_WARNING, "Invalid number of threads, defaulting to auto.\n");
286
287 if (ctx->speed >= 0) {
288 rret = rav1e_config_parse_int(cfg, "speed", ctx->speed);
289 if (rret < 0) {
290 av_log(avctx, AV_LOG_ERROR, "Could not set speed preset.\n");
291 ret = AVERROR_EXTERNAL;
292 goto end;
293 }
294 }
295
296 /* rav1e handles precedence between 'tiles' and cols/rows for us. */
297 if (ctx->tiles > 0) {
298 rret = rav1e_config_parse_int(cfg, "tiles", ctx->tiles);
299 if (rret < 0) {
300 av_log(avctx, AV_LOG_ERROR, "Could not set number of tiles to encode with.\n");
301 ret = AVERROR_EXTERNAL;
302 goto end;
303 }
304 }
305 if (ctx->tile_rows > 0) {
306 rret = rav1e_config_parse_int(cfg, "tile_rows", ctx->tile_rows);
307 if (rret < 0) {
308 av_log(avctx, AV_LOG_ERROR, "Could not set number of tile rows to encode with.\n");
309 ret = AVERROR_EXTERNAL;
310 goto end;
311 }
312 }
313 if (ctx->tile_cols > 0) {
314 rret = rav1e_config_parse_int(cfg, "tile_cols", ctx->tile_cols);
315 if (rret < 0) {
316 av_log(avctx, AV_LOG_ERROR, "Could not set number of tile cols to encode with.\n");
317 ret = AVERROR_EXTERNAL;
318 goto end;
319 }
320 }
321
322 if (avctx->gop_size > 0) {
323 rret = rav1e_config_parse_int(cfg, "key_frame_interval", avctx->gop_size);
324 if (rret < 0) {
325 av_log(avctx, AV_LOG_ERROR, "Could not set max keyint.\n");
326 ret = AVERROR_EXTERNAL;
327 goto end;
328 }
329 }
330
331 if (avctx->keyint_min > 0) {
332 rret = rav1e_config_parse_int(cfg, "min_key_frame_interval", avctx->keyint_min);
333 if (rret < 0) {
334 av_log(avctx, AV_LOG_ERROR, "Could not set min keyint.\n");
335 ret = AVERROR_EXTERNAL;
336 goto end;
337 }
338 }
339
340 if (avctx->bit_rate && ctx->quantizer < 0) {
341 int max_quantizer = avctx->qmax >= 0 ? avctx->qmax : 255;
342
343 rret = rav1e_config_parse_int(cfg, "quantizer", max_quantizer);
344 if (rret < 0) {
345 av_log(avctx, AV_LOG_ERROR, "Could not set max quantizer.\n");
346 ret = AVERROR_EXTERNAL;
347 goto end;
348 }
349
350 if (avctx->qmin >= 0) {
351 rret = rav1e_config_parse_int(cfg, "min_quantizer", avctx->qmin);
352 if (rret < 0) {
353 av_log(avctx, AV_LOG_ERROR, "Could not set min quantizer.\n");
354 ret = AVERROR_EXTERNAL;
355 goto end;
356 }
357 }
358
359 rret = rav1e_config_parse_int(cfg, "bitrate", avctx->bit_rate);
360 if (rret < 0) {
361 av_log(avctx, AV_LOG_ERROR, "Could not set bitrate.\n");
363 goto end;
364 }
365 } else if (ctx->quantizer >= 0) {
366 if (avctx->bit_rate)
367 av_log(avctx, AV_LOG_WARNING, "Both bitrate and quantizer specified. Using quantizer mode.");
368
369 rret = rav1e_config_parse_int(cfg, "quantizer", ctx->quantizer);
370 if (rret < 0) {
371 av_log(avctx, AV_LOG_ERROR, "Could not set quantizer.\n");
372 ret = AVERROR_EXTERNAL;
373 goto end;
374 }
375 }
376
377 rret = rav1e_config_set_pixel_format(cfg, desc->comp[0].depth,
378 pix_fmt_map(avctx->pix_fmt),
380 range_map(avctx->pix_fmt, avctx->color_range));
381 if (rret < 0) {
382 av_log(avctx, AV_LOG_ERROR, "Failed to set pixel format properties.\n");
384 goto end;
385 }
386
387 /* rav1e's colorspace enums match standard values. */
388 rret = rav1e_config_set_color_description(cfg, (RaMatrixCoefficients) avctx->colorspace,
389 (RaColorPrimaries) avctx->color_primaries,
390 (RaTransferCharacteristics) avctx->color_trc);
391 if (rret < 0) {
392 av_log(avctx, AV_LOG_WARNING, "Failed to set color properties.\n");
393 if (avctx->err_recognition & AV_EF_EXPLODE) {
395 goto end;
396 }
397 }
398
399 ctx->ctx = rav1e_context_new(cfg);
400 if (!ctx->ctx) {
401 av_log(avctx, AV_LOG_ERROR, "Failed to create rav1e encode context.\n");
402 ret = AVERROR_EXTERNAL;
403 goto end;
404 }
405
406 if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
407 RaData *seq_hdr = rav1e_container_sequence_header(ctx->ctx);
408
409 if (seq_hdr)
410 avctx->extradata = av_mallocz(seq_hdr->len + AV_INPUT_BUFFER_PADDING_SIZE);
411 if (!seq_hdr || !avctx->extradata) {
412 rav1e_data_unref(seq_hdr);
413 av_log(avctx, AV_LOG_ERROR, "Failed to get extradata.\n");
414 ret = seq_hdr ? AVERROR(ENOMEM) : AVERROR_EXTERNAL;
415 goto end;
416 }
417
418 memcpy(avctx->extradata, seq_hdr->data, seq_hdr->len);
419 avctx->extradata_size = seq_hdr->len;
420 rav1e_data_unref(seq_hdr);
421 }
422
423 ret = 0;
424
425end:
426
427 rav1e_config_unref(cfg);
428
429 return ret;
430}
431
432static void frame_data_free(void *data)
433{
434 FrameData *fd = data;
435
436 if (!fd)
437 return;
438
440 av_free(data);
441}
442
444{
445 librav1eContext *ctx = avctx->priv_data;
446 RaFrame *rframe = ctx->rframe;
447 RaPacket *rpkt = NULL;
448 FrameData *fd;
449 int ret;
450
451 if (!rframe) {
452 AVFrame *frame = ctx->frame;
453
454 ret = ff_encode_get_frame(avctx, frame);
455 if (ret < 0 && ret != AVERROR_EOF)
456 return ret;
457
458 if (frame->buf[0]) {
460
461 fd = av_mallocz(sizeof(*fd));
462 if (!fd) {
463 av_log(avctx, AV_LOG_ERROR, "Could not allocate PTS buffer.\n");
464 return AVERROR(ENOMEM);
465 }
466 fd->pts = frame->pts;
467 fd->duration = frame->duration;
468
469 if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
470 fd->frame_opaque = frame->opaque;
471 fd->frame_opaque_ref = frame->opaque_ref;
472 frame->opaque_ref = NULL;
473 }
474
475 rframe = rav1e_frame_new(ctx->ctx);
476 if (!rframe) {
477 av_log(avctx, AV_LOG_ERROR, "Could not allocate new rav1e frame.\n");
479 frame_data_free(fd);
480 return AVERROR(ENOMEM);
481 }
482
483 for (int i = 0; i < desc->nb_components; i++) {
484 int shift = i ? desc->log2_chroma_h : 0;
485 int bytes = desc->comp[0].depth == 8 ? 1 : 2;
486 rav1e_frame_fill_plane(rframe, i, frame->data[i],
487 (frame->height >> shift) * frame->linesize[i],
488 frame->linesize[i], bytes);
489 }
491 rav1e_frame_set_opaque(rframe, fd, frame_data_free);
492 }
493 }
494
495 ret = rav1e_send_frame(ctx->ctx, rframe);
496 if (rframe)
497 if (ret == RA_ENCODER_STATUS_ENOUGH_DATA) {
498 ctx->rframe = rframe; /* Queue is full. Store the RaFrame to retry next call */
499 } else {
500 rav1e_frame_unref(rframe); /* No need to unref if flushing. */
501 ctx->rframe = NULL;
502 }
503
504 switch (ret) {
505 case RA_ENCODER_STATUS_SUCCESS:
506 case RA_ENCODER_STATUS_ENOUGH_DATA:
507 break;
508 case RA_ENCODER_STATUS_FAILURE:
509 av_log(avctx, AV_LOG_ERROR, "Could not send frame: %s\n", rav1e_status_to_str(ret));
510 return AVERROR_EXTERNAL;
511 default:
512 av_log(avctx, AV_LOG_ERROR, "Unknown return code %d from rav1e_send_frame: %s\n", ret, rav1e_status_to_str(ret));
513 return AVERROR_UNKNOWN;
514 }
515
516retry:
517
518 if (avctx->flags & AV_CODEC_FLAG_PASS1) {
519 int sret = get_stats(avctx, 0);
520 if (sret < 0)
521 return sret;
522 } else if (avctx->flags & AV_CODEC_FLAG_PASS2) {
523 int sret = set_stats(avctx);
524 if (sret < 0)
525 return sret;
526 }
527
528 ret = rav1e_receive_packet(ctx->ctx, &rpkt);
529 switch (ret) {
530 case RA_ENCODER_STATUS_SUCCESS:
531 break;
532 case RA_ENCODER_STATUS_LIMIT_REACHED:
533 if (avctx->flags & AV_CODEC_FLAG_PASS1) {
534 int sret = get_stats(avctx, 1);
535 if (sret < 0)
536 return sret;
537 }
538 return AVERROR_EOF;
539 case RA_ENCODER_STATUS_ENCODED:
540 goto retry;
541 case RA_ENCODER_STATUS_NEED_MORE_DATA:
542 if (avctx->internal->draining) {
543 av_log(avctx, AV_LOG_ERROR, "Unexpected error when receiving packet after EOF.\n");
544 return AVERROR_EXTERNAL;
545 }
546 return AVERROR(EAGAIN);
547 case RA_ENCODER_STATUS_FAILURE:
548 av_log(avctx, AV_LOG_ERROR, "Could not encode frame: %s\n", rav1e_status_to_str(ret));
549 return AVERROR_EXTERNAL;
550 default:
551 av_log(avctx, AV_LOG_ERROR, "Unknown return code %d from rav1e_receive_packet: %s\n", ret, rav1e_status_to_str(ret));
552 return AVERROR_UNKNOWN;
553 }
554
555 ret = ff_get_encode_buffer(avctx, pkt, rpkt->len, 0);
556 if (ret < 0) {
557 av_log(avctx, AV_LOG_ERROR, "Could not allocate packet.\n");
558 rav1e_packet_unref(rpkt);
559 return ret;
560 }
561
562 memcpy(pkt->data, rpkt->data, rpkt->len);
563
564 if (rpkt->frame_type == RA_FRAME_TYPE_KEY)
565 pkt->flags |= AV_PKT_FLAG_KEY;
566
567 fd = rpkt->opaque;
568 pkt->pts = pkt->dts = fd->pts;
569 pkt->duration = fd->duration;
570
571 if (avctx->flags & AV_CODEC_FLAG_COPY_OPAQUE) {
572 pkt->opaque = fd->frame_opaque;
573 pkt->opaque_ref = fd->frame_opaque_ref;
575 }
576
577 frame_data_free(fd);
578
579 if (avctx->flags & AV_CODEC_FLAG_RECON_FRAME) {
580 AVCodecInternal *avci = avctx->internal;
581 AVFrame *frame = avci->recon_frame;
583
585
586 frame->format = avctx->pix_fmt;
587 frame->width = avctx->width;
588 frame->height = avctx->height;
589
590 ret = ff_encode_alloc_frame(avctx, frame);
591 if (ret < 0) {
592 rav1e_packet_unref(rpkt);
593 return ret;
594 }
595
596 for (int i = 0; i < desc->nb_components; i++) {
597 int shift = i ? desc->log2_chroma_h : 0;
598 rav1e_frame_extract_plane(rpkt->rec, i, frame->data[i],
599 (frame->height >> shift) * frame->linesize[i],
600 frame->linesize[i], desc->comp[i].step);
601 }
602 }
603
604 rav1e_packet_unref(rpkt);
605
606 return 0;
607}
608
609#define OFFSET(x) offsetof(librav1eContext, x)
610#define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
611
612static const AVOption options[] = {
613 { "qp", "use constant quantizer mode", OFFSET(quantizer), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 255, VE },
614 { "speed", "what speed preset to use", OFFSET(speed), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 10, VE },
615 { "tiles", "number of tiles encode with", OFFSET(tiles), AV_OPT_TYPE_INT, { .i64 = 0 }, -1, INT64_MAX, VE },
616 { "tile-rows", "number of tiles rows to encode with", OFFSET(tile_rows), AV_OPT_TYPE_INT, { .i64 = 0 }, -1, INT64_MAX, VE },
617 { "tile-columns", "number of tiles columns to encode with", OFFSET(tile_cols), AV_OPT_TYPE_INT, { .i64 = 0 }, -1, INT64_MAX, VE },
618 { "rav1e-params", "set the rav1e configuration using a :-separated list of key=value parameters", OFFSET(rav1e_opts), AV_OPT_TYPE_DICT, { 0 }, 0, 0, VE },
619 { NULL }
620};
621
623 { "b", "0" },
624 { "g", "0" },
625 { "keyint_min", "0" },
626 { "qmax", "-1" },
627 { "qmin", "-1" },
628 { NULL }
629};
630
646
647static const AVClass class = {
648 .class_name = "librav1e",
650 .option = options,
652};
653
655 .p.name = "librav1e",
656 CODEC_LONG_NAME("librav1e AV1"),
657 .p.type = AVMEDIA_TYPE_VIDEO,
658 .p.id = AV_CODEC_ID_AV1,
659 .init = librav1e_encode_init,
661 .close = librav1e_encode_close,
662 .priv_data_size = sizeof(librav1eContext),
663 .p.priv_class = &class,
664 .defaults = librav1e_defaults,
666 .color_ranges = AVCOL_RANGE_MPEG | AVCOL_RANGE_JPEG,
670 .caps_internal = FF_CODEC_CAP_NOT_INIT_THREADSAFE |
672 .p.wrapper_name = "librav1e",
673};
const FFCodec ff_librav1e_encoder
Definition librav1e.c:654
#define VE
Definition amfenc_av1.c:30
static AVFormatContext * ctx
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.
refcounted data buffer API
#define i(width, name, range_min, range_max)
Definition cbs_h264.c:63
#define CODEC_PIXFMTS_ARRAY(array)
#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 NULL
Definition coverity.c:32
long long int64_t
Definition coverity.c:34
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition defs.h:51
static AVPacket * pkt
static enum AVPixelFormat pix_fmt
static AVFrame * frame
int ff_get_encode_buffer(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int flags)
Get a buffer for a packet.
Definition encode.c:106
int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame)
Called by encoders to get the next frame for encoding.
Definition encode.c:218
int ff_encode_alloc_frame(AVCodecContext *avctx, AVFrame *frame)
Allocate buffers for a frame.
Definition encode.c:989
static CheckasmConfig cfg
Definition checkasm.c:74
static void frame_data_free(void *opaque, uint8_t *data)
Definition ffmpeg.c:413
@ 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
#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:147
#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_CAP_DR1
Codec uses get_buffer() or get_encode_buffer() for allocating buffers and supports custom allocators.
Definition codec.h:49
#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
#define AV_CODEC_CAP_ENCODER_RECON_FRAME
The encoder is able to output reconstructed frame data, i.e.
Definition codec.h:162
#define AV_CODEC_FLAG_COPY_OPAQUE
Definition avcodec.h:279
#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:244
@ 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
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:152
#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:86
void av_buffer_unref(AVBufferRef **buf)
Free a given reference and automatically free the buffer if there are no more references to it.
Definition buffer.c:140
const AVDictionaryEntry * av_dict_iterate(const AVDictionary *m, const AVDictionaryEntry *prev)
Iterate over a dictionary.
Definition dict.c:42
#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
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
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition log.h:216
#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
void * av_fast_realloc(void *ptr, unsigned int *size, size_t min_size)
Reallocate the given buffer if it is not large enough, otherwise do nothing.
Definition mem.c:601
@ AVMEDIA_TYPE_VIDEO
Definition avutil.h:200
#define LIBAVUTIL_VERSION_INT
Definition version.h:85
int tile_rows
static int shift(int a, int b)
Definition bonk.c:261
common internal api header.
#define av_cold
Definition attributes.h:117
common internal API header
static const FFCodecDefault librav1e_defaults[]
Definition librav1e.c:622
static int set_stats(AVCodecContext *avctx)
Definition librav1e.c:158
static RaChromaSampling pix_fmt_map(enum AVPixelFormat pix_fmt)
Definition librav1e.c:84
static RaChromaSamplePosition chroma_loc_map(enum AVChromaLocation chroma_loc)
Definition librav1e.c:107
static void frame_data_free(void *data)
Definition librav1e.c:432
static int librav1e_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
Definition librav1e.c:443
static RaPixelRange range_map(enum AVPixelFormat pix_fmt, enum AVColorRange range)
Definition librav1e.c:66
static av_cold int librav1e_encode_close(AVCodecContext *avctx)
Definition librav1e.c:174
#define OFFSET(x)
Definition librav1e.c:609
enum AVPixelFormat librav1e_pix_fmts[]
Definition librav1e.c:631
static av_cold int librav1e_encode_init(AVCodecContext *avctx)
Definition librav1e.c:193
static int get_stats(AVCodecContext *avctx, int eos)
Definition librav1e.c:119
const char * desc
Definition libsvtav1.c:83
enum AVColorRange range
Memory handling functions.
const char data[16]
Definition mxf.c:149
#define av_malloc(s)
Definition ops_static.c:52
AVOptions.
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition pixdesc.c:3484
#define AV_PIX_FMT_YUV444P12
Definition pixfmt.h:555
AVChromaLocation
Location of chroma samples.
Definition pixfmt.h:807
@ AVCHROMA_LOC_TOPLEFT
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
Definition pixfmt.h:811
@ AVCHROMA_LOC_LEFT
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Definition pixfmt.h:809
#define AV_PIX_FMT_YUV420P10
Definition pixfmt.h:548
AVColorRange
Visual content value range.
Definition pixfmt.h:753
@ AVCOL_RANGE_MPEG
Narrow or limited range content.
Definition pixfmt.h:771
@ AVCOL_RANGE_JPEG
Full range content.
Definition pixfmt.h:788
#define AV_PIX_FMT_YUV420P12
Definition pixfmt.h:552
#define AV_PIX_FMT_YUV422P12
Definition pixfmt.h:553
#define AV_PIX_FMT_YUV422P10
Definition pixfmt.h:549
AVPixelFormat
Pixel format.
Definition pixfmt.h:71
@ AV_PIX_FMT_NONE
Definition pixfmt.h:72
@ AV_PIX_FMT_YUV420P
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition pixfmt.h:73
@ AV_PIX_FMT_YUV422P
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition pixfmt.h:77
@ AV_PIX_FMT_YUV444P
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition pixfmt.h:78
@ 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
@ 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
@ 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
#define AV_PIX_FMT_YUV444P10
Definition pixfmt.h:551
A reference to a data buffer.
Definition buffer.h:82
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
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
int keyint_min
minimum GOP size
Definition avcodec.h:1014
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
AVRational sample_aspect_ratio
sample aspect ratio (0 if unknown) That is the width of a pixel divided by the height of the pixel.
Definition avcodec.h:628
int64_t bit_rate
the average bitrate
Definition avcodec.h:493
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
int thread_count
thread count is used to decide how many independent tasks should be passed to execute()
Definition avcodec.h:1584
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
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
struct AVCodecInternal * internal
Private context used for internal data.
Definition avcodec.h:478
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:1417
AVFrame * recon_frame
When the AV_CODEC_FLAG_RECON_FRAME flag is used.
Definition internal.h:114
int draining
decoding: AVERROR_EOF has been returned from ff_decode_get_packet(); must not be used by decoders tha...
Definition internal.h:139
char * key
Definition dict.h:91
char * value
Definition dict.h:92
This structure describes decoded (raw) audio or video data.
Definition frame.h:479
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
int num
Numerator.
Definition rational.h:59
int den
Denominator.
Definition rational.h:60
int64_t pts
Definition ffmpeg.h:716
void * frame_opaque
Definition librav1e.c:62
int64_t duration
Definition librav1e.c:60
AVBufferRef * frame_opaque_ref
Definition librav1e.c:63
AVFrame * frame
Definition librav1e.c:43
uint8_t * pass_data
Definition librav1e.c:46
RaContext * ctx
Definition librav1e.c:42
RaFrame * rframe
Definition librav1e.c:44
AVDictionary * rav1e_opts
Definition librav1e.c:50
size_t pass_pos
Definition librav1e.c:47
#define av_free(p)
#define av_mallocz(s)
#define av_freep(p)
#define av_log(a,...)
static uint8_t tmp[40]
Definition aes_ctr.c:52
int tiles
Definition av1_levels.c:72
int tile_cols
Definition av1_levels.c:73
static int64_t pts