FFmpeg
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/internal.h"
26 #include "libavutil/avassert.h"
27 #include "libavutil/base64.h"
28 #include "libavutil/common.h"
29 #include "libavutil/mathematics.h"
30 #include "libavutil/opt.h"
31 #include "libavutil/pixdesc.h"
32 #include "avcodec.h"
33 #include "encode.h"
34 #include "internal.h"
35 
36 typedef struct librav1eContext {
37  const AVClass *class;
38 
39  RaContext *ctx;
41  RaFrame *rframe;
43 
45  size_t pass_pos;
46  int pass_size;
47 
49  int quantizer;
50  int speed;
51  int tiles;
52  int tile_rows;
53  int tile_cols;
55 
56 static inline RaPixelRange range_map(enum AVPixelFormat pix_fmt, enum AVColorRange range)
57 {
58  switch (pix_fmt) {
62  return RA_PIXEL_RANGE_FULL;
63  }
64 
65  switch (range) {
66  case AVCOL_RANGE_JPEG:
67  return RA_PIXEL_RANGE_FULL;
68  case AVCOL_RANGE_MPEG:
69  default:
70  return RA_PIXEL_RANGE_LIMITED;
71  }
72 }
73 
74 static inline RaChromaSampling pix_fmt_map(enum AVPixelFormat pix_fmt)
75 {
76  switch (pix_fmt) {
77  case AV_PIX_FMT_YUV420P:
81  return RA_CHROMA_SAMPLING_CS420;
82  case AV_PIX_FMT_YUV422P:
86  return RA_CHROMA_SAMPLING_CS422;
87  case AV_PIX_FMT_YUV444P:
91  return RA_CHROMA_SAMPLING_CS444;
92  default:
93  av_assert0(0);
94  }
95 }
96 
97 static inline RaChromaSamplePosition chroma_loc_map(enum AVChromaLocation chroma_loc)
98 {
99  switch (chroma_loc) {
100  case AVCHROMA_LOC_LEFT:
101  return RA_CHROMA_SAMPLE_POSITION_VERTICAL;
103  return RA_CHROMA_SAMPLE_POSITION_COLOCATED;
104  default:
105  return RA_CHROMA_SAMPLE_POSITION_UNKNOWN;
106  }
107 }
108 
109 static int get_stats(AVCodecContext *avctx, int eos)
110 {
111  librav1eContext *ctx = avctx->priv_data;
112  RaData* buf = rav1e_twopass_out(ctx->ctx);
113  if (!buf)
114  return 0;
115 
116  if (!eos) {
118  ctx->pass_pos + buf->len);
119  if (!tmp) {
120  rav1e_data_unref(buf);
121  return AVERROR(ENOMEM);
122  }
123 
124  ctx->pass_data = tmp;
125  memcpy(ctx->pass_data + ctx->pass_pos, buf->data, buf->len);
126  ctx->pass_pos += buf->len;
127  } else {
128  size_t b64_size = AV_BASE64_SIZE(ctx->pass_pos);
129 
130  memcpy(ctx->pass_data, buf->data, buf->len);
131 
132  avctx->stats_out = av_malloc(b64_size);
133  if (!avctx->stats_out) {
134  rav1e_data_unref(buf);
135  return AVERROR(ENOMEM);
136  }
137 
138  av_base64_encode(avctx->stats_out, b64_size, ctx->pass_data, ctx->pass_pos);
139 
140  av_freep(&ctx->pass_data);
141  }
142 
143  rav1e_data_unref(buf);
144 
145  return 0;
146 }
147 
148 static int set_stats(AVCodecContext *avctx)
149 {
150  librav1eContext *ctx = avctx->priv_data;
151  int ret = 1;
152 
153  while (ret > 0 && ctx->pass_size - ctx->pass_pos > 0) {
154  ret = rav1e_twopass_in(ctx->ctx, ctx->pass_data + ctx->pass_pos, ctx->pass_size);
155  if (ret < 0)
156  return AVERROR_EXTERNAL;
157  ctx->pass_pos += ret;
158  }
159 
160  return 0;
161 }
162 
164 {
165  librav1eContext *ctx = avctx->priv_data;
166 
167  if (ctx->ctx) {
168  rav1e_context_unref(ctx->ctx);
169  ctx->ctx = NULL;
170  }
171  if (ctx->rframe) {
172  rav1e_frame_unref(ctx->rframe);
173  ctx->rframe = NULL;
174  }
175 
176  av_frame_free(&ctx->frame);
177  av_bsf_free(&ctx->bsf);
178  av_freep(&ctx->pass_data);
179 
180  return 0;
181 }
182 
184 {
185  librav1eContext *ctx = avctx->priv_data;
187  RaConfig *cfg = NULL;
188  int rret;
189  int ret = 0;
190 
191  ctx->frame = av_frame_alloc();
192  if (!ctx->frame)
193  return AVERROR(ENOMEM);
194 
195  cfg = rav1e_config_default();
196  if (!cfg) {
197  av_log(avctx, AV_LOG_ERROR, "Could not allocate rav1e config.\n");
198  return AVERROR_EXTERNAL;
199  }
200 
201  /*
202  * Rav1e currently uses the time base given to it only for ratecontrol... where
203  * the inverse is taken and used as a framerate. So, do what we do in other wrappers
204  * and use the framerate if we can.
205  */
206  if (avctx->framerate.num > 0 && avctx->framerate.den > 0) {
207  rav1e_config_set_time_base(cfg, (RaRational) {
208  avctx->framerate.den, avctx->framerate.num
209  });
210  } else {
211  rav1e_config_set_time_base(cfg, (RaRational) {
212  avctx->time_base.num * avctx->ticks_per_frame,
213  avctx->time_base.den
214  });
215  }
216 
217  if ((avctx->flags & AV_CODEC_FLAG_PASS1 || avctx->flags & AV_CODEC_FLAG_PASS2) && !avctx->bit_rate) {
218  av_log(avctx, AV_LOG_ERROR, "A bitrate must be set to use two pass mode.\n");
219  ret = AVERROR_INVALIDDATA;
220  goto end;
221  }
222 
223  if (avctx->flags & AV_CODEC_FLAG_PASS2) {
224  if (!avctx->stats_in) {
225  av_log(avctx, AV_LOG_ERROR, "No stats file provided for second pass.\n");
226  ret = AVERROR(EINVAL);
227  goto end;
228  }
229 
230  ctx->pass_size = (strlen(avctx->stats_in) * 3) / 4;
231  ctx->pass_data = av_malloc(ctx->pass_size);
232  if (!ctx->pass_data) {
233  av_log(avctx, AV_LOG_ERROR, "Could not allocate stats buffer.\n");
234  ret = AVERROR(ENOMEM);
235  goto end;
236  }
237 
238  ctx->pass_size = av_base64_decode(ctx->pass_data, avctx->stats_in, ctx->pass_size);
239  if (ctx->pass_size < 0) {
240  av_log(avctx, AV_LOG_ERROR, "Invalid pass file.\n");
241  ret = AVERROR(EINVAL);
242  goto end;
243  }
244  }
245 
246  if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
247  const AVBitStreamFilter *filter = av_bsf_get_by_name("extract_extradata");
248  int bret;
249 
250  if (!filter) {
251  av_log(avctx, AV_LOG_ERROR, "extract_extradata bitstream filter "
252  "not found. This is a bug, please report it.\n");
253  ret = AVERROR_BUG;
254  goto end;
255  }
256 
257  bret = av_bsf_alloc(filter, &ctx->bsf);
258  if (bret < 0) {
259  ret = bret;
260  goto end;
261  }
262 
263  bret = avcodec_parameters_from_context(ctx->bsf->par_in, avctx);
264  if (bret < 0) {
265  ret = bret;
266  goto end;
267  }
268 
269  bret = av_bsf_init(ctx->bsf);
270  if (bret < 0) {
271  ret = bret;
272  goto end;
273  }
274  }
275 
276  {
277  AVDictionaryEntry *en = NULL;
278  while ((en = av_dict_get(ctx->rav1e_opts, "", en, AV_DICT_IGNORE_SUFFIX))) {
279  int parse_ret = rav1e_config_parse(cfg, en->key, en->value);
280  if (parse_ret < 0)
281  av_log(avctx, AV_LOG_WARNING, "Invalid value for %s: %s.\n", en->key, en->value);
282  }
283  }
284 
285  rret = rav1e_config_parse_int(cfg, "width", avctx->width);
286  if (rret < 0) {
287  av_log(avctx, AV_LOG_ERROR, "Invalid width passed to rav1e.\n");
288  ret = AVERROR_INVALIDDATA;
289  goto end;
290  }
291 
292  rret = rav1e_config_parse_int(cfg, "height", avctx->height);
293  if (rret < 0) {
294  av_log(avctx, AV_LOG_ERROR, "Invalid height passed to rav1e.\n");
295  ret = AVERROR_INVALIDDATA;
296  goto end;
297  }
298 
299  rret = rav1e_config_parse_int(cfg, "threads", avctx->thread_count);
300  if (rret < 0)
301  av_log(avctx, AV_LOG_WARNING, "Invalid number of threads, defaulting to auto.\n");
302 
303  if (ctx->speed >= 0) {
304  rret = rav1e_config_parse_int(cfg, "speed", ctx->speed);
305  if (rret < 0) {
306  av_log(avctx, AV_LOG_ERROR, "Could not set speed preset.\n");
307  ret = AVERROR_EXTERNAL;
308  goto end;
309  }
310  }
311 
312  /* rav1e handles precedence between 'tiles' and cols/rows for us. */
313  if (ctx->tiles > 0) {
314  rret = rav1e_config_parse_int(cfg, "tiles", ctx->tiles);
315  if (rret < 0) {
316  av_log(avctx, AV_LOG_ERROR, "Could not set number of tiles to encode with.\n");
317  ret = AVERROR_EXTERNAL;
318  goto end;
319  }
320  }
321  if (ctx->tile_rows > 0) {
322  rret = rav1e_config_parse_int(cfg, "tile_rows", ctx->tile_rows);
323  if (rret < 0) {
324  av_log(avctx, AV_LOG_ERROR, "Could not set number of tile rows to encode with.\n");
325  ret = AVERROR_EXTERNAL;
326  goto end;
327  }
328  }
329  if (ctx->tile_cols > 0) {
330  rret = rav1e_config_parse_int(cfg, "tile_cols", ctx->tile_cols);
331  if (rret < 0) {
332  av_log(avctx, AV_LOG_ERROR, "Could not set number of tile cols to encode with.\n");
333  ret = AVERROR_EXTERNAL;
334  goto end;
335  }
336  }
337 
338  if (avctx->gop_size > 0) {
339  rret = rav1e_config_parse_int(cfg, "key_frame_interval", avctx->gop_size);
340  if (rret < 0) {
341  av_log(avctx, AV_LOG_ERROR, "Could not set max keyint.\n");
342  ret = AVERROR_EXTERNAL;
343  goto end;
344  }
345  }
346 
347  if (avctx->keyint_min > 0) {
348  rret = rav1e_config_parse_int(cfg, "min_key_frame_interval", avctx->keyint_min);
349  if (rret < 0) {
350  av_log(avctx, AV_LOG_ERROR, "Could not set min keyint.\n");
351  ret = AVERROR_EXTERNAL;
352  goto end;
353  }
354  }
355 
356  if (avctx->bit_rate && ctx->quantizer < 0) {
357  int max_quantizer = avctx->qmax >= 0 ? avctx->qmax : 255;
358 
359  rret = rav1e_config_parse_int(cfg, "quantizer", max_quantizer);
360  if (rret < 0) {
361  av_log(avctx, AV_LOG_ERROR, "Could not set max quantizer.\n");
362  ret = AVERROR_EXTERNAL;
363  goto end;
364  }
365 
366  if (avctx->qmin >= 0) {
367  rret = rav1e_config_parse_int(cfg, "min_quantizer", avctx->qmin);
368  if (rret < 0) {
369  av_log(avctx, AV_LOG_ERROR, "Could not set min quantizer.\n");
370  ret = AVERROR_EXTERNAL;
371  goto end;
372  }
373  }
374 
375  rret = rav1e_config_parse_int(cfg, "bitrate", avctx->bit_rate);
376  if (rret < 0) {
377  av_log(avctx, AV_LOG_ERROR, "Could not set bitrate.\n");
378  ret = AVERROR_INVALIDDATA;
379  goto end;
380  }
381  } else if (ctx->quantizer >= 0) {
382  if (avctx->bit_rate)
383  av_log(avctx, AV_LOG_WARNING, "Both bitrate and quantizer specified. Using quantizer mode.");
384 
385  rret = rav1e_config_parse_int(cfg, "quantizer", ctx->quantizer);
386  if (rret < 0) {
387  av_log(avctx, AV_LOG_ERROR, "Could not set quantizer.\n");
388  ret = AVERROR_EXTERNAL;
389  goto end;
390  }
391  }
392 
393  rret = rav1e_config_set_pixel_format(cfg, desc->comp[0].depth,
394  pix_fmt_map(avctx->pix_fmt),
396  range_map(avctx->pix_fmt, avctx->color_range));
397  if (rret < 0) {
398  av_log(avctx, AV_LOG_ERROR, "Failed to set pixel format properties.\n");
399  ret = AVERROR_INVALIDDATA;
400  goto end;
401  }
402 
403  /* rav1e's colorspace enums match standard values. */
404  rret = rav1e_config_set_color_description(cfg, (RaMatrixCoefficients) avctx->colorspace,
405  (RaColorPrimaries) avctx->color_primaries,
406  (RaTransferCharacteristics) avctx->color_trc);
407  if (rret < 0) {
408  av_log(avctx, AV_LOG_WARNING, "Failed to set color properties.\n");
409  if (avctx->err_recognition & AV_EF_EXPLODE) {
410  ret = AVERROR_INVALIDDATA;
411  goto end;
412  }
413  }
414 
415  ctx->ctx = rav1e_context_new(cfg);
416  if (!ctx->ctx) {
417  av_log(avctx, AV_LOG_ERROR, "Failed to create rav1e encode context.\n");
418  ret = AVERROR_EXTERNAL;
419  goto end;
420  }
421 
422  ret = 0;
423 
424 end:
425 
426  rav1e_config_unref(cfg);
427 
428  return ret;
429 }
430 
432 {
433  librav1eContext *ctx = avctx->priv_data;
434  RaFrame *rframe = ctx->rframe;
435  RaPacket *rpkt = NULL;
436  int ret;
437 
438  if (!rframe) {
439  AVFrame *frame = ctx->frame;
440 
441  ret = ff_encode_get_frame(avctx, frame);
442  if (ret < 0 && ret != AVERROR_EOF)
443  return ret;
444 
445  if (frame->buf[0]) {
447 
448  rframe = rav1e_frame_new(ctx->ctx);
449  if (!rframe) {
450  av_log(avctx, AV_LOG_ERROR, "Could not allocate new rav1e frame.\n");
451  av_frame_unref(frame);
452  return AVERROR(ENOMEM);
453  }
454 
455  for (int i = 0; i < desc->nb_components; i++) {
456  int shift = i ? desc->log2_chroma_h : 0;
457  int bytes = desc->comp[0].depth == 8 ? 1 : 2;
458  rav1e_frame_fill_plane(rframe, i, frame->data[i],
459  (frame->height >> shift) * frame->linesize[i],
460  frame->linesize[i], bytes);
461  }
462  av_frame_unref(frame);
463  }
464  }
465 
466  ret = rav1e_send_frame(ctx->ctx, rframe);
467  if (rframe)
468  if (ret == RA_ENCODER_STATUS_ENOUGH_DATA) {
469  ctx->rframe = rframe; /* Queue is full. Store the RaFrame to retry next call */
470  } else {
471  rav1e_frame_unref(rframe); /* No need to unref if flushing. */
472  ctx->rframe = NULL;
473  }
474 
475  switch (ret) {
476  case RA_ENCODER_STATUS_SUCCESS:
477  case RA_ENCODER_STATUS_ENOUGH_DATA:
478  break;
479  case RA_ENCODER_STATUS_FAILURE:
480  av_log(avctx, AV_LOG_ERROR, "Could not send frame: %s\n", rav1e_status_to_str(ret));
481  return AVERROR_EXTERNAL;
482  default:
483  av_log(avctx, AV_LOG_ERROR, "Unknown return code %d from rav1e_send_frame: %s\n", ret, rav1e_status_to_str(ret));
484  return AVERROR_UNKNOWN;
485  }
486 
487 retry:
488 
489  if (avctx->flags & AV_CODEC_FLAG_PASS1) {
490  int sret = get_stats(avctx, 0);
491  if (sret < 0)
492  return sret;
493  } else if (avctx->flags & AV_CODEC_FLAG_PASS2) {
494  int sret = set_stats(avctx);
495  if (sret < 0)
496  return sret;
497  }
498 
499  ret = rav1e_receive_packet(ctx->ctx, &rpkt);
500  switch (ret) {
501  case RA_ENCODER_STATUS_SUCCESS:
502  break;
503  case RA_ENCODER_STATUS_LIMIT_REACHED:
504  if (avctx->flags & AV_CODEC_FLAG_PASS1) {
505  int sret = get_stats(avctx, 1);
506  if (sret < 0)
507  return sret;
508  }
509  return AVERROR_EOF;
510  case RA_ENCODER_STATUS_ENCODED:
511  goto retry;
512  case RA_ENCODER_STATUS_NEED_MORE_DATA:
513  if (avctx->internal->draining) {
514  av_log(avctx, AV_LOG_ERROR, "Unexpected error when receiving packet after EOF.\n");
515  return AVERROR_EXTERNAL;
516  }
517  return AVERROR(EAGAIN);
518  case RA_ENCODER_STATUS_FAILURE:
519  av_log(avctx, AV_LOG_ERROR, "Could not encode frame: %s\n", rav1e_status_to_str(ret));
520  return AVERROR_EXTERNAL;
521  default:
522  av_log(avctx, AV_LOG_ERROR, "Unknown return code %d from rav1e_receive_packet: %s\n", ret, rav1e_status_to_str(ret));
523  return AVERROR_UNKNOWN;
524  }
525 
526  ret = av_new_packet(pkt, rpkt->len);
527  if (ret < 0) {
528  av_log(avctx, AV_LOG_ERROR, "Could not allocate packet.\n");
529  rav1e_packet_unref(rpkt);
530  return ret;
531  }
532 
533  memcpy(pkt->data, rpkt->data, rpkt->len);
534 
535  if (rpkt->frame_type == RA_FRAME_TYPE_KEY)
536  pkt->flags |= AV_PKT_FLAG_KEY;
537 
538  pkt->pts = pkt->dts = rpkt->input_frameno * avctx->ticks_per_frame;
539  rav1e_packet_unref(rpkt);
540 
541  if (avctx->flags & AV_CODEC_FLAG_GLOBAL_HEADER) {
542  int ret = av_bsf_send_packet(ctx->bsf, pkt);
543  if (ret < 0) {
544  av_log(avctx, AV_LOG_ERROR, "extradata extraction send failed.\n");
545  av_packet_unref(pkt);
546  return ret;
547  }
548 
549  ret = av_bsf_receive_packet(ctx->bsf, pkt);
550  if (ret < 0) {
551  av_log(avctx, AV_LOG_ERROR, "extradata extraction receive failed.\n");
552  av_packet_unref(pkt);
553  return ret;
554  }
555  }
556 
557  return 0;
558 }
559 
560 #define OFFSET(x) offsetof(librav1eContext, x)
561 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
562 
563 static const AVOption options[] = {
564  { "qp", "use constant quantizer mode", OFFSET(quantizer), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 255, VE },
565  { "speed", "what speed preset to use", OFFSET(speed), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 10, VE },
566  { "tiles", "number of tiles encode with", OFFSET(tiles), AV_OPT_TYPE_INT, { .i64 = 0 }, -1, INT64_MAX, VE },
567  { "tile-rows", "number of tiles rows to encode with", OFFSET(tile_rows), AV_OPT_TYPE_INT, { .i64 = 0 }, -1, INT64_MAX, VE },
568  { "tile-columns", "number of tiles columns to encode with", OFFSET(tile_cols), AV_OPT_TYPE_INT, { .i64 = 0 }, -1, INT64_MAX, VE },
569  { "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 },
570  { NULL }
571 };
572 
574  { "b", "0" },
575  { "g", "0" },
576  { "keyint_min", "0" },
577  { "qmax", "-1" },
578  { "qmin", "-1" },
579  { NULL }
580 };
581 
596 };
597 
598 static const AVClass class = {
599  .class_name = "librav1e",
600  .item_name = av_default_item_name,
601  .option = options,
603 };
604 
606  .name = "librav1e",
607  .long_name = NULL_IF_CONFIG_SMALL("librav1e AV1"),
608  .type = AVMEDIA_TYPE_VIDEO,
609  .id = AV_CODEC_ID_AV1,
610  .init = librav1e_encode_init,
611  .receive_packet = librav1e_receive_packet,
612  .close = librav1e_encode_close,
613  .priv_data_size = sizeof(librav1eContext),
614  .priv_class = &class,
615  .defaults = librav1e_defaults,
618  .caps_internal = FF_CODEC_CAP_INIT_CLEANUP,
619  .wrapper_name = "librav1e",
620 };
#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:48
#define NULL
Definition: coverity.c:32
const AVBitStreamFilter * av_bsf_get_by_name(const char *name)
AVRational framerate
Definition: avcodec.h:2069
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
static enum AVPixelFormat pix_fmt
static int shift(int a, int b)
Definition: sonic.c:82
const AVPixFmtDescriptor * av_pix_fmt_desc_get(enum AVPixelFormat pix_fmt)
Definition: pixdesc.c:2573
MPEG-2/4 4:2:0, H.264 default for 4:2:0.
Definition: pixfmt.h:559
This structure describes decoded (raw) audio or video data.
Definition: frame.h:308
AVOption.
Definition: opt.h:248
uint8_t * pass_data
Definition: librav1e.c:44
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:71
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:200
int64_t bit_rate
the average bitrate
Definition: avcodec.h:576
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
AVBufferRef * buf[AV_NUM_DATA_POINTERS]
AVBuffer references backing the data for this frame.
Definition: frame.h:499
const char * desc
Definition: nvenc.c:87
AVCodec ff_librav1e_encoder
Definition: librav1e.c:605
static RaChromaSamplePosition chroma_loc_map(enum AVChromaLocation chroma_loc)
Definition: librav1e.c:97
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:1161
int num
Numerator.
Definition: rational.h:59
The bitstream filter state.
Definition: bsf.h:49
const char * av_default_item_name(void *ptr)
Return the context name.
Definition: log.c:235
AVDictionary * rav1e_opts
Definition: librav1e.c:48
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:736
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:403
char * stats_in
pass2 encoding statistics input buffer Concatenated stuff from stats_out of pass1 should be placed he...
Definition: avcodec.h:1553
#define OFFSET(x)
Definition: librav1e.c:560
static AVPacket pkt
#define AV_CODEC_CAP_AUTO_THREADS
Codec supports avctx->thread_count == 0 (auto).
Definition: codec.h:118
AVCodec.
Definition: codec.h:190
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:649
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
#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:75
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
AVComponentDescriptor comp[4]
Parameters that describe how pixels are packed.
Definition: pixdesc.h:117
uint8_t
#define av_cold
Definition: attributes.h:88
#define av_malloc(s)
AVFrame * av_frame_alloc(void)
Allocate an AVFrame and set its fields to default values.
Definition: frame.c:190
static av_cold int librav1e_encode_init(AVCodecContext *avctx)
Definition: librav1e.c:183
AVOptions.
static av_cold int end(AVCodecContext *avctx)
Definition: avrndec.c:90
AVDictionaryEntry * av_dict_get(const AVDictionary *m, const char *key, const AVDictionaryEntry *prev, int flags)
Get a dictionary entry with matching key.
Definition: dict.c:40
uint8_t * data
Definition: packet.h:355
planar YUV 4:2:2, 16bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV422P and setting col...
Definition: pixfmt.h:79
#define AVERROR_EOF
End of file.
Definition: error.h:55
AVColorRange
MPEG vs JPEG YUV range.
Definition: pixfmt.h:535
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:404
char * stats_out
pass1 encoding statistics output buffer
Definition: avcodec.h:1545
enum AVChromaLocation chroma_sample_location
This defines the location of chroma samples.
Definition: avcodec.h:1168
#define av_log(a,...)
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: packet.h:388
static int get_stats(AVCodecContext *avctx, int eos)
Definition: librav1e.c:109
int av_new_packet(AVPacket *pkt, int size)
Allocate the payload of a packet and initialize its fields with default values.
Definition: avpacket.c:88
int av_bsf_alloc(const AVBitStreamFilter *filter, AVBSFContext **pctx)
Allocate a context for a given bitstream filter.
Definition: bsf.c:94
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:194
uint8_t log2_chroma_h
Amount to shift the luma height right to find the chroma height.
Definition: pixdesc.h:101
filter_frame For filters that do not use the this method is called when a frame is pushed to the filter s input It can be called at any time except in a reentrant way If the input frame is enough to produce then the filter should push the output frames on the output link immediately As an exception to the previous rule if the input frame is enough to produce several output frames then the filter needs output only at least one per link The additional frames can be left buffered in the filter
void av_frame_free(AVFrame **frame)
Free the frame and any dynamically allocated objects in it, e.g.
Definition: frame.c:203
int qmax
maximum quantizer
Definition: avcodec.h:1375
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:153
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:606
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
Definition: codec.h:197
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:402
static const AVCodecDefault defaults[]
Definition: amfenc_h264.c:361
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:138
int flags
A combination of AV_PKT_FLAG values.
Definition: packet.h:361
int av_bsf_init(AVBSFContext *ctx)
Prepare the filter for use, after all the parameters and options have been set.
Definition: bsf.c:147
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:70
RaFrame * rframe
Definition: librav1e.c:41
common internal API header
uint8_t nb_components
The number of components each pixel has, (1-4)
Definition: pixdesc.h:83
int err_recognition
Error recognition; may misdetect some more or less valid parts as errors.
Definition: avcodec.h:1655
#define AV_BASE64_SIZE(x)
Calculate the output size needed to base64-encode x bytes to a null-terminated string.
Definition: base64.h:66
static const AVCodecDefault librav1e_defaults[]
Definition: librav1e.c:573
static av_cold int librav1e_encode_close(AVCodecContext *avctx)
Definition: librav1e.c:163
planar YUV 4:2:0, 12bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV420P and setting col...
Definition: pixfmt.h:78
int width
picture width / height.
Definition: avcodec.h:699
ITU-R 601, SMPTE 274M 296M S314M(DV 4:1:1), mpeg2 4:2:2.
Definition: pixfmt.h:561
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition: avcodec.h:296
enum AVColorPrimaries color_primaries
Chromaticity coordinates of the source primaries.
Definition: avcodec.h:1140
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:478
#define AV_EF_EXPLODE
abort decoding on minor error detection
Definition: avcodec.h:1666
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
Definition: avcodec.h:658
static RaChromaSampling pix_fmt_map(enum AVPixelFormat pix_fmt)
Definition: librav1e.c:74
int draining
checks API usage: after codec draining, flush is required to resume operation
Definition: internal.h:172
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
Definition: avcodec.h:1785
the normal 2^n-1 "JPEG" YUV ranges
Definition: pixfmt.h:538
enum AVPixelFormat librav1e_pix_fmts[]
Definition: librav1e.c:582
static int set_stats(AVCodecContext *avctx)
Definition: librav1e.c:148
int format
format of the frame, -1 if unknown or unset Values correspond to enum AVPixelFormat for video frames...
Definition: frame.h:381
int av_bsf_send_packet(AVBSFContext *ctx, AVPacket *pkt)
Submit a packet for filtering.
Definition: bsf.c:200
AVBSFContext * bsf
Definition: librav1e.c:42
Libavcodec external API header.
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:339
Descriptor that unambiguously describes how the bits of a pixel are stored in the up to 4 data planes...
Definition: pixdesc.h:81
main external API structure.
Definition: avcodec.h:526
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:605
int av_bsf_receive_packet(AVBSFContext *ctx, AVPacket *pkt)
Retrieve a filtered packet.
Definition: bsf.c:226
int qmin
minimum quantizer
Definition: avcodec.h:1368
#define AVERROR_BUG
Internal bug, also see AVERROR_BUG2.
Definition: error.h:50
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:399
static RaPixelRange range_map(enum AVPixelFormat pix_fmt, enum AVColorRange range)
Definition: librav1e.c:56
Describe the class of an AVClass context structure.
Definition: log.h:67
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:1154
enum AVColorTransferCharacteristic color_trc
Color Transfer Characteristic.
Definition: avcodec.h:1147
int avcodec_parameters_from_context(AVCodecParameters *par, const AVCodecContext *codec)
Fill the parameters struct based on the values from the supplied codec context.
Definition: utils.c:2091
static int librav1e_receive_packet(AVCodecContext *avctx, AVPacket *pkt)
Definition: librav1e.c:431
#define VE
Definition: librav1e.c:561
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:275
void av_frame_unref(AVFrame *frame)
Unreference all the buffers referenced by frame and reset the frame fields.
Definition: frame.c:554
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:400
AVFrame * frame
Definition: librav1e.c:40
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:406
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:322
#define AV_CODEC_FLAG_GLOBAL_HEADER
Place global headers in extradata instead of every keyframe.
Definition: avcodec.h:329
the normal 219*2^(n-8) "MPEG" YUV ranges
Definition: pixfmt.h:537
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition: avcodec.h:721
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:66
common internal api header.
common internal and external API header
size_t pass_pos
Definition: librav1e.c:45
planar YUV 4:4:4, 24bpp, full scale (JPEG), deprecated in favor of AV_PIX_FMT_YUV444P and setting col...
Definition: pixfmt.h:80
char * key
Definition: dict.h:86
int den
Denominator.
Definition: rational.h:60
#define AVERROR_UNKNOWN
Unknown error, typically from an external library.
Definition: error.h:71
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
Definition: avcodec.h:300
void * priv_data
Definition: avcodec.h:553
RaContext * ctx
Definition: librav1e.c:39
char * value
Definition: dict.h:87
struct AVCodecInternal * internal
Private context used for internal data.
Definition: avcodec.h:561
int av_base64_decode(uint8_t *out, const char *in_str, int out_size)
Decode a base64-encoded string.
Definition: base64.c:79
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: packet.h:354
int height
Definition: frame.h:366
#define av_freep(p)
#define AV_DICT_IGNORE_SUFFIX
Return first entry in a dictionary whose first part corresponds to the search key, ignoring the suffix of the found key string.
Definition: dict.h:70
AVChromaLocation
Location of chroma samples.
Definition: pixfmt.h:557
void av_bsf_free(AVBSFContext **pctx)
Free a bitstream filter context and everything associated with it; write NULL into the supplied point...
Definition: bsf.c:40
Filter the word “frame” indicates either a video frame or a group of audio as stored in an AVFrame structure Format for each input and each output the list of supported formats For video that means pixel format For audio that means channel sample they are references to shared objects When the negotiation mechanism computes the intersection of the formats supported at each end of a all references to both lists are replaced with a reference to the intersection And when a single format is eventually chosen for a link amongst the remaining all references to the list are updated That means that if a filter requires that its input and output have the same format amongst a supported all it has to do is use a reference to the same list of formats query_formats can leave some formats unset and return AVERROR(EAGAIN) to cause the negotiation mechanism toagain later.That can be used by filters with complex requirements to use the format negotiated on one link to set the formats supported on another.Frame references ownership and permissions
int depth
Number of bits in the component.
Definition: pixdesc.h:58
static const AVOption options[]
Definition: librav1e.c:563
#define AVERROR_EXTERNAL
Generic error in an external library.
Definition: error.h:57
AVPixelFormat
Pixel format.
Definition: pixfmt.h:64
This structure stores compressed data.
Definition: packet.h:332
AVCodecParameters * par_in
Parameters of the input stream.
Definition: bsf.h:77
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: packet.h:348
int i
Definition: input.c:406
int ff_encode_get_frame(AVCodecContext *avctx, AVFrame *frame)
Called by encoders to get the next frame for encoding.
Definition: encode.c:107
int keyint_min
minimum GOP size
Definition: avcodec.h:1107
static uint8_t tmp[11]
Definition: aes_ctr.c:26