You can not select more than 25 topics Topics must start with a letter or number, can include dashes ('-') and can be up to 35 characters long.

918 lines
37KB

  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. * @file
  22. * VP8 encoder support via libvpx
  23. */
  24. #define VPX_DISABLE_CTRL_TYPECHECKS 1
  25. #define VPX_CODEC_DISABLE_COMPAT 1
  26. #include <vpx/vpx_encoder.h>
  27. #include <vpx/vp8cx.h>
  28. #include "avcodec.h"
  29. #include "internal.h"
  30. #include "libavutil/avassert.h"
  31. #include "libvpx.h"
  32. #include "libavutil/base64.h"
  33. #include "libavutil/common.h"
  34. #include "libavutil/intreadwrite.h"
  35. #include "libavutil/mathematics.h"
  36. #include "libavutil/opt.h"
  37. /**
  38. * Portion of struct vpx_codec_cx_pkt from vpx_encoder.h.
  39. * One encoded frame returned from the library.
  40. */
  41. struct FrameListData {
  42. void *buf; /**< compressed data buffer */
  43. size_t sz; /**< length of compressed data */
  44. void *buf_alpha;
  45. size_t sz_alpha;
  46. int64_t pts; /**< time stamp to show frame
  47. (in timebase units) */
  48. unsigned long duration; /**< duration to show frame
  49. (in timebase units) */
  50. uint32_t flags; /**< flags for this frame */
  51. uint64_t sse[4];
  52. int have_sse; /**< true if we have pending sse[] */
  53. uint64_t frame_number;
  54. struct FrameListData *next;
  55. };
  56. typedef struct VP8EncoderContext {
  57. AVClass *class;
  58. struct vpx_codec_ctx encoder;
  59. struct vpx_image rawimg;
  60. struct vpx_codec_ctx encoder_alpha;
  61. struct vpx_image rawimg_alpha;
  62. uint8_t is_alpha;
  63. struct vpx_fixed_buf twopass_stats;
  64. int deadline; //i.e., RT/GOOD/BEST
  65. uint64_t sse[4];
  66. int have_sse; /**< true if we have pending sse[] */
  67. uint64_t frame_number;
  68. struct FrameListData *coded_frame_list;
  69. int cpu_used;
  70. /**
  71. * VP8 specific flags, see VP8F_* below.
  72. */
  73. int flags;
  74. #define VP8F_ERROR_RESILIENT 0x00000001 ///< Enable measures appropriate for streaming over lossy links
  75. #define VP8F_AUTO_ALT_REF 0x00000002 ///< Enable automatic alternate reference frame generation
  76. int auto_alt_ref;
  77. int arnr_max_frames;
  78. int arnr_strength;
  79. int arnr_type;
  80. int lag_in_frames;
  81. int error_resilient;
  82. int crf;
  83. int static_thresh;
  84. int max_intra_rate;
  85. // VP9-only
  86. int lossless;
  87. int tile_columns;
  88. int tile_rows;
  89. int frame_parallel;
  90. int aq_mode;
  91. } VP8Context;
  92. /** String mappings for enum vp8e_enc_control_id */
  93. static const char *const ctlidstr[] = {
  94. [VP8E_UPD_ENTROPY] = "VP8E_UPD_ENTROPY",
  95. [VP8E_UPD_REFERENCE] = "VP8E_UPD_REFERENCE",
  96. [VP8E_USE_REFERENCE] = "VP8E_USE_REFERENCE",
  97. [VP8E_SET_ROI_MAP] = "VP8E_SET_ROI_MAP",
  98. [VP8E_SET_ACTIVEMAP] = "VP8E_SET_ACTIVEMAP",
  99. [VP8E_SET_SCALEMODE] = "VP8E_SET_SCALEMODE",
  100. [VP8E_SET_CPUUSED] = "VP8E_SET_CPUUSED",
  101. [VP8E_SET_ENABLEAUTOALTREF] = "VP8E_SET_ENABLEAUTOALTREF",
  102. [VP8E_SET_NOISE_SENSITIVITY] = "VP8E_SET_NOISE_SENSITIVITY",
  103. [VP8E_SET_SHARPNESS] = "VP8E_SET_SHARPNESS",
  104. [VP8E_SET_STATIC_THRESHOLD] = "VP8E_SET_STATIC_THRESHOLD",
  105. [VP8E_SET_TOKEN_PARTITIONS] = "VP8E_SET_TOKEN_PARTITIONS",
  106. [VP8E_GET_LAST_QUANTIZER] = "VP8E_GET_LAST_QUANTIZER",
  107. [VP8E_SET_ARNR_MAXFRAMES] = "VP8E_SET_ARNR_MAXFRAMES",
  108. [VP8E_SET_ARNR_STRENGTH] = "VP8E_SET_ARNR_STRENGTH",
  109. [VP8E_SET_ARNR_TYPE] = "VP8E_SET_ARNR_TYPE",
  110. [VP8E_SET_CQ_LEVEL] = "VP8E_SET_CQ_LEVEL",
  111. [VP8E_SET_MAX_INTRA_BITRATE_PCT] = "VP8E_SET_MAX_INTRA_BITRATE_PCT",
  112. #if CONFIG_LIBVPX_VP9_ENCODER
  113. [VP9E_SET_LOSSLESS] = "VP9E_SET_LOSSLESS",
  114. [VP9E_SET_TILE_COLUMNS] = "VP9E_SET_TILE_COLUMNS",
  115. [VP9E_SET_TILE_ROWS] = "VP9E_SET_TILE_ROWS",
  116. [VP9E_SET_FRAME_PARALLEL_DECODING] = "VP9E_SET_FRAME_PARALLEL_DECODING",
  117. [VP9E_SET_AQ_MODE] = "VP9E_SET_AQ_MODE",
  118. #endif
  119. };
  120. static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
  121. {
  122. VP8Context *ctx = avctx->priv_data;
  123. const char *error = vpx_codec_error(&ctx->encoder);
  124. const char *detail = vpx_codec_error_detail(&ctx->encoder);
  125. av_log(avctx, AV_LOG_ERROR, "%s: %s\n", desc, error);
  126. if (detail)
  127. av_log(avctx, AV_LOG_ERROR, " Additional information: %s\n", detail);
  128. }
  129. static av_cold void dump_enc_cfg(AVCodecContext *avctx,
  130. const struct vpx_codec_enc_cfg *cfg)
  131. {
  132. int width = -30;
  133. int level = AV_LOG_DEBUG;
  134. av_log(avctx, level, "vpx_codec_enc_cfg\n");
  135. av_log(avctx, level, "generic settings\n"
  136. " %*s%u\n %*s%u\n %*s%u\n %*s%u\n %*s%u\n"
  137. " %*s{%u/%u}\n %*s%u\n %*s%d\n %*s%u\n",
  138. width, "g_usage:", cfg->g_usage,
  139. width, "g_threads:", cfg->g_threads,
  140. width, "g_profile:", cfg->g_profile,
  141. width, "g_w:", cfg->g_w,
  142. width, "g_h:", cfg->g_h,
  143. width, "g_timebase:", cfg->g_timebase.num, cfg->g_timebase.den,
  144. width, "g_error_resilient:", cfg->g_error_resilient,
  145. width, "g_pass:", cfg->g_pass,
  146. width, "g_lag_in_frames:", cfg->g_lag_in_frames);
  147. av_log(avctx, level, "rate control settings\n"
  148. " %*s%u\n %*s%u\n %*s%u\n %*s%u\n"
  149. " %*s%d\n %*s%p(%"SIZE_SPECIFIER")\n %*s%u\n",
  150. width, "rc_dropframe_thresh:", cfg->rc_dropframe_thresh,
  151. width, "rc_resize_allowed:", cfg->rc_resize_allowed,
  152. width, "rc_resize_up_thresh:", cfg->rc_resize_up_thresh,
  153. width, "rc_resize_down_thresh:", cfg->rc_resize_down_thresh,
  154. width, "rc_end_usage:", cfg->rc_end_usage,
  155. width, "rc_twopass_stats_in:", cfg->rc_twopass_stats_in.buf, cfg->rc_twopass_stats_in.sz,
  156. width, "rc_target_bitrate:", cfg->rc_target_bitrate);
  157. av_log(avctx, level, "quantizer settings\n"
  158. " %*s%u\n %*s%u\n",
  159. width, "rc_min_quantizer:", cfg->rc_min_quantizer,
  160. width, "rc_max_quantizer:", cfg->rc_max_quantizer);
  161. av_log(avctx, level, "bitrate tolerance\n"
  162. " %*s%u\n %*s%u\n",
  163. width, "rc_undershoot_pct:", cfg->rc_undershoot_pct,
  164. width, "rc_overshoot_pct:", cfg->rc_overshoot_pct);
  165. av_log(avctx, level, "decoder buffer model\n"
  166. " %*s%u\n %*s%u\n %*s%u\n",
  167. width, "rc_buf_sz:", cfg->rc_buf_sz,
  168. width, "rc_buf_initial_sz:", cfg->rc_buf_initial_sz,
  169. width, "rc_buf_optimal_sz:", cfg->rc_buf_optimal_sz);
  170. av_log(avctx, level, "2 pass rate control settings\n"
  171. " %*s%u\n %*s%u\n %*s%u\n",
  172. width, "rc_2pass_vbr_bias_pct:", cfg->rc_2pass_vbr_bias_pct,
  173. width, "rc_2pass_vbr_minsection_pct:", cfg->rc_2pass_vbr_minsection_pct,
  174. width, "rc_2pass_vbr_maxsection_pct:", cfg->rc_2pass_vbr_maxsection_pct);
  175. av_log(avctx, level, "keyframing settings\n"
  176. " %*s%d\n %*s%u\n %*s%u\n",
  177. width, "kf_mode:", cfg->kf_mode,
  178. width, "kf_min_dist:", cfg->kf_min_dist,
  179. width, "kf_max_dist:", cfg->kf_max_dist);
  180. av_log(avctx, level, "\n");
  181. }
  182. static void coded_frame_add(void *list, struct FrameListData *cx_frame)
  183. {
  184. struct FrameListData **p = list;
  185. while (*p)
  186. p = &(*p)->next;
  187. *p = cx_frame;
  188. cx_frame->next = NULL;
  189. }
  190. static av_cold void free_coded_frame(struct FrameListData *cx_frame)
  191. {
  192. av_freep(&cx_frame->buf);
  193. if (cx_frame->buf_alpha)
  194. av_freep(&cx_frame->buf_alpha);
  195. av_freep(&cx_frame);
  196. }
  197. static av_cold void free_frame_list(struct FrameListData *list)
  198. {
  199. struct FrameListData *p = list;
  200. while (p) {
  201. list = list->next;
  202. free_coded_frame(p);
  203. p = list;
  204. }
  205. }
  206. static av_cold int codecctl_int(AVCodecContext *avctx,
  207. enum vp8e_enc_control_id id, int val)
  208. {
  209. VP8Context *ctx = avctx->priv_data;
  210. char buf[80];
  211. int width = -30;
  212. int res;
  213. snprintf(buf, sizeof(buf), "%s:", ctlidstr[id]);
  214. av_log(avctx, AV_LOG_DEBUG, " %*s%d\n", width, buf, val);
  215. res = vpx_codec_control(&ctx->encoder, id, val);
  216. if (res != VPX_CODEC_OK) {
  217. snprintf(buf, sizeof(buf), "Failed to set %s codec control",
  218. ctlidstr[id]);
  219. log_encoder_error(avctx, buf);
  220. }
  221. return res == VPX_CODEC_OK ? 0 : AVERROR(EINVAL);
  222. }
  223. static av_cold int vp8_free(AVCodecContext *avctx)
  224. {
  225. VP8Context *ctx = avctx->priv_data;
  226. vpx_codec_destroy(&ctx->encoder);
  227. if (ctx->is_alpha)
  228. vpx_codec_destroy(&ctx->encoder_alpha);
  229. av_freep(&ctx->twopass_stats.buf);
  230. av_frame_free(&avctx->coded_frame);
  231. av_freep(&avctx->stats_out);
  232. free_frame_list(ctx->coded_frame_list);
  233. return 0;
  234. }
  235. static av_cold int vpx_init(AVCodecContext *avctx,
  236. const struct vpx_codec_iface *iface)
  237. {
  238. VP8Context *ctx = avctx->priv_data;
  239. struct vpx_codec_enc_cfg enccfg;
  240. struct vpx_codec_enc_cfg enccfg_alpha;
  241. vpx_codec_flags_t flags = (avctx->flags & CODEC_FLAG_PSNR) ? VPX_CODEC_USE_PSNR : 0;
  242. int res;
  243. av_log(avctx, AV_LOG_INFO, "%s\n", vpx_codec_version_str());
  244. av_log(avctx, AV_LOG_VERBOSE, "%s\n", vpx_codec_build_config());
  245. if (avctx->pix_fmt == AV_PIX_FMT_YUVA420P)
  246. ctx->is_alpha = 1;
  247. if ((res = vpx_codec_enc_config_default(iface, &enccfg, 0)) != VPX_CODEC_OK) {
  248. av_log(avctx, AV_LOG_ERROR, "Failed to get config: %s\n",
  249. vpx_codec_err_to_string(res));
  250. return AVERROR(EINVAL);
  251. }
  252. if(!avctx->bit_rate)
  253. if(avctx->rc_max_rate || avctx->rc_buffer_size || avctx->rc_initial_buffer_occupancy) {
  254. av_log( avctx, AV_LOG_ERROR, "Rate control parameters set without a bitrate\n");
  255. return AVERROR(EINVAL);
  256. }
  257. dump_enc_cfg(avctx, &enccfg);
  258. enccfg.g_w = avctx->width;
  259. enccfg.g_h = avctx->height;
  260. enccfg.g_timebase.num = avctx->time_base.num;
  261. enccfg.g_timebase.den = avctx->time_base.den;
  262. enccfg.g_threads = avctx->thread_count;
  263. enccfg.g_lag_in_frames= ctx->lag_in_frames;
  264. if (avctx->flags & CODEC_FLAG_PASS1)
  265. enccfg.g_pass = VPX_RC_FIRST_PASS;
  266. else if (avctx->flags & CODEC_FLAG_PASS2)
  267. enccfg.g_pass = VPX_RC_LAST_PASS;
  268. else
  269. enccfg.g_pass = VPX_RC_ONE_PASS;
  270. if (avctx->rc_min_rate == avctx->rc_max_rate &&
  271. avctx->rc_min_rate == avctx->bit_rate && avctx->bit_rate) {
  272. enccfg.rc_end_usage = VPX_CBR;
  273. } else if (ctx->crf >= 0) {
  274. enccfg.rc_end_usage = VPX_CQ;
  275. #if CONFIG_LIBVPX_VP9_ENCODER
  276. if (!avctx->bit_rate && avctx->codec_id == AV_CODEC_ID_VP9)
  277. enccfg.rc_end_usage = VPX_Q;
  278. #endif
  279. }
  280. if (avctx->bit_rate) {
  281. enccfg.rc_target_bitrate = av_rescale_rnd(avctx->bit_rate, 1, 1000,
  282. AV_ROUND_NEAR_INF);
  283. #if CONFIG_LIBVPX_VP9_ENCODER
  284. } else if (enccfg.rc_end_usage == VPX_Q) {
  285. #endif
  286. } else {
  287. if (enccfg.rc_end_usage == VPX_CQ) {
  288. enccfg.rc_target_bitrate = 1000000;
  289. } else {
  290. avctx->bit_rate = enccfg.rc_target_bitrate * 1000;
  291. av_log(avctx, AV_LOG_WARNING,
  292. "Neither bitrate nor constrained quality specified, using default bitrate of %dkbit/sec\n",
  293. enccfg.rc_target_bitrate);
  294. }
  295. }
  296. if (avctx->qmin >= 0)
  297. enccfg.rc_min_quantizer = avctx->qmin;
  298. if (avctx->qmax >= 0)
  299. enccfg.rc_max_quantizer = avctx->qmax;
  300. if (enccfg.rc_end_usage == VPX_CQ
  301. #if CONFIG_LIBVPX_VP9_ENCODER
  302. || enccfg.rc_end_usage == VPX_Q
  303. #endif
  304. ) {
  305. if (ctx->crf < enccfg.rc_min_quantizer || ctx->crf > enccfg.rc_max_quantizer) {
  306. av_log(avctx, AV_LOG_ERROR,
  307. "CQ level %d must be between minimum and maximum quantizer value (%d-%d)\n",
  308. ctx->crf, enccfg.rc_min_quantizer, enccfg.rc_max_quantizer);
  309. return AVERROR(EINVAL);
  310. }
  311. }
  312. enccfg.rc_dropframe_thresh = avctx->frame_skip_threshold;
  313. //0-100 (0 => CBR, 100 => VBR)
  314. enccfg.rc_2pass_vbr_bias_pct = round(avctx->qcompress * 100);
  315. if (avctx->bit_rate)
  316. enccfg.rc_2pass_vbr_minsection_pct =
  317. avctx->rc_min_rate * 100LL / avctx->bit_rate;
  318. if (avctx->rc_max_rate)
  319. enccfg.rc_2pass_vbr_maxsection_pct =
  320. avctx->rc_max_rate * 100LL / avctx->bit_rate;
  321. if (avctx->rc_buffer_size)
  322. enccfg.rc_buf_sz =
  323. avctx->rc_buffer_size * 1000LL / avctx->bit_rate;
  324. if (avctx->rc_initial_buffer_occupancy)
  325. enccfg.rc_buf_initial_sz =
  326. avctx->rc_initial_buffer_occupancy * 1000LL / avctx->bit_rate;
  327. enccfg.rc_buf_optimal_sz = enccfg.rc_buf_sz * 5 / 6;
  328. enccfg.rc_undershoot_pct = round(avctx->rc_buffer_aggressivity * 100);
  329. //_enc_init() will balk if kf_min_dist differs from max w/VPX_KF_AUTO
  330. if (avctx->keyint_min >= 0 && avctx->keyint_min == avctx->gop_size)
  331. enccfg.kf_min_dist = avctx->keyint_min;
  332. if (avctx->gop_size >= 0)
  333. enccfg.kf_max_dist = avctx->gop_size;
  334. if (enccfg.g_pass == VPX_RC_FIRST_PASS)
  335. enccfg.g_lag_in_frames = 0;
  336. else if (enccfg.g_pass == VPX_RC_LAST_PASS) {
  337. int decode_size, ret;
  338. if (!avctx->stats_in) {
  339. av_log(avctx, AV_LOG_ERROR, "No stats file for second pass\n");
  340. return AVERROR_INVALIDDATA;
  341. }
  342. ctx->twopass_stats.sz = strlen(avctx->stats_in) * 3 / 4;
  343. ret = av_reallocp(&ctx->twopass_stats.buf, ctx->twopass_stats.sz);
  344. if (ret < 0) {
  345. av_log(avctx, AV_LOG_ERROR,
  346. "Stat buffer alloc (%"SIZE_SPECIFIER" bytes) failed\n",
  347. ctx->twopass_stats.sz);
  348. return ret;
  349. }
  350. decode_size = av_base64_decode(ctx->twopass_stats.buf, avctx->stats_in,
  351. ctx->twopass_stats.sz);
  352. if (decode_size < 0) {
  353. av_log(avctx, AV_LOG_ERROR, "Stat buffer decode failed\n");
  354. return AVERROR_INVALIDDATA;
  355. }
  356. ctx->twopass_stats.sz = decode_size;
  357. enccfg.rc_twopass_stats_in = ctx->twopass_stats;
  358. }
  359. /* 0-3: For non-zero values the encoder increasingly optimizes for reduced
  360. complexity playback on low powered devices at the expense of encode
  361. quality. */
  362. if (avctx->profile != FF_PROFILE_UNKNOWN)
  363. enccfg.g_profile = avctx->profile;
  364. enccfg.g_error_resilient = ctx->error_resilient || ctx->flags & VP8F_ERROR_RESILIENT;
  365. dump_enc_cfg(avctx, &enccfg);
  366. /* Construct Encoder Context */
  367. res = vpx_codec_enc_init(&ctx->encoder, iface, &enccfg, flags);
  368. if (res != VPX_CODEC_OK) {
  369. log_encoder_error(avctx, "Failed to initialize encoder");
  370. return AVERROR(EINVAL);
  371. }
  372. if (ctx->is_alpha) {
  373. enccfg_alpha = enccfg;
  374. res = vpx_codec_enc_init(&ctx->encoder_alpha, iface, &enccfg_alpha, flags);
  375. if (res != VPX_CODEC_OK) {
  376. log_encoder_error(avctx, "Failed to initialize alpha encoder");
  377. return AVERROR(EINVAL);
  378. }
  379. }
  380. //codec control failures are currently treated only as warnings
  381. av_log(avctx, AV_LOG_DEBUG, "vpx_codec_control\n");
  382. codecctl_int(avctx, VP8E_SET_CPUUSED, ctx->cpu_used);
  383. if (ctx->flags & VP8F_AUTO_ALT_REF)
  384. ctx->auto_alt_ref = 1;
  385. if (ctx->auto_alt_ref >= 0)
  386. codecctl_int(avctx, VP8E_SET_ENABLEAUTOALTREF, ctx->auto_alt_ref);
  387. if (ctx->arnr_max_frames >= 0)
  388. codecctl_int(avctx, VP8E_SET_ARNR_MAXFRAMES, ctx->arnr_max_frames);
  389. if (ctx->arnr_strength >= 0)
  390. codecctl_int(avctx, VP8E_SET_ARNR_STRENGTH, ctx->arnr_strength);
  391. if (ctx->arnr_type >= 0)
  392. codecctl_int(avctx, VP8E_SET_ARNR_TYPE, ctx->arnr_type);
  393. codecctl_int(avctx, VP8E_SET_NOISE_SENSITIVITY, avctx->noise_reduction);
  394. if (avctx->codec_id == AV_CODEC_ID_VP8)
  395. codecctl_int(avctx, VP8E_SET_TOKEN_PARTITIONS, av_log2(avctx->slices));
  396. #if FF_API_MPV_OPT
  397. FF_DISABLE_DEPRECATION_WARNINGS
  398. if (avctx->mb_threshold) {
  399. av_log(avctx, AV_LOG_WARNING, "The mb_threshold option is deprecated, "
  400. "use the static-thresh private option instead.\n");
  401. ctx->static_thresh = avctx->mb_threshold;
  402. }
  403. FF_ENABLE_DEPRECATION_WARNINGS
  404. #endif
  405. codecctl_int(avctx, VP8E_SET_STATIC_THRESHOLD, ctx->static_thresh);
  406. if (ctx->crf >= 0)
  407. codecctl_int(avctx, VP8E_SET_CQ_LEVEL, ctx->crf);
  408. if (ctx->max_intra_rate >= 0)
  409. codecctl_int(avctx, VP8E_SET_MAX_INTRA_BITRATE_PCT, ctx->max_intra_rate);
  410. #if CONFIG_LIBVPX_VP9_ENCODER
  411. if (avctx->codec_id == AV_CODEC_ID_VP9) {
  412. if (ctx->lossless >= 0)
  413. codecctl_int(avctx, VP9E_SET_LOSSLESS, ctx->lossless);
  414. if (ctx->tile_columns >= 0)
  415. codecctl_int(avctx, VP9E_SET_TILE_COLUMNS, ctx->tile_columns);
  416. if (ctx->tile_rows >= 0)
  417. codecctl_int(avctx, VP9E_SET_TILE_ROWS, ctx->tile_rows);
  418. if (ctx->frame_parallel >= 0)
  419. codecctl_int(avctx, VP9E_SET_FRAME_PARALLEL_DECODING, ctx->frame_parallel);
  420. if (ctx->aq_mode >= 0)
  421. codecctl_int(avctx, VP9E_SET_AQ_MODE, ctx->aq_mode);
  422. }
  423. #endif
  424. av_log(avctx, AV_LOG_DEBUG, "Using deadline: %d\n", ctx->deadline);
  425. //provide dummy value to initialize wrapper, values will be updated each _encode()
  426. vpx_img_wrap(&ctx->rawimg, VPX_IMG_FMT_I420, avctx->width, avctx->height, 1,
  427. (unsigned char*)1);
  428. if (ctx->is_alpha)
  429. vpx_img_wrap(&ctx->rawimg_alpha, VPX_IMG_FMT_I420, avctx->width, avctx->height, 1,
  430. (unsigned char*)1);
  431. avctx->coded_frame = av_frame_alloc();
  432. if (!avctx->coded_frame) {
  433. av_log(avctx, AV_LOG_ERROR, "Error allocating coded frame\n");
  434. vp8_free(avctx);
  435. return AVERROR(ENOMEM);
  436. }
  437. return 0;
  438. }
  439. static inline void cx_pktcpy(struct FrameListData *dst,
  440. const struct vpx_codec_cx_pkt *src,
  441. const struct vpx_codec_cx_pkt *src_alpha,
  442. VP8Context *ctx)
  443. {
  444. dst->pts = src->data.frame.pts;
  445. dst->duration = src->data.frame.duration;
  446. dst->flags = src->data.frame.flags;
  447. dst->sz = src->data.frame.sz;
  448. dst->buf = src->data.frame.buf;
  449. dst->have_sse = 0;
  450. /* For alt-ref frame, don't store PSNR or increment frame_number */
  451. if (!(dst->flags & VPX_FRAME_IS_INVISIBLE)) {
  452. dst->frame_number = ++ctx->frame_number;
  453. dst->have_sse = ctx->have_sse;
  454. if (ctx->have_sse) {
  455. /* associate last-seen SSE to the frame. */
  456. /* Transfers ownership from ctx to dst. */
  457. /* WARNING! This makes the assumption that PSNR_PKT comes
  458. just before the frame it refers to! */
  459. memcpy(dst->sse, ctx->sse, sizeof(dst->sse));
  460. ctx->have_sse = 0;
  461. }
  462. } else {
  463. dst->frame_number = -1; /* sanity marker */
  464. }
  465. if (src_alpha) {
  466. dst->buf_alpha = src_alpha->data.frame.buf;
  467. dst->sz_alpha = src_alpha->data.frame.sz;
  468. }
  469. else {
  470. dst->buf_alpha = NULL;
  471. dst->sz_alpha = 0;
  472. }
  473. }
  474. /**
  475. * Store coded frame information in format suitable for return from encode2().
  476. *
  477. * Write information from @a cx_frame to @a pkt
  478. * @return packet data size on success
  479. * @return a negative AVERROR on error
  480. */
  481. static int storeframe(AVCodecContext *avctx, struct FrameListData *cx_frame,
  482. AVPacket *pkt, AVFrame *coded_frame)
  483. {
  484. int ret = ff_alloc_packet2(avctx, pkt, cx_frame->sz);
  485. uint8_t *side_data;
  486. if (ret >= 0) {
  487. memcpy(pkt->data, cx_frame->buf, pkt->size);
  488. pkt->pts = pkt->dts = cx_frame->pts;
  489. coded_frame->pts = cx_frame->pts;
  490. coded_frame->key_frame = !!(cx_frame->flags & VPX_FRAME_IS_KEY);
  491. if (coded_frame->key_frame) {
  492. coded_frame->pict_type = AV_PICTURE_TYPE_I;
  493. pkt->flags |= AV_PKT_FLAG_KEY;
  494. } else
  495. coded_frame->pict_type = AV_PICTURE_TYPE_P;
  496. if (cx_frame->have_sse) {
  497. int i;
  498. /* Beware of the Y/U/V/all order! */
  499. coded_frame->error[0] = cx_frame->sse[1];
  500. coded_frame->error[1] = cx_frame->sse[2];
  501. coded_frame->error[2] = cx_frame->sse[3];
  502. coded_frame->error[3] = 0; // alpha
  503. for (i = 0; i < 4; ++i) {
  504. avctx->error[i] += coded_frame->error[i];
  505. }
  506. cx_frame->have_sse = 0;
  507. }
  508. if (cx_frame->sz_alpha > 0) {
  509. side_data = av_packet_new_side_data(pkt,
  510. AV_PKT_DATA_MATROSKA_BLOCKADDITIONAL,
  511. cx_frame->sz_alpha + 8);
  512. if(!side_data) {
  513. av_free_packet(pkt);
  514. av_free(pkt);
  515. return AVERROR(ENOMEM);
  516. }
  517. AV_WB64(side_data, 1);
  518. memcpy(side_data + 8, cx_frame->buf_alpha, cx_frame->sz_alpha);
  519. }
  520. } else {
  521. return ret;
  522. }
  523. return pkt->size;
  524. }
  525. /**
  526. * Queue multiple output frames from the encoder, returning the front-most.
  527. * In cases where vpx_codec_get_cx_data() returns more than 1 frame append
  528. * the frame queue. Return the head frame if available.
  529. * @return Stored frame size
  530. * @return AVERROR(EINVAL) on output size error
  531. * @return AVERROR(ENOMEM) on coded frame queue data allocation error
  532. */
  533. static int queue_frames(AVCodecContext *avctx, AVPacket *pkt_out,
  534. AVFrame *coded_frame)
  535. {
  536. VP8Context *ctx = avctx->priv_data;
  537. const struct vpx_codec_cx_pkt *pkt;
  538. const struct vpx_codec_cx_pkt *pkt_alpha = NULL;
  539. const void *iter = NULL;
  540. const void *iter_alpha = NULL;
  541. int size = 0;
  542. if (ctx->coded_frame_list) {
  543. struct FrameListData *cx_frame = ctx->coded_frame_list;
  544. /* return the leading frame if we've already begun queueing */
  545. size = storeframe(avctx, cx_frame, pkt_out, coded_frame);
  546. if (size < 0)
  547. return size;
  548. ctx->coded_frame_list = cx_frame->next;
  549. free_coded_frame(cx_frame);
  550. }
  551. /* consume all available output from the encoder before returning. buffers
  552. are only good through the next vpx_codec call */
  553. while ((pkt = vpx_codec_get_cx_data(&ctx->encoder, &iter)) &&
  554. (!ctx->is_alpha ||
  555. (ctx->is_alpha && (pkt_alpha = vpx_codec_get_cx_data(&ctx->encoder_alpha, &iter_alpha))))) {
  556. switch (pkt->kind) {
  557. case VPX_CODEC_CX_FRAME_PKT:
  558. if (!size) {
  559. struct FrameListData cx_frame;
  560. /* avoid storing the frame when the list is empty and we haven't yet
  561. provided a frame for output */
  562. av_assert0(!ctx->coded_frame_list);
  563. cx_pktcpy(&cx_frame, pkt, pkt_alpha, ctx);
  564. size = storeframe(avctx, &cx_frame, pkt_out, coded_frame);
  565. if (size < 0)
  566. return size;
  567. } else {
  568. struct FrameListData *cx_frame =
  569. av_malloc(sizeof(struct FrameListData));
  570. if (!cx_frame) {
  571. av_log(avctx, AV_LOG_ERROR,
  572. "Frame queue element alloc failed\n");
  573. return AVERROR(ENOMEM);
  574. }
  575. cx_pktcpy(cx_frame, pkt, pkt_alpha, ctx);
  576. cx_frame->buf = av_malloc(cx_frame->sz);
  577. if (!cx_frame->buf) {
  578. av_log(avctx, AV_LOG_ERROR,
  579. "Data buffer alloc (%"SIZE_SPECIFIER" bytes) failed\n",
  580. cx_frame->sz);
  581. av_freep(&cx_frame);
  582. return AVERROR(ENOMEM);
  583. }
  584. memcpy(cx_frame->buf, pkt->data.frame.buf, pkt->data.frame.sz);
  585. if (ctx->is_alpha) {
  586. cx_frame->buf_alpha = av_malloc(cx_frame->sz_alpha);
  587. if (!cx_frame->buf_alpha) {
  588. av_log(avctx, AV_LOG_ERROR,
  589. "Data buffer alloc (%"SIZE_SPECIFIER" bytes) failed\n",
  590. cx_frame->sz_alpha);
  591. av_free(cx_frame);
  592. return AVERROR(ENOMEM);
  593. }
  594. memcpy(cx_frame->buf_alpha, pkt_alpha->data.frame.buf, pkt_alpha->data.frame.sz);
  595. }
  596. coded_frame_add(&ctx->coded_frame_list, cx_frame);
  597. }
  598. break;
  599. case VPX_CODEC_STATS_PKT: {
  600. struct vpx_fixed_buf *stats = &ctx->twopass_stats;
  601. int err;
  602. if ((err = av_reallocp(&stats->buf,
  603. stats->sz +
  604. pkt->data.twopass_stats.sz)) < 0) {
  605. stats->sz = 0;
  606. av_log(avctx, AV_LOG_ERROR, "Stat buffer realloc failed\n");
  607. return err;
  608. }
  609. memcpy((uint8_t*)stats->buf + stats->sz,
  610. pkt->data.twopass_stats.buf, pkt->data.twopass_stats.sz);
  611. stats->sz += pkt->data.twopass_stats.sz;
  612. break;
  613. }
  614. case VPX_CODEC_PSNR_PKT:
  615. av_assert0(!ctx->have_sse);
  616. ctx->sse[0] = pkt->data.psnr.sse[0];
  617. ctx->sse[1] = pkt->data.psnr.sse[1];
  618. ctx->sse[2] = pkt->data.psnr.sse[2];
  619. ctx->sse[3] = pkt->data.psnr.sse[3];
  620. ctx->have_sse = 1;
  621. break;
  622. case VPX_CODEC_CUSTOM_PKT:
  623. //ignore unsupported/unrecognized packet types
  624. break;
  625. }
  626. }
  627. return size;
  628. }
  629. static int vp8_encode(AVCodecContext *avctx, AVPacket *pkt,
  630. const AVFrame *frame, int *got_packet)
  631. {
  632. VP8Context *ctx = avctx->priv_data;
  633. struct vpx_image *rawimg = NULL;
  634. struct vpx_image *rawimg_alpha = NULL;
  635. int64_t timestamp = 0;
  636. int res, coded_size;
  637. vpx_enc_frame_flags_t flags = 0;
  638. if (frame) {
  639. rawimg = &ctx->rawimg;
  640. rawimg->planes[VPX_PLANE_Y] = frame->data[0];
  641. rawimg->planes[VPX_PLANE_U] = frame->data[1];
  642. rawimg->planes[VPX_PLANE_V] = frame->data[2];
  643. rawimg->stride[VPX_PLANE_Y] = frame->linesize[0];
  644. rawimg->stride[VPX_PLANE_U] = frame->linesize[1];
  645. rawimg->stride[VPX_PLANE_V] = frame->linesize[2];
  646. if (ctx->is_alpha) {
  647. uint8_t *u_plane, *v_plane;
  648. rawimg_alpha = &ctx->rawimg_alpha;
  649. rawimg_alpha->planes[VPX_PLANE_Y] = frame->data[3];
  650. u_plane = av_malloc(frame->linesize[1] * frame->height);
  651. v_plane = av_malloc(frame->linesize[2] * frame->height);
  652. if (!u_plane || !v_plane) {
  653. av_free(u_plane);
  654. av_free(v_plane);
  655. return AVERROR(ENOMEM);
  656. }
  657. memset(u_plane, 0x80, frame->linesize[1] * frame->height);
  658. rawimg_alpha->planes[VPX_PLANE_U] = u_plane;
  659. memset(v_plane, 0x80, frame->linesize[2] * frame->height);
  660. rawimg_alpha->planes[VPX_PLANE_V] = v_plane;
  661. rawimg_alpha->stride[VPX_PLANE_Y] = frame->linesize[0];
  662. rawimg_alpha->stride[VPX_PLANE_U] = frame->linesize[1];
  663. rawimg_alpha->stride[VPX_PLANE_V] = frame->linesize[2];
  664. }
  665. timestamp = frame->pts;
  666. if (frame->pict_type == AV_PICTURE_TYPE_I)
  667. flags |= VPX_EFLAG_FORCE_KF;
  668. }
  669. res = vpx_codec_encode(&ctx->encoder, rawimg, timestamp,
  670. avctx->ticks_per_frame, flags, ctx->deadline);
  671. if (res != VPX_CODEC_OK) {
  672. log_encoder_error(avctx, "Error encoding frame");
  673. return AVERROR_INVALIDDATA;
  674. }
  675. if (ctx->is_alpha) {
  676. res = vpx_codec_encode(&ctx->encoder_alpha, rawimg_alpha, timestamp,
  677. avctx->ticks_per_frame, flags, ctx->deadline);
  678. if (res != VPX_CODEC_OK) {
  679. log_encoder_error(avctx, "Error encoding alpha frame");
  680. return AVERROR_INVALIDDATA;
  681. }
  682. }
  683. coded_size = queue_frames(avctx, pkt, avctx->coded_frame);
  684. if (!frame && avctx->flags & CODEC_FLAG_PASS1) {
  685. unsigned int b64_size = AV_BASE64_SIZE(ctx->twopass_stats.sz);
  686. avctx->stats_out = av_malloc(b64_size);
  687. if (!avctx->stats_out) {
  688. av_log(avctx, AV_LOG_ERROR, "Stat buffer alloc (%d bytes) failed\n",
  689. b64_size);
  690. return AVERROR(ENOMEM);
  691. }
  692. av_base64_encode(avctx->stats_out, b64_size, ctx->twopass_stats.buf,
  693. ctx->twopass_stats.sz);
  694. }
  695. if (rawimg_alpha) {
  696. av_freep(&rawimg_alpha->planes[VPX_PLANE_U]);
  697. av_freep(&rawimg_alpha->planes[VPX_PLANE_V]);
  698. }
  699. *got_packet = !!coded_size;
  700. return 0;
  701. }
  702. #define OFFSET(x) offsetof(VP8Context, x)
  703. #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
  704. #ifndef VPX_ERROR_RESILIENT_DEFAULT
  705. #define VPX_ERROR_RESILIENT_DEFAULT 1
  706. #define VPX_ERROR_RESILIENT_PARTITIONS 2
  707. #endif
  708. #define COMMON_OPTIONS \
  709. { "cpu-used", "Quality/Speed ratio modifier", OFFSET(cpu_used), AV_OPT_TYPE_INT, {.i64 = 1}, -16, 16, VE}, \
  710. { "auto-alt-ref", "Enable use of alternate reference " \
  711. "frames (2-pass only)", OFFSET(auto_alt_ref), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, VE}, \
  712. { "lag-in-frames", "Number of frames to look ahead for " \
  713. "alternate reference frame selection", OFFSET(lag_in_frames), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
  714. { "arnr-maxframes", "altref noise reduction max frame count", OFFSET(arnr_max_frames), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
  715. { "arnr-strength", "altref noise reduction filter strength", OFFSET(arnr_strength), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
  716. { "arnr-type", "altref noise reduction filter type", OFFSET(arnr_type), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE, "arnr_type"}, \
  717. { "backward", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, "arnr_type" }, \
  718. { "forward", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, VE, "arnr_type" }, \
  719. { "centered", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0, VE, "arnr_type" }, \
  720. { "deadline", "Time to spend encoding, in microseconds.", OFFSET(deadline), AV_OPT_TYPE_INT, {.i64 = VPX_DL_GOOD_QUALITY}, INT_MIN, INT_MAX, VE, "quality"}, \
  721. { "best", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_DL_BEST_QUALITY}, 0, 0, VE, "quality"}, \
  722. { "good", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_DL_GOOD_QUALITY}, 0, 0, VE, "quality"}, \
  723. { "realtime", NULL, 0, AV_OPT_TYPE_CONST, {.i64 = VPX_DL_REALTIME}, 0, 0, VE, "quality"}, \
  724. { "error-resilient", "Error resilience configuration", OFFSET(error_resilient), AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX, VE, "er"}, \
  725. { "max-intra-rate", "Maximum I-frame bitrate (pct) 0=unlimited", OFFSET(max_intra_rate), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE}, \
  726. { "default", "Improve resiliency against losses of whole frames", 0, AV_OPT_TYPE_CONST, {.i64 = VPX_ERROR_RESILIENT_DEFAULT}, 0, 0, VE, "er"}, \
  727. { "partitions", "The frame partitions are independently decodable " \
  728. "by the bool decoder, meaning that partitions can be decoded even " \
  729. "though earlier partitions have been lost. Note that intra predicition" \
  730. " is still done over the partition boundary.", 0, AV_OPT_TYPE_CONST, {.i64 = VPX_ERROR_RESILIENT_PARTITIONS}, 0, 0, VE, "er"}, \
  731. { "crf", "Select the quality for constant quality mode", offsetof(VP8Context, crf), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 63, VE }, \
  732. { "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 }, \
  733. #define LEGACY_OPTIONS \
  734. {"speed", "", offsetof(VP8Context, cpu_used), AV_OPT_TYPE_INT, {.i64 = 1}, -16, 16, VE}, \
  735. {"quality", "", offsetof(VP8Context, deadline), AV_OPT_TYPE_INT, {.i64 = VPX_DL_GOOD_QUALITY}, INT_MIN, INT_MAX, VE, "quality"}, \
  736. {"vp8flags", "", offsetof(VP8Context, flags), FF_OPT_TYPE_FLAGS, {.i64 = 0}, 0, UINT_MAX, VE, "flags"}, \
  737. {"error_resilient", "enable error resilience", 0, FF_OPT_TYPE_CONST, {.dbl = VP8F_ERROR_RESILIENT}, INT_MIN, INT_MAX, VE, "flags"}, \
  738. {"altref", "enable use of alternate reference frames (VP8/2-pass only)", 0, FF_OPT_TYPE_CONST, {.dbl = VP8F_AUTO_ALT_REF}, INT_MIN, INT_MAX, VE, "flags"}, \
  739. {"arnr_max_frames", "altref noise reduction max frame count", offsetof(VP8Context, arnr_max_frames), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 15, VE}, \
  740. {"arnr_strength", "altref noise reduction filter strength", offsetof(VP8Context, arnr_strength), AV_OPT_TYPE_INT, {.i64 = 3}, 0, 6, VE}, \
  741. {"arnr_type", "altref noise reduction filter type", offsetof(VP8Context, arnr_type), AV_OPT_TYPE_INT, {.i64 = 3}, 1, 3, VE}, \
  742. {"rc_lookahead", "Number of frames to look ahead for alternate reference frame selection", offsetof(VP8Context, lag_in_frames), AV_OPT_TYPE_INT, {.i64 = 25}, 0, 25, VE}, \
  743. #if CONFIG_LIBVPX_VP8_ENCODER
  744. static const AVOption vp8_options[] = {
  745. COMMON_OPTIONS
  746. LEGACY_OPTIONS
  747. { NULL }
  748. };
  749. #endif
  750. #if CONFIG_LIBVPX_VP9_ENCODER
  751. static const AVOption vp9_options[] = {
  752. COMMON_OPTIONS
  753. { "lossless", "Lossless mode", OFFSET(lossless), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, VE},
  754. { "tile-columns", "Number of tile columns to use, log2", OFFSET(tile_columns), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 6, VE},
  755. { "tile-rows", "Number of tile rows to use, log2", OFFSET(tile_rows), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 2, VE},
  756. { "frame-parallel", "Enable frame parallel decodability features", OFFSET(frame_parallel), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, VE},
  757. { "aq-mode", "adaptive quantization mode", OFFSET(aq_mode), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 3, VE, "aq_mode"},
  758. { "none", "Aq not used", 0, AV_OPT_TYPE_CONST, {.i64 = 0}, 0, 0, VE, "aq_mode" }, \
  759. { "variance", "Variance based Aq", 0, AV_OPT_TYPE_CONST, {.i64 = 1}, 0, 0, VE, "aq_mode" }, \
  760. { "complexity", "Complexity based Aq", 0, AV_OPT_TYPE_CONST, {.i64 = 2}, 0, 0, VE, "aq_mode" }, \
  761. { "cyclic", "Cyclic Refresh Aq", 0, AV_OPT_TYPE_CONST, {.i64 = 3}, 0, 0, VE, "aq_mode" }, \
  762. LEGACY_OPTIONS
  763. { NULL }
  764. };
  765. #endif
  766. #undef COMMON_OPTIONS
  767. #undef LEGACY_OPTIONS
  768. static const AVCodecDefault defaults[] = {
  769. { "qmin", "-1" },
  770. { "qmax", "-1" },
  771. { "g", "-1" },
  772. { "keyint_min", "-1" },
  773. { NULL },
  774. };
  775. #if CONFIG_LIBVPX_VP8_ENCODER
  776. static av_cold int vp8_init(AVCodecContext *avctx)
  777. {
  778. return vpx_init(avctx, vpx_codec_vp8_cx());
  779. }
  780. static const AVClass class_vp8 = {
  781. .class_name = "libvpx-vp8 encoder",
  782. .item_name = av_default_item_name,
  783. .option = vp8_options,
  784. .version = LIBAVUTIL_VERSION_INT,
  785. };
  786. AVCodec ff_libvpx_vp8_encoder = {
  787. .name = "libvpx",
  788. .long_name = NULL_IF_CONFIG_SMALL("libvpx VP8"),
  789. .type = AVMEDIA_TYPE_VIDEO,
  790. .id = AV_CODEC_ID_VP8,
  791. .priv_data_size = sizeof(VP8Context),
  792. .init = vp8_init,
  793. .encode2 = vp8_encode,
  794. .close = vp8_free,
  795. .capabilities = CODEC_CAP_DELAY | CODEC_CAP_AUTO_THREADS,
  796. .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_YUVA420P, AV_PIX_FMT_NONE },
  797. .priv_class = &class_vp8,
  798. .defaults = defaults,
  799. };
  800. #endif /* CONFIG_LIBVPX_VP8_ENCODER */
  801. #if CONFIG_LIBVPX_VP9_ENCODER
  802. static av_cold int vp9_init(AVCodecContext *avctx)
  803. {
  804. return vpx_init(avctx, vpx_codec_vp9_cx());
  805. }
  806. static const AVClass class_vp9 = {
  807. .class_name = "libvpx-vp9 encoder",
  808. .item_name = av_default_item_name,
  809. .option = vp9_options,
  810. .version = LIBAVUTIL_VERSION_INT,
  811. };
  812. AVCodec ff_libvpx_vp9_encoder = {
  813. .name = "libvpx-vp9",
  814. .long_name = NULL_IF_CONFIG_SMALL("libvpx VP9"),
  815. .type = AVMEDIA_TYPE_VIDEO,
  816. .id = AV_CODEC_ID_VP9,
  817. .priv_data_size = sizeof(VP8Context),
  818. .init = vp9_init,
  819. .encode2 = vp8_encode,
  820. .close = vp8_free,
  821. .capabilities = CODEC_CAP_DELAY | CODEC_CAP_AUTO_THREADS,
  822. .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
  823. .priv_class = &class_vp9,
  824. .defaults = defaults,
  825. .init_static_data = ff_vp9_init_static,
  826. };
  827. #endif /* CONFIG_LIBVPX_VP9_ENCODER */