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