FFmpeg
 All Data Structures Namespaces Files Functions Variables Typedefs Enumerations Enumerator Macros Groups Pages
libvpxenc.c
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010, Google, Inc.
3  *
4  * This file is part of FFmpeg.
5  *
6  * FFmpeg is free software; you can redistribute it and/or
7  * modify it under the terms of the GNU Lesser General Public
8  * License as published by the Free Software Foundation; either
9  * version 2.1 of the License, or (at your option) any later version.
10  *
11  * FFmpeg is distributed in the hope that it will be useful,
12  * but WITHOUT ANY WARRANTY; without even the implied warranty of
13  * MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the GNU
14  * Lesser General Public License for more details.
15  *
16  * You should have received a copy of the GNU Lesser General Public
17  * License along with FFmpeg; if not, write to the Free Software
18  * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
19  */
20 
21 /**
22  * @file
23  * VP8/9 encoder support via libvpx
24  */
25 
26 #define VPX_DISABLE_CTRL_TYPECHECKS 1
27 #define VPX_CODEC_DISABLE_COMPAT 1
28 #include <vpx/vpx_encoder.h>
29 #include <vpx/vp8cx.h>
30 
31 #include "avcodec.h"
32 #include "internal.h"
33 #include "libavutil/avassert.h"
34 #include "libvpx.h"
35 #include "profiles.h"
36 #include "libavutil/base64.h"
37 #include "libavutil/common.h"
38 #include "libavutil/internal.h"
39 #include "libavutil/intreadwrite.h"
40 #include "libavutil/mathematics.h"
41 #include "libavutil/opt.h"
42 
43 /**
44  * Portion of struct vpx_codec_cx_pkt from vpx_encoder.h.
45  * One encoded frame returned from the library.
46  */
47 struct FrameListData {
48  void *buf; /**< compressed data buffer */
49  size_t sz; /**< length of compressed data */
50  void *buf_alpha;
51  size_t sz_alpha;
52  int64_t pts; /**< time stamp to show frame
53  (in timebase units) */
54  unsigned long duration; /**< duration to show frame
55  (in timebase units) */
56  uint32_t flags; /**< flags for this frame */
57  uint64_t sse[4];
58  int have_sse; /**< true if we have pending sse[] */
59  uint64_t frame_number;
61 };
62 
63 typedef struct VPxEncoderContext {
64  AVClass *class;
65  struct vpx_codec_ctx encoder;
66  struct vpx_image rawimg;
67  struct vpx_codec_ctx encoder_alpha;
68  struct vpx_image rawimg_alpha;
70  struct vpx_fixed_buf twopass_stats;
71  int deadline; //i.e., RT/GOOD/BEST
72  uint64_t sse[4];
73  int have_sse; /**< true if we have pending sse[] */
74  uint64_t frame_number;
76 
77  int cpu_used;
78  /**
79  * VP8 specific flags, see VP8F_* below.
80  */
81  int flags;
82 #define VP8F_ERROR_RESILIENT 0x00000001 ///< Enable measures appropriate for streaming over lossy links
83 #define VP8F_AUTO_ALT_REF 0x00000002 ///< Enable automatic alternate reference frame generation
84 
86 
89  int arnr_type;
90 
91  int tune;
92 
95  int crf;
100 
101  // VP9-only
102  int lossless;
106  int aq_mode;
109  int vpx_cs;
110  float level;
111 } VPxContext;
112 
113 /** String mappings for enum vp8e_enc_control_id */
114 static const char *const ctlidstr[] = {
115  [VP8E_SET_CPUUSED] = "VP8E_SET_CPUUSED",
116  [VP8E_SET_ENABLEAUTOALTREF] = "VP8E_SET_ENABLEAUTOALTREF",
117  [VP8E_SET_NOISE_SENSITIVITY] = "VP8E_SET_NOISE_SENSITIVITY",
118  [VP8E_SET_STATIC_THRESHOLD] = "VP8E_SET_STATIC_THRESHOLD",
119  [VP8E_SET_TOKEN_PARTITIONS] = "VP8E_SET_TOKEN_PARTITIONS",
120  [VP8E_SET_ARNR_MAXFRAMES] = "VP8E_SET_ARNR_MAXFRAMES",
121  [VP8E_SET_ARNR_STRENGTH] = "VP8E_SET_ARNR_STRENGTH",
122  [VP8E_SET_ARNR_TYPE] = "VP8E_SET_ARNR_TYPE",
123  [VP8E_SET_TUNING] = "VP8E_SET_TUNING",
124  [VP8E_SET_CQ_LEVEL] = "VP8E_SET_CQ_LEVEL",
125  [VP8E_SET_MAX_INTRA_BITRATE_PCT] = "VP8E_SET_MAX_INTRA_BITRATE_PCT",
126 #if CONFIG_LIBVPX_VP9_ENCODER
127  [VP9E_SET_LOSSLESS] = "VP9E_SET_LOSSLESS",
128  [VP9E_SET_TILE_COLUMNS] = "VP9E_SET_TILE_COLUMNS",
129  [VP9E_SET_TILE_ROWS] = "VP9E_SET_TILE_ROWS",
130  [VP9E_SET_FRAME_PARALLEL_DECODING] = "VP9E_SET_FRAME_PARALLEL_DECODING",
131  [VP9E_SET_AQ_MODE] = "VP9E_SET_AQ_MODE",
132 #if VPX_ENCODER_ABI_VERSION > 8
133  [VP9E_SET_COLOR_SPACE] = "VP9E_SET_COLOR_SPACE",
134 #endif
135 #if VPX_ENCODER_ABI_VERSION >= 11
136  [VP9E_SET_COLOR_RANGE] = "VP9E_SET_COLOR_RANGE",
137 #endif
138 #if VPX_ENCODER_ABI_VERSION >= 12
139  [VP9E_SET_TARGET_LEVEL] = "VP9E_SET_TARGET_LEVEL",
140  [VP9E_GET_LEVEL] = "VP9E_GET_LEVEL",
141 #endif
142 #endif
143 };
144 
145 static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
146 {
147  VPxContext *ctx = avctx->priv_data;
148  const char *error = vpx_codec_error(&ctx->encoder);
149  const char *detail = vpx_codec_error_detail(&ctx->encoder);
150 
151  av_log(avctx, AV_LOG_ERROR, "%s: %s\n", desc, error);
152  if (detail)
153  av_log(avctx, AV_LOG_ERROR, " Additional information: %s\n", detail);
154 }
155 
157  const struct vpx_codec_enc_cfg *cfg)
158 {
159  int width = -30;
160  int level = AV_LOG_DEBUG;
161 
162  av_log(avctx, level, "vpx_codec_enc_cfg\n");
163  av_log(avctx, level, "generic settings\n"
164  " %*s%u\n %*s%u\n %*s%u\n %*s%u\n %*s%u\n"
165 #if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_IMG_FMT_HIGHBITDEPTH)
166  " %*s%u\n %*s%u\n"
167 #endif
168  " %*s{%u/%u}\n %*s%u\n %*s%d\n %*s%u\n",
169  width, "g_usage:", cfg->g_usage,
170  width, "g_threads:", cfg->g_threads,
171  width, "g_profile:", cfg->g_profile,
172  width, "g_w:", cfg->g_w,
173  width, "g_h:", cfg->g_h,
174 #if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_IMG_FMT_HIGHBITDEPTH)
175  width, "g_bit_depth:", cfg->g_bit_depth,
176  width, "g_input_bit_depth:", cfg->g_input_bit_depth,
177 #endif
178  width, "g_timebase:", cfg->g_timebase.num, cfg->g_timebase.den,
179  width, "g_error_resilient:", cfg->g_error_resilient,
180  width, "g_pass:", cfg->g_pass,
181  width, "g_lag_in_frames:", cfg->g_lag_in_frames);
182  av_log(avctx, level, "rate control settings\n"
183  " %*s%u\n %*s%u\n %*s%u\n %*s%u\n"
184  " %*s%d\n %*s%p(%"SIZE_SPECIFIER")\n %*s%u\n",
185  width, "rc_dropframe_thresh:", cfg->rc_dropframe_thresh,
186  width, "rc_resize_allowed:", cfg->rc_resize_allowed,
187  width, "rc_resize_up_thresh:", cfg->rc_resize_up_thresh,
188  width, "rc_resize_down_thresh:", cfg->rc_resize_down_thresh,
189  width, "rc_end_usage:", cfg->rc_end_usage,
190  width, "rc_twopass_stats_in:", cfg->rc_twopass_stats_in.buf, cfg->rc_twopass_stats_in.sz,
191  width, "rc_target_bitrate:", cfg->rc_target_bitrate);
192  av_log(avctx, level, "quantizer settings\n"
193  " %*s%u\n %*s%u\n",
194  width, "rc_min_quantizer:", cfg->rc_min_quantizer,
195  width, "rc_max_quantizer:", cfg->rc_max_quantizer);
196  av_log(avctx, level, "bitrate tolerance\n"
197  " %*s%u\n %*s%u\n",
198  width, "rc_undershoot_pct:", cfg->rc_undershoot_pct,
199  width, "rc_overshoot_pct:", cfg->rc_overshoot_pct);
200  av_log(avctx, level, "decoder buffer model\n"
201  " %*s%u\n %*s%u\n %*s%u\n",
202  width, "rc_buf_sz:", cfg->rc_buf_sz,
203  width, "rc_buf_initial_sz:", cfg->rc_buf_initial_sz,
204  width, "rc_buf_optimal_sz:", cfg->rc_buf_optimal_sz);
205  av_log(avctx, level, "2 pass rate control settings\n"
206  " %*s%u\n %*s%u\n %*s%u\n",
207  width, "rc_2pass_vbr_bias_pct:", cfg->rc_2pass_vbr_bias_pct,
208  width, "rc_2pass_vbr_minsection_pct:", cfg->rc_2pass_vbr_minsection_pct,
209  width, "rc_2pass_vbr_maxsection_pct:", cfg->rc_2pass_vbr_maxsection_pct);
210  av_log(avctx, level, "keyframing settings\n"
211  " %*s%d\n %*s%u\n %*s%u\n",
212  width, "kf_mode:", cfg->kf_mode,
213  width, "kf_min_dist:", cfg->kf_min_dist,
214  width, "kf_max_dist:", cfg->kf_max_dist);
215  av_log(avctx, level, "\n");
216 }
217 
218 static void coded_frame_add(void *list, struct FrameListData *cx_frame)
219 {
220  struct FrameListData **p = list;
221 
222  while (*p)
223  p = &(*p)->next;
224  *p = cx_frame;
225  cx_frame->next = NULL;
226 }
227 
228 static av_cold void free_coded_frame(struct FrameListData *cx_frame)
229 {
230  av_freep(&cx_frame->buf);
231  if (cx_frame->buf_alpha)
232  av_freep(&cx_frame->buf_alpha);
233  av_freep(&cx_frame);
234 }
235 
236 static av_cold void free_frame_list(struct FrameListData *list)
237 {
238  struct FrameListData *p = list;
239 
240  while (p) {
241  list = list->next;
242  free_coded_frame(p);
243  p = list;
244  }
245 }
246 
248  enum vp8e_enc_control_id id, int val)
249 {
250  VPxContext *ctx = avctx->priv_data;
251  char buf[80];
252  int width = -30;
253  int res;
254 
255  snprintf(buf, sizeof(buf), "%s:", ctlidstr[id]);
256  av_log(avctx, AV_LOG_DEBUG, " %*s%d\n", width, buf, val);
257 
258  res = vpx_codec_control(&ctx->encoder, id, val);
259  if (res != VPX_CODEC_OK) {
260  snprintf(buf, sizeof(buf), "Failed to set %s codec control",
261  ctlidstr[id]);
262  log_encoder_error(avctx, buf);
263  }
264 
265  return res == VPX_CODEC_OK ? 0 : AVERROR(EINVAL);
266 }
267 
268 #if VPX_ENCODER_ABI_VERSION >= 12
269 static av_cold int codecctl_intp(AVCodecContext *avctx,
270  enum vp8e_enc_control_id id, int *val)
271 {
272  VPxContext *ctx = avctx->priv_data;
273  char buf[80];
274  int width = -30;
275  int res;
276 
277  snprintf(buf, sizeof(buf), "%s:", ctlidstr[id]);
278  av_log(avctx, AV_LOG_DEBUG, " %*s%d\n", width, buf, *val);
279 
280  res = vpx_codec_control(&ctx->encoder, id, val);
281  if (res != VPX_CODEC_OK) {
282  snprintf(buf, sizeof(buf), "Failed to set %s codec control",
283  ctlidstr[id]);
284  log_encoder_error(avctx, buf);
285  }
286 
287  return res == VPX_CODEC_OK ? 0 : AVERROR(EINVAL);
288 }
289 #endif
290 
291 static av_cold int vpx_free(AVCodecContext *avctx)
292 {
293  VPxContext *ctx = avctx->priv_data;
294 
295 #if VPX_ENCODER_ABI_VERSION >= 12
296  if (ctx->level >= 0 && !(avctx->flags & AV_CODEC_FLAG_PASS1)) {
297  int level_out = 0;
298  if (!codecctl_intp(avctx, VP9E_GET_LEVEL, &level_out))
299  av_log(avctx, AV_LOG_INFO, "Encoded level %.1f\n", level_out * 0.1);
300  }
301 #endif
302 
303  vpx_codec_destroy(&ctx->encoder);
304  if (ctx->is_alpha)
305  vpx_codec_destroy(&ctx->encoder_alpha);
306  av_freep(&ctx->twopass_stats.buf);
307  av_freep(&avctx->stats_out);
309  return 0;
310 }
311 
312 #if CONFIG_LIBVPX_VP9_ENCODER
313 static int set_pix_fmt(AVCodecContext *avctx, vpx_codec_caps_t codec_caps,
314  struct vpx_codec_enc_cfg *enccfg, vpx_codec_flags_t *flags,
315  vpx_img_fmt_t *img_fmt)
316 {
317  VPxContext av_unused *ctx = avctx->priv_data;
318 #ifdef VPX_IMG_FMT_HIGHBITDEPTH
319  enccfg->g_bit_depth = enccfg->g_input_bit_depth = 8;
320 #endif
321  switch (avctx->pix_fmt) {
322  case AV_PIX_FMT_YUV420P:
323  case AV_PIX_FMT_YUVA420P:
324  enccfg->g_profile = 0;
325  *img_fmt = VPX_IMG_FMT_I420;
326  return 0;
327  case AV_PIX_FMT_YUV422P:
328  enccfg->g_profile = 1;
329  *img_fmt = VPX_IMG_FMT_I422;
330  return 0;
331 #if VPX_IMAGE_ABI_VERSION >= 3
332  case AV_PIX_FMT_YUV440P:
333  enccfg->g_profile = 1;
334  *img_fmt = VPX_IMG_FMT_I440;
335  return 0;
336  case AV_PIX_FMT_GBRP:
337  ctx->vpx_cs = VPX_CS_SRGB;
338 #endif
339  case AV_PIX_FMT_YUV444P:
340  enccfg->g_profile = 1;
341  *img_fmt = VPX_IMG_FMT_I444;
342  return 0;
343 #ifdef VPX_IMG_FMT_HIGHBITDEPTH
346  if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
347  enccfg->g_bit_depth = enccfg->g_input_bit_depth =
348  avctx->pix_fmt == AV_PIX_FMT_YUV420P10 ? 10 : 12;
349  enccfg->g_profile = 2;
350  *img_fmt = VPX_IMG_FMT_I42016;
351  *flags |= VPX_CODEC_USE_HIGHBITDEPTH;
352  return 0;
353  }
354  break;
357  if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
358  enccfg->g_bit_depth = enccfg->g_input_bit_depth =
359  avctx->pix_fmt == AV_PIX_FMT_YUV422P10 ? 10 : 12;
360  enccfg->g_profile = 3;
361  *img_fmt = VPX_IMG_FMT_I42216;
362  *flags |= VPX_CODEC_USE_HIGHBITDEPTH;
363  return 0;
364  }
365  break;
366 #if VPX_IMAGE_ABI_VERSION >= 3
369  if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
370  enccfg->g_bit_depth = enccfg->g_input_bit_depth =
371  avctx->pix_fmt == AV_PIX_FMT_YUV440P10 ? 10 : 12;
372  enccfg->g_profile = 3;
373  *img_fmt = VPX_IMG_FMT_I44016;
374  *flags |= VPX_CODEC_USE_HIGHBITDEPTH;
375  return 0;
376  }
377  break;
378  case AV_PIX_FMT_GBRP10:
379  case AV_PIX_FMT_GBRP12:
380  ctx->vpx_cs = VPX_CS_SRGB;
381 #endif
384  if (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH) {
385  enccfg->g_bit_depth = enccfg->g_input_bit_depth =
386  avctx->pix_fmt == AV_PIX_FMT_YUV444P10 ||
387  avctx->pix_fmt == AV_PIX_FMT_GBRP10 ? 10 : 12;
388  enccfg->g_profile = 3;
389  *img_fmt = VPX_IMG_FMT_I44416;
390  *flags |= VPX_CODEC_USE_HIGHBITDEPTH;
391  return 0;
392  }
393  break;
394 #endif
395  default:
396  break;
397  }
398  av_log(avctx, AV_LOG_ERROR, "Unsupported pixel format.\n");
399  return AVERROR_INVALIDDATA;
400 }
401 
402 #if VPX_ENCODER_ABI_VERSION > 8
403 static void set_colorspace(AVCodecContext *avctx)
404 {
405  enum vpx_color_space vpx_cs;
406  VPxContext *ctx = avctx->priv_data;
407 
408  if (ctx->vpx_cs) {
409  vpx_cs = ctx->vpx_cs;
410  } else {
411  switch (avctx->colorspace) {
412  case AVCOL_SPC_RGB: vpx_cs = VPX_CS_SRGB; break;
413  case AVCOL_SPC_BT709: vpx_cs = VPX_CS_BT_709; break;
414  case AVCOL_SPC_UNSPECIFIED: vpx_cs = VPX_CS_UNKNOWN; break;
415  case AVCOL_SPC_RESERVED: vpx_cs = VPX_CS_RESERVED; break;
416  case AVCOL_SPC_BT470BG: vpx_cs = VPX_CS_BT_601; break;
417  case AVCOL_SPC_SMPTE170M: vpx_cs = VPX_CS_SMPTE_170; break;
418  case AVCOL_SPC_SMPTE240M: vpx_cs = VPX_CS_SMPTE_240; break;
419  case AVCOL_SPC_BT2020_NCL: vpx_cs = VPX_CS_BT_2020; break;
420  default:
421  av_log(avctx, AV_LOG_WARNING, "Unsupported colorspace (%d)\n",
422  avctx->colorspace);
423  return;
424  }
425  }
426  codecctl_int(avctx, VP9E_SET_COLOR_SPACE, vpx_cs);
427 }
428 #endif
429 
430 #if VPX_ENCODER_ABI_VERSION >= 11
431 static void set_color_range(AVCodecContext *avctx)
432 {
433  enum vpx_color_range vpx_cr;
434  switch (avctx->color_range) {
436  case AVCOL_RANGE_MPEG: vpx_cr = VPX_CR_STUDIO_RANGE; break;
437  case AVCOL_RANGE_JPEG: vpx_cr = VPX_CR_FULL_RANGE; break;
438  default:
439  av_log(avctx, AV_LOG_WARNING, "Unsupported color range (%d)\n",
440  avctx->color_range);
441  return;
442  }
443 
444  codecctl_int(avctx, VP9E_SET_COLOR_RANGE, vpx_cr);
445 }
446 #endif
447 #endif
448 
449 static av_cold int vpx_init(AVCodecContext *avctx,
450  const struct vpx_codec_iface *iface)
451 {
452  VPxContext *ctx = avctx->priv_data;
453  struct vpx_codec_enc_cfg enccfg = { 0 };
454  struct vpx_codec_enc_cfg enccfg_alpha;
455  vpx_codec_flags_t flags = (avctx->flags & AV_CODEC_FLAG_PSNR) ? VPX_CODEC_USE_PSNR : 0;
456  AVCPBProperties *cpb_props;
457  int res;
458  vpx_img_fmt_t img_fmt = VPX_IMG_FMT_I420;
459 #if CONFIG_LIBVPX_VP9_ENCODER
460  vpx_codec_caps_t codec_caps = vpx_codec_get_caps(iface);
461 #endif
462 
463  av_log(avctx, AV_LOG_INFO, "%s\n", vpx_codec_version_str());
464  av_log(avctx, AV_LOG_VERBOSE, "%s\n", vpx_codec_build_config());
465 
466  if (avctx->pix_fmt == AV_PIX_FMT_YUVA420P)
467  ctx->is_alpha = 1;
468 
469  if ((res = vpx_codec_enc_config_default(iface, &enccfg, 0)) != VPX_CODEC_OK) {
470  av_log(avctx, AV_LOG_ERROR, "Failed to get config: %s\n",
471  vpx_codec_err_to_string(res));
472  return AVERROR(EINVAL);
473  }
474 
475 #if CONFIG_LIBVPX_VP9_ENCODER
476  if (avctx->codec_id == AV_CODEC_ID_VP9) {
477  if (set_pix_fmt(avctx, codec_caps, &enccfg, &flags, &img_fmt))
478  return AVERROR(EINVAL);
479  }
480 #endif
481 
482  if(!avctx->bit_rate)
483  if(avctx->rc_max_rate || avctx->rc_buffer_size || avctx->rc_initial_buffer_occupancy) {
484  av_log( avctx, AV_LOG_ERROR, "Rate control parameters set without a bitrate\n");
485  return AVERROR(EINVAL);
486  }
487 
488  dump_enc_cfg(avctx, &enccfg);
489 
490  enccfg.g_w = avctx->width;
491  enccfg.g_h = avctx->height;
492  enccfg.g_timebase.num = avctx->time_base.num;
493  enccfg.g_timebase.den = avctx->time_base.den;
494  enccfg.g_threads = avctx->thread_count;
495  enccfg.g_lag_in_frames= ctx->lag_in_frames;
496 
497  if (avctx->flags & AV_CODEC_FLAG_PASS1)
498  enccfg.g_pass = VPX_RC_FIRST_PASS;
499  else if (avctx->flags & AV_CODEC_FLAG_PASS2)
500  enccfg.g_pass = VPX_RC_LAST_PASS;
501  else
502  enccfg.g_pass = VPX_RC_ONE_PASS;
503 
504  if (avctx->rc_min_rate == avctx->rc_max_rate &&
505  avctx->rc_min_rate == avctx->bit_rate && avctx->bit_rate) {
506  enccfg.rc_end_usage = VPX_CBR;
507  } else if (ctx->crf >= 0) {
508  enccfg.rc_end_usage = VPX_CQ;
509 #if CONFIG_LIBVPX_VP9_ENCODER
510  if (!avctx->bit_rate && avctx->codec_id == AV_CODEC_ID_VP9)
511  enccfg.rc_end_usage = VPX_Q;
512 #endif
513  }
514 
515  if (avctx->bit_rate) {
516  enccfg.rc_target_bitrate = av_rescale_rnd(avctx->bit_rate, 1, 1000,
518 #if CONFIG_LIBVPX_VP9_ENCODER
519  } else if (enccfg.rc_end_usage == VPX_Q) {
520 #endif
521  } else {
522  if (enccfg.rc_end_usage == VPX_CQ) {
523  enccfg.rc_target_bitrate = 1000000;
524  } else {
525  avctx->bit_rate = enccfg.rc_target_bitrate * 1000;
526  av_log(avctx, AV_LOG_WARNING,
527  "Neither bitrate nor constrained quality specified, using default bitrate of %dkbit/sec\n",
528  enccfg.rc_target_bitrate);
529  }
530  }
531 
532  if (avctx->codec_id == AV_CODEC_ID_VP9 && ctx->lossless == 1) {
533  enccfg.rc_min_quantizer =
534  enccfg.rc_max_quantizer = 0;
535  } else {
536  if (avctx->qmin >= 0)
537  enccfg.rc_min_quantizer = avctx->qmin;
538  if (avctx->qmax >= 0)
539  enccfg.rc_max_quantizer = avctx->qmax;
540  }
541 
542  if (enccfg.rc_end_usage == VPX_CQ
543 #if CONFIG_LIBVPX_VP9_ENCODER
544  || enccfg.rc_end_usage == VPX_Q
545 #endif
546  ) {
547  if (ctx->crf < enccfg.rc_min_quantizer || ctx->crf > enccfg.rc_max_quantizer) {
548  av_log(avctx, AV_LOG_ERROR,
549  "CQ level %d must be between minimum and maximum quantizer value (%d-%d)\n",
550  ctx->crf, enccfg.rc_min_quantizer, enccfg.rc_max_quantizer);
551  return AVERROR(EINVAL);
552  }
553  }
554 
555 #if FF_API_PRIVATE_OPT
557  if (avctx->frame_skip_threshold)
558  ctx->drop_threshold = avctx->frame_skip_threshold;
560 #endif
561  enccfg.rc_dropframe_thresh = ctx->drop_threshold;
562 
563  //0-100 (0 => CBR, 100 => VBR)
564  enccfg.rc_2pass_vbr_bias_pct = lrint(avctx->qcompress * 100);
565  if (avctx->bit_rate)
566  enccfg.rc_2pass_vbr_minsection_pct =
567  avctx->rc_min_rate * 100LL / avctx->bit_rate;
568  if (avctx->rc_max_rate)
569  enccfg.rc_2pass_vbr_maxsection_pct =
570  avctx->rc_max_rate * 100LL / avctx->bit_rate;
571 
572  if (avctx->rc_buffer_size)
573  enccfg.rc_buf_sz =
574  avctx->rc_buffer_size * 1000LL / avctx->bit_rate;
575  if (avctx->rc_initial_buffer_occupancy)
576  enccfg.rc_buf_initial_sz =
577  avctx->rc_initial_buffer_occupancy * 1000LL / avctx->bit_rate;
578  enccfg.rc_buf_optimal_sz = enccfg.rc_buf_sz * 5 / 6;
579 #if FF_API_MPV_OPT
581  if (avctx->rc_buffer_aggressivity != 1.0) {
582  av_log(avctx, AV_LOG_WARNING, "The rc_buffer_aggressivity option is "
583  "deprecated, use the undershoot-pct private option instead.\n");
584  enccfg.rc_undershoot_pct = lrint(avctx->rc_buffer_aggressivity * 100);
585  }
587 #endif
588  if (ctx->rc_undershoot_pct >= 0)
589  enccfg.rc_undershoot_pct = ctx->rc_undershoot_pct;
590  if (ctx->rc_overshoot_pct >= 0)
591  enccfg.rc_overshoot_pct = ctx->rc_overshoot_pct;
592 
593  //_enc_init() will balk if kf_min_dist differs from max w/VPX_KF_AUTO
594  if (avctx->keyint_min >= 0 && avctx->keyint_min == avctx->gop_size)
595  enccfg.kf_min_dist = avctx->keyint_min;
596  if (avctx->gop_size >= 0)
597  enccfg.kf_max_dist = avctx->gop_size;
598 
599  if (enccfg.g_pass == VPX_RC_FIRST_PASS)
600  enccfg.g_lag_in_frames = 0;
601  else if (enccfg.g_pass == VPX_RC_LAST_PASS) {
602  int decode_size, ret;
603 
604  if (!avctx->stats_in) {
605  av_log(avctx, AV_LOG_ERROR, "No stats file for second pass\n");
606  return AVERROR_INVALIDDATA;
607  }
608 
609  ctx->twopass_stats.sz = strlen(avctx->stats_in) * 3 / 4;
610  ret = av_reallocp(&ctx->twopass_stats.buf, ctx->twopass_stats.sz);
611  if (ret < 0) {
612  av_log(avctx, AV_LOG_ERROR,
613  "Stat buffer alloc (%"SIZE_SPECIFIER" bytes) failed\n",
614  ctx->twopass_stats.sz);
615  ctx->twopass_stats.sz = 0;
616  return ret;
617  }
618  decode_size = av_base64_decode(ctx->twopass_stats.buf, avctx->stats_in,
619  ctx->twopass_stats.sz);
620  if (decode_size < 0) {
621  av_log(avctx, AV_LOG_ERROR, "Stat buffer decode failed\n");
622  return AVERROR_INVALIDDATA;
623  }
624 
625  ctx->twopass_stats.sz = decode_size;
626  enccfg.rc_twopass_stats_in = ctx->twopass_stats;
627  }
628 
629  /* 0-3: For non-zero values the encoder increasingly optimizes for reduced
630  complexity playback on low powered devices at the expense of encode
631  quality. */
632  if (avctx->profile != FF_PROFILE_UNKNOWN)
633  enccfg.g_profile = avctx->profile;
634 
635  enccfg.g_error_resilient = ctx->error_resilient || ctx->flags & VP8F_ERROR_RESILIENT;
636 
637  dump_enc_cfg(avctx, &enccfg);
638  /* Construct Encoder Context */
639  res = vpx_codec_enc_init(&ctx->encoder, iface, &enccfg, flags);
640  if (res != VPX_CODEC_OK) {
641  log_encoder_error(avctx, "Failed to initialize encoder");
642  return AVERROR(EINVAL);
643  }
644 
645  if (ctx->is_alpha) {
646  enccfg_alpha = enccfg;
647  res = vpx_codec_enc_init(&ctx->encoder_alpha, iface, &enccfg_alpha, flags);
648  if (res != VPX_CODEC_OK) {
649  log_encoder_error(avctx, "Failed to initialize alpha encoder");
650  return AVERROR(EINVAL);
651  }
652  }
653 
654  //codec control failures are currently treated only as warnings
655  av_log(avctx, AV_LOG_DEBUG, "vpx_codec_control\n");
656  codecctl_int(avctx, VP8E_SET_CPUUSED, ctx->cpu_used);
657  if (ctx->flags & VP8F_AUTO_ALT_REF)
658  ctx->auto_alt_ref = 1;
659  if (ctx->auto_alt_ref >= 0)
660  codecctl_int(avctx, VP8E_SET_ENABLEAUTOALTREF,
661  avctx->codec_id == AV_CODEC_ID_VP8 ? !!ctx->auto_alt_ref : ctx->auto_alt_ref);
662  if (ctx->arnr_max_frames >= 0)
663  codecctl_int(avctx, VP8E_SET_ARNR_MAXFRAMES, ctx->arnr_max_frames);
664  if (ctx->arnr_strength >= 0)
665  codecctl_int(avctx, VP8E_SET_ARNR_STRENGTH, ctx->arnr_strength);
666  if (ctx->arnr_type >= 0)
667  codecctl_int(avctx, VP8E_SET_ARNR_TYPE, ctx->arnr_type);
668  if (ctx->tune >= 0)
669  codecctl_int(avctx, VP8E_SET_TUNING, ctx->tune);
670 
671  if (ctx->auto_alt_ref && ctx->is_alpha && avctx->codec_id == AV_CODEC_ID_VP8) {
672  av_log(avctx, AV_LOG_ERROR, "Transparency encoding with auto_alt_ref does not work\n");
673  return AVERROR(EINVAL);
674  }
675 
676  if (CONFIG_LIBVPX_VP8_ENCODER && avctx->codec_id == AV_CODEC_ID_VP8) {
677 #if FF_API_PRIVATE_OPT
679  if (avctx->noise_reduction)
680  ctx->noise_sensitivity = avctx->noise_reduction;
682 #endif
683  codecctl_int(avctx, VP8E_SET_NOISE_SENSITIVITY, ctx->noise_sensitivity);
684  codecctl_int(avctx, VP8E_SET_TOKEN_PARTITIONS, av_log2(avctx->slices));
685  }
686 #if FF_API_MPV_OPT
688  if (avctx->mb_threshold) {
689  av_log(avctx, AV_LOG_WARNING, "The mb_threshold option is deprecated, "
690  "use the static-thresh private option instead.\n");
691  ctx->static_thresh = avctx->mb_threshold;
692  }
694 #endif
695  codecctl_int(avctx, VP8E_SET_STATIC_THRESHOLD, ctx->static_thresh);
696  if (ctx->crf >= 0)
697  codecctl_int(avctx, VP8E_SET_CQ_LEVEL, ctx->crf);
698  if (ctx->max_intra_rate >= 0)
699  codecctl_int(avctx, VP8E_SET_MAX_INTRA_BITRATE_PCT, ctx->max_intra_rate);
700 
701 #if CONFIG_LIBVPX_VP9_ENCODER
702  if (avctx->codec_id == AV_CODEC_ID_VP9) {
703  if (ctx->lossless >= 0)
704  codecctl_int(avctx, VP9E_SET_LOSSLESS, ctx->lossless);
705  if (ctx->tile_columns >= 0)
706  codecctl_int(avctx, VP9E_SET_TILE_COLUMNS, ctx->tile_columns);
707  if (ctx->tile_rows >= 0)
708  codecctl_int(avctx, VP9E_SET_TILE_ROWS, ctx->tile_rows);
709  if (ctx->frame_parallel >= 0)
710  codecctl_int(avctx, VP9E_SET_FRAME_PARALLEL_DECODING, ctx->frame_parallel);
711  if (ctx->aq_mode >= 0)
712  codecctl_int(avctx, VP9E_SET_AQ_MODE, ctx->aq_mode);
713 #if VPX_ENCODER_ABI_VERSION > 8
714  set_colorspace(avctx);
715 #endif
716 #if VPX_ENCODER_ABI_VERSION >= 11
717  set_color_range(avctx);
718 #endif
719 #if VPX_ENCODER_ABI_VERSION >= 12
720  codecctl_int(avctx, VP9E_SET_TARGET_LEVEL, ctx->level < 0 ? 255 : lrint(ctx->level * 10));
721 #endif
722  }
723 #endif
724 
725  av_log(avctx, AV_LOG_DEBUG, "Using deadline: %d\n", ctx->deadline);
726 
727  //provide dummy value to initialize wrapper, values will be updated each _encode()
728  vpx_img_wrap(&ctx->rawimg, img_fmt, avctx->width, avctx->height, 1,
729  (unsigned char*)1);
730 #if CONFIG_LIBVPX_VP9_ENCODER && defined(VPX_IMG_FMT_HIGHBITDEPTH)
731  if (avctx->codec_id == AV_CODEC_ID_VP9 && (codec_caps & VPX_CODEC_CAP_HIGHBITDEPTH))
732  ctx->rawimg.bit_depth = enccfg.g_bit_depth;
733 #endif
734 
735  if (ctx->is_alpha)
736  vpx_img_wrap(&ctx->rawimg_alpha, VPX_IMG_FMT_I420, avctx->width, avctx->height, 1,
737  (unsigned char*)1);
738 
739  cpb_props = ff_add_cpb_side_data(avctx);
740  if (!cpb_props)
741  return AVERROR(ENOMEM);
742 
743  if (enccfg.rc_end_usage == VPX_CBR ||
744  enccfg.g_pass != VPX_RC_ONE_PASS) {
745  cpb_props->max_bitrate = avctx->rc_max_rate;
746  cpb_props->min_bitrate = avctx->rc_min_rate;
747  cpb_props->avg_bitrate = avctx->bit_rate;
748  }
749  cpb_props->buffer_size = avctx->rc_buffer_size;
750 
751  return 0;
752 }
753 
754 static inline void cx_pktcpy(struct FrameListData *dst,
755  const struct vpx_codec_cx_pkt *src,
756  const struct vpx_codec_cx_pkt *src_alpha,
757  VPxContext *ctx)
758 {
759  dst->pts = src->data.frame.pts;
760  dst->duration = src->data.frame.duration;
761  dst->flags = src->data.frame.flags;
762  dst->sz = src->data.frame.sz;
763  dst->buf = src->data.frame.buf;
764  dst->have_sse = 0;
765  /* For alt-ref frame, don't store PSNR or increment frame_number */
766  if (!(dst->flags & VPX_FRAME_IS_INVISIBLE)) {
767  dst->frame_number = ++ctx->frame_number;
768  dst->have_sse = ctx->have_sse;
769  if (ctx->have_sse) {
770  /* associate last-seen SSE to the frame. */
771  /* Transfers ownership from ctx to dst. */
772  /* WARNING! This makes the assumption that PSNR_PKT comes
773  just before the frame it refers to! */
774  memcpy(dst->sse, ctx->sse, sizeof(dst->sse));
775  ctx->have_sse = 0;
776  }
777  } else {
778  dst->frame_number = -1; /* sanity marker */
779  }
780  if (src_alpha) {
781  dst->buf_alpha = src_alpha->data.frame.buf;
782  dst->sz_alpha = src_alpha->data.frame.sz;
783  } else {
784  dst->buf_alpha = NULL;
785  dst->sz_alpha = 0;
786  }
787 }
788 
789 /**
790  * Store coded frame information in format suitable for return from encode2().
791  *
792  * Write information from @a cx_frame to @a pkt
793  * @return packet data size on success
794  * @return a negative AVERROR on error
795  */
796 static int storeframe(AVCodecContext *avctx, struct FrameListData *cx_frame,
797  AVPacket *pkt)
798 {
799  int ret = ff_alloc_packet2(avctx, pkt, cx_frame->sz, 0);
800  uint8_t *side_data;
801  if (ret >= 0) {
802  int pict_type;
803  memcpy(pkt->data, cx_frame->buf, pkt->size);
804  pkt->pts = pkt->dts = cx_frame->pts;
805 #if FF_API_CODED_FRAME
807  avctx->coded_frame->pts = cx_frame->pts;
808  avctx->coded_frame->key_frame = !!(cx_frame->flags & VPX_FRAME_IS_KEY);
810 #endif
811 
812  if (!!(cx_frame->flags & VPX_FRAME_IS_KEY)) {
813  pict_type = AV_PICTURE_TYPE_I;
814 #if FF_API_CODED_FRAME
816  avctx->coded_frame->pict_type = pict_type;
818 #endif
819  pkt->flags |= AV_PKT_FLAG_KEY;
820  } else {
821  pict_type = AV_PICTURE_TYPE_P;
822 #if FF_API_CODED_FRAME
824  avctx->coded_frame->pict_type = pict_type;
826 #endif
827  }
828 
829  ff_side_data_set_encoder_stats(pkt, 0, cx_frame->sse + 1,
830  cx_frame->have_sse ? 3 : 0, pict_type);
831 
832  if (cx_frame->have_sse) {
833  int i;
834  /* Beware of the Y/U/V/all order! */
835 #if FF_API_CODED_FRAME
837  avctx->coded_frame->error[0] = cx_frame->sse[1];
838  avctx->coded_frame->error[1] = cx_frame->sse[2];
839  avctx->coded_frame->error[2] = cx_frame->sse[3];
840  avctx->coded_frame->error[3] = 0; // alpha
842 #endif
843  for (i = 0; i < 3; ++i) {
844  avctx->error[i] += cx_frame->sse[i + 1];
845  }
846  cx_frame->have_sse = 0;
847  }
848  if (cx_frame->sz_alpha > 0) {
849  side_data = av_packet_new_side_data(pkt,
851  cx_frame->sz_alpha + 8);
852  if(!side_data) {
853  av_packet_unref(pkt);
854  av_free(pkt);
855  return AVERROR(ENOMEM);
856  }
857  AV_WB64(side_data, 1);
858  memcpy(side_data + 8, cx_frame->buf_alpha, cx_frame->sz_alpha);
859  }
860  } else {
861  return ret;
862  }
863  return pkt->size;
864 }
865 
866 /**
867  * Queue multiple output frames from the encoder, returning the front-most.
868  * In cases where vpx_codec_get_cx_data() returns more than 1 frame append
869  * the frame queue. Return the head frame if available.
870  * @return Stored frame size
871  * @return AVERROR(EINVAL) on output size error
872  * @return AVERROR(ENOMEM) on coded frame queue data allocation error
873  */
874 static int queue_frames(AVCodecContext *avctx, AVPacket *pkt_out)
875 {
876  VPxContext *ctx = avctx->priv_data;
877  const struct vpx_codec_cx_pkt *pkt;
878  const struct vpx_codec_cx_pkt *pkt_alpha = NULL;
879  const void *iter = NULL;
880  const void *iter_alpha = NULL;
881  int size = 0;
882 
883  if (ctx->coded_frame_list) {
884  struct FrameListData *cx_frame = ctx->coded_frame_list;
885  /* return the leading frame if we've already begun queueing */
886  size = storeframe(avctx, cx_frame, pkt_out);
887  if (size < 0)
888  return size;
889  ctx->coded_frame_list = cx_frame->next;
890  free_coded_frame(cx_frame);
891  }
892 
893  /* consume all available output from the encoder before returning. buffers
894  are only good through the next vpx_codec call */
895  while ((pkt = vpx_codec_get_cx_data(&ctx->encoder, &iter)) &&
896  (!ctx->is_alpha ||
897  (ctx->is_alpha && (pkt_alpha = vpx_codec_get_cx_data(&ctx->encoder_alpha, &iter_alpha))))) {
898  switch (pkt->kind) {
899  case VPX_CODEC_CX_FRAME_PKT:
900  if (!size) {
901  struct FrameListData cx_frame;
902 
903  /* avoid storing the frame when the list is empty and we haven't yet
904  provided a frame for output */
906  cx_pktcpy(&cx_frame, pkt, pkt_alpha, ctx);
907  size = storeframe(avctx, &cx_frame, pkt_out);
908  if (size < 0)
909  return size;
910  } else {
911  struct FrameListData *cx_frame =
912  av_malloc(sizeof(struct FrameListData));
913 
914  if (!cx_frame) {
915  av_log(avctx, AV_LOG_ERROR,
916  "Frame queue element alloc failed\n");
917  return AVERROR(ENOMEM);
918  }
919  cx_pktcpy(cx_frame, pkt, pkt_alpha, ctx);
920  cx_frame->buf = av_malloc(cx_frame->sz);
921 
922  if (!cx_frame->buf) {
923  av_log(avctx, AV_LOG_ERROR,
924  "Data buffer alloc (%"SIZE_SPECIFIER" bytes) failed\n",
925  cx_frame->sz);
926  av_freep(&cx_frame);
927  return AVERROR(ENOMEM);
928  }
929  memcpy(cx_frame->buf, pkt->data.frame.buf, pkt->data.frame.sz);
930  if (ctx->is_alpha) {
931  cx_frame->buf_alpha = av_malloc(cx_frame->sz_alpha);
932  if (!cx_frame->buf_alpha) {
933  av_log(avctx, AV_LOG_ERROR,
934  "Data buffer alloc (%"SIZE_SPECIFIER" bytes) failed\n",
935  cx_frame->sz_alpha);
936  av_free(cx_frame);
937  return AVERROR(ENOMEM);
938  }
939  memcpy(cx_frame->buf_alpha, pkt_alpha->data.frame.buf, pkt_alpha->data.frame.sz);
940  }
941  coded_frame_add(&ctx->coded_frame_list, cx_frame);
942  }
943  break;
944  case VPX_CODEC_STATS_PKT: {
945  struct vpx_fixed_buf *stats = &ctx->twopass_stats;
946  int err;
947  if ((err = av_reallocp(&stats->buf,
948  stats->sz +
949  pkt->data.twopass_stats.sz)) < 0) {
950  stats->sz = 0;
951  av_log(avctx, AV_LOG_ERROR, "Stat buffer realloc failed\n");
952  return err;
953  }
954  memcpy((uint8_t*)stats->buf + stats->sz,
955  pkt->data.twopass_stats.buf, pkt->data.twopass_stats.sz);
956  stats->sz += pkt->data.twopass_stats.sz;
957  break;
958  }
959  case VPX_CODEC_PSNR_PKT:
960  av_assert0(!ctx->have_sse);
961  ctx->sse[0] = pkt->data.psnr.sse[0];
962  ctx->sse[1] = pkt->data.psnr.sse[1];
963  ctx->sse[2] = pkt->data.psnr.sse[2];
964  ctx->sse[3] = pkt->data.psnr.sse[3];
965  ctx->have_sse = 1;
966  break;
967  case VPX_CODEC_CUSTOM_PKT:
968  //ignore unsupported/unrecognized packet types
969  break;
970  }
971  }
972 
973  return size;
974 }
975 
976 static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt,
977  const AVFrame *frame, int *got_packet)
978 {
979  VPxContext *ctx = avctx->priv_data;
980  struct vpx_image *rawimg = NULL;
981  struct vpx_image *rawimg_alpha = NULL;
982  int64_t timestamp = 0;
983  int res, coded_size;
984  vpx_enc_frame_flags_t flags = 0;
985 
986  if (frame) {
987  rawimg = &ctx->rawimg;
988  rawimg->planes[VPX_PLANE_Y] = frame->data[0];
989  rawimg->planes[VPX_PLANE_U] = frame->data[1];
990  rawimg->planes[VPX_PLANE_V] = frame->data[2];
991  rawimg->stride[VPX_PLANE_Y] = frame->linesize[0];
992  rawimg->stride[VPX_PLANE_U] = frame->linesize[1];
993  rawimg->stride[VPX_PLANE_V] = frame->linesize[2];
994  if (ctx->is_alpha) {
995  uint8_t *u_plane, *v_plane;
996  rawimg_alpha = &ctx->rawimg_alpha;
997  rawimg_alpha->planes[VPX_PLANE_Y] = frame->data[3];
998  u_plane = av_malloc(frame->linesize[1] * frame->height);
999  v_plane = av_malloc(frame->linesize[2] * frame->height);
1000  if (!u_plane || !v_plane) {
1001  av_free(u_plane);
1002  av_free(v_plane);
1003  return AVERROR(ENOMEM);
1004  }
1005  memset(u_plane, 0x80, frame->linesize[1] * frame->height);
1006  rawimg_alpha->planes[VPX_PLANE_U] = u_plane;
1007  memset(v_plane, 0x80, frame->linesize[2] * frame->height);
1008  rawimg_alpha->planes[VPX_PLANE_V] = v_plane;
1009  rawimg_alpha->stride[VPX_PLANE_Y] = frame->linesize[0];
1010  rawimg_alpha->stride[VPX_PLANE_U] = frame->linesize[1];
1011  rawimg_alpha->stride[VPX_PLANE_V] = frame->linesize[2];
1012  }
1013  timestamp = frame->pts;
1014  if (frame->pict_type == AV_PICTURE_TYPE_I)
1015  flags |= VPX_EFLAG_FORCE_KF;
1016  }
1017 
1018  res = vpx_codec_encode(&ctx->encoder, rawimg, timestamp,
1019  avctx->ticks_per_frame, flags, ctx->deadline);
1020  if (res != VPX_CODEC_OK) {
1021  log_encoder_error(avctx, "Error encoding frame");
1022  return AVERROR_INVALIDDATA;
1023  }
1024 
1025  if (ctx->is_alpha) {
1026  res = vpx_codec_encode(&ctx->encoder_alpha, rawimg_alpha, timestamp,
1027  avctx->ticks_per_frame, flags, ctx->deadline);
1028  if (res != VPX_CODEC_OK) {
1029  log_encoder_error(avctx, "Error encoding alpha frame");
1030  return AVERROR_INVALIDDATA;
1031  }
1032  }
1033 
1034  coded_size = queue_frames(avctx, pkt);
1035 
1036  if (!frame && avctx->flags & AV_CODEC_FLAG_PASS1) {
1037  unsigned int b64_size = AV_BASE64_SIZE(ctx->twopass_stats.sz);
1038 
1039  avctx->stats_out = av_malloc(b64_size);
1040  if (!avctx->stats_out) {
1041  av_log(avctx, AV_LOG_ERROR, "Stat buffer alloc (%d bytes) failed\n",
1042  b64_size);
1043  return AVERROR(ENOMEM);
1044  }
1045  av_base64_encode(avctx->stats_out, b64_size, ctx->twopass_stats.buf,
1046  ctx->twopass_stats.sz);
1047  }
1048 
1049  if (rawimg_alpha) {
1050  av_freep(&rawimg_alpha->planes[VPX_PLANE_U]);
1051  av_freep(&rawimg_alpha->planes[VPX_PLANE_V]);
1052  }
1053 
1054  *got_packet = !!coded_size;
1055  return 0;
1056 }
1057 
1058 #define OFFSET(x) offsetof(VPxContext, x)
1059 #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
1060 
1061 #ifndef VPX_ERROR_RESILIENT_DEFAULT
1062 #define VPX_ERROR_RESILIENT_DEFAULT 1
1063 #define VPX_ERROR_RESILIENT_PARTITIONS 2
1064 #endif
1065 
1066 #define COMMON_OPTIONS \
1067  { "auto-alt-ref", "Enable use of alternate reference " \
1068  "frames (2-pass only)", OFFSET(auto_alt_ref), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 2, VE}, \
1069  { "lag-in-frames", "Number of frames to look ahead for " \
1070  "alternate reference frame selection", OFFSET(lag_in_frames), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
1071  { "arnr-maxframes", "altref noise reduction max frame count", OFFSET(arnr_max_frames), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
1072  { "arnr-strength", "altref noise reduction filter strength", OFFSET(arnr_strength), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
1073  { "arnr-type", "altref noise reduction filter type", OFFSET(arnr_type), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, "arnr_type"}, \
1074  { "backward", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, "arnr_type" }, \
1075  { "forward", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, VE, "arnr_type" }, \
1076  { "centered", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0, VE, "arnr_type" }, \
1077  { "tune", "Tune the encoding to a specific scenario", OFFSET(tune), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, "tune"}, \
1078  { "psnr", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VP8_TUNE_PSNR}, 0, 0, VE, "tune"}, \
1079  { "ssim", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VP8_TUNE_SSIM}, 0, 0, VE, "tune"}, \
1080  { "deadline", "Time to spend encoding, in microseconds.", OFFSET(deadline), AV_OPT_TYPE_INT, {.i64 = VPX_DL_GOOD_QUALITY}, INT_MIN, INT_MAX, VE, "quality"}, \
1081  { "best", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_DL_BEST_QUALITY}, 0, 0, VE, "quality"}, \
1082  { "good", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_DL_GOOD_QUALITY}, 0, 0, VE, "quality"}, \
1083  { "realtime", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_DL_REALTIME}, 0, 0, VE, "quality"}, \
1084  { "error-resilient", "Error resilience configuration", OFFSET(error_resilient), AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX, VE, "er"}, \
1085  { "max-intra-rate", "Maximum I-frame bitrate (pct) 0=unlimited", OFFSET(max_intra_rate), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
1086  { "default", "Improve resiliency against losses of whole frames", 0, AV_OPT_TYPE_CONST, {.i64 = VPX_ERROR_RESILIENT_DEFAULT}, 0, 0, VE, "er"}, \
1087  { "partitions", "The frame partitions are independently decodable " \
1088  "by the bool decoder, meaning that partitions can be decoded even " \
1089  "though earlier partitions have been lost. Note that intra predicition" \
1090  " is still done over the partition boundary.", 0, AV_OPT_TYPE_CONST, {.i64 = VPX_ERROR_RESILIENT_PARTITIONS}, 0, 0, VE, "er"}, \
1091  { "crf", "Select the quality for constant quality mode", offsetof(VPxContext, crf), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 63, VE }, \
1092  { "static-thresh", "A change threshold on blocks below which they will be skipped by the encoder", OFFSET(static_thresh), AV_OPT_TYPE_INT, { .i64 = 0 }, 0, INT_MAX, VE }, \
1093  { "drop-threshold", "Frame drop threshold", offsetof(VPxContext, drop_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, VE }, \
1094  { "noise-sensitivity", "Noise sensitivity", OFFSET(noise_sensitivity), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 4, VE}, \
1095  { "undershoot-pct", "Datarate undershoot (min) target (%)", OFFSET(rc_undershoot_pct), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 100, VE }, \
1096  { "overshoot-pct", "Datarate overshoot (max) target (%)", OFFSET(rc_overshoot_pct), AV_OPT_TYPE_INT, { .i64 = -1 }, -1, 1000, VE }, \
1097 
1098 #define LEGACY_OPTIONS \
1099  {"speed", "", offsetof(VPxContext, cpu_used), AV_OPT_TYPE_INT, {.i64 = 1}, -16, 16, VE}, \
1100  {"quality", "", offsetof(VPxContext, deadline), AV_OPT_TYPE_INT, {.i64 = VPX_DL_GOOD_QUALITY}, INT_MIN, INT_MAX, VE, "quality"}, \
1101  {"vp8flags", "", offsetof(VPxContext, flags), AV_OPT_TYPE_FLAGS, {.i64 = 0}, 0, UINT_MAX, VE, "flags"}, \
1102  {"error_resilient", "enable error resilience", 0, AV_OPT_TYPE_CONST, {.i64 = VP8F_ERROR_RESILIENT}, INT_MIN, INT_MAX, VE, "flags"}, \
1103  {"altref", "enable use of alternate reference frames (VP8/2-pass only)", 0, AV_OPT_TYPE_CONST, {.i64 = VP8F_AUTO_ALT_REF}, INT_MIN, INT_MAX, VE, "flags"}, \
1104  {"arnr_max_frames", "altref noise reduction max frame count", offsetof(VPxContext, arnr_max_frames), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 15, VE}, \
1105  {"arnr_strength", "altref noise reduction filter strength", offsetof(VPxContext, arnr_strength), AV_OPT_TYPE_INT, {.i64 = 3}, 0, 6, VE}, \
1106  {"arnr_type", "altref noise reduction filter type", offsetof(VPxContext, arnr_type), AV_OPT_TYPE_INT, {.i64 = 3}, 1, 3, VE}, \
1107  {"rc_lookahead", "Number of frames to look ahead for alternate reference frame selection", offsetof(VPxContext, lag_in_frames), AV_OPT_TYPE_INT, {.i64 = 25}, 0, 25, VE}, \
1108 
1109 #if CONFIG_LIBVPX_VP8_ENCODER
1110 static const AVOption vp8_options[] = {
1112  { "cpu-used", "Quality/Speed ratio modifier", OFFSET(cpu_used), AV_OPT_TYPE_INT, {.i64 = 1}, -16, 16, VE},
1114  { NULL }
1115 };
1116 #endif
1117 
1118 #if CONFIG_LIBVPX_VP9_ENCODER
1119 static const AVOption vp9_options[] = {
1121  { "cpu-used", "Quality/Speed ratio modifier", OFFSET(cpu_used), AV_OPT_TYPE_INT, {.i64 = 1}, -8, 8, VE},
1122  { "lossless", "Lossless mode", OFFSET(lossless), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, VE},
1123  { "tile-columns", "Number of tile columns to use, log2", OFFSET(tile_columns), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6, VE},
1124  { "tile-rows", "Number of tile rows to use, log2", OFFSET(tile_rows), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 2, VE},
1125  { "frame-parallel", "Enable frame parallel decodability features", OFFSET(frame_parallel), AV_OPT_TYPE_BOOL,{.i64 = -1}, -1, 1, VE},
1126  { "aq-mode", "adaptive quantization mode", OFFSET(aq_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 3, VE, "aq_mode"},
1127  { "none", "Aq not used", 0, AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, VE, "aq_mode" },
1128  { "variance", "Variance based Aq", 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, "aq_mode" },
1129  { "complexity", "Complexity based Aq", 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, VE, "aq_mode" },
1130  { "cyclic", "Cyclic Refresh Aq", 0, AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0, VE, "aq_mode" },
1131 #if VPX_ENCODER_ABI_VERSION >= 12
1132  {"level", "Specify level", OFFSET(level), AV_OPT_TYPE_FLOAT, {.dbl=-1}, -1, 6.2, VE},
1133 #endif
1135  { NULL }
1136 };
1137 #endif
1138 
1139 #undef COMMON_OPTIONS
1140 #undef LEGACY_OPTIONS
1141 
1142 static const AVCodecDefault defaults[] = {
1143  { "qmin", "-1" },
1144  { "qmax", "-1" },
1145  { "g", "-1" },
1146  { "keyint_min", "-1" },
1147  { NULL },
1148 };
1149 
1150 #if CONFIG_LIBVPX_VP8_ENCODER
1151 static av_cold int vp8_init(AVCodecContext *avctx)
1152 {
1153  return vpx_init(avctx, vpx_codec_vp8_cx());
1154 }
1155 
1156 static const AVClass class_vp8 = {
1157  .class_name = "libvpx-vp8 encoder",
1158  .item_name = av_default_item_name,
1159  .option = vp8_options,
1160  .version = LIBAVUTIL_VERSION_INT,
1161 };
1162 
1163 AVCodec ff_libvpx_vp8_encoder = {
1164  .name = "libvpx",
1165  .long_name = NULL_IF_CONFIG_SMALL("libvpx VP8"),
1166  .type = AVMEDIA_TYPE_VIDEO,
1167  .id = AV_CODEC_ID_VP8,
1168  .priv_data_size = sizeof(VPxContext),
1169  .init = vp8_init,
1170  .encode2 = vpx_encode,
1171  .close = vpx_free,
1174  .priv_class = &class_vp8,
1175  .defaults = defaults,
1176 };
1177 #endif /* CONFIG_LIBVPX_VP8_ENCODER */
1178 
1179 #if CONFIG_LIBVPX_VP9_ENCODER
1180 static av_cold int vp9_init(AVCodecContext *avctx)
1181 {
1182  return vpx_init(avctx, vpx_codec_vp9_cx());
1183 }
1184 
1185 static const AVClass class_vp9 = {
1186  .class_name = "libvpx-vp9 encoder",
1187  .item_name = av_default_item_name,
1188  .option = vp9_options,
1189  .version = LIBAVUTIL_VERSION_INT,
1190 };
1191 
1192 AVCodec ff_libvpx_vp9_encoder = {
1193  .name = "libvpx-vp9",
1194  .long_name = NULL_IF_CONFIG_SMALL("libvpx VP9"),
1195  .type = AVMEDIA_TYPE_VIDEO,
1196  .id = AV_CODEC_ID_VP9,
1197  .priv_data_size = sizeof(VPxContext),
1198  .init = vp9_init,
1199  .encode2 = vpx_encode,
1200  .close = vpx_free,
1203  .priv_class = &class_vp9,
1204  .defaults = defaults,
1205  .init_static_data = ff_vp9_init_static,
1206 };
1207 #endif /* CONFIG_LIBVPX_VP9_ENCODER */
uint8_t is_alpha
Definition: libvpxenc.c:69
uint64_t sse[4]
Definition: libvpxenc.c:57
also ITU-R BT1361 / IEC 61966-2-4 xvYCC709 / SMPTE RP177 Annex B
Definition: pixfmt.h:452
struct vpx_image rawimg
Definition: libvpxenc.c:66
int arnr_max_frames
Definition: libvpxenc.c:87
#define NULL
Definition: coverity.c:32
const char const char void * val
Definition: avisynth_c.h:771
#define AVERROR_INVALIDDATA
Invalid data found when processing input.
Definition: error.h:59
#define AV_PIX_FMT_YUV440P10
Definition: pixfmt.h:353
This structure describes decoded (raw) audio or video data.
Definition: frame.h:184
static av_cold int vpx_free(AVCodecContext *avctx)
Definition: libvpxenc.c:291
AVOption.
Definition: opt.h:246
int ff_side_data_set_encoder_stats(AVPacket *pkt, int quality, int64_t *error, int error_count, int pict_type)
Definition: avpacket.c:647
uint64_t error[AV_NUM_DATA_POINTERS]
error
Definition: avcodec.h:3016
#define OFFSET(x)
Definition: libvpxenc.c:1058
planar YUV 4:4:4, 24bpp, (1 Cr & Cb sample per 1x1 Y samples)
Definition: pixfmt.h:67
#define AV_LOG_WARNING
Something somehow does not look correct.
Definition: log.h:182
int64_t bit_rate
the average bitrate
Definition: avcodec.h:1741
#define LIBAVUTIL_VERSION_INT
Definition: version.h:85
int rc_overshoot_pct
Definition: libvpxenc.c:99
const char * desc
Definition: nvenc.c:60
static av_cold int init(AVCodecContext *avctx)
Definition: avrndec.c:35
struct FrameListData * coded_frame_list
Definition: libvpxenc.c:75
int max_bitrate
Maximum bitrate of the stream, in bits per second.
Definition: avcodec.h:1316
also ITU-R BT601-6 625 / ITU-R BT1358 625 / ITU-R BT1700 625 PAL & SECAM / IEC 61966-2-4 xvYCC601 ...
Definition: pixfmt.h:456
int rc_initial_buffer_occupancy
Number of bits which should be loaded into the rc buffer before decoding starts.
Definition: avcodec.h:2715
enum AVColorRange color_range
MPEG vs JPEG YUV range.
Definition: avcodec.h:2413
planar GBR 4:4:4 24bpp
Definition: pixfmt.h:180
int num
Numerator.
Definition: rational.h:59
int size
Definition: avcodec.h:1602
#define AV_PIX_FMT_GBRP10
Definition: pixfmt.h:367
int av_log2(unsigned v)
Definition: intmath.c:26
int aq_mode
Definition: libvpxenc.c:106
also ITU-R BT601-6 525 / ITU-R BT1358 525 / ITU-R BT1700 NTSC
Definition: pixfmt.h:457
enum AVPixelFormat pix_fmt
Pixel format, see AV_PIX_FMT_xxx.
Definition: avcodec.h:1904
size_t sz
length of compressed data
Definition: libvpxenc.c:49
static int sse(MpegEncContext *s, uint8_t *src1, uint8_t *src2, int w, int h, int stride)
#define AV_PIX_FMT_YUV420P12
Definition: pixfmt.h:355
char * stats_in
pass2 encoding statistics input buffer Concatenated stuff from stats_out of pass1 should be placed he...
Definition: avcodec.h:2853
static void cx_pktcpy(struct FrameListData *dst, const struct vpx_codec_cx_pkt *src, const struct vpx_codec_cx_pkt *src_alpha, VPxContext *ctx)
Definition: libvpxenc.c:754
int frame_parallel
Definition: libvpxenc.c:105
int static_thresh
Definition: libvpxenc.c:96
static AVPacket pkt
#define AV_CODEC_CAP_AUTO_THREADS
Codec supports avctx->thread_count == 0 (auto).
Definition: avcodec.h:1034
#define src
Definition: vp8dsp.c:254
int profile
profile
Definition: avcodec.h:3182
AVCodec.
Definition: avcodec.h:3601
struct vpx_fixed_buf twopass_stats
Definition: libvpxenc.c:70
int error_resilient
Definition: libvpxenc.c:94
order of coefficients is actually GBR, also IEC 61966-2-1 (sRGB)
Definition: pixfmt.h:451
int tile_rows
Definition: libvpxenc.c:104
uint64_t frame_number
Definition: libvpxenc.c:74
int min_bitrate
Minimum bitrate of the stream, in bits per second.
Definition: avcodec.h:1321
functionally identical to above
Definition: pixfmt.h:458
AVRational time_base
This is the fundamental unit of time (in seconds) in terms of which frame timestamps are represented...
Definition: avcodec.h:1813
#define VP8F_AUTO_ALT_REF
Enable automatic alternate reference frame generation.
Definition: libvpxenc.c:83
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_WB64(p, v)
Definition: intreadwrite.h:433
#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: avcodec.h:984
#define av_assert0(cond)
assert() equivalent, that is always enabled.
Definition: avassert.h:37
planar YUV 4:2:0, 20bpp, (1 Cr & Cb sample per 2x2 Y & A samples)
Definition: pixfmt.h:102
attribute_deprecated float rc_buffer_aggressivity
Definition: avcodec.h:2690
uint8_t
#define av_cold
Definition: attributes.h:82
static av_cold int codecctl_int(AVCodecContext *avctx, enum vp8e_enc_control_id id, int val)
Definition: libvpxenc.c:247
#define av_malloc(s)
int64_t pts
time stamp to show frame (in timebase units)
Definition: libvpxenc.c:52
AVOptions.
static void coded_frame_add(void *list, struct FrameListData *cx_frame)
Definition: libvpxenc.c:218
int64_t pts
Presentation timestamp in time_base units (time when frame should be shown to user).
Definition: frame.h:268
static AVFrame * frame
int auto_alt_ref
Definition: libvpxenc.c:85
uint8_t * data
Definition: avcodec.h:1601
static int flags
Definition: log.c:57
#define AV_LOG_VERBOSE
Detailed information.
Definition: log.h:192
int vpx_cs
Definition: libvpxenc.c:109
uint64_t sse[4]
Definition: libvpxenc.c:72
int buffer_size
The size of the buffer to which the ratecontrol is applied, in bits.
Definition: avcodec.h:1332
ptrdiff_t size
Definition: opengl_enc.c:101
#define AV_PIX_FMT_YUV422P12
Definition: pixfmt.h:356
char * stats_out
pass1 encoding statistics output buffer
Definition: avcodec.h:2845
attribute_deprecated uint64_t error[AV_NUM_DATA_POINTERS]
Definition: frame.h:310
attribute_deprecated int frame_skip_threshold
Definition: avcodec.h:2755
#define av_log(a,...)
int noise_sensitivity
Definition: libvpxenc.c:108
#define LEGACY_OPTIONS
Definition: libvpxenc.c:1098
#define AV_PKT_FLAG_KEY
The packet contains a keyframe.
Definition: avcodec.h:1633
static int vpx_encode(AVCodecContext *avctx, AVPacket *pkt, const AVFrame *frame, int *got_packet)
Definition: libvpxenc.c:976
#define AV_LOG_ERROR
Something went wrong and cannot losslessly be recovered.
Definition: log.h:176
int arnr_type
Definition: libvpxenc.c:89
int tune
Definition: libvpxenc.c:91
static int storeframe(AVCodecContext *avctx, struct FrameListData *cx_frame, AVPacket *pkt)
Store coded frame information in format suitable for return from encode2().
Definition: libvpxenc.c:796
av_default_item_name
#define AVERROR(e)
Definition: error.h:43
#define COMMON_OPTIONS
Definition: libvpxenc.c:1066
int qmax
maximum quantizer
Definition: avcodec.h:2626
#define NULL_IF_CONFIG_SMALL(x)
Return NULL if CONFIG_SMALL is true, otherwise the argument without modification. ...
Definition: internal.h:176
#define AV_LOG_DEBUG
Stuff which is only useful for libav* developers.
Definition: log.h:197
int flags
AV_CODEC_FLAG_*.
Definition: avcodec.h:1771
Round to nearest and halfway cases away from zero.
Definition: mathematics.h:84
simple assert() macros that are a bit more flexible than ISO C assert().
const char * name
Name of the codec implementation.
Definition: avcodec.h:3608
#define AV_PIX_FMT_YUV444P10
Definition: pixfmt.h:354
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
static void error(const char *err)
int flags
A combination of AV_PKT_FLAG values.
Definition: avcodec.h:1607
planar YUV 4:2:2, 16bpp, (1 Cr & Cb sample per 2x1 Y samples)
Definition: pixfmt.h:66
int rc_buffer_size
decoder bitstream buffer size
Definition: avcodec.h:2653
int64_t rc_min_rate
minimum bitrate
Definition: avcodec.h:2683
common internal API header
float level
Definition: libvpxenc.c:110
int lossless
Definition: libvpxenc.c:102
static av_cold void dump_enc_cfg(AVCodecContext *avctx, const struct vpx_codec_enc_cfg *cfg)
Definition: libvpxenc.c:156
enum AVPictureType pict_type
Picture type of the frame.
Definition: frame.h:258
struct vpx_image rawimg_alpha
Definition: libvpxenc.c:68
#define AV_BASE64_SIZE(x)
Calculate the output size needed to base64-encode x bytes to a null-terminated string.
Definition: base64.h:66
#define width
int width
picture width / height.
Definition: avcodec.h:1863
#define FF_PROFILE_UNKNOWN
Definition: avcodec.h:3183
ITU-R BT2020 non-constant luminance system.
Definition: pixfmt.h:460
attribute_deprecated int noise_reduction
Definition: avcodec.h:2265
AVFormatContext * ctx
Definition: movenc.c:48
#define AV_CODEC_FLAG_PSNR
error[?] variables will be set during encoding.
Definition: avcodec.h:865
#define AV_CODEC_FLAG_PASS1
Use internal 2pass ratecontrol in first pass mode.
Definition: avcodec.h:849
int deadline
Definition: libvpxenc.c:71
int ticks_per_frame
For some codecs, the time base is closer to the field rate than the frame rate.
Definition: avcodec.h:1822
static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
Definition: libvpxenc.c:145
attribute_deprecated int mb_threshold
Definition: avcodec.h:2279
int64_t av_rescale_rnd(int64_t a, int64_t b, int64_t c, enum AVRounding rnd)
Rescale a 64-bit integer with specified rounding.
Definition: mathematics.c:58
int thread_count
thread count is used to decide how many independent tasks should be passed to execute() ...
Definition: avcodec.h:3108
struct FrameListData * next
Definition: libvpxenc.c:60
the normal 2^n-1 "JPEG" YUV ranges
Definition: pixfmt.h:474
#define VP8F_ERROR_RESILIENT
Enable measures appropriate for streaming over lossy links.
Definition: libvpxenc.c:82
int cpu_used
Definition: libvpxenc.c:77
static av_cold int vpx_init(AVCodecContext *avctx, const struct vpx_codec_iface *iface)
Definition: libvpxenc.c:449
This structure describes the bitrate properties of an encoded bitstream.
Definition: avcodec.h:1311
static const AVCodecDefault defaults[]
Definition: libvpxenc.c:1142
#define AV_LOG_INFO
Standard information.
Definition: log.h:187
int max_intra_rate
Definition: libvpxenc.c:97
#define VE
Definition: libvpxenc.c:1059
int av_reallocp(void *ptr, size_t size)
Allocate, reallocate, or free a block of memory through a pointer to a pointer.
Definition: mem.c:187
Libavcodec external API header.
enum AVCodecID codec_id
Definition: avcodec.h:1693
av_cold void ff_vp9_init_static(AVCodec *codec)
Definition: libvpx.c:72
int lag_in_frames
Definition: libvpxenc.c:93
int linesize[AV_NUM_DATA_POINTERS]
For video, size in bytes of each picture line.
Definition: frame.h:215
static av_cold int vp9_init(AVFormatContext *ctx, int st_index, PayloadContext *data)
Definition: rtpdec_vp9.c:34
static int set_pix_fmt(AVCodecContext *avctx, struct vpx_image *img, int has_alpha_channel)
Definition: libvpxdec.c:70
main external API structure.
Definition: avcodec.h:1676
static int queue_frames(AVCodecContext *avctx, AVPacket *pkt_out)
Queue multiple output frames from the encoder, returning the front-most.
Definition: libvpxenc.c:874
void av_packet_unref(AVPacket *pkt)
Wipe the packet.
Definition: avpacket.c:568
int qmin
minimum quantizer
Definition: avcodec.h:2619
void * buf
Definition: avisynth_c.h:690
Data found in BlockAdditional element of matroska container.
Definition: avcodec.h:1508
#define AV_PIX_FMT_YUV420P10
Definition: pixfmt.h:351
Describe the class of an AVClass context structure.
Definition: log.h:67
static const AVProfile profiles[]
enum AVColorSpace colorspace
YUV colorspace type.
Definition: avcodec.h:2406
uint32_t flags
flags for this frame
Definition: libvpxenc.c:56
#define AV_PIX_FMT_YUV440P12
Definition: pixfmt.h:357
#define snprintf
Definition: snprintf.h:34
int ff_alloc_packet2(AVCodecContext *avctx, AVPacket *avpkt, int64_t size, int64_t min_size)
Check AVPacket size and/or allocate data.
Definition: utils.c:1722
static av_cold void free_coded_frame(struct FrameListData *cx_frame)
Definition: libvpxenc.c:228
uint64_t frame_number
Definition: libvpxenc.c:59
float qcompress
amount of qscale change between easy & hard scenes (0.0-1.0)
Definition: avcodec.h:2611
static enum AVPixelFormat pix_fmts[]
Definition: libkvazaar.c:262
void * buf
compressed data buffer
Definition: libvpxenc.c:48
size_t sz_alpha
Definition: libvpxenc.c:51
#define AV_PIX_FMT_GBRP12
Definition: pixfmt.h:368
int have_sse
true if we have pending sse[]
Definition: libvpxenc.c:58
#define SIZE_SPECIFIER
Definition: internal.h:252
#define AV_PIX_FMT_YUV422P10
Definition: pixfmt.h:352
#define AV_PIX_FMT_YUV444P12
Definition: pixfmt.h:358
uint8_t * data[AV_NUM_DATA_POINTERS]
pointer to the picture/channel planes.
Definition: frame.h:198
uint8_t level
Definition: svq3.c:207
the normal 219*2^(n-8) "MPEG" YUV ranges
Definition: pixfmt.h:473
int flags
VP8 specific flags, see VP8F_* below.
Definition: libvpxenc.c:81
int gop_size
the number of pictures in a group of pictures, or 0 for intra_only
Definition: avcodec.h:1889
static const char *const ctlidstr[]
String mappings for enum vp8e_enc_control_id.
Definition: libvpxenc.c:114
struct vpx_codec_ctx encoder_alpha
Definition: libvpxenc.c:67
static av_cold int vp8_init(AVFormatContext *s, int st_index, PayloadContext *vp8)
Definition: rtpdec_vp8.c:263
planar YUV 4:2:0, 12bpp, (1 Cr & Cb sample per 2x2 Y samples)
Definition: pixfmt.h:62
#define FF_DISABLE_DEPRECATION_WARNINGS
Definition: internal.h:80
common internal api header.
common internal and external API header
struct vpx_codec_ctx encoder
Definition: libvpxenc.c:65
attribute_deprecated AVFrame * coded_frame
the picture in the bitstream
Definition: avcodec.h:3099
int den
Denominator.
Definition: rational.h:60
AVCPBProperties * ff_add_cpb_side_data(AVCodecContext *avctx)
Add a CPB properties side data to an encoding context.
Definition: utils.c:4081
static av_cold void free_frame_list(struct FrameListData *list)
Definition: libvpxenc.c:236
#define AV_CODEC_FLAG_PASS2
Use internal 2pass ratecontrol in second pass mode.
Definition: avcodec.h:853
void * buf_alpha
Definition: libvpxenc.c:50
int slices
Number of slices.
Definition: avcodec.h:2429
void * priv_data
Definition: avcodec.h:1718
#define av_free(p)
#define FF_ENABLE_DEPRECATION_WARNINGS
Definition: internal.h:81
Portion of struct vpx_codec_cx_pkt from vpx_encoder.h.
Definition: libvpxenc.c:47
int avg_bitrate
Average bitrate of the stream, in bits per second.
Definition: avcodec.h:1326
int arnr_strength
Definition: libvpxenc.c:88
int key_frame
1 -> keyframe, 0-> not
Definition: frame.h:253
unsigned long duration
duration to show frame (in timebase units)
Definition: libvpxenc.c:54
int av_base64_decode(uint8_t *out, const char *in_str, int out_size)
Decode a base64-encoded string.
Definition: base64.c:79
#define lrint
Definition: tablegen.h:53
static void stats(const struct CachedBuf *in, int n_in, unsigned *_max, unsigned *_sum)
int drop_threshold
Definition: libvpxenc.c:107
int64_t dts
Decompression timestamp in AVStream->time_base units; the time at which the packet is decompressed...
Definition: avcodec.h:1600
int have_sse
true if we have pending sse[]
Definition: libvpxenc.c:73
int height
Definition: frame.h:236
#define av_freep(p)
int rc_undershoot_pct
Definition: libvpxenc.c:98
planar YUV 4:4:0 (1 Cr & Cb sample per 1x2 Y samples)
Definition: pixfmt.h:100
uint8_t * av_packet_new_side_data(AVPacket *pkt, enum AVPacketSideDataType type, int size)
Allocate new information of a packet.
Definition: avpacket.c:318
const AVProfile ff_vp9_profiles[]
Definition: profiles.c:135
AVPixelFormat
Pixel format.
Definition: pixfmt.h:60
This structure stores compressed data.
Definition: avcodec.h:1578
int64_t pts
Presentation timestamp in AVStream->time_base units; the time at which the decompressed packet will b...
Definition: avcodec.h:1594
Predicted.
Definition: avutil.h:269
#define av_unused
Definition: attributes.h:126
int tile_columns
Definition: libvpxenc.c:103
int64_t rc_max_rate
maximum bitrate
Definition: avcodec.h:2676
int keyint_min
minimum GOP size
Definition: avcodec.h:2350