blob: e94b713e44ddced4c1917e4cd6dde9779f0b3c72 [file] [log] [blame] [edit]
/*
* Copyright (c) 2021, Alliance for Open Media. All rights reserved
*
* This source code is subject to the terms of the BSD 3-Clause Clear License
* and the Alliance for Open Media Patent License 1.0. If the BSD 3-Clause Clear
* License was not distributed with this source code in the LICENSE file, you
* can obtain it at aomedia.org/license/software-license/bsd-3-c-c/. If the
* Alliance for Open Media Patent License 1.0 was not distributed with this
* source code in the PATENTS file, you can obtain it at
* aomedia.org/license/patent-license/.
*/
#ifndef AOM_AOM_AOM_ENCODER_H_
#define AOM_AOM_AOM_ENCODER_H_
/*!\defgroup encoder Encoder Algorithm Interface
* \ingroup codec
* This abstraction allows applications using this encoder to easily support
* multiple video formats with minimal code duplication. This section describes
* the interface common to all encoders.
* @{
*/
/*!\file
* \brief Describes the encoder algorithm interface to applications.
*
* This file describes the interface between an application and a
* video encoder algorithm.
*
*/
#ifdef __cplusplus
extern "C" {
#endif
#include "config/aom_config.h"
#include "aom/aom_codec.h"
/*!\brief Current ABI version number
*
* \internal
* If this file is altered in any way that changes the ABI, this value
* must be bumped. Examples include, but are not limited to, changing
* types, removing or reassigning enums, adding/removing/rearranging
* fields to structures
*/
#define AOM_ENCODER_ABI_VERSION \
(8 + AOM_CODEC_ABI_VERSION) /**<\hideinitializer*/
/*! \brief Encoder capabilities bitfield
*
* Each encoder advertises the capabilities it supports as part of its
* ::aom_codec_iface_t interface structure. Capabilities are extra
* interfaces or functionality, and are not required to be supported
* by an encoder.
*
* The available flags are specified by AOM_CODEC_CAP_* defines.
*/
#define AOM_CODEC_CAP_PSNR 0x10000 /**< Can issue PSNR packets */
/*! \brief Initialization-time Feature Enabling
*
* Certain codec features must be known at initialization time, to allow
* for proper memory allocation.
*
* The available flags are specified by AOM_CODEC_USE_* defines.
*/
#define AOM_CODEC_USE_PSNR 0x10000 /**< Calculate PSNR on each frame */
/*!\brief Use stream PSNR instead of input PSNR. */
#define AOM_CODEC_USE_STREAM_PSNR 0x20000
/*!\brief Print per frame stats. */
#define AOM_CODEC_USE_PER_FRAME_STATS 0x80000 /**< Enable printing of stats */
/*!\brief Generic fixed size buffer structure
*
* This structure is able to hold a reference to any fixed size buffer.
*/
typedef struct aom_fixed_buf {
void *buf; /**< Pointer to the data. Does NOT own the data! */
size_t sz; /**< Length of the buffer, in chars */
} aom_fixed_buf_t; /**< alias for struct aom_fixed_buf */
/*!\brief Error Resilient flags
*
* These flags define which error resilient features to enable in the
* encoder. The flags are specified through the
* aom_codec_enc_cfg::g_error_resilient variable.
*/
typedef uint32_t aom_codec_er_flags_t;
/*!\brief Improve resiliency against losses of whole frames */
#define AOM_ERROR_RESILIENT_DEFAULT 0x1
/*!\brief Encoder output packet variants
*
* This enumeration lists the different kinds of data packets that can be
* returned by calls to aom_codec_get_cx_data(). Algorithms \ref MAY
* extend this list to provide additional functionality.
*/
enum aom_codec_cx_pkt_kind {
AOM_CODEC_CX_FRAME_PKT, /**< Compressed video frame */
AOM_CODEC_STATS_PKT, /**< Two-pass statistics for this frame */
AOM_CODEC_FPMB_STATS_PKT, /**< first pass mb statistics for this frame */
AOM_CODEC_PSNR_PKT, /**< PSNR statistics for this frame */
#if CONFIG_OUTPUT_FRAME_BASED_ON_ORDER_HINT
AOM_CODEC_CX_FRAME_NULL_PKT, /**< Null show-existing frame */
#endif // CONFIG_OUTPUT_FRAME_BASED_ON_ORDER_HINT
AOM_CODEC_CUSTOM_PKT = 256 /**< Algorithm extensions */
};
/*!\brief Encoder output packet
*
* This structure contains the different kinds of output data the encoder
* may produce while compressing a frame.
*/
typedef struct aom_codec_cx_pkt {
enum aom_codec_cx_pkt_kind kind; /**< packet variant */
union {
struct {
void *buf; /**< compressed data buffer */
size_t sz; /**< length of compressed data */
/*!\brief time stamp to show frame (in timebase units) */
aom_codec_pts_t pts;
/*!\brief duration to show frame (in timebase units) */
unsigned long duration;
aom_codec_frame_flags_t flags; /**< flags for this frame */
/*!\brief the partition id defines the decoding order of the partitions.
* Only applicable when "output partition" mode is enabled. First
* partition has id 0.*/
int partition_id;
/*!\brief size of the visible frame in this packet */
size_t vis_frame_size;
} frame; /**< data for compressed frame packet */
aom_fixed_buf_t twopass_stats; /**< data for two-pass packet */
aom_fixed_buf_t firstpass_mb_stats; /**< first pass mb packet */
struct aom_psnr_pkt {
unsigned int samples[4]; /**< Number of samples, total/y/u/v */
uint64_t sse[4]; /**< sum squared error, total/y/u/v */
double psnr[4]; /**< PSNR, total/y/u/v */
/*!\brief Number of samples, total/y/u/v when
* input bit-depth < stream bit-depth.*/
unsigned int samples_hbd[4];
/*!\brief sum squared error, total/y/u/v when
* input bit-depth < stream bit-depth.*/
uint64_t sse_hbd[4];
/*!\brief PSNR, total/y/u/v when
* input bit-depth < stream bit-depth.*/
double psnr_hbd[4];
} psnr; /**< data for PSNR packet */
aom_fixed_buf_t raw; /**< data for arbitrary packets */
/* This packet size is fixed to allow codecs to extend this
* interface without having to manage storage for raw packets,
* i.e., if it's smaller than 128 bytes, you can store in the
* packet list directly.
*/
char pad[128 - sizeof(enum aom_codec_cx_pkt_kind)]; /**< fixed sz */
} data; /**< packet data */
} aom_codec_cx_pkt_t; /**< alias for struct aom_codec_cx_pkt */
/*!\brief Rational Number
*
* This structure holds a fractional value.
*/
typedef struct aom_rational {
int num; /**< fraction numerator */
int den; /**< fraction denominator */
} aom_rational_t; /**< alias for struct aom_rational */
/*!\brief Multi-pass Encoding Pass */
enum aom_enc_pass {
AOM_RC_ONE_PASS, /**< Single pass mode */
AOM_RC_FIRST_PASS, /**< First pass of multi-pass mode */
AOM_RC_LAST_PASS /**< Final pass of multi-pass mode */
};
/*!\brief Rate control mode */
enum aom_rc_mode {
AOM_VBR, /**< Variable Bit Rate (VBR) mode */
AOM_CBR, /**< Constant Bit Rate (CBR) mode */
AOM_CQ, /**< Constrained Quality (CQ) mode */
AOM_Q, /**< Constant Quality (Q) mode */
};
/*!\brief Keyframe placement mode.
*
* This enumeration determines whether keyframes are placed automatically by
* the encoder or whether this behavior is disabled. Older releases of this
* SDK were implemented such that AOM_KF_FIXED meant keyframes were disabled.
* This name is confusing for this behavior, so the new symbols to be used
* are AOM_KF_AUTO and AOM_KF_DISABLED.
*/
enum aom_kf_mode {
AOM_KF_FIXED, /**< deprecated, implies AOM_KF_DISABLED */
AOM_KF_AUTO, /**< Encoder determines optimal placement automatically */
AOM_KF_DISABLED = 0 /**< Encoder does not place keyframes. */
};
/*!\brief Frame super-resolution mode. */
typedef enum {
/**< Frame super-resolution is disabled for all frames. */
AOM_SUPERRES_NONE,
/**< All frames are coded at the specified scale and super-resolved. */
AOM_SUPERRES_FIXED,
/**< All frames are coded at a random scale and super-resolved. */
AOM_SUPERRES_RANDOM,
/**< Super-resolution scale for each frame is determined based on the q index
of that frame. */
AOM_SUPERRES_QTHRESH,
/**< Full-resolution or super-resolution and the scale (in case of
super-resolution) are automatically selected for each frame. */
AOM_SUPERRES_AUTO,
} aom_superres_mode;
#if CONFIG_OPTFLOW_REFINEMENT
/*!\brief Frame super-resolution mode. */
typedef enum {
/**< MV refinement is disabled for all frames. */
AOM_OPFL_REFINE_NONE,
/**< MV refinement is switchable per block and signaled by the encoder for all
* frames. */
AOM_OPFL_REFINE_SWITCHABLE,
/**< MV refinement is done for all compound average blocks for all frames. */
AOM_OPFL_REFINE_ALL,
/**< One among the three above types is automatically selected by the encoder
* for each frame. */
AOM_OPFL_REFINE_AUTO,
} aom_opfl_refine_type;
#endif // CONFIG_OPTFLOW_REFINEMENT
/*!\brief Decoded Frame Hash Metadata OBU writing mode.
*
* This enumeration determines whether one or more metadata OBUs of type
* Decoded Frame Hash are written before each encoded frame.
*/
enum aom_frame_hash_mode {
/**< Encoder does not write Decoded Frame Hash Metadata OBUs. */
AOM_DFH_DISABLED,
/**< Encoder writes Decoded Frame Hash Metadata OBUs for frames as
* they are in reference picture buffer. */
AOM_DFH_RAW,
/**< Encoder writes Decoded Frame Hash Metadata OBUs for frames as
* they are output, which may be as they are in reference picture buffer
* or after Film Grain has been applied if such parameters are present. */
AOM_DFH_FG,
/**< Encoder writes Decoded Frame Hash Metadata OBUs for frames both
* as they are in reference picture buffer and as they are output.
* The latter is only written if it differs from the former (e.g.,
* film grain has been applied if such parameters are present.) */
AOM_DFH_BOTH,
};
/*!\brief Encoder Config Options
*
* This type allows to enumerate and control flags defined for encoder control
* via config file at runtime.
*/
typedef struct cfg_options {
/*!\brief Indicate init by cfg file
* 0 or 1
*/
unsigned int init_by_cfg_file;
#if CONFIG_BLOCK_256
/*!\brief Superblock size
* 0, 64, 128 or 256
*/
unsigned int superblock_size;
/*!\brief max partition size
* 8, 16, 32, 64, 128, 256
*/
unsigned int max_partition_size;
/*!\brief min partition size
* 8, 16, 32, 64, 128, 256
*/
unsigned int min_partition_size;
#else
/*!\brief Superblock size
* 0, 64 or 128
*/
unsigned int superblock_size;
/*!\brief max partition size
* 8, 16, 32, 64, 128
*/
unsigned int max_partition_size;
/*!\brief min partition size
* 8, 16, 32, 64, 128
*/
unsigned int min_partition_size;
#endif // CONFIG_BLOCK_256
/*!\brief enable AB Shape partition type
*
*/
unsigned int enable_ab_partitions;
/*!\brief enable rectangular partition type
*
*/
unsigned int enable_rect_partitions;
/*!\brief enable 1:4/4:1 partition type
*
*/
unsigned int enable_1to4_partitions;
/*!\brief disable ml-based speed-up for partition search
*
*/
unsigned int disable_ml_partition_speed_features;
#if CONFIG_EXT_RECUR_PARTITIONS
/*!\brief prune partitions for ERP
*
*/
unsigned int erp_pruning_level;
/*!\brief use ml model for erp pruning
*
*/
unsigned int use_ml_erp_pruning;
/*!\brief enable extended partitions
*
*/
unsigned int enable_ext_partitions;
#endif // CONFIG_EXT_RECUR_PARTITIONS
/*!\brief disable ml-based speed-up for transform search
*
*/
unsigned int disable_ml_transform_speed_features;
/*!\brief enable Semi-decoupled partitioning
*
*/
unsigned int enable_sdp;
/*!\brief enable Multiple reference line selection
*
*/
unsigned int enable_mrls;
/*!\brief enable temporal interpolated prediction
*
*/
unsigned int enable_tip;
#if CONFIG_BAWP
/*!\brief enable block adaptive weighted prediction
*
*/
unsigned int enable_bawp;
#endif // CONFIG_BAWP
/*!\brief enable compound weighted prediction
*
*/
unsigned int enable_cwp;
#if CONFIG_D071_IMP_MSK_BLD
/*!\brief enable implicit maksed blending
*
*/
unsigned int enable_imp_msk_bld;
#endif // CONFIG_D071_IMP_MSK_BLD
/*!\brief enable Forward skip coding
*
*/
unsigned int enable_fsc;
/*!\brief enable Offset based refinement of Intra prediction
*
*/
unsigned int enable_orip;
#if CONFIG_IDIF
/*!\brief enable Intra Directional Interpolation Filter
*
*/
unsigned int enable_idif;
#endif // CONFIG_IDIF
/*!\brief enable Intra secondary transform
*
*/
unsigned int enable_ist;
/*!\brief enable cross-chroma component transform
*
*/
unsigned int enable_cctx;
/*!\brief enable Intra Bi-Prediction (IBP)
*
*/
unsigned int enable_ibp;
/*!\brief enable Adaptive MVD resolution
*
*/
unsigned int enable_adaptive_mvd;
/*!\brief enable Flexible MV resolution
*
*/
unsigned int enable_flex_mvres;
#if CONFIG_IMPROVED_CFL
/*!\brief enable downsample filter options for CFL
*
*/
unsigned int enable_cfl_ds_filter;
#endif // CONFIG_IMPROVED_CFL
/*!\brief enable joint MVD coding
*
*/
unsigned int enable_joint_mvd;
#if CONFIG_REFINEMV
/*!\brief enable refine MV mode
*
*/
unsigned int enable_refinemv;
#endif // CONFIG_REFINEMV
/*!\brief enable flip and identity transform type
*
*/
unsigned int enable_flip_idtx;
/*!\brief enable deblocking filter
*
*/
unsigned int enable_deblocking;
/*!\brief enable CDEF filter
*
*/
unsigned int enable_cdef;
/*!\brief enable Loop Restoration Filter
*
*/
unsigned int enable_restoration;
/*!\brief enable Wiener Filter in Loop Restoration
*
*/
unsigned int enable_wiener;
/*!\brief enable Self-Guided Filter in Loop Restoration
*
*/
unsigned int enable_sgrproj;
#if CONFIG_LR_IMPROVEMENTS
/*!\brief enable Pixel-Classified Wiener Filter in Loop Restoration
*
*/
unsigned int enable_pc_wiener;
/*!\brief enable Noseparable Wiener Filter in Loop Restoration
*
*/
unsigned int enable_wiener_nonsep;
#endif // CONFIG_LR_IMPROVEMENTS
#if CONFIG_CCSO
/*!\brief enable cross-component sample offset
*
*/
unsigned int enable_ccso;
#endif
/*!\brief enable prediction enhancement filter
*
*/
unsigned int enable_pef;
/*!\brief enable OBMC
*
*/
unsigned int enable_obmc;
/*!\brief enable local warped motion
*
*/
unsigned int enable_warped_motion;
#if CONFIG_EXTENDED_WARP_PREDICTION
/*!\brief enable spatial warp prediction
*
*/
unsigned int enable_warped_causal;
/*!\brief enable explicit warp models
*
*/
unsigned int enable_warp_delta;
/*!\brief enable warp extension
*
*/
unsigned int enable_warp_extend;
#endif // CONFIG_EXTENDED_WARP_PREDICTION
/*!\brief enable global motion
*
*/
unsigned int enable_global_motion;
/*!\brief enable diff weighted compound
*
*/
unsigned int enable_diff_wtd_comp;
/*!\brief enable inter/intra compound
*
*/
unsigned int enable_interintra_comp;
/*!\brief enable masked compound
*
*/
unsigned int enable_masked_comp;
/*!\brief enable one sided compound
*
*/
unsigned int enable_onesided_comp;
/*!\brief enable Palette
*
*/
unsigned int enable_palette;
/*!\brief enable Intra Block Copy
*
*/
unsigned int enable_intrabc;
#if CONFIG_IBC_SR_EXT
/*!\brief enable search range extension for Intra Block Copy
*
*/
unsigned int enable_intrabc_ext;
#endif // CONFIG_IBC_SR_EXT
/*!\brief enable chroma from luma
*
*/
unsigned int enable_cfl_intra;
/*!\brief enable intra smooth mode
*
*/
unsigned int enable_smooth_intra;
/*!\brief enable filter intra
*
*/
unsigned int enable_filter_intra;
/*!\brief enable intra angle delta
*
*/
unsigned int enable_angle_delta;
#if CONFIG_OPTFLOW_REFINEMENT
/*!\brief enable optical flow refinement
*
*/
aom_opfl_refine_type enable_opfl_refine;
#endif // CONFIG_OPTFLOW_REFINEMENT
#if CONFIG_AFFINE_REFINEMENT
/*!\brief enable affine refinement
*
*/
unsigned int enable_affine_refine;
#endif // CONFIG_AFFINE_REFINEMENT
/*!\brief enable intra edge filter
*
*/
unsigned int enable_intra_edge_filter;
/*!\brief enable 64x64 transform
*
*/
unsigned int enable_tx64;
/*!\brief enable smooth inter/intra
*
*/
unsigned int enable_smooth_interintra;
/*!\brief enable inter/inter wedge comp
*
*/
unsigned int enable_interinter_wedge;
/*!\brief enable inter/intra wedge comp
*
*/
unsigned int enable_interintra_wedge;
/*!\brief enable paeth intra
*
*/
unsigned int enable_paeth_intra;
/*!\brief enable trellis quantization
*
*/
unsigned int enable_trellis_quant;
#if CONFIG_DQ
/*!\brief enable dependentquantization
*
*/
unsigned int enable_dq;
#endif
/*!\brief enable ref frame MV
*
*/
unsigned int enable_ref_frame_mvs;
/*!\brief use reduced reference frame set
*
*/
unsigned int enable_reduced_reference_set;
/*!\brief explicitly signal reference frame mapping
*
*/
unsigned int explicit_ref_frame_map;
#if CONFIG_OUTPUT_FRAME_BASED_ON_ORDER_HINT
/*!\brief enable frame output order derivation based on order hint
*
*/
unsigned int enable_frame_output_order;
#endif // CONFIG_OUTPUT_FRAME_BASED_ON_ORDER_HINT
/*!\brief use reduced transform type set
*
*/
unsigned int reduced_tx_type_set;
/*!\brief Max number of reference mvs in dynamic reference list
*
*/
unsigned int max_drl_refmvs;
#if CONFIG_IBC_BV_IMPROVEMENT && CONFIG_IBC_MAX_DRL
/*!\brief Max number of reference bvs in IntraBC ref bv list
*
*/
unsigned int max_drl_refbvs;
#endif // CONFIG_IBC_BV_IMPROVEMENT && CONFIG_IBC_MAX_DRL
/*!\brief enable reference MV Bank
*
*/
unsigned int enable_refmvbank;
/*!\brief enable parity hiding for coefficients coding
*
*/
unsigned int enable_parity_hiding;
#if CONFIG_MRSSE
/*!\brief enable mrsse for mean removed SSE
*
*/
unsigned int enable_mrsse;
#endif // CONFIG_MRSSE
#if CONFIG_REFRESH_FLAG
/*!\brief enable signaling refresh frame flags with 3 bits.
* If 0, signal refresh frame flags with 8 bits, which allows to refresh
* any number of frame buffers (up to 8).
* If 1, signal refresh frame flags with 3 bits, which allows to refresh
* exactly 1 frame buffer.
*/
unsigned int enable_short_refresh_frame_flags;
#endif // CONFIG_REFRESH_FLAG
} cfg_options_t;
/*!\brief Encoded Frame Flags
*
* This type indicates a bitfield to be passed to aom_codec_encode(), defining
* per-frame boolean values. By convention, bits common to all codecs will be
* named AOM_EFLAG_*, and bits specific to an algorithm will be named
* /algo/_eflag_*. The lower order 16 bits are reserved for common use.
*/
typedef long aom_enc_frame_flags_t;
/*!\brief Force this frame to be a keyframe */
#define AOM_EFLAG_FORCE_KF (1 << 0)
/*!\brief Encoder configuration structure
*
* This structure contains the encoder settings that have common representations
* across all codecs. This doesn't imply that all codecs support all features,
* however.
*/
typedef struct aom_codec_enc_cfg {
/*
* generic settings (g)
*/
/*!\brief Algorithm specific "usage" value
*
* Algorithms may define multiple values for usage, which may convey the
* intent of how the application intends to use the stream. If this value
* is non-zero, consult the documentation for the codec to determine its
* meaning.
*/
unsigned int g_usage;
/*!\brief Maximum number of threads to use
*
* For multi-threaded implementations, use no more than this number of
* threads. The codec may use fewer threads than allowed. The value
* 0 is equivalent to the value 1.
*/
unsigned int g_threads;
/*!\brief Bitstream profile to use
*
* Some codecs support a notion of multiple bitstream profiles. Typically
* this maps to a set of features that are turned on or off. Often the
* profile to use is determined by the features of the intended decoder.
* Consult the documentation for the codec to determine the valid values
* for this parameter, or set to zero for a sane default.
*/
unsigned int g_profile; /**< profile of bitstream to use */
/*!\brief Width of the frame
*
* This value identifies the presentation resolution of the frame,
* in pixels. Note that the frames passed as input to the encoder must
* have this resolution. Frames will be presented by the decoder in this
* resolution, independent of any spatial resampling the encoder may do.
*/
unsigned int g_w;
/*!\brief Height of the frame
*
* This value identifies the presentation resolution of the frame,
* in pixels. Note that the frames passed as input to the encoder must
* have this resolution. Frames will be presented by the decoder in this
* resolution, independent of any spatial resampling the encoder may do.
*/
unsigned int g_h;
/*!\brief Max number of frames to encode
*
*/
unsigned int g_limit;
/*!\brief Forced maximum width of the frame
*
* If this value is non-zero then it is used to force the maximum frame
* width written in write_sequence_header().
*/
unsigned int g_forced_max_frame_width;
/*!\brief Forced maximum height of the frame
*
* If this value is non-zero then it is used to force the maximum frame
* height written in write_sequence_header().
*/
unsigned int g_forced_max_frame_height;
/*!\brief Bit-depth of the codec
*
* This value identifies the bit_depth of the codec,
* Only certain bit-depths are supported as identified in the
* aom_bit_depth_t enum.
*/
aom_bit_depth_t g_bit_depth;
/*!\brief Bit-depth of the input frames
*
* This value identifies the bit_depth of the input frames in bits.
* Note that the frames passed as input to the encoder must have
* this bit-depth.
*/
unsigned int g_input_bit_depth;
/*!\brief Stream timebase units
*
* Indicates the smallest interval of time, in seconds, used by the stream.
* For fixed frame rate material, or variable frame rate material where
* frames are timed at a multiple of a given clock (ex: video capture),
* the \ref RECOMMENDED method is to set the timebase to the reciprocal
* of the frame rate (ex: 1001/30000 for 29.970 Hz NTSC). This allows the
* pts to correspond to the frame number, which can be handy. For
* re-encoding video from containers with absolute time timestamps, the
* \ref RECOMMENDED method is to set the timebase to that of the parent
* container or multimedia framework (ex: 1/1000 for ms, as in FLV).
*/
struct aom_rational g_timebase;
/*!\brief Enable error resilient modes.
*
* The error resilient bitfield indicates to the encoder which features
* it should enable to take measures for streaming over lossy or noisy
* links.
*/
aom_codec_er_flags_t g_error_resilient;
/*!\brief Multi-pass Encoding Mode
*
* This value should be set to the current phase for multi-pass encoding.
* For single pass, set to #AOM_RC_ONE_PASS.
*/
enum aom_enc_pass g_pass;
/*!\brief Allow lagged encoding
*
* If set, this value allows the encoder to consume a number of input
* frames before producing output frames. This allows the encoder to
* base decisions for the current frame on future frames. This does
* increase the latency of the encoding pipeline, so it is not appropriate
* in all situations (ex: realtime encoding).
*
* Note that this is a maximum value -- the encoder may produce frames
* sooner than the given limit. Set this value to 0 to disable this
* feature.
*/
unsigned int g_lag_in_frames;
/*
* rate control settings (rc)
*/
/*!\brief Temporal resampling configuration, if supported by the codec.
*
* Temporal resampling allows the codec to "drop" frames as a strategy to
* meet its target data rate. This can cause temporal discontinuities in
* the encoded video, which may appear as stuttering during playback. This
* trade-off is often acceptable, but for many applications is not. It can
* be disabled in these cases.
*
* Note that not all codecs support this feature. All aom AVx codecs do.
* For other codecs, consult the documentation for that algorithm.
*
* This threshold is described as a percentage of the target data buffer.
* When the data buffer falls below this percentage of fullness, a
* dropped frame is indicated. Set the threshold to zero (0) to disable
* this feature.
*/
unsigned int rc_dropframe_thresh;
/*!\brief Mode for spatial resampling, if supported by the codec.
*
* Spatial resampling allows the codec to compress a lower resolution
* version of the frame, which is then upscaled by the decoder to the
* correct presentation resolution. This increases visual quality at
* low data rates, at the expense of CPU time on the encoder/decoder.
*/
unsigned int rc_resize_mode;
/*!\brief Frame resize denominator.
*
* The denominator for resize to use, assuming 8 as the numerator.
*
* Valid denominators are 8 - 16 for now.
*/
unsigned int rc_resize_denominator;
/*!\brief Keyframe resize denominator.
*
* The denominator for resize to use, assuming 8 as the numerator.
*
* Valid denominators are 8 - 16 for now.
*/
unsigned int rc_resize_kf_denominator;
/*!\brief Frame super-resolution scaling mode.
*
* Similar to spatial resampling, frame super-resolution integrates
* upscaling after the encode/decode process. Taking control of upscaling and
* using restoration filters should allow it to outperform normal resizing.
*/
aom_superres_mode rc_superres_mode;
/*!\brief Frame super-resolution denominator.
*
* The denominator for superres to use. If fixed it will only change if the
* cumulative scale change over resizing and superres is greater than 1/2;
* this forces superres to reduce scaling.
*
* Valid denominators are 8 to 16.
*
* Used only by AOM_SUPERRES_FIXED.
*/
unsigned int rc_superres_denominator;
/*!\brief Keyframe super-resolution denominator.
*
* The denominator for superres to use. If fixed it will only change if the
* cumulative scale change over resizing and superres is greater than 1/2;
* this forces superres to reduce scaling.
*
* Valid denominators are 8 - 16 for now.
*/
unsigned int rc_superres_kf_denominator;
/*!\brief Frame super-resolution q threshold.
*
* The q level threshold after which superres is used.
* Valid values are 1 to 255.
*
* Used only by AOM_SUPERRES_QTHRESH
*/
unsigned int rc_superres_qthresh;
/*!\brief Keyframe super-resolution q threshold.
*
* The q level threshold after which superres is used for key frames.
* Valid values are 1 to 255.
*
* Used only by AOM_SUPERRES_QTHRESH
*/
unsigned int rc_superres_kf_qthresh;
/*!\brief Rate control algorithm to use.
*
* Indicates whether the end usage of this stream is to be streamed over
* a bandwidth constrained link, indicating that Constant Bit Rate (CBR)
* mode should be used, or whether it will be played back on a high
* bandwidth link, as from a local disk, where higher variations in
* bitrate are acceptable.
*/
enum aom_rc_mode rc_end_usage;
/*!\brief first pass mb stats buffer.
*
* A buffer containing all of the first pass mb stats packets produced
* in the first pass, concatenated.
*/
aom_fixed_buf_t rc_firstpass_mb_stats_in;
/*!\brief Target data rate
*
* Target bandwidth to use for this stream, in kilobits per second.
*/
unsigned int rc_target_bitrate;
/*
* quantizer settings
*/
/*!\brief Minimum (Best Quality) Quantizer
*
* The quantizer is the most direct control over the quality of the
* encoded image. The range of valid values for the quantizer is codec
* specific. Consult the documentation for the codec to determine the
* values to use. To determine the range programmatically, call
* aom_codec_enc_config_default() with a usage value of 0.
*/
int rc_min_quantizer;
/*!\brief Maximum (Worst Quality) Quantizer
*
* The quantizer is the most direct control over the quality of the
* encoded image. The range of valid values for the quantizer is codec
* specific. Consult the documentation for the codec to determine the
* values to use. To determine the range programmatically, call
* aom_codec_enc_config_default() with a usage value of 0.
*/
int rc_max_quantizer;
/*
* bitrate tolerance
*/
/*!\brief Rate control adaptation undershoot control
*
* This value, controls the tolerance of the VBR algorithm to undershoot
* and is used as a trigger threshold for more aggressive adaptation of Q.
*
* Valid values in the range 0-100.
*/
unsigned int rc_undershoot_pct;
/*!\brief Rate control adaptation overshoot control
*
* This value, controls the tolerance of the VBR algorithm to overshoot
* and is used as a trigger threshold for more aggressive adaptation of Q.
*
* Valid values in the range 0-1000.
*/
unsigned int rc_overshoot_pct;
/*
* decoder buffer model parameters
*/
/*!\brief Decoder Buffer Size
*
* This value indicates the amount of data that may be buffered by the
* decoding application. Note that this value is expressed in units of
* time (milliseconds). For example, a value of 5000 indicates that the
* client will buffer (at least) 5000ms worth of encoded data. Use the
* target bitrate (#rc_target_bitrate) to convert to bits/bytes, if
* necessary.
*/
unsigned int rc_buf_sz;
/*!\brief Decoder Buffer Initial Size
*
* This value indicates the amount of data that will be buffered by the
* decoding application prior to beginning playback. This value is
* expressed in units of time (milliseconds). Use the target bitrate
* (#rc_target_bitrate) to convert to bits/bytes, if necessary.
*/
unsigned int rc_buf_initial_sz;
/*!\brief Decoder Buffer Optimal Size
*
* This value indicates the amount of data that the encoder should try
* to maintain in the decoder's buffer. This value is expressed in units
* of time (milliseconds). Use the target bitrate (#rc_target_bitrate)
* to convert to bits/bytes, if necessary.
*/
unsigned int rc_buf_optimal_sz;
/*
* 2 pass rate control parameters
*/
/*!\brief Two-pass mode per-GOP minimum bitrate
*
* This value, expressed as a percentage of the target bitrate, indicates
* the minimum bitrate to be used for a single GOP (aka "section")
*/
unsigned int rc_2pass_vbr_minsection_pct;
/*!\brief Two-pass mode per-GOP maximum bitrate
*
* This value, expressed as a percentage of the target bitrate, indicates
* the maximum bitrate to be used for a single GOP (aka "section")
*/
unsigned int rc_2pass_vbr_maxsection_pct;
/*
* keyframing settings (kf)
*/
/*!\brief Option to enable forward reference key frame
*
*/
int fwd_kf_enabled;
/*!\brief Keyframe placement mode
*
* This value indicates whether the encoder should place keyframes at a
* fixed interval, or determine the optimal placement automatically
* (as governed by the #kf_min_dist and #kf_max_dist parameters)
*/
enum aom_kf_mode kf_mode;
/*!\brief Keyframe minimum interval
*
* This value, expressed as a number of frames, prevents the encoder from
* placing a keyframe nearer than kf_min_dist to the previous keyframe. At
* least kf_min_dist frames non-keyframes will be coded before the next
* keyframe. Set kf_min_dist equal to kf_max_dist for a fixed interval.
*/
unsigned int kf_min_dist;
/*!\brief Keyframe maximum interval
*
* This value, expressed as a number of frames, forces the encoder to code
* a keyframe if one has not been coded in the last kf_max_dist frames.
* A value of 0 implies all frames will be keyframes. Set kf_min_dist
* equal to kf_max_dist for a fixed interval.
*/
unsigned int kf_max_dist;
/*!\brief sframe interval
*
* This value, expressed as a number of frames, forces the encoder to code
* an S-Frame every sframe_dist frames.
*/
unsigned int sframe_dist;
/*!\brief sframe insertion mode
*
* This value must be set to 1 or 2, and tells the encoder how to insert
* S-Frames. It will only have an effect if sframe_dist != 0.
*
* If altref is enabled:
* - if sframe_mode == 1, the considered frame will be made into an
* S-Frame only if it is an altref frame
* - if sframe_mode == 2, the next altref frame will be made into an
* S-Frame.
*
* Otherwise: the considered frame will be made into an S-Frame.
*/
unsigned int sframe_mode;
/*!\brief Tile coding mode
*
* This value indicates the tile coding mode.
* A value of 0 implies a normal non-large-scale tile coding. A value of 1
* implies a large-scale tile coding.
*/
unsigned int large_scale_tile;
/*!\brief Monochrome mode
*
* If this is nonzero, the encoder will generate a monochrome stream
* with no chroma planes.
*/
unsigned int monochrome;
/*!\brief full_still_picture_hdr
*
* If this is nonzero, the encoder will generate a full header even for
* still picture encoding. if zero, a reduced header is used for still
* picture. This flag has no effect when a regular video with more than
* a single frame is encoded.
*/
unsigned int full_still_picture_hdr;
/*!\brief Bitstream syntax mode
*
* This value indicates the bitstream syntax mode.
* A value of 0 indicates bitstream is saved as Section 5 bitstream. A value
* of 1 indicates the bitstream is saved in Annex-B format
*/
unsigned int save_as_annexb;
/*!\brief Number of explicit tile widths specified
*
* This value indicates the number of tile widths specified
* A value of 0 implies no tile widths are specified.
* Tile widths are given in the array tile_widths[]
*/
int tile_width_count;
/*!\brief Number of explicit tile heights specified
*
* This value indicates the number of tile heights specified
* A value of 0 implies no tile heights are specified.
* Tile heights are given in the array tile_heights[]
*/
int tile_height_count;
/*!\brief Maximum number of tile widths in tile widths array
*
* This define gives the maximum number of elements in the tile_widths array.
*/
#define MAX_TILE_WIDTHS 64 // maximum tile width array length
/*!\brief Array of specified tile widths
*
* This array specifies tile widths (and may be empty)
* The number of widths specified is given by tile_width_count
*/
int tile_widths[MAX_TILE_WIDTHS];
/*!\brief Maximum number of tile heights in tile heights array.
*
* This define gives the maximum number of elements in the tile_heights array.
*/
#define MAX_TILE_HEIGHTS 64 // maximum tile height array length
/*!\brief Array of specified tile heights
*
* This array specifies tile heights (and may be empty)
* The number of heights specified is given by tile_height_count
*/
int tile_heights[MAX_TILE_HEIGHTS];
/*!\brief Whether encoder should use fixed QP offsets.
*
* If a value of 1 is provided, encoder will use fixed QP offsets for frames
* at different levels of the pyramid.
* - If 'fixed_qp_offsets' is also provided, encoder will use the given
* offsets
* - If not, encoder will select the fixed offsets based on the --qp
* provided.
* If a value of 0 is provided and fixed_qp_offset are not provided, encoder
* will NOT use fixed QP offsets.
* Note: This option is only relevant for --end-usage=q.
*/
unsigned int use_fixed_qp_offsets;
/*!\brief Max number of fixed QP offsets
*
* This defines the number of elements in the fixed_qp_offsets array.
*/
#define FIXED_QP_OFFSET_COUNT 6
/*!\brief Array of fixed QP offsets
*
* This array specifies fixed QP offsets (range: 0 to 255) for frames at
* different levels of the pyramid. It is a comma-separated list of 5 values:
* - QP offset for keyframe
* - QP offset for ALTREF frame
* - QP offset for 1st level internal ARF
* - QP offset for 2nd level internal ARF
* - QP offset for 3rd level internal ARF
* Notes:
* - QP offset for leaf level frames is not explicitly specified. These frames
* use the worst quality allowed (--qp).
* - This option is only relevant for --end-usage=q.
*/
int fixed_qp_offsets[FIXED_QP_OFFSET_COUNT];
/*!\brief Codec control function to set what decoded frame hash metadata to
* write
*/
enum aom_frame_hash_mode frame_hash_metadata;
/*!\brief Codec control function to set if the hash values are written for
* each plane instead of the entire frame, unsigned int parameter
*
* \attention Only applicable if decoded frame hash metadata is not disabled.
*
* - 0 = per frame (default)
* - 1 = per plane
*/
unsigned int frame_hash_per_plane;
/*!\brief Options defined per config file
*
*/
cfg_options_t encoder_cfg;
} aom_codec_enc_cfg_t; /**< alias for struct aom_codec_enc_cfg */
/*!\brief Initialize an encoder instance
*
* Initializes a encoder context using the given interface. Applications
* should call the aom_codec_enc_init convenience macro instead of this
* function directly, to ensure that the ABI version number parameter
* is properly initialized.
*
* If the library was configured with --disable-multithread, this call
* is not thread safe and should be guarded with a lock if being used
* in a multithreaded context.
*
* \param[in] ctx Pointer to this instance's context.
* \param[in] iface Pointer to the algorithm interface to use.
* \param[in] cfg Configuration to use, if known.
* \param[in] flags Bitfield of AOM_CODEC_USE_* flags
* \param[in] ver ABI version number. Must be set to
* AOM_ENCODER_ABI_VERSION
* \retval #AOM_CODEC_OK
* The decoder algorithm initialized.
* \retval #AOM_CODEC_MEM_ERROR
* Memory allocation failed.
*/
aom_codec_err_t aom_codec_enc_init_ver(aom_codec_ctx_t *ctx,
aom_codec_iface_t *iface,
const aom_codec_enc_cfg_t *cfg,
aom_codec_flags_t flags, int ver);
/*!\brief Convenience macro for aom_codec_enc_init_ver()
*
* Ensures the ABI version parameter is properly set.
*/
#define aom_codec_enc_init(ctx, iface, cfg, flags) \
aom_codec_enc_init_ver(ctx, iface, cfg, flags, AOM_ENCODER_ABI_VERSION)
/*!\brief Get the default configuration for a usage.
*
* Initializes an encoder configuration structure with default values. Supports
* the notion of "usages" so that an algorithm may offer different default
* settings depending on the user's intended goal. This function \ref SHOULD
* be called by all applications to initialize the configuration structure
* before specializing the configuration with application specific values.
*
* \param[in] iface Pointer to the algorithm interface to use.
* \param[out] cfg Configuration buffer to populate.
* \param[in] usage Algorithm specific usage value. For AV1, must be
* set to AOM_USAGE_GOOD_QUALITY (0).
*
* \retval #AOM_CODEC_OK
* The configuration was populated.
* \retval #AOM_CODEC_INCAPABLE
* Interface is not an encoder interface.
* \retval #AOM_CODEC_INVALID_PARAM
* A parameter was NULL, or the usage value was not recognized.
*/
aom_codec_err_t aom_codec_enc_config_default(aom_codec_iface_t *iface,
aom_codec_enc_cfg_t *cfg,
unsigned int usage);
/*!\brief Set or change configuration
*
* Reconfigures an encoder instance according to the given configuration.
*
* \param[in] ctx Pointer to this instance's context
* \param[in] cfg Configuration buffer to use
*
* \retval #AOM_CODEC_OK
* The configuration was populated.
* \retval #AOM_CODEC_INCAPABLE
* Interface is not an encoder interface.
* \retval #AOM_CODEC_INVALID_PARAM
* A parameter was NULL, or the usage value was not recognized.
*/
aom_codec_err_t aom_codec_enc_config_set(aom_codec_ctx_t *ctx,
const aom_codec_enc_cfg_t *cfg);
/*!\brief Get global stream headers
*
* Retrieves a stream level global header packet, if supported by the codec.
* Calls to this function should be deferred until all configuration information
* has been passed to libaom. Otherwise the global header data may be
* invalidated by additional configuration changes.
*
* The AV1 implementation of this function returns an OBU. The OBU returned is
* in Low Overhead Bitstream Format. Specifically, the obu_has_size_field bit is
* set, and the buffer contains the obu_size field for the returned OBU.
*
* \param[in] ctx Pointer to this instance's context
*
* \retval NULL
* Encoder does not support global header, or an error occurred while
* generating the global header.
*
* \retval Non-NULL
* Pointer to buffer containing global header packet. The caller owns the
* memory associated with this buffer, and must free the 'buf' member of the
* aom_fixed_buf_t as well as the aom_fixed_buf_t pointer. Memory returned
* must be freed via call to free().
*/
aom_fixed_buf_t *aom_codec_get_global_headers(aom_codec_ctx_t *ctx);
/*!\brief usage parameter analogous to AV1 GOOD QUALITY mode. */
#define AOM_USAGE_GOOD_QUALITY (0)
/*!\brief Encode a frame
*
* Encodes a video frame at the given "presentation time." The presentation
* time stamp (PTS) \ref MUST be strictly increasing.
*
* When the last frame has been passed to the encoder, this function should
* continue to be called in a loop, with the img parameter set to NULL. This
* will signal the end-of-stream condition to the encoder and allow it to
* encode any held buffers. Encoding is complete when aom_codec_encode() is
* called with img set to NULL and aom_codec_get_cx_data() returns no data.
*
* \param[in] ctx Pointer to this instance's context
* \param[in] img Image data to encode, NULL to flush.
* \param[in] pts Presentation time stamp, in timebase units. If img
* is NULL, pts is ignored.
* \param[in] duration Duration to show frame, in timebase units. If img
* is not NULL, duration must be nonzero. If img is
* NULL, duration is ignored.
* \param[in] flags Flags to use for encoding this frame.
*
* \retval #AOM_CODEC_OK
* The configuration was populated.
* \retval #AOM_CODEC_INCAPABLE
* Interface is not an encoder interface.
* \retval #AOM_CODEC_INVALID_PARAM
* A parameter was NULL, the image format is unsupported, etc.
*/
aom_codec_err_t aom_codec_encode(aom_codec_ctx_t *ctx, const aom_image_t *img,
aom_codec_pts_t pts, unsigned long duration,
aom_enc_frame_flags_t flags);
/*!\brief Set compressed data output buffer
*
* Sets the buffer that the codec should output the compressed data
* into. This call effectively sets the buffer pointer returned in the
* next AOM_CODEC_CX_FRAME_PKT packet. Subsequent packets will be
* appended into this buffer. The buffer is preserved across frames,
* so applications must periodically call this function after flushing
* the accumulated compressed data to disk or to the network to reset
* the pointer to the buffer's head.
*
* `pad_before` bytes will be skipped before writing the compressed
* data, and `pad_after` bytes will be appended to the packet. The size
* of the packet will be the sum of the size of the actual compressed
* data, pad_before, and pad_after. The padding bytes will be preserved
* (not overwritten).
*
* Note that calling this function does not guarantee that the returned
* compressed data will be placed into the specified buffer. In the
* event that the encoded data will not fit into the buffer provided,
* the returned packet \ref MAY point to an internal buffer, as it would
* if this call were never used. In this event, the output packet will
* NOT have any padding, and the application must free space and copy it
* to the proper place. This is of particular note in configurations
* that may output multiple packets for a single encoded frame (e.g., lagged
* encoding) or if the application does not reset the buffer periodically.
*
* Applications may restore the default behavior of the codec providing
* the compressed data buffer by calling this function with a NULL
* buffer.
*
* Applications \ref MUSTNOT call this function during iteration of
* aom_codec_get_cx_data().
*
* \param[in] ctx Pointer to this instance's context
* \param[in] buf Buffer to store compressed data into
* \param[in] pad_before Bytes to skip before writing compressed data
* \param[in] pad_after Bytes to skip after writing compressed data
*
* \retval #AOM_CODEC_OK
* The buffer was set successfully.
* \retval #AOM_CODEC_INVALID_PARAM
* A parameter was NULL, the image format is unsupported, etc.
*/
aom_codec_err_t aom_codec_set_cx_data_buf(aom_codec_ctx_t *ctx,
const aom_fixed_buf_t *buf,
unsigned int pad_before,
unsigned int pad_after);
/*!\brief Encoded data iterator
*
* Iterates over a list of data packets to be passed from the encoder to the
* application. The different kinds of packets available are enumerated in
* #aom_codec_cx_pkt_kind.
*
* #AOM_CODEC_CX_FRAME_PKT packets should be passed to the application's
* muxer. Multiple compressed frames may be in the list.
* #AOM_CODEC_STATS_PKT packets should be appended to a global buffer.
*
* The application \ref MUST silently ignore any packet kinds that it does
* not recognize or support.
*
* The data buffers returned from this function are only guaranteed to be
* valid until the application makes another call to any aom_codec_* function.
*
* \param[in] ctx Pointer to this instance's context
* \param[in,out] iter Iterator storage, initialized to NULL
*
* \return Returns a pointer to an output data packet (compressed frame data,
* two-pass statistics, etc.) or NULL to signal end-of-list.
*
*/
const aom_codec_cx_pkt_t *aom_codec_get_cx_data(aom_codec_ctx_t *ctx,
aom_codec_iter_t *iter);
/*!\brief Get Preview Frame
*
* Returns an image that can be used as a preview. Shows the image as it would
* exist at the decompressor. The application \ref MUST NOT write into this
* image buffer.
*
* \param[in] ctx Pointer to this instance's context
*
* \return Returns a pointer to a preview image, or NULL if no image is
* available.
*
*/
const aom_image_t *aom_codec_get_preview_frame(aom_codec_ctx_t *ctx);
/*!@} - end defgroup encoder*/
#ifdef __cplusplus
}
#endif
#endif // AOM_AOM_AOM_ENCODER_H_