aom_encoder.h 36 KB

123456789101112131415161718192021222324252627282930313233343536373839404142434445464748495051525354555657585960616263646566676869707172737475767778798081828384858687888990919293949596979899100101102103104105106107108109110111112113114115116117118119120121122123124125126127128129130131132133134135136137138139140141142143144145146147148149150151152153154155156157158159160161162163164165166167168169170171172173174175176177178179180181182183184185186187188189190191192193194195196197198199200201202203204205206207208209210211212213214215216217218219220221222223224225226227228229230231232233234235236237238239240241242243244245246247248249250251252253254255256257258259260261262263264265266267268269270271272273274275276277278279280281282283284285286287288289290291292293294295296297298299300301302303304305306307308309310311312313314315316317318319320321322323324325326327328329330331332333334335336337338339340341342343344345346347348349350351352353354355356357358359360361362363364365366367368369370371372373374375376377378379380381382383384385386387388389390391392393394395396397398399400401402403404405406407408409410411412413414415416417418419420421422423424425426427428429430431432433434435436437438439440441442443444445446447448449450451452453454455456457458459460461462463464465466467468469470471472473474475476477478479480481482483484485486487488489490491492493494495496497498499500501502503504505506507508509510511512513514515516517518519520521522523524525526527528529530531532533534535536537538539540541542543544545546547548549550551552553554555556557558559560561562563564565566567568569570571572573574575576577578579580581582583584585586587588589590591592593594595596597598599600601602603604605606607608609610611612613614615616617618619620621622623624625626627628629630631632633634635636637638639640641642643644645646647648649650651652653654655656657658659660661662663664665666667668669670671672673674675676677678679680681682683684685686687688689690691692693694695696697698699700701702703704705706707708709710711712713714715716717718719720721722723724725726727728729730731732733734735736737738739740741742743744745746747748749750751752753754755756757758759760761762763764765766767768769770771772773774775776777778779780781782783784785786787788789790791792793794795796797798799800801802803804805806807808809810811812813814815816817818819820821822823824825826827828829830831832833834835836837838839840841842843844845846847848849850851852853854855856857858859860861862863864865866867868869870871872873874875876877878879880881882883884885886887888889890891892893894895896897898899900901902903904905906907908909910911912913914915916917918919920921922923924925926927928929930931932933934935936937938939940941942943944945946947948949950951952953954955956957958959960961962963964965966967968969970971972973974975976977978979980981982
  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_ENCODER_H_
  12. #define 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"
  31. /*!\brief Current ABI version number
  32. *
  33. * \internal
  34. * If this file is altered in any way that changes the ABI, this value
  35. * must be bumped. Examples include, but are not limited to, changing
  36. * types, removing or reassigning enums, adding/removing/rearranging
  37. * fields to structures
  38. */
  39. #define AOM_ENCODER_ABI_VERSION \
  40. (5 + AOM_CODEC_ABI_VERSION) /**<\hideinitializer*/
  41. /*! \brief Encoder capabilities bitfield
  42. *
  43. * Each encoder advertises the capabilities it supports as part of its
  44. * ::aom_codec_iface_t interface structure. Capabilities are extra
  45. * interfaces or functionality, and are not required to be supported
  46. * by an encoder.
  47. *
  48. * The available flags are specified by AOM_CODEC_CAP_* defines.
  49. */
  50. #define AOM_CODEC_CAP_PSNR 0x10000 /**< Can issue PSNR packets */
  51. /*! Can output one partition at a time. Each partition is returned in its
  52. * own AOM_CODEC_CX_FRAME_PKT, with the FRAME_IS_FRAGMENT flag set for
  53. * every partition but the last. In this mode all frames are always
  54. * returned partition by partition.
  55. */
  56. #define AOM_CODEC_CAP_OUTPUT_PARTITION 0x20000
  57. /*! Can support input images at greater than 8 bitdepth.
  58. */
  59. #define AOM_CODEC_CAP_HIGHBITDEPTH 0x40000
  60. /*! \brief Initialization-time Feature Enabling
  61. *
  62. * Certain codec features must be known at initialization time, to allow
  63. * for proper memory allocation.
  64. *
  65. * The available flags are specified by AOM_CODEC_USE_* defines.
  66. */
  67. #define AOM_CODEC_USE_PSNR 0x10000 /**< Calculate PSNR on each frame */
  68. /*!\brief Make the encoder output one partition at a time. */
  69. #define AOM_CODEC_USE_OUTPUT_PARTITION 0x20000
  70. #define AOM_CODEC_USE_HIGHBITDEPTH 0x40000 /**< Use high bitdepth */
  71. /*!\brief Generic fixed size buffer structure
  72. *
  73. * This structure is able to hold a reference to any fixed size buffer.
  74. */
  75. typedef struct aom_fixed_buf {
  76. void *buf; /**< Pointer to the data */
  77. size_t sz; /**< Length of the buffer, in chars */
  78. } aom_fixed_buf_t; /**< alias for struct aom_fixed_buf */
  79. /*!\brief Time Stamp Type
  80. *
  81. * An integer, which when multiplied by the stream's time base, provides
  82. * the absolute time of a sample.
  83. */
  84. typedef int64_t aom_codec_pts_t;
  85. /*!\brief Compressed Frame Flags
  86. *
  87. * This type represents a bitfield containing information about a compressed
  88. * frame that may be useful to an application. The most significant 16 bits
  89. * can be used by an algorithm to provide additional detail, for example to
  90. * support frame types that are codec specific (MPEG-1 D-frames for example)
  91. */
  92. typedef uint32_t aom_codec_frame_flags_t;
  93. #define AOM_FRAME_IS_KEY 0x1 /**< frame is the start of a GOP */
  94. /*!\brief frame can be dropped without affecting the stream (no future frame
  95. * depends on this one) */
  96. #define AOM_FRAME_IS_DROPPABLE 0x2
  97. /*!\brief frame should be decoded but will not be shown */
  98. #define AOM_FRAME_IS_INVISIBLE 0x4
  99. /*!\brief this is a fragment of the encoded frame */
  100. #define AOM_FRAME_IS_FRAGMENT 0x8
  101. /*!\brief Error Resilient flags
  102. *
  103. * These flags define which error resilient features to enable in the
  104. * encoder. The flags are specified through the
  105. * aom_codec_enc_cfg::g_error_resilient variable.
  106. */
  107. typedef uint32_t aom_codec_er_flags_t;
  108. /*!\brief Improve resiliency against losses of whole frames */
  109. #define AOM_ERROR_RESILIENT_DEFAULT 0x1
  110. /*!\brief The frame partitions are independently decodable by the bool decoder,
  111. * meaning that partitions can be decoded even though earlier partitions have
  112. * been lost. Note that intra prediction is still done over the partition
  113. * boundary. */
  114. #define AOM_ERROR_RESILIENT_PARTITIONS 0x2
  115. /*!\brief Encoder output packet variants
  116. *
  117. * This enumeration lists the different kinds of data packets that can be
  118. * returned by calls to aom_codec_get_cx_data(). Algorithms \ref MAY
  119. * extend this list to provide additional functionality.
  120. */
  121. enum aom_codec_cx_pkt_kind {
  122. AOM_CODEC_CX_FRAME_PKT, /**< Compressed video frame */
  123. AOM_CODEC_STATS_PKT, /**< Two-pass statistics for this frame */
  124. AOM_CODEC_FPMB_STATS_PKT, /**< first pass mb statistics for this frame */
  125. AOM_CODEC_PSNR_PKT, /**< PSNR statistics for this frame */
  126. AOM_CODEC_CUSTOM_PKT = 256 /**< Algorithm extensions */
  127. };
  128. /*!\brief Encoder output packet
  129. *
  130. * This structure contains the different kinds of output data the encoder
  131. * may produce while compressing a frame.
  132. */
  133. typedef struct aom_codec_cx_pkt {
  134. enum aom_codec_cx_pkt_kind kind; /**< packet variant */
  135. union {
  136. struct {
  137. void *buf; /**< compressed data buffer */
  138. size_t sz; /**< length of compressed data */
  139. /*!\brief time stamp to show frame (in timebase units) */
  140. aom_codec_pts_t pts;
  141. /*!\brief duration to show frame (in timebase units) */
  142. unsigned long duration;
  143. aom_codec_frame_flags_t flags; /**< flags for this frame */
  144. /*!\brief the partition id defines the decoding order of the partitions.
  145. * Only applicable when "output partition" mode is enabled. First
  146. * partition has id 0.*/
  147. int partition_id;
  148. /*!\brief size of the visible frame in this packet */
  149. size_t vis_frame_size;
  150. } frame; /**< data for compressed frame packet */
  151. aom_fixed_buf_t twopass_stats; /**< data for two-pass packet */
  152. aom_fixed_buf_t firstpass_mb_stats; /**< first pass mb packet */
  153. struct aom_psnr_pkt {
  154. unsigned int samples[4]; /**< Number of samples, total/y/u/v */
  155. uint64_t sse[4]; /**< sum squared error, total/y/u/v */
  156. double psnr[4]; /**< PSNR, total/y/u/v */
  157. } psnr; /**< data for PSNR packet */
  158. aom_fixed_buf_t raw; /**< data for arbitrary packets */
  159. /* This packet size is fixed to allow codecs to extend this
  160. * interface without having to manage storage for raw packets,
  161. * i.e., if it's smaller than 128 bytes, you can store in the
  162. * packet list directly.
  163. */
  164. char pad[128 - sizeof(enum aom_codec_cx_pkt_kind)]; /**< fixed sz */
  165. } data; /**< packet data */
  166. } aom_codec_cx_pkt_t; /**< alias for struct aom_codec_cx_pkt */
  167. /*!\brief Rational Number
  168. *
  169. * This structure holds a fractional value.
  170. */
  171. typedef struct aom_rational {
  172. int num; /**< fraction numerator */
  173. int den; /**< fraction denominator */
  174. } aom_rational_t; /**< alias for struct aom_rational */
  175. /*!\brief Multi-pass Encoding Pass */
  176. enum aom_enc_pass {
  177. AOM_RC_ONE_PASS, /**< Single pass mode */
  178. AOM_RC_FIRST_PASS, /**< First pass of multi-pass mode */
  179. AOM_RC_LAST_PASS /**< Final pass of multi-pass mode */
  180. };
  181. /*!\brief Rate control mode */
  182. enum aom_rc_mode {
  183. AOM_VBR, /**< Variable Bit Rate (VBR) mode */
  184. AOM_CBR, /**< Constant Bit Rate (CBR) mode */
  185. AOM_CQ, /**< Constrained Quality (CQ) mode */
  186. AOM_Q, /**< Constant Quality (Q) mode */
  187. };
  188. /*!\brief Keyframe placement mode.
  189. *
  190. * This enumeration determines whether keyframes are placed automatically by
  191. * the encoder or whether this behavior is disabled. Older releases of this
  192. * SDK were implemented such that AOM_KF_FIXED meant keyframes were disabled.
  193. * This name is confusing for this behavior, so the new symbols to be used
  194. * are AOM_KF_AUTO and AOM_KF_DISABLED.
  195. */
  196. enum aom_kf_mode {
  197. AOM_KF_FIXED, /**< deprecated, implies AOM_KF_DISABLED */
  198. AOM_KF_AUTO, /**< Encoder determines optimal placement automatically */
  199. AOM_KF_DISABLED = 0 /**< Encoder does not place keyframes. */
  200. };
  201. /*!\brief Encoded Frame Flags
  202. *
  203. * This type indicates a bitfield to be passed to aom_codec_encode(), defining
  204. * per-frame boolean values. By convention, bits common to all codecs will be
  205. * named AOM_EFLAG_*, and bits specific to an algorithm will be named
  206. * /algo/_eflag_*. The lower order 16 bits are reserved for common use.
  207. */
  208. typedef long aom_enc_frame_flags_t;
  209. #define AOM_EFLAG_FORCE_KF (1 << 0) /**< Force this frame to be a keyframe */
  210. /*!\brief Encoder configuration structure
  211. *
  212. * This structure contains the encoder settings that have common representations
  213. * across all codecs. This doesn't imply that all codecs support all features,
  214. * however.
  215. */
  216. typedef struct aom_codec_enc_cfg {
  217. /*
  218. * generic settings (g)
  219. */
  220. /*!\brief Algorithm specific "usage" value
  221. *
  222. * Algorithms may define multiple values for usage, which may convey the
  223. * intent of how the application intends to use the stream. If this value
  224. * is non-zero, consult the documentation for the codec to determine its
  225. * meaning.
  226. */
  227. unsigned int g_usage;
  228. /*!\brief Maximum number of threads to use
  229. *
  230. * For multi-threaded implementations, use no more than this number of
  231. * threads. The codec may use fewer threads than allowed. The value
  232. * 0 is equivalent to the value 1.
  233. */
  234. unsigned int g_threads;
  235. /*!\brief Bitstream profile to use
  236. *
  237. * Some codecs support a notion of multiple bitstream profiles. Typically
  238. * this maps to a set of features that are turned on or off. Often the
  239. * profile to use is determined by the features of the intended decoder.
  240. * Consult the documentation for the codec to determine the valid values
  241. * for this parameter, or set to zero for a sane default.
  242. */
  243. unsigned int g_profile; /**< profile of bitstream to use */
  244. /*!\brief Width of the frame
  245. *
  246. * This value identifies the presentation resolution of the frame,
  247. * in pixels. Note that the frames passed as input to the encoder must
  248. * have this resolution. Frames will be presented by the decoder in this
  249. * resolution, independent of any spatial resampling the encoder may do.
  250. */
  251. unsigned int g_w;
  252. /*!\brief Height of the frame
  253. *
  254. * This value identifies the presentation resolution of the frame,
  255. * in pixels. Note that the frames passed as input to the encoder must
  256. * have this resolution. Frames will be presented by the decoder in this
  257. * resolution, independent of any spatial resampling the encoder may do.
  258. */
  259. unsigned int g_h;
  260. /*!\brief Max number of frames to encode
  261. *
  262. */
  263. unsigned int g_limit;
  264. /*!\brief Forced maximum width of the frame
  265. *
  266. * If this value is non-zero then it is used to force the maximum frame
  267. * width written in write_sequence_header().
  268. */
  269. unsigned int g_forced_max_frame_width;
  270. /*!\brief Forced maximum height of the frame
  271. *
  272. * If this value is non-zero then it is used to force the maximum frame
  273. * height written in write_sequence_header().
  274. */
  275. unsigned int g_forced_max_frame_height;
  276. /*!\brief Bit-depth of the codec
  277. *
  278. * This value identifies the bit_depth of the codec,
  279. * Only certain bit-depths are supported as identified in the
  280. * aom_bit_depth_t enum.
  281. */
  282. aom_bit_depth_t g_bit_depth;
  283. /*!\brief Bit-depth of the input frames
  284. *
  285. * This value identifies the bit_depth of the input frames in bits.
  286. * Note that the frames passed as input to the encoder must have
  287. * this bit-depth.
  288. */
  289. unsigned int g_input_bit_depth;
  290. /*!\brief Stream timebase units
  291. *
  292. * Indicates the smallest interval of time, in seconds, used by the stream.
  293. * For fixed frame rate material, or variable frame rate material where
  294. * frames are timed at a multiple of a given clock (ex: video capture),
  295. * the \ref RECOMMENDED method is to set the timebase to the reciprocal
  296. * of the frame rate (ex: 1001/30000 for 29.970 Hz NTSC). This allows the
  297. * pts to correspond to the frame number, which can be handy. For
  298. * re-encoding video from containers with absolute time timestamps, the
  299. * \ref RECOMMENDED method is to set the timebase to that of the parent
  300. * container or multimedia framework (ex: 1/1000 for ms, as in FLV).
  301. */
  302. struct aom_rational g_timebase;
  303. /*!\brief Enable error resilient modes.
  304. *
  305. * The error resilient bitfield indicates to the encoder which features
  306. * it should enable to take measures for streaming over lossy or noisy
  307. * links.
  308. */
  309. aom_codec_er_flags_t g_error_resilient;
  310. /*!\brief Multi-pass Encoding Mode
  311. *
  312. * This value should be set to the current phase for multi-pass encoding.
  313. * For single pass, set to #AOM_RC_ONE_PASS.
  314. */
  315. enum aom_enc_pass g_pass;
  316. /*!\brief Allow lagged encoding
  317. *
  318. * If set, this value allows the encoder to consume a number of input
  319. * frames before producing output frames. This allows the encoder to
  320. * base decisions for the current frame on future frames. This does
  321. * increase the latency of the encoding pipeline, so it is not appropriate
  322. * in all situations (ex: realtime encoding).
  323. *
  324. * Note that this is a maximum value -- the encoder may produce frames
  325. * sooner than the given limit. Set this value to 0 to disable this
  326. * feature.
  327. */
  328. unsigned int g_lag_in_frames;
  329. /*
  330. * rate control settings (rc)
  331. */
  332. /*!\brief Temporal resampling configuration, if supported by the codec.
  333. *
  334. * Temporal resampling allows the codec to "drop" frames as a strategy to
  335. * meet its target data rate. This can cause temporal discontinuities in
  336. * the encoded video, which may appear as stuttering during playback. This
  337. * trade-off is often acceptable, but for many applications is not. It can
  338. * be disabled in these cases.
  339. *
  340. * Note that not all codecs support this feature. All aom AVx codecs do.
  341. * For other codecs, consult the documentation for that algorithm.
  342. *
  343. * This threshold is described as a percentage of the target data buffer.
  344. * When the data buffer falls below this percentage of fullness, a
  345. * dropped frame is indicated. Set the threshold to zero (0) to disable
  346. * this feature.
  347. */
  348. unsigned int rc_dropframe_thresh;
  349. /*!\brief Mode for spatial resampling, if supported by the codec.
  350. *
  351. * Spatial resampling allows the codec to compress a lower resolution
  352. * version of the frame, which is then upscaled by the decoder to the
  353. * correct presentation resolution. This increases visual quality at
  354. * low data rates, at the expense of CPU time on the encoder/decoder.
  355. */
  356. unsigned int rc_resize_mode;
  357. /*!\brief Frame resize denominator.
  358. *
  359. * The denominator for resize to use, assuming 8 as the numerator.
  360. *
  361. * Valid denominators are 8 - 16 for now.
  362. */
  363. unsigned int rc_resize_denominator;
  364. /*!\brief Keyframe resize denominator.
  365. *
  366. * The denominator for resize to use, assuming 8 as the numerator.
  367. *
  368. * Valid denominators are 8 - 16 for now.
  369. */
  370. unsigned int rc_resize_kf_denominator;
  371. /*!\brief Frame super-resolution scaling mode.
  372. *
  373. * Similar to spatial resampling, frame super-resolution integrates
  374. * upscaling after the encode/decode process. Taking control of upscaling and
  375. * using restoration filters should allow it to outperform normal resizing.
  376. *
  377. * Mode 0 is SUPERRES_NONE, mode 1 is SUPERRES_FIXED, mode 2 is
  378. * SUPERRES_RANDOM and mode 3 is SUPERRES_QTHRESH.
  379. */
  380. unsigned int rc_superres_mode;
  381. /*!\brief Frame super-resolution denominator.
  382. *
  383. * The denominator for superres to use. If fixed it will only change if the
  384. * cumulative scale change over resizing and superres is greater than 1/2;
  385. * this forces superres to reduce scaling.
  386. *
  387. * Valid denominators are 8 to 16.
  388. *
  389. * Used only by SUPERRES_FIXED.
  390. */
  391. unsigned int rc_superres_denominator;
  392. /*!\brief Keyframe super-resolution denominator.
  393. *
  394. * The denominator for superres to use. If fixed it will only change if the
  395. * cumulative scale change over resizing and superres is greater than 1/2;
  396. * this forces superres to reduce scaling.
  397. *
  398. * Valid denominators are 8 - 16 for now.
  399. */
  400. unsigned int rc_superres_kf_denominator;
  401. /*!\brief Frame super-resolution q threshold.
  402. *
  403. * The q level threshold after which superres is used.
  404. * Valid values are 1 to 63.
  405. *
  406. * Used only by SUPERRES_QTHRESH
  407. */
  408. unsigned int rc_superres_qthresh;
  409. /*!\brief Keyframe super-resolution q threshold.
  410. *
  411. * The q level threshold after which superres is used for key frames.
  412. * Valid values are 1 to 63.
  413. *
  414. * Used only by SUPERRES_QTHRESH
  415. */
  416. unsigned int rc_superres_kf_qthresh;
  417. /*!\brief Rate control algorithm to use.
  418. *
  419. * Indicates whether the end usage of this stream is to be streamed over
  420. * a bandwidth constrained link, indicating that Constant Bit Rate (CBR)
  421. * mode should be used, or whether it will be played back on a high
  422. * bandwidth link, as from a local disk, where higher variations in
  423. * bitrate are acceptable.
  424. */
  425. enum aom_rc_mode rc_end_usage;
  426. /*!\brief Two-pass stats buffer.
  427. *
  428. * A buffer containing all of the stats packets produced in the first
  429. * pass, concatenated.
  430. */
  431. aom_fixed_buf_t rc_twopass_stats_in;
  432. /*!\brief first pass mb stats buffer.
  433. *
  434. * A buffer containing all of the first pass mb stats packets produced
  435. * in the first pass, concatenated.
  436. */
  437. aom_fixed_buf_t rc_firstpass_mb_stats_in;
  438. /*!\brief Target data rate
  439. *
  440. * Target bandwidth to use for this stream, in kilobits per second.
  441. */
  442. unsigned int rc_target_bitrate;
  443. /*
  444. * quantizer settings
  445. */
  446. /*!\brief Minimum (Best Quality) Quantizer
  447. *
  448. * The quantizer is the most direct control over the quality of the
  449. * encoded image. The range of valid values for the quantizer is codec
  450. * specific. Consult the documentation for the codec to determine the
  451. * values to use. To determine the range programmatically, call
  452. * aom_codec_enc_config_default() with a usage value of 0.
  453. */
  454. unsigned int rc_min_quantizer;
  455. /*!\brief Maximum (Worst Quality) Quantizer
  456. *
  457. * The quantizer is the most direct control over the quality of the
  458. * encoded image. The range of valid values for the quantizer is codec
  459. * specific. Consult the documentation for the codec to determine the
  460. * values to use. To determine the range programmatically, call
  461. * aom_codec_enc_config_default() with a usage value of 0.
  462. */
  463. unsigned int rc_max_quantizer;
  464. /*
  465. * bitrate tolerance
  466. */
  467. /*!\brief Rate control adaptation undershoot control
  468. *
  469. * This value, expressed as a percentage of the target bitrate,
  470. * controls the maximum allowed adaptation speed of the codec.
  471. * This factor controls the maximum amount of bits that can
  472. * be subtracted from the target bitrate in order to compensate
  473. * for prior overshoot.
  474. *
  475. * Valid values in the range 0-1000.
  476. */
  477. unsigned int rc_undershoot_pct;
  478. /*!\brief Rate control adaptation overshoot control
  479. *
  480. * This value, expressed as a percentage of the target bitrate,
  481. * controls the maximum allowed adaptation speed of the codec.
  482. * This factor controls the maximum amount of bits that can
  483. * be added to the target bitrate in order to compensate for
  484. * prior undershoot.
  485. *
  486. * Valid values in the range 0-1000.
  487. */
  488. unsigned int rc_overshoot_pct;
  489. /*
  490. * decoder buffer model parameters
  491. */
  492. /*!\brief Decoder Buffer Size
  493. *
  494. * This value indicates the amount of data that may be buffered by the
  495. * decoding application. Note that this value is expressed in units of
  496. * time (milliseconds). For example, a value of 5000 indicates that the
  497. * client will buffer (at least) 5000ms worth of encoded data. Use the
  498. * target bitrate (#rc_target_bitrate) to convert to bits/bytes, if
  499. * necessary.
  500. */
  501. unsigned int rc_buf_sz;
  502. /*!\brief Decoder Buffer Initial Size
  503. *
  504. * This value indicates the amount of data that will be buffered by the
  505. * decoding application prior to beginning playback. This value is
  506. * expressed in units of time (milliseconds). Use the target bitrate
  507. * (#rc_target_bitrate) to convert to bits/bytes, if necessary.
  508. */
  509. unsigned int rc_buf_initial_sz;
  510. /*!\brief Decoder Buffer Optimal Size
  511. *
  512. * This value indicates the amount of data that the encoder should try
  513. * to maintain in the decoder's buffer. This value is expressed in units
  514. * of time (milliseconds). Use the target bitrate (#rc_target_bitrate)
  515. * to convert to bits/bytes, if necessary.
  516. */
  517. unsigned int rc_buf_optimal_sz;
  518. /*
  519. * 2 pass rate control parameters
  520. */
  521. /*!\brief Two-pass mode CBR/VBR bias
  522. *
  523. * Bias, expressed on a scale of 0 to 100, for determining target size
  524. * for the current frame. The value 0 indicates the optimal CBR mode
  525. * value should be used. The value 100 indicates the optimal VBR mode
  526. * value should be used. Values in between indicate which way the
  527. * encoder should "lean."
  528. */
  529. unsigned int rc_2pass_vbr_bias_pct;
  530. /*!\brief Two-pass mode per-GOP minimum bitrate
  531. *
  532. * This value, expressed as a percentage of the target bitrate, indicates
  533. * the minimum bitrate to be used for a single GOP (aka "section")
  534. */
  535. unsigned int rc_2pass_vbr_minsection_pct;
  536. /*!\brief Two-pass mode per-GOP maximum bitrate
  537. *
  538. * This value, expressed as a percentage of the target bitrate, indicates
  539. * the maximum bitrate to be used for a single GOP (aka "section")
  540. */
  541. unsigned int rc_2pass_vbr_maxsection_pct;
  542. /*
  543. * keyframing settings (kf)
  544. */
  545. /*!\brief Option to enable forward reference key frame
  546. *
  547. */
  548. int fwd_kf_enabled;
  549. /*!\brief Keyframe placement mode
  550. *
  551. * This value indicates whether the encoder should place keyframes at a
  552. * fixed interval, or determine the optimal placement automatically
  553. * (as governed by the #kf_min_dist and #kf_max_dist parameters)
  554. */
  555. enum aom_kf_mode kf_mode;
  556. /*!\brief Keyframe minimum interval
  557. *
  558. * This value, expressed as a number of frames, prevents the encoder from
  559. * placing a keyframe nearer than kf_min_dist to the previous keyframe. At
  560. * least kf_min_dist frames non-keyframes will be coded before the next
  561. * keyframe. Set kf_min_dist equal to kf_max_dist for a fixed interval.
  562. */
  563. unsigned int kf_min_dist;
  564. /*!\brief Keyframe maximum interval
  565. *
  566. * This value, expressed as a number of frames, forces the encoder to code
  567. * a keyframe if one has not been coded in the last kf_max_dist frames.
  568. * A value of 0 implies all frames will be keyframes. Set kf_min_dist
  569. * equal to kf_max_dist for a fixed interval.
  570. */
  571. unsigned int kf_max_dist;
  572. /*!\brief sframe interval
  573. *
  574. * This value, expressed as a number of frames, forces the encoder to code
  575. * an S-Frame every sframe_dist frames.
  576. */
  577. unsigned int sframe_dist;
  578. /*!\brief sframe insertion mode
  579. *
  580. * This value must be set to 1 or 2, and tells the encoder how to insert
  581. * S-Frames. It will only have an effect if sframe_dist != 0.
  582. *
  583. * If altref is enabled:
  584. * - if sframe_mode == 1, the considered frame will be made into an
  585. * S-Frame only if it is an altref frame
  586. * - if sframe_mode == 2, the next altref frame will be made into an
  587. * S-Frame.
  588. *
  589. * Otherwise: the considered frame will be made into an S-Frame.
  590. */
  591. unsigned int sframe_mode;
  592. /*!\brief Tile coding mode
  593. *
  594. * This value indicates the tile coding mode.
  595. * A value of 0 implies a normal non-large-scale tile coding. A value of 1
  596. * implies a large-scale tile coding.
  597. */
  598. unsigned int large_scale_tile;
  599. /*!\brief Monochrome mode
  600. *
  601. * If this is nonzero, the encoder will generate a monochrome stream
  602. * with no chroma planes.
  603. */
  604. unsigned int monochrome;
  605. /*!\brief full_still_picture_hdr
  606. *
  607. * If this is nonzero, the encoder will generate a full header even for
  608. * still picture encoding. if zero, a reduced header is used for still
  609. * picture. This flag has no effect when a regular video with more than
  610. * a single frame is encoded.
  611. */
  612. unsigned int full_still_picture_hdr;
  613. /*!\brief Bitstream syntax mode
  614. *
  615. * This value indicates the bitstream syntax mode.
  616. * A value of 0 indicates bitstream is saved as Section 5 bitstream. A value
  617. * of 1 indicates the bitstream is saved in Annex-B format
  618. */
  619. unsigned int save_as_annexb;
  620. /*!\brief Number of explicit tile widths specified
  621. *
  622. * This value indicates the number of tile widths specified
  623. * A value of 0 implies no tile widths are specified.
  624. * Tile widths are given in the array tile_widths[]
  625. */
  626. int tile_width_count;
  627. /*!\brief Number of explicit tile heights specified
  628. *
  629. * This value indicates the number of tile heights specified
  630. * A value of 0 implies no tile heights are specified.
  631. * Tile heights are given in the array tile_heights[]
  632. */
  633. int tile_height_count;
  634. /*!\brief Maximum number of tile widths in tile widths array
  635. *
  636. * This define gives the maximum number of elements in the tile_widths array.
  637. */
  638. #define MAX_TILE_WIDTHS 64 // maximum tile width array length
  639. /*!\brief Array of specified tile widths
  640. *
  641. * This array specifies tile widths (and may be empty)
  642. * The number of widths specified is given by tile_width_count
  643. */
  644. int tile_widths[MAX_TILE_WIDTHS];
  645. /*!\brief Maximum number of tile heights in tile heights array.
  646. *
  647. * This define gives the maximum number of elements in the tile_heights array.
  648. */
  649. #define MAX_TILE_HEIGHTS 64 // maximum tile height array length
  650. /*!\brief Array of specified tile heights
  651. *
  652. * This array specifies tile heights (and may be empty)
  653. * The number of heights specified is given by tile_height_count
  654. */
  655. int tile_heights[MAX_TILE_HEIGHTS];
  656. /*!\brief Options defined per config file
  657. *
  658. */
  659. cfg_options_t cfg;
  660. } aom_codec_enc_cfg_t; /**< alias for struct aom_codec_enc_cfg */
  661. /*!\brief Initialize an encoder instance
  662. *
  663. * Initializes a encoder context using the given interface. Applications
  664. * should call the aom_codec_enc_init convenience macro instead of this
  665. * function directly, to ensure that the ABI version number parameter
  666. * is properly initialized.
  667. *
  668. * If the library was configured with --disable-multithread, this call
  669. * is not thread safe and should be guarded with a lock if being used
  670. * in a multithreaded context.
  671. *
  672. * \param[in] ctx Pointer to this instance's context.
  673. * \param[in] iface Pointer to the algorithm interface to use.
  674. * \param[in] cfg Configuration to use, if known.
  675. * \param[in] flags Bitfield of AOM_CODEC_USE_* flags
  676. * \param[in] ver ABI version number. Must be set to
  677. * AOM_ENCODER_ABI_VERSION
  678. * \retval #AOM_CODEC_OK
  679. * The decoder algorithm initialized.
  680. * \retval #AOM_CODEC_MEM_ERROR
  681. * Memory allocation failed.
  682. */
  683. aom_codec_err_t aom_codec_enc_init_ver(aom_codec_ctx_t *ctx,
  684. aom_codec_iface_t *iface,
  685. const aom_codec_enc_cfg_t *cfg,
  686. aom_codec_flags_t flags, int ver);
  687. /*!\brief Convenience macro for aom_codec_enc_init_ver()
  688. *
  689. * Ensures the ABI version parameter is properly set.
  690. */
  691. #define aom_codec_enc_init(ctx, iface, cfg, flags) \
  692. aom_codec_enc_init_ver(ctx, iface, cfg, flags, AOM_ENCODER_ABI_VERSION)
  693. /*!\brief Initialize multi-encoder instance
  694. *
  695. * Initializes multi-encoder context using the given interface.
  696. * Applications should call the aom_codec_enc_init_multi convenience macro
  697. * instead of this function directly, to ensure that the ABI version number
  698. * parameter is properly initialized.
  699. *
  700. * \param[in] ctx Pointer to this instance's context.
  701. * \param[in] iface Pointer to the algorithm interface to use.
  702. * \param[in] cfg Configuration to use, if known.
  703. * \param[in] num_enc Total number of encoders.
  704. * \param[in] flags Bitfield of AOM_CODEC_USE_* flags
  705. * \param[in] dsf Pointer to down-sampling factors.
  706. * \param[in] ver ABI version number. Must be set to
  707. * AOM_ENCODER_ABI_VERSION
  708. * \retval #AOM_CODEC_OK
  709. * The decoder algorithm initialized.
  710. * \retval #AOM_CODEC_MEM_ERROR
  711. * Memory allocation failed.
  712. */
  713. aom_codec_err_t aom_codec_enc_init_multi_ver(
  714. aom_codec_ctx_t *ctx, aom_codec_iface_t *iface, aom_codec_enc_cfg_t *cfg,
  715. int num_enc, aom_codec_flags_t flags, aom_rational_t *dsf, int ver);
  716. /*!\brief Convenience macro for aom_codec_enc_init_multi_ver()
  717. *
  718. * Ensures the ABI version parameter is properly set.
  719. */
  720. #define aom_codec_enc_init_multi(ctx, iface, cfg, num_enc, flags, dsf) \
  721. aom_codec_enc_init_multi_ver(ctx, iface, cfg, num_enc, flags, dsf, \
  722. AOM_ENCODER_ABI_VERSION)
  723. /*!\brief Get a default configuration
  724. *
  725. * Initializes a encoder configuration structure with default values. Supports
  726. * the notion of "usages" so that an algorithm may offer different default
  727. * settings depending on the user's intended goal. This function \ref SHOULD
  728. * be called by all applications to initialize the configuration structure
  729. * before specializing the configuration with application specific values.
  730. *
  731. * \param[in] iface Pointer to the algorithm interface to use.
  732. * \param[out] cfg Configuration buffer to populate.
  733. * \param[in] reserved Must set to 0.
  734. *
  735. * \retval #AOM_CODEC_OK
  736. * The configuration was populated.
  737. * \retval #AOM_CODEC_INCAPABLE
  738. * Interface is not an encoder interface.
  739. * \retval #AOM_CODEC_INVALID_PARAM
  740. * A parameter was NULL, or the usage value was not recognized.
  741. */
  742. aom_codec_err_t aom_codec_enc_config_default(aom_codec_iface_t *iface,
  743. aom_codec_enc_cfg_t *cfg,
  744. unsigned int reserved);
  745. /*!\brief Set or change configuration
  746. *
  747. * Reconfigures an encoder instance according to the given configuration.
  748. *
  749. * \param[in] ctx Pointer to this instance's context
  750. * \param[in] cfg Configuration buffer to use
  751. *
  752. * \retval #AOM_CODEC_OK
  753. * The configuration was populated.
  754. * \retval #AOM_CODEC_INCAPABLE
  755. * Interface is not an encoder interface.
  756. * \retval #AOM_CODEC_INVALID_PARAM
  757. * A parameter was NULL, or the usage value was not recognized.
  758. */
  759. aom_codec_err_t aom_codec_enc_config_set(aom_codec_ctx_t *ctx,
  760. const aom_codec_enc_cfg_t *cfg);
  761. /*!\brief Get global stream headers
  762. *
  763. * Retrieves a stream level global header packet, if supported by the codec.
  764. *
  765. * \param[in] ctx Pointer to this instance's context
  766. *
  767. * \retval NULL
  768. * Encoder does not support global header
  769. * \retval Non-NULL
  770. * Pointer to buffer containing global header packet
  771. */
  772. aom_fixed_buf_t *aom_codec_get_global_headers(aom_codec_ctx_t *ctx);
  773. /*!\brief Encode a frame
  774. *
  775. * Encodes a video frame at the given "presentation time." The presentation
  776. * time stamp (PTS) \ref MUST be strictly increasing.
  777. *
  778. * When the last frame has been passed to the encoder, this function should
  779. * continue to be called, with the img parameter set to NULL. This will
  780. * signal the end-of-stream condition to the encoder and allow it to encode
  781. * any held buffers. Encoding is complete when aom_codec_encode() is called
  782. * and aom_codec_get_cx_data() returns no data.
  783. *
  784. * \param[in] ctx Pointer to this instance's context
  785. * \param[in] img Image data to encode, NULL to flush.
  786. * \param[in] pts Presentation time stamp, in timebase units.
  787. * \param[in] duration Duration to show frame, in timebase units.
  788. * \param[in] flags Flags to use for encoding this frame.
  789. *
  790. * \retval #AOM_CODEC_OK
  791. * The configuration was populated.
  792. * \retval #AOM_CODEC_INCAPABLE
  793. * Interface is not an encoder interface.
  794. * \retval #AOM_CODEC_INVALID_PARAM
  795. * A parameter was NULL, the image format is unsupported, etc.
  796. */
  797. aom_codec_err_t aom_codec_encode(aom_codec_ctx_t *ctx, const aom_image_t *img,
  798. aom_codec_pts_t pts, unsigned long duration,
  799. aom_enc_frame_flags_t flags);
  800. /*!\brief Set compressed data output buffer
  801. *
  802. * Sets the buffer that the codec should output the compressed data
  803. * into. This call effectively sets the buffer pointer returned in the
  804. * next AOM_CODEC_CX_FRAME_PKT packet. Subsequent packets will be
  805. * appended into this buffer. The buffer is preserved across frames,
  806. * so applications must periodically call this function after flushing
  807. * the accumulated compressed data to disk or to the network to reset
  808. * the pointer to the buffer's head.
  809. *
  810. * `pad_before` bytes will be skipped before writing the compressed
  811. * data, and `pad_after` bytes will be appended to the packet. The size
  812. * of the packet will be the sum of the size of the actual compressed
  813. * data, pad_before, and pad_after. The padding bytes will be preserved
  814. * (not overwritten).
  815. *
  816. * Note that calling this function does not guarantee that the returned
  817. * compressed data will be placed into the specified buffer. In the
  818. * event that the encoded data will not fit into the buffer provided,
  819. * the returned packet \ref MAY point to an internal buffer, as it would
  820. * if this call were never used. In this event, the output packet will
  821. * NOT have any padding, and the application must free space and copy it
  822. * to the proper place. This is of particular note in configurations
  823. * that may output multiple packets for a single encoded frame (e.g., lagged
  824. * encoding) or if the application does not reset the buffer periodically.
  825. *
  826. * Applications may restore the default behavior of the codec providing
  827. * the compressed data buffer by calling this function with a NULL
  828. * buffer.
  829. *
  830. * Applications \ref MUSTNOT call this function during iteration of
  831. * aom_codec_get_cx_data().
  832. *
  833. * \param[in] ctx Pointer to this instance's context
  834. * \param[in] buf Buffer to store compressed data into
  835. * \param[in] pad_before Bytes to skip before writing compressed data
  836. * \param[in] pad_after Bytes to skip after writing compressed data
  837. *
  838. * \retval #AOM_CODEC_OK
  839. * The buffer was set successfully.
  840. * \retval #AOM_CODEC_INVALID_PARAM
  841. * A parameter was NULL, the image format is unsupported, etc.
  842. */
  843. aom_codec_err_t aom_codec_set_cx_data_buf(aom_codec_ctx_t *ctx,
  844. const aom_fixed_buf_t *buf,
  845. unsigned int pad_before,
  846. unsigned int pad_after);
  847. /*!\brief Encoded data iterator
  848. *
  849. * Iterates over a list of data packets to be passed from the encoder to the
  850. * application. The different kinds of packets available are enumerated in
  851. * #aom_codec_cx_pkt_kind.
  852. *
  853. * #AOM_CODEC_CX_FRAME_PKT packets should be passed to the application's
  854. * muxer. Multiple compressed frames may be in the list.
  855. * #AOM_CODEC_STATS_PKT packets should be appended to a global buffer.
  856. *
  857. * The application \ref MUST silently ignore any packet kinds that it does
  858. * not recognize or support.
  859. *
  860. * The data buffers returned from this function are only guaranteed to be
  861. * valid until the application makes another call to any aom_codec_* function.
  862. *
  863. * \param[in] ctx Pointer to this instance's context
  864. * \param[in,out] iter Iterator storage, initialized to NULL
  865. *
  866. * \return Returns a pointer to an output data packet (compressed frame data,
  867. * two-pass statistics, etc.) or NULL to signal end-of-list.
  868. *
  869. */
  870. const aom_codec_cx_pkt_t *aom_codec_get_cx_data(aom_codec_ctx_t *ctx,
  871. aom_codec_iter_t *iter);
  872. /*!\brief Get Preview Frame
  873. *
  874. * Returns an image that can be used as a preview. Shows the image as it would
  875. * exist at the decompressor. The application \ref MUST NOT write into this
  876. * image buffer.
  877. *
  878. * \param[in] ctx Pointer to this instance's context
  879. *
  880. * \return Returns a pointer to a preview image, or NULL if no image is
  881. * available.
  882. *
  883. */
  884. const aom_image_t *aom_codec_get_preview_frame(aom_codec_ctx_t *ctx);
  885. /*!@} - end defgroup encoder*/
  886. #ifdef __cplusplus
  887. }
  888. #endif
  889. #endif // AOM_AOM_ENCODER_H_