hadamard: Add 4x4 test.
[aom.git] / aom / aom_encoder.h
blobc324c56263ac66b3898f660419ad03eff48e2c37
1 /*
2 * Copyright (c) 2016, Alliance for Open Media. All rights reserved
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.
11 #ifndef AOM_AOM_AOM_ENCODER_H_
12 #define AOM_AOM_AOM_ENCODER_H_
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 * @{
22 /*!\file
23 * \brief Describes the encoder algorithm interface to applications.
25 * This file describes the interface between an application and a
26 * video encoder algorithm.
29 #ifdef __cplusplus
30 extern "C" {
31 #endif
33 #include "aom/aom_codec.h"
34 #include "aom/aom_external_partition.h"
36 /*!\brief Current ABI version number
38 * \internal
39 * If this file is altered in any way that changes the ABI, this value
40 * must be bumped. Examples include, but are not limited to, changing
41 * types, removing or reassigning enums, adding/removing/rearranging
42 * fields to structures
44 #define AOM_ENCODER_ABI_VERSION \
45 (10 + AOM_CODEC_ABI_VERSION + AOM_EXT_PART_ABI_VERSION) /**<\hideinitializer*/
47 /*! \brief Encoder capabilities bitfield
49 * Each encoder advertises the capabilities it supports as part of its
50 * ::aom_codec_iface_t interface structure. Capabilities are extra
51 * interfaces or functionality, and are not required to be supported
52 * by an encoder.
54 * The available flags are specified by AOM_CODEC_CAP_* defines.
56 #define AOM_CODEC_CAP_PSNR 0x10000 /**< Can issue PSNR packets */
58 /*! Can support input images at greater than 8 bitdepth.
60 #define AOM_CODEC_CAP_HIGHBITDEPTH 0x40000
62 /*! \brief Initialization-time Feature Enabling
64 * Certain codec features must be known at initialization time, to allow
65 * for proper memory allocation.
67 * The available flags are specified by AOM_CODEC_USE_* defines.
69 #define AOM_CODEC_USE_PSNR 0x10000 /**< Calculate PSNR on each frame */
70 /*!\brief Make the encoder output one partition at a time. */
71 #define AOM_CODEC_USE_HIGHBITDEPTH 0x40000 /**< Use high bitdepth */
73 /*!\brief Generic fixed size buffer structure
75 * This structure is able to hold a reference to any fixed size buffer.
77 typedef struct aom_fixed_buf {
78 void *buf; /**< Pointer to the data. Does NOT own the data! */
79 size_t sz; /**< Length of the buffer, in chars */
80 } aom_fixed_buf_t; /**< alias for struct aom_fixed_buf */
82 /*!\brief Error Resilient flags
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.
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
92 /*!\brief Encoder output packet variants
94 * This enumeration lists the different kinds of data packets that can be
95 * returned by calls to aom_codec_get_cx_data(). Algorithms \ref MAY
96 * extend this list to provide additional functionality.
98 enum aom_codec_cx_pkt_kind {
99 AOM_CODEC_CX_FRAME_PKT, /**< Compressed video frame */
100 AOM_CODEC_STATS_PKT, /**< Two-pass statistics for this frame */
101 AOM_CODEC_FPMB_STATS_PKT, /**< first pass mb statistics for this frame */
102 AOM_CODEC_PSNR_PKT, /**< PSNR statistics for this frame */
103 AOM_CODEC_CUSTOM_PKT = 256 /**< Algorithm extensions */
106 /*!\brief Encoder output packet
108 * This structure contains the different kinds of output data the encoder
109 * may produce while compressing a frame.
111 typedef struct aom_codec_cx_pkt {
112 enum aom_codec_cx_pkt_kind kind; /**< packet variant */
113 union {
114 struct {
115 void *buf; /**< compressed data buffer */
116 size_t sz; /**< length of compressed data */
117 /*!\brief time stamp to show frame (in timebase units) */
118 aom_codec_pts_t pts;
119 /*!\brief duration to show frame (in timebase units) */
120 unsigned long duration;
121 aom_codec_frame_flags_t flags; /**< flags for this frame */
122 /*!\brief the partition id defines the decoding order of the partitions.
123 * Only applicable when "output partition" mode is enabled. First
124 * partition has id 0.*/
125 int partition_id;
126 /*!\brief size of the visible frame in this packet */
127 size_t vis_frame_size;
128 } frame; /**< data for compressed frame packet */
129 aom_fixed_buf_t twopass_stats; /**< data for two-pass packet */
130 aom_fixed_buf_t firstpass_mb_stats; /**< first pass mb packet */
131 struct aom_psnr_pkt {
132 unsigned int samples[4]; /**< Number of samples, total/y/u/v */
133 uint64_t sse[4]; /**< sum squared error, total/y/u/v */
134 double psnr[4]; /**< PSNR, total/y/u/v */
135 /*!\brief Number of samples, total/y/u/v when
136 * input bit-depth < stream bit-depth.*/
137 unsigned int samples_hbd[4];
138 /*!\brief sum squared error, total/y/u/v when
139 * input bit-depth < stream bit-depth.*/
140 uint64_t sse_hbd[4];
141 /*!\brief PSNR, total/y/u/v when
142 * input bit-depth < stream bit-depth.*/
143 double psnr_hbd[4];
144 } psnr; /**< data for PSNR packet */
145 aom_fixed_buf_t raw; /**< data for arbitrary packets */
146 } data; /**< packet data */
147 } aom_codec_cx_pkt_t; /**< alias for struct aom_codec_cx_pkt */
149 /*!\brief Rational Number
151 * This structure holds a fractional value.
153 typedef struct aom_rational {
154 int num; /**< fraction numerator */
155 int den; /**< fraction denominator */
156 } aom_rational_t; /**< alias for struct aom_rational */
158 /*!\brief Multi-pass Encoding Pass
160 * AOM_RC_LAST_PASS is kept for backward compatibility.
161 * If passes is not given and pass==2, the codec will assume passes=2.
162 * For new code, it is recommended to use AOM_RC_SECOND_PASS and set
163 * the "passes" member to 2 via the key & val API for two-pass encoding.
165 enum aom_enc_pass {
166 AOM_RC_ONE_PASS = 0, /**< Single pass mode */
167 AOM_RC_FIRST_PASS = 1, /**< First pass of multi-pass mode */
168 AOM_RC_SECOND_PASS = 2, /**< Second pass of multi-pass mode */
169 AOM_RC_THIRD_PASS = 3, /**< Third pass of multi-pass mode */
170 AOM_RC_LAST_PASS = 2, /**< Final pass of two-pass mode */
173 /*!\brief Rate control mode */
174 enum aom_rc_mode {
175 AOM_VBR, /**< Variable Bit Rate (VBR) mode */
176 AOM_CBR, /**< Constant Bit Rate (CBR) mode */
177 AOM_CQ, /**< Constrained Quality (CQ) mode */
178 AOM_Q, /**< Constant Quality (Q) mode */
181 /*!\brief Keyframe placement mode.
183 * This enumeration determines whether keyframes are placed automatically by
184 * the encoder or whether this behavior is disabled. Older releases of this
185 * SDK were implemented such that AOM_KF_FIXED meant keyframes were disabled.
186 * This name is confusing for this behavior, so the new symbols to be used
187 * are AOM_KF_AUTO and AOM_KF_DISABLED.
189 enum aom_kf_mode {
190 AOM_KF_FIXED, /**< deprecated, implies AOM_KF_DISABLED */
191 AOM_KF_AUTO, /**< Encoder determines optimal placement automatically */
192 AOM_KF_DISABLED = 0 /**< Encoder does not place keyframes. */
195 /*!\brief Frame super-resolution mode. */
196 typedef enum {
197 /**< Frame super-resolution is disabled for all frames. */
198 AOM_SUPERRES_NONE,
199 /**< All frames are coded at the specified scale and super-resolved. */
200 AOM_SUPERRES_FIXED,
201 /**< All frames are coded at a random scale and super-resolved. */
202 AOM_SUPERRES_RANDOM,
203 /**< Super-resolution scale for each frame is determined based on the q index
204 of that frame. */
205 AOM_SUPERRES_QTHRESH,
206 /**< Full-resolution or super-resolution and the scale (in case of
207 super-resolution) are automatically selected for each frame. */
208 AOM_SUPERRES_AUTO,
209 } aom_superres_mode;
211 /*!\brief Encoder Config Options
213 * This type allows to enumerate and control flags defined for encoder control
214 * via config file at runtime.
216 typedef struct cfg_options {
217 /*!\brief Indicate init by cfg file
218 * 0 or 1
220 unsigned int init_by_cfg_file;
221 /*!\brief Superblock size
222 * 0, 64 or 128
224 unsigned int super_block_size;
225 /*!\brief max partition size
226 * 8, 16, 32, 64, 128
228 unsigned int max_partition_size;
229 /*!\brief min partition size
230 * 8, 16, 32, 64, 128
232 unsigned int min_partition_size;
233 /*!\brief disable AB Shape partition type
236 unsigned int disable_ab_partition_type;
237 /*!\brief disable rectangular partition type
240 unsigned int disable_rect_partition_type;
241 /*!\brief disable 1:4/4:1 partition type
244 unsigned int disable_1to4_partition_type;
245 /*!\brief disable flip and identity transform type
248 unsigned int disable_flip_idtx;
249 /*!\brief disable CDEF filter
252 unsigned int disable_cdef;
253 /*!\brief disable Loop Restoration Filter
256 unsigned int disable_lr;
257 /*!\brief disable OBMC
260 unsigned int disable_obmc;
261 /*!\brief disable Warped Motion
264 unsigned int disable_warp_motion;
265 /*!\brief disable global motion
268 unsigned int disable_global_motion;
269 /*!\brief disable dist weighted compound
272 unsigned int disable_dist_wtd_comp;
273 /*!\brief disable diff weighted compound
276 unsigned int disable_diff_wtd_comp;
277 /*!\brief disable inter/intra compound
280 unsigned int disable_inter_intra_comp;
281 /*!\brief disable masked compound
284 unsigned int disable_masked_comp;
285 /*!\brief disable one sided compound
288 unsigned int disable_one_sided_comp;
289 /*!\brief disable Palette
292 unsigned int disable_palette;
293 /*!\brief disable Intra Block Copy
296 unsigned int disable_intrabc;
297 /*!\brief disable chroma from luma
300 unsigned int disable_cfl;
301 /*!\brief disable intra smooth mode
304 unsigned int disable_smooth_intra;
305 /*!\brief disable filter intra
308 unsigned int disable_filter_intra;
309 /*!\brief disable dual filter
312 unsigned int disable_dual_filter;
313 /*!\brief disable intra angle delta
316 unsigned int disable_intra_angle_delta;
317 /*!\brief disable intra edge filter
320 unsigned int disable_intra_edge_filter;
321 /*!\brief disable 64x64 transform
324 unsigned int disable_tx_64x64;
325 /*!\brief disable smooth inter/intra
328 unsigned int disable_smooth_inter_intra;
329 /*!\brief disable inter/inter wedge comp
332 unsigned int disable_inter_inter_wedge;
333 /*!\brief disable inter/intra wedge comp
336 unsigned int disable_inter_intra_wedge;
337 /*!\brief disable paeth intra
340 unsigned int disable_paeth_intra;
341 /*!\brief disable trellis quantization
344 unsigned int disable_trellis_quant;
345 /*!\brief disable ref frame MV
348 unsigned int disable_ref_frame_mv;
349 /*!\brief use reduced reference frame set
352 unsigned int reduced_reference_set;
353 /*!\brief use reduced transform type set
356 unsigned int reduced_tx_type_set;
357 } cfg_options_t;
359 /*!\brief Encoded Frame Flags
361 * This type indicates a bitfield to be passed to aom_codec_encode(), defining
362 * per-frame boolean values. By convention, bits common to all codecs will be
363 * named AOM_EFLAG_*, and bits specific to an algorithm will be named
364 * /algo/_eflag_*. The lower order 16 bits are reserved for common use.
366 typedef long aom_enc_frame_flags_t;
367 /*!\brief Force this frame to be a keyframe */
368 #define AOM_EFLAG_FORCE_KF (1 << 0)
370 /*!\brief Encoder configuration structure
372 * This structure contains the encoder settings that have common representations
373 * across all codecs. This doesn't imply that all codecs support all features,
374 * however.
376 typedef struct aom_codec_enc_cfg {
378 * generic settings (g)
381 /*!\brief Algorithm specific "usage" value
383 * Algorithms may define multiple values for usage, which may convey the
384 * intent of how the application intends to use the stream. If this value
385 * is non-zero, consult the documentation for the codec to determine its
386 * meaning.
388 unsigned int g_usage;
390 /*!\brief Maximum number of threads to use
392 * For multi-threaded implementations, use no more than this number of
393 * threads. The codec may use fewer threads than allowed. The value
394 * 0 is equivalent to the value 1.
396 unsigned int g_threads;
398 /*!\brief Bitstream profile to use
400 * Some codecs support a notion of multiple bitstream profiles. Typically
401 * this maps to a set of features that are turned on or off. Often the
402 * profile to use is determined by the features of the intended decoder.
403 * Consult the documentation for the codec to determine the valid values
404 * for this parameter, or set to zero for a sane default.
406 unsigned int g_profile; /**< profile of bitstream to use */
408 /*!\brief Width of the frame
410 * This value identifies the presentation resolution of the frame,
411 * in pixels. Note that the frames passed as input to the encoder must
412 * have this resolution. Frames will be presented by the decoder in this
413 * resolution, independent of any spatial resampling the encoder may do.
415 unsigned int g_w;
417 /*!\brief Height of the frame
419 * This value identifies the presentation resolution of the frame,
420 * in pixels. Note that the frames passed as input to the encoder must
421 * have this resolution. Frames will be presented by the decoder in this
422 * resolution, independent of any spatial resampling the encoder may do.
424 unsigned int g_h;
426 /*!\brief Max number of frames to encode
429 unsigned int g_limit;
431 /*!\brief Forced maximum width of the frame
433 * If this value is non-zero then it is used to force the maximum frame
434 * width written in write_sequence_header().
436 unsigned int g_forced_max_frame_width;
438 /*!\brief Forced maximum height of the frame
440 * If this value is non-zero then it is used to force the maximum frame
441 * height written in write_sequence_header().
443 unsigned int g_forced_max_frame_height;
445 /*!\brief Bit-depth of the codec
447 * This value identifies the bit_depth of the codec,
448 * Only certain bit-depths are supported as identified in the
449 * aom_bit_depth_t enum.
451 aom_bit_depth_t g_bit_depth;
453 /*!\brief Bit-depth of the input frames
455 * This value identifies the bit_depth of the input frames in bits.
456 * Note that the frames passed as input to the encoder must have
457 * this bit-depth.
459 unsigned int g_input_bit_depth;
461 /*!\brief Stream timebase units
463 * Indicates the smallest interval of time, in seconds, used by the stream.
464 * For fixed frame rate material, or variable frame rate material where
465 * frames are timed at a multiple of a given clock (ex: video capture),
466 * the \ref RECOMMENDED method is to set the timebase to the reciprocal
467 * of the frame rate (ex: 1001/30000 for 29.970 Hz NTSC). This allows the
468 * pts to correspond to the frame number, which can be handy. For
469 * re-encoding video from containers with absolute time timestamps, the
470 * \ref RECOMMENDED method is to set the timebase to that of the parent
471 * container or multimedia framework (ex: 1/1000 for ms, as in FLV).
473 struct aom_rational g_timebase;
475 /*!\brief Enable error resilient modes.
477 * The error resilient bitfield indicates to the encoder which features
478 * it should enable to take measures for streaming over lossy or noisy
479 * links.
481 aom_codec_er_flags_t g_error_resilient;
483 /*!\brief Multi-pass Encoding Mode
485 * This value should be set to the current phase for multi-pass encoding.
486 * For single pass, set to #AOM_RC_ONE_PASS.
488 enum aom_enc_pass g_pass;
490 /*!\brief Allow lagged encoding
492 * If set, this value allows the encoder to consume a number of input
493 * frames before producing output frames. This allows the encoder to
494 * base decisions for the current frame on future frames. This does
495 * increase the latency of the encoding pipeline, so it is not appropriate
496 * in all situations (ex: realtime encoding).
498 * Note that this is a maximum value -- the encoder may produce frames
499 * sooner than the given limit. Set this value to 0 to disable this
500 * feature.
502 unsigned int g_lag_in_frames;
505 * rate control settings (rc)
508 /*!\brief Temporal resampling configuration, if supported by the codec.
510 * Temporal resampling allows the codec to "drop" frames as a strategy to
511 * meet its target data rate. This can cause temporal discontinuities in
512 * the encoded video, which may appear as stuttering during playback. This
513 * trade-off is often acceptable, but for many applications is not. It can
514 * be disabled in these cases.
516 * Note that not all codecs support this feature. All aom AVx codecs do.
517 * For other codecs, consult the documentation for that algorithm.
519 * This threshold is described as a percentage of the target data buffer.
520 * When the data buffer falls below this percentage of fullness, a
521 * dropped frame is indicated. Set the threshold to zero (0) to disable
522 * this feature.
524 unsigned int rc_dropframe_thresh;
526 /*!\brief Mode for spatial resampling, if supported by the codec.
528 * Spatial resampling allows the codec to compress a lower resolution
529 * version of the frame, which is then upscaled by the decoder to the
530 * correct presentation resolution. This increases visual quality at
531 * low data rates, at the expense of CPU time on the encoder/decoder.
533 unsigned int rc_resize_mode;
535 /*!\brief Frame resize denominator.
537 * The denominator for resize to use, assuming 8 as the numerator.
539 * Valid denominators are 8 - 16 for now.
541 unsigned int rc_resize_denominator;
543 /*!\brief Keyframe resize denominator.
545 * The denominator for resize to use, assuming 8 as the numerator.
547 * Valid denominators are 8 - 16 for now.
549 unsigned int rc_resize_kf_denominator;
551 /*!\brief Frame super-resolution scaling mode.
553 * Similar to spatial resampling, frame super-resolution integrates
554 * upscaling after the encode/decode process. Taking control of upscaling and
555 * using restoration filters should allow it to outperform normal resizing.
557 aom_superres_mode rc_superres_mode;
559 /*!\brief Frame super-resolution denominator.
561 * The denominator for superres to use. If fixed it will only change if the
562 * cumulative scale change over resizing and superres is greater than 1/2;
563 * this forces superres to reduce scaling.
565 * Valid denominators are 8 to 16.
567 * Used only by AOM_SUPERRES_FIXED.
569 unsigned int rc_superres_denominator;
571 /*!\brief Keyframe super-resolution denominator.
573 * The denominator for superres to use. If fixed it will only change if the
574 * cumulative scale change over resizing and superres is greater than 1/2;
575 * this forces superres to reduce scaling.
577 * Valid denominators are 8 - 16 for now.
579 unsigned int rc_superres_kf_denominator;
581 /*!\brief Frame super-resolution q threshold.
583 * The q level threshold after which superres is used.
584 * Valid values are 1 to 63.
586 * Used only by AOM_SUPERRES_QTHRESH
588 unsigned int rc_superres_qthresh;
590 /*!\brief Keyframe super-resolution q threshold.
592 * The q level threshold after which superres is used for key frames.
593 * Valid values are 1 to 63.
595 * Used only by AOM_SUPERRES_QTHRESH
597 unsigned int rc_superres_kf_qthresh;
599 /*!\brief Rate control algorithm to use.
601 * Indicates whether the end usage of this stream is to be streamed over
602 * a bandwidth constrained link, indicating that Constant Bit Rate (CBR)
603 * mode should be used, or whether it will be played back on a high
604 * bandwidth link, as from a local disk, where higher variations in
605 * bitrate are acceptable.
607 enum aom_rc_mode rc_end_usage;
609 /*!\brief Two-pass stats buffer.
611 * A buffer containing all of the stats packets produced in the first
612 * pass, concatenated.
614 aom_fixed_buf_t rc_twopass_stats_in;
616 /*!\brief first pass mb stats buffer.
618 * A buffer containing all of the first pass mb stats packets produced
619 * in the first pass, concatenated.
621 aom_fixed_buf_t rc_firstpass_mb_stats_in;
623 /*!\brief Target data rate
625 * Target bitrate to use for this stream, in kilobits per second.
627 unsigned int rc_target_bitrate;
630 * quantizer settings
633 /*!\brief Minimum (Best Quality) Quantizer
635 * The quantizer is the most direct control over the quality of the
636 * encoded image. The range of valid values for the quantizer is codec
637 * specific. Consult the documentation for the codec to determine the
638 * values to use. To determine the range programmatically, call
639 * aom_codec_enc_config_default() with a usage value of 0.
641 unsigned int rc_min_quantizer;
643 /*!\brief Maximum (Worst Quality) Quantizer
645 * The quantizer is the most direct control over the quality of the
646 * encoded image. The range of valid values for the quantizer is codec
647 * specific. Consult the documentation for the codec to determine the
648 * values to use. To determine the range programmatically, call
649 * aom_codec_enc_config_default() with a usage value of 0.
651 unsigned int rc_max_quantizer;
654 * bitrate tolerance
657 /*!\brief Rate control adaptation undershoot control
659 * This value, controls the tolerance of the VBR algorithm to undershoot
660 * and is used as a trigger threshold for more aggressive adaptation of Q.
662 * Valid values in the range 0-100.
664 unsigned int rc_undershoot_pct;
666 /*!\brief Rate control adaptation overshoot control
668 * This value, controls the tolerance of the VBR algorithm to overshoot
669 * and is used as a trigger threshold for more aggressive adaptation of Q.
671 * Valid values in the range 0-100.
673 unsigned int rc_overshoot_pct;
676 * decoder buffer model parameters
679 /*!\brief Decoder Buffer Size
681 * This value indicates the amount of data that may be buffered by the
682 * decoding application. Note that this value is expressed in units of
683 * time (milliseconds). For example, a value of 5000 indicates that the
684 * client will buffer (at least) 5000ms worth of encoded data. Use the
685 * target bitrate (#rc_target_bitrate) to convert to bits/bytes, if
686 * necessary.
688 unsigned int rc_buf_sz;
690 /*!\brief Decoder Buffer Initial Size
692 * This value indicates the amount of data that will be buffered by the
693 * decoding application prior to beginning playback. This value is
694 * expressed in units of time (milliseconds). Use the target bitrate
695 * (#rc_target_bitrate) to convert to bits/bytes, if necessary.
697 unsigned int rc_buf_initial_sz;
699 /*!\brief Decoder Buffer Optimal Size
701 * This value indicates the amount of data that the encoder should try
702 * to maintain in the decoder's buffer. This value is expressed in units
703 * of time (milliseconds). Use the target bitrate (#rc_target_bitrate)
704 * to convert to bits/bytes, if necessary.
706 unsigned int rc_buf_optimal_sz;
709 * 2 pass rate control parameters
712 /*!\brief Two-pass mode CBR/VBR bias
714 * Bias, expressed on a scale of 0 to 100, for determining target size
715 * for the current frame. The value 0 indicates the optimal CBR mode
716 * value should be used. The value 100 indicates the optimal VBR mode
717 * value should be used. Values in between indicate which way the
718 * encoder should "lean."
720 unsigned int rc_2pass_vbr_bias_pct;
722 /*!\brief Two-pass mode per-GOP minimum bitrate
724 * This value, expressed as a percentage of the target bitrate, indicates
725 * the minimum bitrate to be used for a single GOP (aka "section")
727 unsigned int rc_2pass_vbr_minsection_pct;
729 /*!\brief Two-pass mode per-GOP maximum bitrate
731 * This value, expressed as a percentage of the target bitrate, indicates
732 * the maximum bitrate to be used for a single GOP (aka "section")
734 unsigned int rc_2pass_vbr_maxsection_pct;
737 * keyframing settings (kf)
740 /*!\brief Option to enable forward reference key frame
743 int fwd_kf_enabled;
745 /*!\brief Keyframe placement mode
747 * This value indicates whether the encoder should place keyframes at a
748 * fixed interval, or determine the optimal placement automatically
749 * (as governed by the #kf_min_dist and #kf_max_dist parameters)
751 enum aom_kf_mode kf_mode;
753 /*!\brief Keyframe minimum interval
755 * This value, expressed as a number of frames, prevents the encoder from
756 * placing a keyframe nearer than kf_min_dist to the previous keyframe. At
757 * least kf_min_dist frames non-keyframes will be coded before the next
758 * keyframe. Set kf_min_dist equal to kf_max_dist for a fixed interval.
760 unsigned int kf_min_dist;
762 /*!\brief Keyframe maximum interval
764 * This value, expressed as a number of frames, forces the encoder to code
765 * a keyframe if one has not been coded in the last kf_max_dist frames.
766 * A value of 0 implies all frames will be keyframes. Set kf_min_dist
767 * equal to kf_max_dist for a fixed interval.
769 unsigned int kf_max_dist;
771 /*!\brief sframe interval
773 * This value, expressed as a number of frames, forces the encoder to code
774 * an S-Frame every sframe_dist frames.
776 unsigned int sframe_dist;
778 /*!\brief sframe insertion mode
780 * This value must be set to 1 or 2, and tells the encoder how to insert
781 * S-Frames. It will only have an effect if sframe_dist != 0.
783 * If altref is enabled:
784 * - if sframe_mode == 1, the considered frame will be made into an
785 * S-Frame only if it is an altref frame
786 * - if sframe_mode == 2, the next altref frame will be made into an
787 * S-Frame.
789 * Otherwise: the considered frame will be made into an S-Frame.
791 unsigned int sframe_mode;
793 /*!\brief Tile coding mode
795 * This value indicates the tile coding mode.
796 * A value of 0 implies a normal non-large-scale tile coding. A value of 1
797 * implies a large-scale tile coding.
799 unsigned int large_scale_tile;
801 /*!\brief Monochrome mode
803 * If this is nonzero, the encoder will generate a monochrome stream
804 * with no chroma planes.
806 unsigned int monochrome;
808 /*!\brief full_still_picture_hdr
810 * If this is nonzero, the encoder will generate a full header even for
811 * still picture encoding. if zero, a reduced header is used for still
812 * picture. This flag has no effect when a regular video with more than
813 * a single frame is encoded.
815 unsigned int full_still_picture_hdr;
817 /*!\brief Bitstream syntax mode
819 * This value indicates the bitstream syntax mode.
820 * A value of 0 indicates bitstream is saved as Section 5 bitstream. A value
821 * of 1 indicates the bitstream is saved in Annex-B format
823 unsigned int save_as_annexb;
825 /*!\brief Number of explicit tile widths specified
827 * This value indicates the number of tile widths specified
828 * A value of 0 implies no tile widths are specified.
829 * Tile widths are given in the array tile_widths[]
831 int tile_width_count;
833 /*!\brief Number of explicit tile heights specified
835 * This value indicates the number of tile heights specified
836 * A value of 0 implies no tile heights are specified.
837 * Tile heights are given in the array tile_heights[]
839 int tile_height_count;
841 /*!\brief Maximum number of tile widths in tile widths array
843 * This define gives the maximum number of elements in the tile_widths array.
845 #define MAX_TILE_WIDTHS 64 // maximum tile width array length
847 /*!\brief Array of specified tile widths
849 * This array specifies tile widths (and may be empty)
850 * The number of widths specified is given by tile_width_count
852 int tile_widths[MAX_TILE_WIDTHS];
854 /*!\brief Maximum number of tile heights in tile heights array.
856 * This define gives the maximum number of elements in the tile_heights array.
858 #define MAX_TILE_HEIGHTS 64 // maximum tile height array length
860 /*!\brief Array of specified tile heights
862 * This array specifies tile heights (and may be empty)
863 * The number of heights specified is given by tile_height_count
865 int tile_heights[MAX_TILE_HEIGHTS];
867 /*!\brief Whether encoder should use fixed QP offsets.
869 * If a value of 1 is provided, encoder will use fixed QP offsets for frames
870 * at different levels of the pyramid.
871 * - If 'fixed_qp_offsets' is also provided, encoder will use the given
872 * offsets
873 * - If not, encoder will select the fixed offsets based on the cq-level
874 * provided.
875 * If a value of 0 is provided and fixed_qp_offset are not provided, encoder
876 * will NOT use fixed QP offsets.
877 * Note: This option is only relevant for --end-usage=q.
879 unsigned int use_fixed_qp_offsets;
881 /*!\brief Number of fixed QP offsets
883 * This defines the number of elements in the fixed_qp_offsets array.
885 #define FIXED_QP_OFFSET_COUNT 5
887 /*!\brief Array of fixed QP offsets
889 * This array specifies fixed QP offsets (range: 0 to 63) for frames at
890 * different levels of the pyramid. It is a comma-separated list of 5 values:
891 * - QP offset for keyframe
892 * - QP offset for ALTREF frame
893 * - QP offset for 1st level internal ARF
894 * - QP offset for 2nd level internal ARF
895 * - QP offset for 3rd level internal ARF
896 * Notes:
897 * - QP offset for leaf level frames is not explicitly specified. These frames
898 * use the worst quality allowed (--cq-level).
899 * - This option is only relevant for --end-usage=q.
901 int fixed_qp_offsets[FIXED_QP_OFFSET_COUNT];
903 /*!\brief Options defined per config file
906 cfg_options_t encoder_cfg;
907 } aom_codec_enc_cfg_t; /**< alias for struct aom_codec_enc_cfg */
909 /*!\brief Initialize an encoder instance
911 * Initializes a 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.
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.
920 * \param[in] ctx Pointer to this instance's context.
921 * \param[in] iface Pointer to the algorithm interface to use.
922 * \param[in] cfg Configuration to use, if known.
923 * \param[in] flags Bitfield of AOM_CODEC_USE_* flags
924 * \param[in] ver ABI version number. Must be set to
925 * AOM_ENCODER_ABI_VERSION
926 * \retval #AOM_CODEC_OK
927 * The decoder algorithm initialized.
928 * \retval #AOM_CODEC_MEM_ERROR
929 * Memory allocation failed.
931 aom_codec_err_t aom_codec_enc_init_ver(aom_codec_ctx_t *ctx,
932 aom_codec_iface_t *iface,
933 const aom_codec_enc_cfg_t *cfg,
934 aom_codec_flags_t flags, int ver);
936 /*!\brief Convenience macro for aom_codec_enc_init_ver()
938 * Ensures the ABI version parameter is properly set.
940 #define aom_codec_enc_init(ctx, iface, cfg, flags) \
941 aom_codec_enc_init_ver(ctx, iface, cfg, flags, AOM_ENCODER_ABI_VERSION)
943 /*!\brief Get the default configuration for a usage.
945 * Initializes an encoder configuration structure with default values. Supports
946 * the notion of "usages" so that an algorithm may offer different default
947 * settings depending on the user's intended goal. This function \ref SHOULD
948 * be called by all applications to initialize the configuration structure
949 * before specializing the configuration with application specific values.
951 * \param[in] iface Pointer to the algorithm interface to use.
952 * \param[out] cfg Configuration buffer to populate.
953 * \param[in] usage Algorithm specific usage value. For AV1, must be
954 * set to AOM_USAGE_GOOD_QUALITY (0),
955 * AOM_USAGE_REALTIME (1), or AOM_USAGE_ALL_INTRA (2).
957 * \retval #AOM_CODEC_OK
958 * The configuration was populated.
959 * \retval #AOM_CODEC_INCAPABLE
960 * Interface is not an encoder interface.
961 * \retval #AOM_CODEC_INVALID_PARAM
962 * A parameter was NULL, or the usage value was not recognized.
964 aom_codec_err_t aom_codec_enc_config_default(aom_codec_iface_t *iface,
965 aom_codec_enc_cfg_t *cfg,
966 unsigned int usage);
968 /*!\brief Set or change configuration
970 * Reconfigures an encoder instance according to the given configuration.
972 * \param[in] ctx Pointer to this instance's context
973 * \param[in] cfg Configuration buffer to use
975 * \retval #AOM_CODEC_OK
976 * The configuration was populated.
977 * \retval #AOM_CODEC_INCAPABLE
978 * Interface is not an encoder interface.
979 * \retval #AOM_CODEC_INVALID_PARAM
980 * A parameter was NULL, or the usage value was not recognized.
982 aom_codec_err_t aom_codec_enc_config_set(aom_codec_ctx_t *ctx,
983 const aom_codec_enc_cfg_t *cfg);
985 /*!\brief Get global stream headers
987 * Retrieves a stream level global header packet, if supported by the codec.
988 * Calls to this function should be deferred until all configuration information
989 * has been passed to libaom. Otherwise the global header data may be
990 * invalidated by additional configuration changes.
992 * The AV1 implementation of this function returns an OBU. The OBU returned is
993 * in Low Overhead Bitstream Format. Specifically, the obu_has_size_field bit is
994 * set, and the buffer contains the obu_size field for the returned OBU.
996 * \param[in] ctx Pointer to this instance's context
998 * \retval NULL
999 * Encoder does not support global header, or an error occurred while
1000 * generating the global header.
1002 * \retval Non-NULL
1003 * Pointer to buffer containing global header packet. The caller owns the
1004 * memory associated with this buffer, and must free the 'buf' member of the
1005 * aom_fixed_buf_t as well as the aom_fixed_buf_t pointer. Memory returned
1006 * must be freed via call to free().
1008 aom_fixed_buf_t *aom_codec_get_global_headers(aom_codec_ctx_t *ctx);
1010 /*!\brief usage parameter analogous to AV1 GOOD QUALITY mode. */
1011 #define AOM_USAGE_GOOD_QUALITY (0)
1012 /*!\brief usage parameter analogous to AV1 REALTIME mode. */
1013 #define AOM_USAGE_REALTIME (1)
1014 /*!\brief usage parameter analogous to AV1 all intra mode. */
1015 #define AOM_USAGE_ALL_INTRA (2)
1017 /*!\brief Encode a frame
1019 * Encodes a video frame at the given "presentation time." The presentation
1020 * time stamp (PTS) \ref MUST be strictly increasing.
1022 * When the last frame has been passed to the encoder, this function should
1023 * continue to be called in a loop, with the img parameter set to NULL. This
1024 * will signal the end-of-stream condition to the encoder and allow it to
1025 * encode any held buffers. Encoding is complete when aom_codec_encode() is
1026 * called with img set to NULL and aom_codec_get_cx_data() returns no data.
1028 * \param[in] ctx Pointer to this instance's context
1029 * \param[in] img Image data to encode, NULL to flush.
1030 * \param[in] pts Presentation time stamp, in timebase units. If img
1031 * is NULL, pts is ignored.
1032 * \param[in] duration Duration to show frame, in timebase units. If img
1033 * is not NULL, duration must be nonzero. If img is
1034 * NULL, duration is ignored.
1035 * \param[in] flags Flags to use for encoding this frame.
1037 * \retval #AOM_CODEC_OK
1038 * The configuration was populated.
1039 * \retval #AOM_CODEC_INCAPABLE
1040 * Interface is not an encoder interface.
1041 * \retval #AOM_CODEC_INVALID_PARAM
1042 * A parameter was NULL, the image format is unsupported, etc.
1044 aom_codec_err_t aom_codec_encode(aom_codec_ctx_t *ctx, const aom_image_t *img,
1045 aom_codec_pts_t pts, unsigned long duration,
1046 aom_enc_frame_flags_t flags);
1048 /*!\brief Set compressed data output buffer
1050 * Sets the buffer that the codec should output the compressed data
1051 * into. This call effectively sets the buffer pointer returned in the
1052 * next AOM_CODEC_CX_FRAME_PKT packet. Subsequent packets will be
1053 * appended into this buffer. The buffer is preserved across frames,
1054 * so applications must periodically call this function after flushing
1055 * the accumulated compressed data to disk or to the network to reset
1056 * the pointer to the buffer's head.
1058 * `pad_before` bytes will be skipped before writing the compressed
1059 * data, and `pad_after` bytes will be appended to the packet. The size
1060 * of the packet will be the sum of the size of the actual compressed
1061 * data, pad_before, and pad_after. The padding bytes will be preserved
1062 * (not overwritten).
1064 * Note that calling this function does not guarantee that the returned
1065 * compressed data will be placed into the specified buffer. In the
1066 * event that the encoded data will not fit into the buffer provided,
1067 * the returned packet \ref MAY point to an internal buffer, as it would
1068 * if this call were never used. In this event, the output packet will
1069 * NOT have any padding, and the application must free space and copy it
1070 * to the proper place. This is of particular note in configurations
1071 * that may output multiple packets for a single encoded frame (e.g., lagged
1072 * encoding) or if the application does not reset the buffer periodically.
1074 * Applications may restore the default behavior of the codec providing
1075 * the compressed data buffer by calling this function with a NULL
1076 * buffer.
1078 * Applications \ref MUSTNOT call this function during iteration of
1079 * aom_codec_get_cx_data().
1081 * \param[in] ctx Pointer to this instance's context
1082 * \param[in] buf Buffer to store compressed data into
1083 * \param[in] pad_before Bytes to skip before writing compressed data
1084 * \param[in] pad_after Bytes to skip after writing compressed data
1086 * \retval #AOM_CODEC_OK
1087 * The buffer was set successfully.
1088 * \retval #AOM_CODEC_INVALID_PARAM
1089 * A parameter was NULL, the image format is unsupported, etc.
1091 aom_codec_err_t aom_codec_set_cx_data_buf(aom_codec_ctx_t *ctx,
1092 const aom_fixed_buf_t *buf,
1093 unsigned int pad_before,
1094 unsigned int pad_after);
1096 /*!\brief Encoded data iterator
1098 * Iterates over a list of data packets to be passed from the encoder to the
1099 * application. The different kinds of packets available are enumerated in
1100 * #aom_codec_cx_pkt_kind.
1102 * #AOM_CODEC_CX_FRAME_PKT packets should be passed to the application's
1103 * muxer. Multiple compressed frames may be in the list.
1104 * #AOM_CODEC_STATS_PKT packets should be appended to a global buffer.
1106 * The application \ref MUST silently ignore any packet kinds that it does
1107 * not recognize or support.
1109 * The data buffers returned from this function are only guaranteed to be
1110 * valid until the application makes another call to any aom_codec_* function.
1112 * \param[in] ctx Pointer to this instance's context
1113 * \param[in,out] iter Iterator storage, initialized to NULL
1115 * \return Returns a pointer to an output data packet (compressed frame data,
1116 * two-pass statistics, etc.) or NULL to signal end-of-list.
1119 const aom_codec_cx_pkt_t *aom_codec_get_cx_data(aom_codec_ctx_t *ctx,
1120 aom_codec_iter_t *iter);
1122 /*!\brief Get Preview Frame
1124 * Returns an image that can be used as a preview. Shows the image as it would
1125 * exist at the decompressor. The application \ref MUST NOT write into this
1126 * image buffer.
1128 * \param[in] ctx Pointer to this instance's context
1130 * \return Returns a pointer to a preview image, or NULL if no image is
1131 * available.
1134 const aom_image_t *aom_codec_get_preview_frame(aom_codec_ctx_t *ctx);
1136 /*!@} - end defgroup encoder*/
1137 #ifdef __cplusplus
1139 #endif
1140 #endif // AOM_AOM_AOM_ENCODER_H_