aom_encoder.h 41 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982983984985986987988989990991992993994995996997998999100010011002100310041005100610071008100910101011101210131014101510161017101810191020102110221023102410251026102710281029103010311032103310341035103610371038103910401041104210431044104510461047104810491050105110521053105410551056105710581059106010611062106310641065106610671068106910701071107210731074107510761077107810791080108110821083108410851086108710881089109010911092109310941095109610971098109911001101110211031104110511061107110811091110111111121113111411151116111711181119112011211122112311241125112611271128112911301131113211331134113511361137113811391140114111421143114411451146114711481149115011511152
  1. /*
  2. * Copyright (c) 2016, Alliance for Open Media. All rights reserved.
  3. *
  4. * This source code is subject to the terms of the BSD 2 Clause License and
  5. * the Alliance for Open Media Patent License 1.0. If the BSD 2 Clause License
  6. * was not distributed with this source code in the LICENSE file, you can
  7. * obtain it at www.aomedia.org/license/software. If the Alliance for Open
  8. * Media Patent License 1.0 was not distributed with this source code in the
  9. * PATENTS file, you can obtain it at www.aomedia.org/license/patent.
  10. */
  11. #ifndef AOM_AOM_AOM_ENCODER_H_
  12. #define AOM_AOM_AOM_ENCODER_H_
  13. /*!\defgroup encoder Encoder Algorithm Interface
  14. * \ingroup codec
  15. * This abstraction allows applications using this encoder to easily support
  16. * multiple video formats with minimal code duplication. This section describes
  17. * the interface common to all encoders.
  18. * @{
  19. */
  20. /*!\file
  21. * \brief Describes the encoder algorithm interface to applications.
  22. *
  23. * This file describes the interface between an application and a
  24. * video encoder algorithm.
  25. *
  26. */
  27. #ifdef __cplusplus
  28. extern "C" {
  29. #endif
  30. #include "aom/aom_codec.h" // IWYU pragma: export
  31. #include "aom/aom_external_partition.h"
  32. /*!\brief Current ABI version number
  33. *
  34. * \hideinitializer
  35. * \internal
  36. * If this file is altered in any way that changes the ABI, this value
  37. * must be bumped. Examples include, but are not limited to, changing
  38. * types, removing or reassigning enums, adding/removing/rearranging
  39. * fields to structures
  40. *
  41. * Note: In the definition of AOM_ENCODER_ABI_VERSION, 3 is the value of
  42. * AOM_EXT_PART_ABI_VERSION in libaom v3.2.0. The old value of
  43. * AOM_EXT_PART_ABI_VERSION is used so as to not break the ABI version check in
  44. * aom_codec_enc_init_ver() when an application compiled against libaom v3.2.0
  45. * passes the old value of AOM_ENCODER_ABI_VERSION to aom_codec_enc_init_ver().
  46. * The external partition API is still experimental. When it is declared stable,
  47. * we will replace 3 with AOM_EXT_PART_ABI_VERSION in the definition of
  48. * AOM_ENCODER_ABI_VERSION.
  49. */
  50. #define AOM_ENCODER_ABI_VERSION \
  51. (10 + AOM_CODEC_ABI_VERSION + /*AOM_EXT_PART_ABI_VERSION=*/3)
  52. /*! \brief Encoder capabilities bitfield
  53. *
  54. * Each encoder advertises the capabilities it supports as part of its
  55. * ::aom_codec_iface_t interface structure. Capabilities are extra
  56. * interfaces or functionality, and are not required to be supported
  57. * by an encoder.
  58. *
  59. * The available flags are specified by AOM_CODEC_CAP_* defines.
  60. */
  61. #define AOM_CODEC_CAP_PSNR 0x10000 /**< Can issue PSNR packets */
  62. /*! Can support input images at greater than 8 bitdepth.
  63. */
  64. #define AOM_CODEC_CAP_HIGHBITDEPTH 0x40000
  65. /*! \brief Initialization-time Feature Enabling
  66. *
  67. * Certain codec features must be known at initialization time, to allow
  68. * for proper memory allocation.
  69. *
  70. * The available flags are specified by AOM_CODEC_USE_* defines.
  71. */
  72. #define AOM_CODEC_USE_PSNR 0x10000 /**< Calculate PSNR on each frame */
  73. #define AOM_CODEC_USE_HIGHBITDEPTH 0x40000 /**< Use high bitdepth */
  74. /*!\brief Generic fixed size buffer structure
  75. *
  76. * This structure is able to hold a reference to any fixed size buffer.
  77. */
  78. typedef struct aom_fixed_buf {
  79. void *buf; /**< Pointer to the data. Does NOT own the data! */
  80. size_t sz; /**< Length of the buffer, in chars */
  81. } aom_fixed_buf_t; /**< alias for struct aom_fixed_buf */
  82. /*!\brief Error Resilient flags
  83. *
  84. * These flags define which error resilient features to enable in the
  85. * encoder. The flags are specified through the
  86. * aom_codec_enc_cfg::g_error_resilient variable.
  87. */
  88. typedef uint32_t aom_codec_er_flags_t;
  89. /*!\brief Improve resiliency against losses of whole frames */
  90. #define AOM_ERROR_RESILIENT_DEFAULT 0x1
  91. /*!\brief Encoder output packet variants
  92. *
  93. * This enumeration lists the different kinds of data packets that can be
  94. * returned by calls to aom_codec_get_cx_data(). Algorithms \ref MAY
  95. * extend this list to provide additional functionality.
  96. */
  97. enum aom_codec_cx_pkt_kind {
  98. AOM_CODEC_CX_FRAME_PKT, /**< Compressed video frame */
  99. AOM_CODEC_STATS_PKT, /**< Two-pass statistics for this frame */
  100. AOM_CODEC_FPMB_STATS_PKT, /**< first pass mb statistics for this frame */
  101. AOM_CODEC_PSNR_PKT, /**< PSNR statistics for this frame */
  102. AOM_CODEC_CUSTOM_PKT = 256 /**< Algorithm extensions */
  103. };
  104. /*!\brief Encoder output packet
  105. *
  106. * This structure contains the different kinds of output data the encoder
  107. * may produce while compressing a frame.
  108. */
  109. typedef struct aom_codec_cx_pkt {
  110. enum aom_codec_cx_pkt_kind kind; /**< packet variant */
  111. union {
  112. struct {
  113. void *buf; /**< compressed data buffer */
  114. size_t sz; /**< length of compressed data */
  115. /*!\brief time stamp to show frame (in timebase units) */
  116. aom_codec_pts_t pts;
  117. /*!\brief duration to show frame (in timebase units) */
  118. unsigned long duration;
  119. aom_codec_frame_flags_t flags; /**< flags for this frame */
  120. /*!\brief the partition id defines the decoding order of the partitions.
  121. * Only applicable when "output partition" mode is enabled. First
  122. * partition has id 0.*/
  123. int partition_id;
  124. /*!\brief size of the visible frame in this packet */
  125. size_t vis_frame_size;
  126. } frame; /**< data for compressed frame packet */
  127. aom_fixed_buf_t twopass_stats; /**< data for two-pass packet */
  128. aom_fixed_buf_t firstpass_mb_stats; /**< first pass mb packet */
  129. struct aom_psnr_pkt {
  130. unsigned int samples[4]; /**< Number of samples, total/y/u/v */
  131. uint64_t sse[4]; /**< sum squared error, total/y/u/v */
  132. double psnr[4]; /**< PSNR, total/y/u/v */
  133. /*!\brief Number of samples, total/y/u/v when
  134. * input bit-depth < stream bit-depth.*/
  135. unsigned int samples_hbd[4];
  136. /*!\brief sum squared error, total/y/u/v when
  137. * input bit-depth < stream bit-depth.*/
  138. uint64_t sse_hbd[4];
  139. /*!\brief PSNR, total/y/u/v when
  140. * input bit-depth < stream bit-depth.*/
  141. double psnr_hbd[4];
  142. } psnr; /**< data for PSNR packet */
  143. aom_fixed_buf_t raw; /**< data for arbitrary packets */
  144. } data; /**< packet data */
  145. } aom_codec_cx_pkt_t; /**< alias for struct aom_codec_cx_pkt */
  146. /*!\brief Rational Number
  147. *
  148. * This structure holds a fractional value.
  149. */
  150. typedef struct aom_rational {
  151. int num; /**< fraction numerator */
  152. int den; /**< fraction denominator */
  153. } aom_rational_t; /**< alias for struct aom_rational */
  154. /*!\brief Multi-pass Encoding Pass
  155. *
  156. * AOM_RC_LAST_PASS is kept for backward compatibility.
  157. * If passes is not given and pass==2, the codec will assume passes=2.
  158. * For new code, it is recommended to use AOM_RC_SECOND_PASS and set
  159. * the "passes" member to 2 via the key & val API for two-pass encoding.
  160. */
  161. enum aom_enc_pass {
  162. AOM_RC_ONE_PASS = 0, /**< Single pass mode */
  163. AOM_RC_FIRST_PASS = 1, /**< First pass of multi-pass mode */
  164. AOM_RC_SECOND_PASS = 2, /**< Second pass of multi-pass mode */
  165. AOM_RC_THIRD_PASS = 3, /**< Third pass of multi-pass mode */
  166. AOM_RC_LAST_PASS = 2, /**< Final pass of two-pass mode */
  167. };
  168. /*!\brief Rate control mode */
  169. enum aom_rc_mode {
  170. AOM_VBR, /**< Variable Bit Rate (VBR) mode */
  171. AOM_CBR, /**< Constant Bit Rate (CBR) mode */
  172. AOM_CQ, /**< Constrained Quality (CQ) mode */
  173. AOM_Q, /**< Constant Quality (Q) mode */
  174. };
  175. /*!\brief Keyframe placement mode.
  176. *
  177. * This enumeration determines whether keyframes are placed automatically by
  178. * the encoder or whether this behavior is disabled. Older releases of this
  179. * SDK were implemented such that AOM_KF_FIXED meant keyframes were disabled.
  180. * This name is confusing for this behavior, so the new symbols to be used
  181. * are AOM_KF_AUTO and AOM_KF_DISABLED.
  182. */
  183. enum aom_kf_mode {
  184. AOM_KF_FIXED, /**< deprecated, implies AOM_KF_DISABLED */
  185. AOM_KF_AUTO, /**< Encoder determines optimal placement automatically */
  186. AOM_KF_DISABLED = 0 /**< Encoder does not place keyframes. */
  187. };
  188. /*!\brief Frame super-resolution mode. */
  189. typedef enum {
  190. /**< Frame super-resolution is disabled for all frames. */
  191. AOM_SUPERRES_NONE,
  192. /**< All frames are coded at the specified scale and super-resolved. */
  193. AOM_SUPERRES_FIXED,
  194. /**< All frames are coded at a random scale and super-resolved. */
  195. AOM_SUPERRES_RANDOM,
  196. /**< Super-resolution scale for each frame is determined based on the q index
  197. of that frame. */
  198. AOM_SUPERRES_QTHRESH,
  199. /**< Full-resolution or super-resolution and the scale (in case of
  200. super-resolution) are automatically selected for each frame. */
  201. AOM_SUPERRES_AUTO,
  202. } aom_superres_mode;
  203. /*!\brief Encoder Config Options
  204. *
  205. * This type allows to enumerate and control flags defined for encoder control
  206. * via config file at runtime.
  207. */
  208. typedef struct cfg_options {
  209. /*!\brief Indicate init by cfg file
  210. * 0 or 1
  211. */
  212. unsigned int init_by_cfg_file;
  213. /*!\brief Superblock size
  214. * 0, 64 or 128
  215. */
  216. unsigned int super_block_size;
  217. /*!\brief max partition size
  218. * 8, 16, 32, 64, 128
  219. */
  220. unsigned int max_partition_size;
  221. /*!\brief min partition size
  222. * 8, 16, 32, 64, 128
  223. */
  224. unsigned int min_partition_size;
  225. /*!\brief disable AB Shape partition type
  226. *
  227. */
  228. unsigned int disable_ab_partition_type;
  229. /*!\brief disable rectangular partition type
  230. *
  231. */
  232. unsigned int disable_rect_partition_type;
  233. /*!\brief disable 1:4/4:1 partition type
  234. *
  235. */
  236. unsigned int disable_1to4_partition_type;
  237. /*!\brief disable flip and identity transform type
  238. *
  239. */
  240. unsigned int disable_flip_idtx;
  241. /*!\brief disable CDEF filter
  242. *
  243. */
  244. unsigned int disable_cdef;
  245. /*!\brief disable Loop Restoration Filter
  246. *
  247. */
  248. unsigned int disable_lr;
  249. /*!\brief disable OBMC
  250. *
  251. */
  252. unsigned int disable_obmc;
  253. /*!\brief disable Warped Motion
  254. *
  255. */
  256. unsigned int disable_warp_motion;
  257. /*!\brief disable global motion
  258. *
  259. */
  260. unsigned int disable_global_motion;
  261. /*!\brief disable dist weighted compound
  262. *
  263. */
  264. unsigned int disable_dist_wtd_comp;
  265. /*!\brief disable diff weighted compound
  266. *
  267. */
  268. unsigned int disable_diff_wtd_comp;
  269. /*!\brief disable inter/intra compound
  270. *
  271. */
  272. unsigned int disable_inter_intra_comp;
  273. /*!\brief disable masked compound
  274. *
  275. */
  276. unsigned int disable_masked_comp;
  277. /*!\brief disable one sided compound
  278. *
  279. */
  280. unsigned int disable_one_sided_comp;
  281. /*!\brief disable Palette
  282. *
  283. */
  284. unsigned int disable_palette;
  285. /*!\brief disable Intra Block Copy
  286. *
  287. */
  288. unsigned int disable_intrabc;
  289. /*!\brief disable chroma from luma
  290. *
  291. */
  292. unsigned int disable_cfl;
  293. /*!\brief disable intra smooth mode
  294. *
  295. */
  296. unsigned int disable_smooth_intra;
  297. /*!\brief disable filter intra
  298. *
  299. */
  300. unsigned int disable_filter_intra;
  301. /*!\brief disable dual filter
  302. *
  303. */
  304. unsigned int disable_dual_filter;
  305. /*!\brief disable intra angle delta
  306. *
  307. */
  308. unsigned int disable_intra_angle_delta;
  309. /*!\brief disable intra edge filter
  310. *
  311. */
  312. unsigned int disable_intra_edge_filter;
  313. /*!\brief disable 64x64 transform
  314. *
  315. */
  316. unsigned int disable_tx_64x64;
  317. /*!\brief disable smooth inter/intra
  318. *
  319. */
  320. unsigned int disable_smooth_inter_intra;
  321. /*!\brief disable inter/inter wedge comp
  322. *
  323. */
  324. unsigned int disable_inter_inter_wedge;
  325. /*!\brief disable inter/intra wedge comp
  326. *
  327. */
  328. unsigned int disable_inter_intra_wedge;
  329. /*!\brief disable paeth intra
  330. *
  331. */
  332. unsigned int disable_paeth_intra;
  333. /*!\brief disable trellis quantization
  334. *
  335. */
  336. unsigned int disable_trellis_quant;
  337. /*!\brief disable ref frame MV
  338. *
  339. */
  340. unsigned int disable_ref_frame_mv;
  341. /*!\brief use reduced reference frame set
  342. *
  343. */
  344. unsigned int reduced_reference_set;
  345. /*!\brief use reduced transform type set
  346. *
  347. */
  348. unsigned int reduced_tx_type_set;
  349. } cfg_options_t;
  350. /*!\brief Encoded Frame Flags
  351. *
  352. * This type indicates a bitfield to be passed to aom_codec_encode(), defining
  353. * per-frame boolean values. By convention, bits common to all codecs will be
  354. * named AOM_EFLAG_*, and bits specific to an algorithm will be named
  355. * /algo/_eflag_*. The lower order 16 bits are reserved for common use.
  356. */
  357. typedef long aom_enc_frame_flags_t;
  358. /*!\brief Force this frame to be a keyframe */
  359. #define AOM_EFLAG_FORCE_KF (1 << 0)
  360. /*!\brief Encoder configuration structure
  361. *
  362. * This structure contains the encoder settings that have common representations
  363. * across all codecs. This doesn't imply that all codecs support all features,
  364. * however.
  365. */
  366. typedef struct aom_codec_enc_cfg {
  367. /*
  368. * generic settings (g)
  369. */
  370. /*!\brief Algorithm specific "usage" value
  371. *
  372. * Algorithms may define multiple values for usage, which may convey the
  373. * intent of how the application intends to use the stream. If this value
  374. * is non-zero, consult the documentation for the codec to determine its
  375. * meaning.
  376. */
  377. unsigned int g_usage;
  378. /*!\brief Maximum number of threads to use
  379. *
  380. * For multi-threaded implementations, use no more than this number of
  381. * threads. The codec may use fewer threads than allowed. The value
  382. * 0 is equivalent to the value 1.
  383. */
  384. unsigned int g_threads;
  385. /*!\brief Bitstream profile to use
  386. *
  387. * Some codecs support a notion of multiple bitstream profiles. Typically
  388. * this maps to a set of features that are turned on or off. Often the
  389. * profile to use is determined by the features of the intended decoder.
  390. * Consult the documentation for the codec to determine the valid values
  391. * for this parameter, or set to zero for a sane default.
  392. */
  393. unsigned int g_profile; /**< profile of bitstream to use */
  394. /*!\brief Width of the frame
  395. *
  396. * This value identifies the presentation resolution of the frame,
  397. * in pixels. Note that the frames passed as input to the encoder must
  398. * have this resolution. Frames will be presented by the decoder in this
  399. * resolution, independent of any spatial resampling the encoder may do.
  400. */
  401. unsigned int g_w;
  402. /*!\brief Height of the frame
  403. *
  404. * This value identifies the presentation resolution of the frame,
  405. * in pixels. Note that the frames passed as input to the encoder must
  406. * have this resolution. Frames will be presented by the decoder in this
  407. * resolution, independent of any spatial resampling the encoder may do.
  408. */
  409. unsigned int g_h;
  410. /*!\brief Max number of frames to encode
  411. *
  412. * If force video mode is off (the default) and g_limit is 1, the encoder
  413. * will encode a still picture (still_picture is set to 1 in the sequence
  414. * header OBU). If in addition full_still_picture_hdr is 0 (the default),
  415. * the encoder will use a reduced header (reduced_still_picture_header is
  416. * set to 1 in the sequence header OBU) for the still picture.
  417. */
  418. unsigned int g_limit;
  419. /*!\brief Forced maximum width of the frame
  420. *
  421. * If this value is non-zero then it is used to force the maximum frame
  422. * width written in write_sequence_header().
  423. */
  424. unsigned int g_forced_max_frame_width;
  425. /*!\brief Forced maximum height of the frame
  426. *
  427. * If this value is non-zero then it is used to force the maximum frame
  428. * height written in write_sequence_header().
  429. */
  430. unsigned int g_forced_max_frame_height;
  431. /*!\brief Bit-depth of the codec
  432. *
  433. * This value identifies the bit_depth of the codec,
  434. * Only certain bit-depths are supported as identified in the
  435. * aom_bit_depth_t enum.
  436. */
  437. aom_bit_depth_t g_bit_depth;
  438. /*!\brief Bit-depth of the input frames
  439. *
  440. * This value identifies the bit_depth of the input frames in bits.
  441. * Note that the frames passed as input to the encoder must have
  442. * this bit-depth.
  443. */
  444. unsigned int g_input_bit_depth;
  445. /*!\brief Stream timebase units
  446. *
  447. * Indicates the smallest interval of time, in seconds, used by the stream.
  448. * For fixed frame rate material, or variable frame rate material where
  449. * frames are timed at a multiple of a given clock (ex: video capture),
  450. * the \ref RECOMMENDED method is to set the timebase to the reciprocal
  451. * of the frame rate (ex: 1001/30000 for 29.970 Hz NTSC). This allows the
  452. * pts to correspond to the frame number, which can be handy. For
  453. * re-encoding video from containers with absolute time timestamps, the
  454. * \ref RECOMMENDED method is to set the timebase to that of the parent
  455. * container or multimedia framework (ex: 1/1000 for ms, as in FLV).
  456. */
  457. struct aom_rational g_timebase;
  458. /*!\brief Enable error resilient modes.
  459. *
  460. * The error resilient bitfield indicates to the encoder which features
  461. * it should enable to take measures for streaming over lossy or noisy
  462. * links.
  463. */
  464. aom_codec_er_flags_t g_error_resilient;
  465. /*!\brief Multi-pass Encoding Mode
  466. *
  467. * This value should be set to the current phase for multi-pass encoding.
  468. * For single pass, set to #AOM_RC_ONE_PASS.
  469. */
  470. enum aom_enc_pass g_pass;
  471. /*!\brief Allow lagged encoding
  472. *
  473. * If set, this value allows the encoder to consume a number of input
  474. * frames before producing output frames. This allows the encoder to
  475. * base decisions for the current frame on future frames. This does
  476. * increase the latency of the encoding pipeline, so it is not appropriate
  477. * in all situations (ex: realtime encoding).
  478. *
  479. * Note that this is a maximum value -- the encoder may produce frames
  480. * sooner than the given limit. Set this value to 0 to disable this
  481. * feature.
  482. */
  483. unsigned int g_lag_in_frames;
  484. /*
  485. * rate control settings (rc)
  486. */
  487. /*!\brief Temporal resampling configuration, if supported by the codec.
  488. *
  489. * Temporal resampling allows the codec to "drop" frames as a strategy to
  490. * meet its target data rate. This can cause temporal discontinuities in
  491. * the encoded video, which may appear as stuttering during playback. This
  492. * trade-off is often acceptable, but for many applications is not. It can
  493. * be disabled in these cases.
  494. *
  495. * Note that not all codecs support this feature. All aom AVx codecs do.
  496. * For other codecs, consult the documentation for that algorithm.
  497. *
  498. * This threshold is described as a percentage of the target data buffer.
  499. * When the data buffer falls below this percentage of fullness, a
  500. * dropped frame is indicated. Set the threshold to zero (0) to disable
  501. * this feature.
  502. */
  503. unsigned int rc_dropframe_thresh;
  504. /*!\brief Mode for spatial resampling, if supported by the codec.
  505. *
  506. * Spatial resampling allows the codec to compress a lower resolution
  507. * version of the frame, which is then upscaled by the decoder to the
  508. * correct presentation resolution. This increases visual quality at
  509. * low data rates, at the expense of CPU time on the encoder/decoder.
  510. */
  511. unsigned int rc_resize_mode;
  512. /*!\brief Frame resize denominator.
  513. *
  514. * The denominator for resize to use, assuming 8 as the numerator.
  515. *
  516. * Valid denominators are 8 - 16 for now.
  517. */
  518. unsigned int rc_resize_denominator;
  519. /*!\brief Keyframe resize denominator.
  520. *
  521. * The denominator for resize to use, assuming 8 as the numerator.
  522. *
  523. * Valid denominators are 8 - 16 for now.
  524. */
  525. unsigned int rc_resize_kf_denominator;
  526. /*!\brief Frame super-resolution scaling mode.
  527. *
  528. * Similar to spatial resampling, frame super-resolution integrates
  529. * upscaling after the encode/decode process. Taking control of upscaling and
  530. * using restoration filters should allow it to outperform normal resizing.
  531. */
  532. aom_superres_mode rc_superres_mode;
  533. /*!\brief Frame super-resolution denominator.
  534. *
  535. * The denominator for superres to use. If fixed it will only change if the
  536. * cumulative scale change over resizing and superres is greater than 1/2;
  537. * this forces superres to reduce scaling.
  538. *
  539. * Valid denominators are 8 to 16.
  540. *
  541. * Used only by AOM_SUPERRES_FIXED.
  542. */
  543. unsigned int rc_superres_denominator;
  544. /*!\brief Keyframe super-resolution denominator.
  545. *
  546. * The denominator for superres to use. If fixed it will only change if the
  547. * cumulative scale change over resizing and superres is greater than 1/2;
  548. * this forces superres to reduce scaling.
  549. *
  550. * Valid denominators are 8 - 16 for now.
  551. */
  552. unsigned int rc_superres_kf_denominator;
  553. /*!\brief Frame super-resolution q threshold.
  554. *
  555. * The q level threshold after which superres is used.
  556. * Valid values are 1 to 63.
  557. *
  558. * Used only by AOM_SUPERRES_QTHRESH
  559. */
  560. unsigned int rc_superres_qthresh;
  561. /*!\brief Keyframe super-resolution q threshold.
  562. *
  563. * The q level threshold after which superres is used for key frames.
  564. * Valid values are 1 to 63.
  565. *
  566. * Used only by AOM_SUPERRES_QTHRESH
  567. */
  568. unsigned int rc_superres_kf_qthresh;
  569. /*!\brief Rate control algorithm to use.
  570. *
  571. * Indicates whether the end usage of this stream is to be streamed over
  572. * a bandwidth constrained link, indicating that Constant Bit Rate (CBR)
  573. * mode should be used, or whether it will be played back on a high
  574. * bandwidth link, as from a local disk, where higher variations in
  575. * bitrate are acceptable.
  576. */
  577. enum aom_rc_mode rc_end_usage;
  578. /*!\brief Two-pass stats buffer.
  579. *
  580. * A buffer containing all of the stats packets produced in the first
  581. * pass, concatenated.
  582. */
  583. aom_fixed_buf_t rc_twopass_stats_in;
  584. /*!\brief first pass mb stats buffer.
  585. *
  586. * A buffer containing all of the first pass mb stats packets produced
  587. * in the first pass, concatenated.
  588. */
  589. aom_fixed_buf_t rc_firstpass_mb_stats_in;
  590. /*!\brief Target data rate
  591. *
  592. * Target bitrate to use for this stream, in kilobits per second.
  593. * Max allowed value is 2000000
  594. */
  595. unsigned int rc_target_bitrate;
  596. /*
  597. * quantizer settings
  598. */
  599. /*!\brief Minimum (Best Quality) Quantizer
  600. *
  601. * The quantizer is the most direct control over the quality of the
  602. * encoded image. The range of valid values for the quantizer is codec
  603. * specific. Consult the documentation for the codec to determine the
  604. * values to use. To determine the range programmatically, call
  605. * aom_codec_enc_config_default() with a usage value of 0.
  606. */
  607. unsigned int rc_min_quantizer;
  608. /*!\brief Maximum (Worst Quality) Quantizer
  609. *
  610. * The quantizer is the most direct control over the quality of the
  611. * encoded image. The range of valid values for the quantizer is codec
  612. * specific. Consult the documentation for the codec to determine the
  613. * values to use. To determine the range programmatically, call
  614. * aom_codec_enc_config_default() with a usage value of 0.
  615. */
  616. unsigned int rc_max_quantizer;
  617. /*
  618. * bitrate tolerance
  619. */
  620. /*!\brief Rate control adaptation undershoot control
  621. *
  622. * This value, controls the tolerance of the VBR algorithm to undershoot
  623. * and is used as a trigger threshold for more aggressive adaptation of Q.
  624. *
  625. * Valid values in the range 0-100.
  626. */
  627. unsigned int rc_undershoot_pct;
  628. /*!\brief Rate control adaptation overshoot control
  629. *
  630. * This value, controls the tolerance of the VBR algorithm to overshoot
  631. * and is used as a trigger threshold for more aggressive adaptation of Q.
  632. *
  633. * Valid values in the range 0-100.
  634. */
  635. unsigned int rc_overshoot_pct;
  636. /*
  637. * decoder buffer model parameters
  638. */
  639. /*!\brief Decoder Buffer Size
  640. *
  641. * This value indicates the amount of data that may be buffered by the
  642. * decoding application. Note that this value is expressed in units of
  643. * time (milliseconds). For example, a value of 5000 indicates that the
  644. * client will buffer (at least) 5000ms worth of encoded data. Use the
  645. * target bitrate (#rc_target_bitrate) to convert to bits/bytes, if
  646. * necessary.
  647. */
  648. unsigned int rc_buf_sz;
  649. /*!\brief Decoder Buffer Initial Size
  650. *
  651. * This value indicates the amount of data that will be buffered by the
  652. * decoding application prior to beginning playback. This value is
  653. * expressed in units of time (milliseconds). Use the target bitrate
  654. * (#rc_target_bitrate) to convert to bits/bytes, if necessary.
  655. */
  656. unsigned int rc_buf_initial_sz;
  657. /*!\brief Decoder Buffer Optimal Size
  658. *
  659. * This value indicates the amount of data that the encoder should try
  660. * to maintain in the decoder's buffer. This value is expressed in units
  661. * of time (milliseconds). Use the target bitrate (#rc_target_bitrate)
  662. * to convert to bits/bytes, if necessary.
  663. */
  664. unsigned int rc_buf_optimal_sz;
  665. /*
  666. * 2 pass rate control parameters
  667. */
  668. /*!\brief Two-pass mode CBR/VBR bias
  669. *
  670. * Bias, expressed on a scale of 0 to 100, for determining target size
  671. * for the current frame. The value 0 indicates the optimal CBR mode
  672. * value should be used. The value 100 indicates the optimal VBR mode
  673. * value should be used. Values in between indicate which way the
  674. * encoder should "lean."
  675. */
  676. unsigned int rc_2pass_vbr_bias_pct;
  677. /*!\brief Two-pass mode per-GOP minimum bitrate
  678. *
  679. * This value, expressed as a percentage of the target bitrate, indicates
  680. * the minimum bitrate to be used for a single GOP (aka "section")
  681. */
  682. unsigned int rc_2pass_vbr_minsection_pct;
  683. /*!\brief Two-pass mode per-GOP maximum bitrate
  684. *
  685. * This value, expressed as a percentage of the target bitrate, indicates
  686. * the maximum bitrate to be used for a single GOP (aka "section")
  687. */
  688. unsigned int rc_2pass_vbr_maxsection_pct;
  689. /*
  690. * keyframing settings (kf)
  691. */
  692. /*!\brief Option to enable forward reference key frame
  693. *
  694. */
  695. int fwd_kf_enabled;
  696. /*!\brief Keyframe placement mode
  697. *
  698. * This value indicates whether the encoder should place keyframes at a
  699. * fixed interval, or determine the optimal placement automatically
  700. * (as governed by the #kf_min_dist and #kf_max_dist parameters)
  701. */
  702. enum aom_kf_mode kf_mode;
  703. /*!\brief Keyframe minimum interval
  704. *
  705. * This value, expressed as a number of frames, prevents the encoder from
  706. * placing a keyframe nearer than kf_min_dist to the previous keyframe. At
  707. * least kf_min_dist frames non-keyframes will be coded before the next
  708. * keyframe. Set kf_min_dist equal to kf_max_dist for a fixed interval.
  709. */
  710. unsigned int kf_min_dist;
  711. /*!\brief Keyframe maximum interval
  712. *
  713. * This value, expressed as a number of frames, forces the encoder to code
  714. * a keyframe if one has not been coded in the last kf_max_dist frames.
  715. * A value of 0 implies all frames will be keyframes. Set kf_min_dist
  716. * equal to kf_max_dist for a fixed interval.
  717. */
  718. unsigned int kf_max_dist;
  719. /*!\brief sframe interval
  720. *
  721. * This value, expressed as a number of frames, forces the encoder to code
  722. * an S-Frame every sframe_dist frames.
  723. */
  724. unsigned int sframe_dist;
  725. /*!\brief sframe insertion mode
  726. *
  727. * This value must be set to 1 or 2, and tells the encoder how to insert
  728. * S-Frames. It will only have an effect if sframe_dist != 0.
  729. *
  730. * If altref is enabled:
  731. * - if sframe_mode == 1, the considered frame will be made into an
  732. * S-Frame only if it is an altref frame
  733. * - if sframe_mode == 2, the next altref frame will be made into an
  734. * S-Frame.
  735. *
  736. * Otherwise: the considered frame will be made into an S-Frame.
  737. *
  738. * \attention Not implemented.
  739. */
  740. unsigned int sframe_mode;
  741. /*!\brief Tile coding mode
  742. *
  743. * This value indicates the tile coding mode.
  744. * A value of 0 implies a normal non-large-scale tile coding. A value of 1
  745. * implies a large-scale tile coding.
  746. */
  747. unsigned int large_scale_tile;
  748. /*!\brief Monochrome mode
  749. *
  750. * If this is nonzero, the encoder will generate a monochrome stream
  751. * with no chroma planes.
  752. */
  753. unsigned int monochrome;
  754. /*!\brief full_still_picture_hdr
  755. *
  756. * If this is nonzero, the encoder will generate a full header
  757. * (reduced_still_picture_header is set to 0 in the sequence header OBU) even
  758. * for still picture encoding. If this is zero (the default), a reduced
  759. * header (reduced_still_picture_header is set to 1 in the sequence header
  760. * OBU) is used for still picture encoding. This flag has no effect when a
  761. * regular video with more than a single frame is encoded.
  762. */
  763. unsigned int full_still_picture_hdr;
  764. /*!\brief Bitstream syntax mode
  765. *
  766. * This value indicates the bitstream syntax mode.
  767. * A value of 0 indicates bitstream is saved as Section 5 bitstream. A value
  768. * of 1 indicates the bitstream is saved in Annex-B format
  769. */
  770. unsigned int save_as_annexb;
  771. /*!\brief Number of explicit tile widths specified
  772. *
  773. * This value indicates the number of tile widths specified
  774. * A value of 0 implies no tile widths are specified.
  775. * Tile widths are given in the array tile_widths[]
  776. */
  777. int tile_width_count;
  778. /*!\brief Number of explicit tile heights specified
  779. *
  780. * This value indicates the number of tile heights specified
  781. * A value of 0 implies no tile heights are specified.
  782. * Tile heights are given in the array tile_heights[]
  783. */
  784. int tile_height_count;
  785. /*!\brief Maximum number of tile widths in tile widths array
  786. *
  787. * This define gives the maximum number of elements in the tile_widths array.
  788. */
  789. #define MAX_TILE_WIDTHS 64 // maximum tile width array length
  790. /*!\brief Array of specified tile widths
  791. *
  792. * This array specifies tile widths (and may be empty)
  793. * The number of widths specified is given by tile_width_count
  794. */
  795. int tile_widths[MAX_TILE_WIDTHS];
  796. /*!\brief Maximum number of tile heights in tile heights array.
  797. *
  798. * This define gives the maximum number of elements in the tile_heights array.
  799. */
  800. #define MAX_TILE_HEIGHTS 64 // maximum tile height array length
  801. /*!\brief Array of specified tile heights
  802. *
  803. * This array specifies tile heights (and may be empty)
  804. * The number of heights specified is given by tile_height_count
  805. */
  806. int tile_heights[MAX_TILE_HEIGHTS];
  807. /*!\brief Whether encoder should use fixed QP offsets.
  808. *
  809. * If a value of 1 is provided, encoder will use fixed QP offsets for frames
  810. * at different levels of the pyramid.
  811. * If a value of 0 is provided, encoder will NOT use fixed QP offsets.
  812. * Note: This option is only relevant for --end-usage=q.
  813. */
  814. unsigned int use_fixed_qp_offsets;
  815. /*!\brief Deprecated and ignored. DO NOT USE.
  816. *
  817. * TODO(aomedia:3269): Remove fixed_qp_offsets in libaom v4.0.0.
  818. */
  819. int fixed_qp_offsets[5];
  820. /*!\brief Options defined per config file
  821. *
  822. */
  823. cfg_options_t encoder_cfg;
  824. } aom_codec_enc_cfg_t; /**< alias for struct aom_codec_enc_cfg */
  825. /*!\brief Initialize an encoder instance
  826. *
  827. * Initializes an encoder context using the given interface. Applications
  828. * should call the aom_codec_enc_init convenience macro instead of this
  829. * function directly, to ensure that the ABI version number parameter
  830. * is properly initialized.
  831. *
  832. * If the library was configured with -DCONFIG_MULTITHREAD=0, this call
  833. * is not thread safe and should be guarded with a lock if being used
  834. * in a multithreaded context.
  835. *
  836. * If aom_codec_enc_init_ver() fails, it is not necessary to call
  837. * aom_codec_destroy() on the encoder context.
  838. *
  839. * \param[in] ctx Pointer to this instance's context.
  840. * \param[in] iface Pointer to the algorithm interface to use.
  841. * \param[in] cfg Configuration to use, if known.
  842. * \param[in] flags Bitfield of AOM_CODEC_USE_* flags
  843. * \param[in] ver ABI version number. Must be set to
  844. * AOM_ENCODER_ABI_VERSION
  845. * \retval #AOM_CODEC_OK
  846. * The encoder algorithm has been initialized.
  847. * \retval #AOM_CODEC_MEM_ERROR
  848. * Memory allocation failed.
  849. */
  850. aom_codec_err_t aom_codec_enc_init_ver(aom_codec_ctx_t *ctx,
  851. aom_codec_iface_t *iface,
  852. const aom_codec_enc_cfg_t *cfg,
  853. aom_codec_flags_t flags, int ver);
  854. /*!\brief Convenience macro for aom_codec_enc_init_ver()
  855. *
  856. * Ensures the ABI version parameter is properly set.
  857. */
  858. #define aom_codec_enc_init(ctx, iface, cfg, flags) \
  859. aom_codec_enc_init_ver(ctx, iface, cfg, flags, AOM_ENCODER_ABI_VERSION)
  860. /*!\brief Get the default configuration for a usage.
  861. *
  862. * Initializes an encoder configuration structure with default values. Supports
  863. * the notion of "usages" so that an algorithm may offer different default
  864. * settings depending on the user's intended goal. This function \ref SHOULD
  865. * be called by all applications to initialize the configuration structure
  866. * before specializing the configuration with application specific values.
  867. *
  868. * \param[in] iface Pointer to the algorithm interface to use.
  869. * \param[out] cfg Configuration buffer to populate.
  870. * \param[in] usage Algorithm specific usage value. For AV1, must be
  871. * set to AOM_USAGE_GOOD_QUALITY (0),
  872. * AOM_USAGE_REALTIME (1), or AOM_USAGE_ALL_INTRA (2).
  873. *
  874. * \retval #AOM_CODEC_OK
  875. * The configuration was populated.
  876. * \retval #AOM_CODEC_INCAPABLE
  877. * Interface is not an encoder interface.
  878. * \retval #AOM_CODEC_INVALID_PARAM
  879. * A parameter was NULL, or the usage value was not recognized.
  880. */
  881. aom_codec_err_t aom_codec_enc_config_default(aom_codec_iface_t *iface,
  882. aom_codec_enc_cfg_t *cfg,
  883. unsigned int usage);
  884. /*!\brief Set or change configuration
  885. *
  886. * Reconfigures an encoder instance according to the given configuration.
  887. *
  888. * \param[in] ctx Pointer to this instance's context
  889. * \param[in] cfg Configuration buffer to use
  890. *
  891. * \retval #AOM_CODEC_OK
  892. * The configuration was populated.
  893. * \retval #AOM_CODEC_INCAPABLE
  894. * Interface is not an encoder interface.
  895. * \retval #AOM_CODEC_INVALID_PARAM
  896. * A parameter was NULL, or the usage value was not recognized.
  897. */
  898. aom_codec_err_t aom_codec_enc_config_set(aom_codec_ctx_t *ctx,
  899. const aom_codec_enc_cfg_t *cfg);
  900. /*!\brief Get global stream headers
  901. *
  902. * Retrieves a stream level global header packet, if supported by the codec.
  903. * Calls to this function should be deferred until all configuration information
  904. * has been passed to libaom. Otherwise the global header data may be
  905. * invalidated by additional configuration changes.
  906. *
  907. * The AV1 implementation of this function returns an OBU. The OBU returned is
  908. * in Low Overhead Bitstream Format. Specifically, the obu_has_size_field bit is
  909. * set, and the buffer contains the obu_size field for the returned OBU.
  910. *
  911. * \param[in] ctx Pointer to this instance's context
  912. *
  913. * \retval NULL
  914. * Encoder does not support global header, or an error occurred while
  915. * generating the global header.
  916. *
  917. * \retval Non-NULL
  918. * Pointer to buffer containing global header packet. The caller owns the
  919. * memory associated with this buffer, and must free the 'buf' member of the
  920. * aom_fixed_buf_t as well as the aom_fixed_buf_t pointer. Memory returned
  921. * must be freed via call to free().
  922. */
  923. aom_fixed_buf_t *aom_codec_get_global_headers(aom_codec_ctx_t *ctx);
  924. /*!\brief usage parameter analogous to AV1 GOOD QUALITY mode. */
  925. #define AOM_USAGE_GOOD_QUALITY 0u
  926. /*!\brief usage parameter analogous to AV1 REALTIME mode. */
  927. #define AOM_USAGE_REALTIME 1u
  928. /*!\brief usage parameter analogous to AV1 all intra mode. */
  929. #define AOM_USAGE_ALL_INTRA 2u
  930. /*!\brief Encode a frame
  931. *
  932. * Encodes a video frame at the given "presentation time." The presentation
  933. * time stamp (PTS) \ref MUST be strictly increasing.
  934. *
  935. * When the last frame has been passed to the encoder, this function should
  936. * continue to be called in a loop, with the img parameter set to NULL. This
  937. * will signal the end-of-stream condition to the encoder and allow it to
  938. * encode any held buffers. Encoding is complete when aom_codec_encode() is
  939. * called with img set to NULL and aom_codec_get_cx_data() returns no data.
  940. *
  941. * \param[in] ctx Pointer to this instance's context
  942. * \param[in] img Image data to encode, NULL to flush.
  943. * Encoding sample values outside the range
  944. * [0..(1<<img->bit_depth)-1] is undefined behavior.
  945. * Note: Although img is declared as a const pointer,
  946. * if AV1E_SET_DENOISE_NOISE_LEVEL is set to a nonzero
  947. * value aom_codec_encode() modifies (denoises) the
  948. * samples in img->planes[i] .
  949. * \param[in] pts Presentation time stamp, in timebase units. If img
  950. * is NULL, pts is ignored.
  951. * \param[in] duration Duration to show frame, in timebase units. If img
  952. * is not NULL, duration must be nonzero. If img is
  953. * NULL, duration is ignored.
  954. * \param[in] flags Flags to use for encoding this frame.
  955. *
  956. * \retval #AOM_CODEC_OK
  957. * The configuration was populated.
  958. * \retval #AOM_CODEC_INCAPABLE
  959. * Interface is not an encoder interface.
  960. * \retval #AOM_CODEC_INVALID_PARAM
  961. * A parameter was NULL, the image format is unsupported, etc.
  962. *
  963. * \note
  964. * `duration` is of the unsigned long type, which can be 32 or 64 bits.
  965. * `duration` must be less than or equal to UINT32_MAX so that its range is
  966. * independent of the size of unsigned long.
  967. */
  968. aom_codec_err_t aom_codec_encode(aom_codec_ctx_t *ctx, const aom_image_t *img,
  969. aom_codec_pts_t pts, unsigned long duration,
  970. aom_enc_frame_flags_t flags);
  971. /*!\brief Set compressed data output buffer
  972. *
  973. * Sets the buffer that the codec should output the compressed data
  974. * into. This call effectively sets the buffer pointer returned in the
  975. * next AOM_CODEC_CX_FRAME_PKT packet. Subsequent packets will be
  976. * appended into this buffer. The buffer is preserved across frames,
  977. * so applications must periodically call this function after flushing
  978. * the accumulated compressed data to disk or to the network to reset
  979. * the pointer to the buffer's head.
  980. *
  981. * `pad_before` bytes will be skipped before writing the compressed
  982. * data, and `pad_after` bytes will be appended to the packet. The size
  983. * of the packet will be the sum of the size of the actual compressed
  984. * data, pad_before, and pad_after. The padding bytes will be preserved
  985. * (not overwritten).
  986. *
  987. * Note that calling this function does not guarantee that the returned
  988. * compressed data will be placed into the specified buffer. In the
  989. * event that the encoded data will not fit into the buffer provided,
  990. * the returned packet \ref MAY point to an internal buffer, as it would
  991. * if this call were never used. In this event, the output packet will
  992. * NOT have any padding, and the application must free space and copy it
  993. * to the proper place. This is of particular note in configurations
  994. * that may output multiple packets for a single encoded frame (e.g., lagged
  995. * encoding) or if the application does not reset the buffer periodically.
  996. *
  997. * Applications may restore the default behavior of the codec providing
  998. * the compressed data buffer by calling this function with a NULL
  999. * buffer.
  1000. *
  1001. * Applications \ref MUSTNOT call this function during iteration of
  1002. * aom_codec_get_cx_data().
  1003. *
  1004. * \param[in] ctx Pointer to this instance's context
  1005. * \param[in] buf Buffer to store compressed data into
  1006. * \param[in] pad_before Bytes to skip before writing compressed data
  1007. * \param[in] pad_after Bytes to skip after writing compressed data
  1008. *
  1009. * \retval #AOM_CODEC_OK
  1010. * The buffer was set successfully.
  1011. * \retval #AOM_CODEC_INVALID_PARAM
  1012. * A parameter was NULL, the image format is unsupported, etc.
  1013. */
  1014. aom_codec_err_t aom_codec_set_cx_data_buf(aom_codec_ctx_t *ctx,
  1015. const aom_fixed_buf_t *buf,
  1016. unsigned int pad_before,
  1017. unsigned int pad_after);
  1018. /*!\brief Encoded data iterator
  1019. *
  1020. * Iterates over a list of data packets to be passed from the encoder to the
  1021. * application. The different kinds of packets available are enumerated in
  1022. * #aom_codec_cx_pkt_kind.
  1023. *
  1024. * #AOM_CODEC_CX_FRAME_PKT packets should be passed to the application's
  1025. * muxer. Multiple compressed frames may be in the list.
  1026. * #AOM_CODEC_STATS_PKT packets should be appended to a global buffer.
  1027. *
  1028. * The application \ref MUST silently ignore any packet kinds that it does
  1029. * not recognize or support.
  1030. *
  1031. * The data buffers returned from this function are only guaranteed to be
  1032. * valid until the application makes another call to any aom_codec_* function.
  1033. *
  1034. * \param[in] ctx Pointer to this instance's context
  1035. * \param[in,out] iter Iterator storage, initialized to NULL
  1036. *
  1037. * \return Returns a pointer to an output data packet (compressed frame data,
  1038. * two-pass statistics, etc.) or NULL to signal end-of-list.
  1039. *
  1040. */
  1041. const aom_codec_cx_pkt_t *aom_codec_get_cx_data(aom_codec_ctx_t *ctx,
  1042. aom_codec_iter_t *iter);
  1043. /*!\brief Get Preview Frame
  1044. *
  1045. * Returns an image that can be used as a preview. Shows the image as it would
  1046. * exist at the decompressor. The application \ref MUST NOT write into this
  1047. * image buffer.
  1048. *
  1049. * \param[in] ctx Pointer to this instance's context
  1050. *
  1051. * \return Returns a pointer to a preview image, or NULL if no image is
  1052. * available.
  1053. *
  1054. */
  1055. const aom_image_t *aom_codec_get_preview_frame(aom_codec_ctx_t *ctx);
  1056. /*!@} - end defgroup encoder*/
  1057. #ifdef __cplusplus
  1058. }
  1059. #endif
  1060. #endif // AOM_AOM_AOM_ENCODER_H_