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.

580 lines
21KB

  1. /*
  2. * Copyright (c) 2010, Google, Inc.
  3. *
  4. * This file is part of Libav.
  5. *
  6. * Libav 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. * Libav 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 Libav; if not, write to the Free Software
  18. * Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301 USA
  19. */
  20. #define AOM_DISABLE_CTRL_TYPECHECKS 1
  21. #include <aom/aom_encoder.h>
  22. #include <aom/aomcx.h>
  23. #include "libavutil/base64.h"
  24. #include "libavutil/common.h"
  25. #include "libavutil/mathematics.h"
  26. #include "libavutil/opt.h"
  27. #include "libavutil/pixdesc.h"
  28. #include "avcodec.h"
  29. #include "internal.h"
  30. #include "libaom.h"
  31. /*
  32. * Portion of struct aom_codec_cx_pkt from aom_encoder.h.
  33. * One encoded frame returned from the library.
  34. */
  35. struct FrameListData {
  36. void *buf; /* compressed data buffer */
  37. size_t sz; /* length of compressed data */
  38. int64_t pts; /* time stamp to show frame
  39. * (in timebase units) */
  40. unsigned long duration; /* duration to show frame
  41. * (in timebase units) */
  42. uint32_t flags; /* flags for this frame */
  43. struct FrameListData *next;
  44. };
  45. typedef struct AOMEncoderContext {
  46. AVClass *class;
  47. struct aom_codec_ctx encoder;
  48. struct aom_image rawimg;
  49. struct aom_fixed_buf twopass_stats;
  50. struct FrameListData *coded_frame_list;
  51. int cpu_used;
  52. int auto_alt_ref;
  53. int lag_in_frames;
  54. int error_resilient;
  55. int crf;
  56. int static_thresh;
  57. int drop_threshold;
  58. int noise_sensitivity;
  59. } AOMContext;
  60. static const char *const ctlidstr[] = {
  61. [AOME_SET_CPUUSED] = "AOME_SET_CPUUSED",
  62. [AOME_SET_CQ_LEVEL] = "AOME_SET_CQ_LEVEL",
  63. [AOME_SET_ENABLEAUTOALTREF] = "AOME_SET_ENABLEAUTOALTREF",
  64. [AOME_SET_STATIC_THRESHOLD] = "AOME_SET_STATIC_THRESHOLD",
  65. };
  66. static av_cold void log_encoder_error(AVCodecContext *avctx, const char *desc)
  67. {
  68. AOMContext *ctx = avctx->priv_data;
  69. const char *error = aom_codec_error(&ctx->encoder);
  70. const char *detail = aom_codec_error_detail(&ctx->encoder);
  71. av_log(avctx, AV_LOG_ERROR, "%s: %s\n", desc, error);
  72. if (detail)
  73. av_log(avctx, AV_LOG_ERROR, " Additional information: %s\n", detail);
  74. }
  75. static av_cold void dump_enc_cfg(AVCodecContext *avctx,
  76. const struct aom_codec_enc_cfg *cfg)
  77. {
  78. int width = -30;
  79. int level = AV_LOG_DEBUG;
  80. av_log(avctx, level, "aom_codec_enc_cfg\n");
  81. av_log(avctx, level, "generic settings\n"
  82. " %*s%u\n %*s%u\n %*s%u\n %*s%u\n %*s%u\n"
  83. " %*s{%u/%u}\n %*s%u\n %*s%d\n %*s%u\n",
  84. width, "g_usage:", cfg->g_usage,
  85. width, "g_threads:", cfg->g_threads,
  86. width, "g_profile:", cfg->g_profile,
  87. width, "g_w:", cfg->g_w,
  88. width, "g_h:", cfg->g_h,
  89. width, "g_timebase:", cfg->g_timebase.num, cfg->g_timebase.den,
  90. width, "g_error_resilient:", cfg->g_error_resilient,
  91. width, "g_pass:", cfg->g_pass,
  92. width, "g_lag_in_frames:", cfg->g_lag_in_frames);
  93. av_log(avctx, level, "rate control settings\n"
  94. " %*s%u\n %*s%d\n %*s%p(%zu)\n %*s%u\n",
  95. width, "rc_dropframe_thresh:", cfg->rc_dropframe_thresh,
  96. width, "rc_end_usage:", cfg->rc_end_usage,
  97. width, "rc_twopass_stats_in:", cfg->rc_twopass_stats_in.buf, cfg->rc_twopass_stats_in.sz,
  98. width, "rc_target_bitrate:", cfg->rc_target_bitrate);
  99. av_log(avctx, level, "quantizer settings\n"
  100. " %*s%u\n %*s%u\n",
  101. width, "rc_min_quantizer:", cfg->rc_min_quantizer,
  102. width, "rc_max_quantizer:", cfg->rc_max_quantizer);
  103. av_log(avctx, level, "bitrate tolerance\n"
  104. " %*s%u\n %*s%u\n",
  105. width, "rc_undershoot_pct:", cfg->rc_undershoot_pct,
  106. width, "rc_overshoot_pct:", cfg->rc_overshoot_pct);
  107. av_log(avctx, level, "decoder buffer model\n"
  108. " %*s%u\n %*s%u\n %*s%u\n",
  109. width, "rc_buf_sz:", cfg->rc_buf_sz,
  110. width, "rc_buf_initial_sz:", cfg->rc_buf_initial_sz,
  111. width, "rc_buf_optimal_sz:", cfg->rc_buf_optimal_sz);
  112. av_log(avctx, level, "2 pass rate control settings\n"
  113. " %*s%u\n %*s%u\n %*s%u\n",
  114. width, "rc_2pass_vbr_bias_pct:", cfg->rc_2pass_vbr_bias_pct,
  115. width, "rc_2pass_vbr_minsection_pct:", cfg->rc_2pass_vbr_minsection_pct,
  116. width, "rc_2pass_vbr_maxsection_pct:", cfg->rc_2pass_vbr_maxsection_pct);
  117. av_log(avctx, level, "keyframing settings\n"
  118. " %*s%d\n %*s%u\n %*s%u\n",
  119. width, "kf_mode:", cfg->kf_mode,
  120. width, "kf_min_dist:", cfg->kf_min_dist,
  121. width, "kf_max_dist:", cfg->kf_max_dist);
  122. av_log(avctx, level, "\n");
  123. }
  124. static void coded_frame_add(void *list, struct FrameListData *cx_frame)
  125. {
  126. struct FrameListData **p = list;
  127. while (*p)
  128. p = &(*p)->next;
  129. *p = cx_frame;
  130. cx_frame->next = NULL;
  131. }
  132. static av_cold void free_coded_frame(struct FrameListData *cx_frame)
  133. {
  134. av_freep(&cx_frame->buf);
  135. av_freep(&cx_frame);
  136. }
  137. static av_cold void free_frame_list(struct FrameListData *list)
  138. {
  139. struct FrameListData *p = list;
  140. while (p) {
  141. list = list->next;
  142. free_coded_frame(p);
  143. p = list;
  144. }
  145. }
  146. static av_cold int codecctl_int(AVCodecContext *avctx,
  147. enum aome_enc_control_id id, int val)
  148. {
  149. AOMContext *ctx = avctx->priv_data;
  150. char buf[80];
  151. int width = -30;
  152. int res;
  153. snprintf(buf, sizeof(buf), "%s:", ctlidstr[id]);
  154. av_log(avctx, AV_LOG_DEBUG, " %*s%d\n", width, buf, val);
  155. res = aom_codec_control(&ctx->encoder, id, val);
  156. if (res != AOM_CODEC_OK) {
  157. snprintf(buf, sizeof(buf), "Failed to set %s codec control",
  158. ctlidstr[id]);
  159. log_encoder_error(avctx, buf);
  160. return AVERROR(EINVAL);
  161. }
  162. return 0;
  163. }
  164. static av_cold int aom_free(AVCodecContext *avctx)
  165. {
  166. AOMContext *ctx = avctx->priv_data;
  167. aom_codec_destroy(&ctx->encoder);
  168. av_freep(&ctx->twopass_stats.buf);
  169. av_freep(&avctx->stats_out);
  170. free_frame_list(ctx->coded_frame_list);
  171. return 0;
  172. }
  173. static av_cold int aom_init(AVCodecContext *avctx)
  174. {
  175. AOMContext *ctx = avctx->priv_data;
  176. struct aom_codec_enc_cfg enccfg = { 0 };
  177. AVCPBProperties *cpb_props;
  178. int res;
  179. const struct aom_codec_iface *iface = &aom_codec_av1_cx_algo;
  180. av_log(avctx, AV_LOG_INFO, "%s\n", aom_codec_version_str());
  181. av_log(avctx, AV_LOG_VERBOSE, "%s\n", aom_codec_build_config());
  182. if ((res = aom_codec_enc_config_default(iface, &enccfg, 0)) != AOM_CODEC_OK) {
  183. av_log(avctx, AV_LOG_ERROR, "Failed to get config: %s\n",
  184. aom_codec_err_to_string(res));
  185. return AVERROR(EINVAL);
  186. }
  187. dump_enc_cfg(avctx, &enccfg);
  188. enccfg.g_w = avctx->width;
  189. enccfg.g_h = avctx->height;
  190. enccfg.g_timebase.num = avctx->time_base.num;
  191. enccfg.g_timebase.den = avctx->time_base.den;
  192. enccfg.g_threads = avctx->thread_count;
  193. if (ctx->lag_in_frames >= 0)
  194. enccfg.g_lag_in_frames = ctx->lag_in_frames;
  195. if (avctx->flags & AV_CODEC_FLAG_PASS1)
  196. enccfg.g_pass = AOM_RC_FIRST_PASS;
  197. else if (avctx->flags & AV_CODEC_FLAG_PASS2)
  198. enccfg.g_pass = AOM_RC_LAST_PASS;
  199. else
  200. enccfg.g_pass = AOM_RC_ONE_PASS;
  201. if (!avctx->bit_rate)
  202. avctx->bit_rate = enccfg.rc_target_bitrate * 1000;
  203. else
  204. enccfg.rc_target_bitrate = av_rescale_rnd(avctx->bit_rate, 1, 1000,
  205. AV_ROUND_NEAR_INF);
  206. if (ctx->crf)
  207. enccfg.rc_end_usage = AOM_CQ;
  208. else if (avctx->rc_min_rate == avctx->rc_max_rate &&
  209. avctx->rc_min_rate == avctx->bit_rate)
  210. enccfg.rc_end_usage = AOM_CBR;
  211. if (avctx->qmin > 0)
  212. enccfg.rc_min_quantizer = avctx->qmin;
  213. if (avctx->qmax > 0)
  214. enccfg.rc_max_quantizer = avctx->qmax;
  215. enccfg.rc_dropframe_thresh = ctx->drop_threshold;
  216. // 0-100 (0 => CBR, 100 => VBR)
  217. enccfg.rc_2pass_vbr_bias_pct = round(avctx->qcompress * 100);
  218. enccfg.rc_2pass_vbr_minsection_pct =
  219. avctx->rc_min_rate * 100LL / avctx->bit_rate;
  220. if (avctx->rc_max_rate)
  221. enccfg.rc_2pass_vbr_maxsection_pct =
  222. avctx->rc_max_rate * 100LL / avctx->bit_rate;
  223. if (avctx->rc_buffer_size)
  224. enccfg.rc_buf_sz =
  225. avctx->rc_buffer_size * 1000LL / avctx->bit_rate;
  226. if (avctx->rc_initial_buffer_occupancy)
  227. enccfg.rc_buf_initial_sz =
  228. avctx->rc_initial_buffer_occupancy * 1000LL / avctx->bit_rate;
  229. enccfg.rc_buf_optimal_sz = enccfg.rc_buf_sz * 5 / 6;
  230. // _enc_init() will balk if kf_min_dist differs from max w/AOM_KF_AUTO
  231. if (avctx->keyint_min >= 0 && avctx->keyint_min == avctx->gop_size)
  232. enccfg.kf_min_dist = avctx->keyint_min;
  233. if (avctx->gop_size >= 0)
  234. enccfg.kf_max_dist = avctx->gop_size;
  235. if (enccfg.g_pass == AOM_RC_FIRST_PASS)
  236. enccfg.g_lag_in_frames = 0;
  237. else if (enccfg.g_pass == AOM_RC_LAST_PASS) {
  238. int decode_size, ret;
  239. if (!avctx->stats_in) {
  240. av_log(avctx, AV_LOG_ERROR, "No stats file for second pass\n");
  241. return AVERROR_INVALIDDATA;
  242. }
  243. ctx->twopass_stats.sz = strlen(avctx->stats_in) * 3 / 4;
  244. ret = av_reallocp(&ctx->twopass_stats.buf, ctx->twopass_stats.sz);
  245. if (ret < 0) {
  246. av_log(avctx, AV_LOG_ERROR,
  247. "Stat buffer alloc (%zu bytes) failed\n",
  248. ctx->twopass_stats.sz);
  249. return ret;
  250. }
  251. decode_size = av_base64_decode(ctx->twopass_stats.buf, avctx->stats_in,
  252. ctx->twopass_stats.sz);
  253. if (decode_size < 0) {
  254. av_log(avctx, AV_LOG_ERROR, "Stat buffer decode failed\n");
  255. return AVERROR_INVALIDDATA;
  256. }
  257. ctx->twopass_stats.sz = decode_size;
  258. enccfg.rc_twopass_stats_in = ctx->twopass_stats;
  259. }
  260. /* 0-3: For non-zero values the encoder increasingly optimizes for reduced
  261. * complexity playback on low powered devices at the expense of encode
  262. * quality. */
  263. if (avctx->profile != FF_PROFILE_UNKNOWN)
  264. enccfg.g_profile = avctx->profile;
  265. else if (avctx->pix_fmt == AV_PIX_FMT_YUV420P ||
  266. avctx->pix_fmt == AV_PIX_FMT_YUV420P10)
  267. avctx->profile = enccfg.g_profile = FF_PROFILE_AV1_MAIN;
  268. else if (avctx->pix_fmt == AV_PIX_FMT_YUV444P ||
  269. avctx->pix_fmt == AV_PIX_FMT_YUV444P10)
  270. avctx->profile = enccfg.g_profile = FF_PROFILE_AV1_HIGH;
  271. else {
  272. avctx->profile = enccfg.g_profile = FF_PROFILE_AV1_PROFESSIONAL;
  273. }
  274. enccfg.g_error_resilient = ctx->error_resilient;
  275. dump_enc_cfg(avctx, &enccfg);
  276. /* Construct Encoder Context */
  277. res = aom_codec_enc_init(&ctx->encoder, iface, &enccfg, 0);
  278. if (res != AOM_CODEC_OK) {
  279. log_encoder_error(avctx, "Failed to initialize encoder");
  280. return AVERROR(EINVAL);
  281. }
  282. // codec control failures are currently treated only as warnings
  283. av_log(avctx, AV_LOG_DEBUG, "aom_codec_control\n");
  284. if (ctx->cpu_used != INT_MIN)
  285. codecctl_int(avctx, AOME_SET_CPUUSED, ctx->cpu_used);
  286. if (ctx->auto_alt_ref >= 0)
  287. codecctl_int(avctx, AOME_SET_ENABLEAUTOALTREF, ctx->auto_alt_ref);
  288. codecctl_int(avctx, AOME_SET_STATIC_THRESHOLD, ctx->static_thresh);
  289. codecctl_int(avctx, AOME_SET_CQ_LEVEL, ctx->crf);
  290. // provide dummy value to initialize wrapper, values will be updated each _encode()
  291. aom_img_wrap(&ctx->rawimg, ff_aom_pixfmt_to_imgfmt(avctx->pix_fmt),
  292. avctx->width, avctx->height, 1, (unsigned char *)1);
  293. cpb_props = ff_add_cpb_side_data(avctx);
  294. if (!cpb_props)
  295. return AVERROR(ENOMEM);
  296. if (enccfg.rc_end_usage == AOM_CBR ||
  297. enccfg.g_pass != AOM_RC_ONE_PASS) {
  298. cpb_props->max_bitrate = avctx->rc_max_rate;
  299. cpb_props->min_bitrate = avctx->rc_min_rate;
  300. cpb_props->avg_bitrate = avctx->bit_rate;
  301. }
  302. cpb_props->buffer_size = avctx->rc_buffer_size;
  303. return 0;
  304. }
  305. static inline void cx_pktcpy(struct FrameListData *dst,
  306. const struct aom_codec_cx_pkt *src)
  307. {
  308. dst->pts = src->data.frame.pts;
  309. dst->duration = src->data.frame.duration;
  310. dst->flags = src->data.frame.flags;
  311. dst->sz = src->data.frame.sz;
  312. dst->buf = src->data.frame.buf;
  313. }
  314. /**
  315. * Store coded frame information in format suitable for return from encode2().
  316. *
  317. * Write information from @a cx_frame to @a pkt
  318. * @return packet data size on success
  319. * @return a negative AVERROR on error
  320. */
  321. static int storeframe(AVCodecContext *avctx, struct FrameListData *cx_frame,
  322. AVPacket *pkt)
  323. {
  324. int ret = ff_alloc_packet(pkt, cx_frame->sz);
  325. if (ret < 0) {
  326. av_log(avctx, AV_LOG_ERROR,
  327. "Error getting output packet of size %zu.\n", cx_frame->sz);
  328. return ret;
  329. }
  330. memcpy(pkt->data, cx_frame->buf, pkt->size);
  331. pkt->pts = pkt->dts = cx_frame->pts;
  332. if (!!(cx_frame->flags & AOM_FRAME_IS_KEY))
  333. pkt->flags |= AV_PKT_FLAG_KEY;
  334. return pkt->size;
  335. }
  336. /**
  337. * Queue multiple output frames from the encoder, returning the front-most.
  338. * In cases where aom_codec_get_cx_data() returns more than 1 frame append
  339. * the frame queue. Return the head frame if available.
  340. * @return Stored frame size
  341. * @return AVERROR(EINVAL) on output size error
  342. * @return AVERROR(ENOMEM) on coded frame queue data allocation error
  343. */
  344. static int queue_frames(AVCodecContext *avctx, AVPacket *pkt_out)
  345. {
  346. AOMContext *ctx = avctx->priv_data;
  347. const struct aom_codec_cx_pkt *pkt;
  348. const void *iter = NULL;
  349. int size = 0;
  350. if (ctx->coded_frame_list) {
  351. struct FrameListData *cx_frame = ctx->coded_frame_list;
  352. /* return the leading frame if we've already begun queueing */
  353. size = storeframe(avctx, cx_frame, pkt_out);
  354. if (size < 0)
  355. return size;
  356. ctx->coded_frame_list = cx_frame->next;
  357. free_coded_frame(cx_frame);
  358. }
  359. /* consume all available output from the encoder before returning. buffers
  360. * are only good through the next aom_codec call */
  361. while ((pkt = aom_codec_get_cx_data(&ctx->encoder, &iter))) {
  362. switch (pkt->kind) {
  363. case AOM_CODEC_CX_FRAME_PKT:
  364. if (!size) {
  365. struct FrameListData cx_frame;
  366. /* avoid storing the frame when the list is empty and we haven't yet
  367. * provided a frame for output */
  368. assert(!ctx->coded_frame_list);
  369. cx_pktcpy(&cx_frame, pkt);
  370. size = storeframe(avctx, &cx_frame, pkt_out);
  371. if (size < 0)
  372. return size;
  373. } else {
  374. struct FrameListData *cx_frame =
  375. av_malloc(sizeof(struct FrameListData));
  376. if (!cx_frame) {
  377. av_log(avctx, AV_LOG_ERROR,
  378. "Frame queue element alloc failed\n");
  379. return AVERROR(ENOMEM);
  380. }
  381. cx_pktcpy(cx_frame, pkt);
  382. cx_frame->buf = av_malloc(cx_frame->sz);
  383. if (!cx_frame->buf) {
  384. av_log(avctx, AV_LOG_ERROR,
  385. "Data buffer alloc (%zu bytes) failed\n",
  386. cx_frame->sz);
  387. av_freep(&cx_frame);
  388. return AVERROR(ENOMEM);
  389. }
  390. memcpy(cx_frame->buf, pkt->data.frame.buf, pkt->data.frame.sz);
  391. coded_frame_add(&ctx->coded_frame_list, cx_frame);
  392. }
  393. break;
  394. case AOM_CODEC_STATS_PKT:
  395. {
  396. struct aom_fixed_buf *stats = &ctx->twopass_stats;
  397. int err;
  398. if ((err = av_reallocp(&stats->buf,
  399. stats->sz +
  400. pkt->data.twopass_stats.sz)) < 0) {
  401. stats->sz = 0;
  402. av_log(avctx, AV_LOG_ERROR, "Stat buffer realloc failed\n");
  403. return err;
  404. }
  405. memcpy((uint8_t *)stats->buf + stats->sz,
  406. pkt->data.twopass_stats.buf, pkt->data.twopass_stats.sz);
  407. stats->sz += pkt->data.twopass_stats.sz;
  408. break;
  409. }
  410. case AOM_CODEC_PSNR_PKT: // FIXME add support for AV_CODEC_FLAG_PSNR
  411. case AOM_CODEC_CUSTOM_PKT:
  412. // ignore unsupported/unrecognized packet types
  413. break;
  414. }
  415. }
  416. return size;
  417. }
  418. static int aom_encode(AVCodecContext *avctx, AVPacket *pkt,
  419. const AVFrame *frame, int *got_packet)
  420. {
  421. AOMContext *ctx = avctx->priv_data;
  422. struct aom_image *rawimg = NULL;
  423. int64_t timestamp = 0;
  424. int res, coded_size;
  425. aom_enc_frame_flags_t flags = 0;
  426. if (frame) {
  427. rawimg = &ctx->rawimg;
  428. rawimg->planes[AOM_PLANE_Y] = frame->data[0];
  429. rawimg->planes[AOM_PLANE_U] = frame->data[1];
  430. rawimg->planes[AOM_PLANE_V] = frame->data[2];
  431. rawimg->stride[AOM_PLANE_Y] = frame->linesize[0];
  432. rawimg->stride[AOM_PLANE_U] = frame->linesize[1];
  433. rawimg->stride[AOM_PLANE_V] = frame->linesize[2];
  434. timestamp = frame->pts;
  435. switch (frame->color_range) {
  436. case AVCOL_RANGE_MPEG:
  437. rawimg->range = AOM_CR_STUDIO_RANGE;
  438. break;
  439. case AVCOL_RANGE_JPEG:
  440. rawimg->range = AOM_CR_FULL_RANGE;
  441. break;
  442. }
  443. if (frame->pict_type == AV_PICTURE_TYPE_I)
  444. flags |= AOM_EFLAG_FORCE_KF;
  445. }
  446. res = aom_codec_encode(&ctx->encoder, rawimg, timestamp,
  447. avctx->ticks_per_frame, flags);
  448. if (res != AOM_CODEC_OK) {
  449. log_encoder_error(avctx, "Error encoding frame");
  450. return AVERROR_INVALIDDATA;
  451. }
  452. coded_size = queue_frames(avctx, pkt);
  453. if (!frame && avctx->flags & AV_CODEC_FLAG_PASS1) {
  454. size_t b64_size = AV_BASE64_SIZE(ctx->twopass_stats.sz);
  455. avctx->stats_out = av_malloc(b64_size);
  456. if (!avctx->stats_out) {
  457. av_log(avctx, AV_LOG_ERROR, "Stat buffer alloc (%zu bytes) failed\n",
  458. b64_size);
  459. return AVERROR(ENOMEM);
  460. }
  461. av_base64_encode(avctx->stats_out, b64_size, ctx->twopass_stats.buf,
  462. ctx->twopass_stats.sz);
  463. }
  464. *got_packet = !!coded_size;
  465. return 0;
  466. }
  467. #define OFFSET(x) offsetof(AOMContext, x)
  468. #define VE AV_OPT_FLAG_VIDEO_PARAM | AV_OPT_FLAG_ENCODING_PARAM
  469. static const AVOption options[] = {
  470. { "cpu-used", "Quality/Speed ratio modifier", OFFSET(cpu_used), AV_OPT_TYPE_INT, {.i64 = 1}, INT_MIN, INT_MAX, VE},
  471. { "auto-alt-ref", "Enable use of alternate reference "
  472. "frames (2-pass only)", OFFSET(auto_alt_ref), AV_OPT_TYPE_INT, {.i64 = -1}, -1, 1, VE},
  473. { "lag-in-frames", "Number of frames to look ahead at for "
  474. "alternate reference frame selection", OFFSET(lag_in_frames), AV_OPT_TYPE_INT, {.i64 = -1}, -1, INT_MAX, VE},
  475. { "error-resilience", "Error resilience configuration", OFFSET(error_resilient), AV_OPT_TYPE_FLAGS, {.i64 = 0}, INT_MIN, INT_MAX, VE, "er"},
  476. { "default", "Improve resiliency against losses of whole frames", 0, AV_OPT_TYPE_CONST, {.i64 = AOM_ERROR_RESILIENT_DEFAULT}, 0, 0, VE, "er"},
  477. { "crf", "Select the quality for constant quality mode", offsetof(AOMContext, crf), AV_OPT_TYPE_INT, {.i64 = 0}, 0, 63, VE },
  478. { "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 },
  479. { "drop-threshold", "Frame drop threshold", offsetof(AOMContext, drop_threshold), AV_OPT_TYPE_INT, {.i64 = 0 }, INT_MIN, INT_MAX, VE },
  480. { "noise-sensitivity", "Noise sensitivity", OFFSET(noise_sensitivity), AV_OPT_TYPE_INT, {.i64 = 0 }, 0, 4, VE},
  481. { NULL }
  482. };
  483. static const AVCodecDefault defaults[] = {
  484. { "qmin", "-1" },
  485. { "qmax", "-1" },
  486. { "g", "-1" },
  487. { "keyint_min", "-1" },
  488. { NULL },
  489. };
  490. static const AVClass class_aom = {
  491. .class_name = "libaom encoder",
  492. .item_name = av_default_item_name,
  493. .option = options,
  494. .version = LIBAVUTIL_VERSION_INT,
  495. };
  496. AVCodec ff_libaom_av1_encoder = {
  497. .name = "libaom-av1",
  498. .long_name = NULL_IF_CONFIG_SMALL("libaom AV1"),
  499. .type = AVMEDIA_TYPE_VIDEO,
  500. .id = AV_CODEC_ID_AV1,
  501. .priv_data_size = sizeof(AOMContext),
  502. .init = aom_init,
  503. .encode2 = aom_encode,
  504. .close = aom_free,
  505. .capabilities = AV_CODEC_CAP_DELAY | AV_CODEC_CAP_AUTO_THREADS | AV_CODEC_CAP_EXPERIMENTAL,
  506. .pix_fmts = (const enum AVPixelFormat[]){ AV_PIX_FMT_YUV420P, AV_PIX_FMT_NONE },
  507. .priv_class = &class_aom,
  508. .defaults = defaults,
  509. .wrapper_name = "libaom",
  510. };