| 6 | * tree. An additional intellectual property rights grant can be found |
| 7 | * in the file PATENTS. All contributing project authors may |
| 8 | * be found in the AUTHORS file in the root of the source tree. |
| 9 | */ |
| 10 | #ifndef VPX_VPX_VPX_ENCODER_H_ |
| 11 | #define VPX_VPX_VPX_ENCODER_H_ |
| 12 |
| 13 | /*!\defgroup encoder Encoder Algorithm Interface |
| 14 | * \ingroup codec |
| 15 | * This abstraction allows applications using this encoder to easily support |
| 16 | * multiple video formats with minimal code duplication. This section describes |
| 17 | * the interface common to all encoders. |
| 18 | * @{ |
| 19 | */ |
| 20 |
| 21 | /*!\file |
| 22 | * \brief Describes the encoder algorithm interface to applications. |
| 23 | * |
| 24 | * This file describes the interface between an application and a |
| 25 | * video encoder algorithm. |
| 26 | * |
| 27 | */ |
| 28 | #ifdef __cplusplus |
| 29 | extern "C" { |
| 30 | #endif |
| 31 |
| 32 | #include "./vpx_codec.h" // IWYU pragma: export |
| 33 | #include "./vpx_ext_ratectrl.h" |
| 34 |
| 35 | /*! Temporal Scalability: Maximum length of the sequence defining frame |
| 36 | * layer membership |
| 37 | */ |
| 38 | #define VPX_TS_MAX_PERIODICITY 16 |
| 39 |
| 40 | /*! Temporal Scalability: Maximum number of coding layers */ |
| 41 | #define VPX_TS_MAX_LAYERS 5 |
| 42 |
| 43 | /*! Temporal+Spatial Scalability: Maximum number of coding layers */ |
| 44 | #define VPX_MAX_LAYERS 12 // 3 temporal + 4 spatial layers are allowed. |
| 45 |
| 46 | /*! Spatial Scalability: Maximum number of coding layers */ |
| 47 | #define VPX_SS_MAX_LAYERS 5 |
| 48 |
| 49 | /*! Spatial Scalability: Default number of coding layers */ |
| 50 | #define VPX_SS_DEFAULT_LAYERS 1 |
| 51 |
| 52 | /*!\brief Current ABI version number |
| 53 | * |
| 54 | * \internal |
| 55 | * If this file is altered in any way that changes the ABI, this value |
| 56 | * must be bumped. Examples include, but are not limited to, changing |
| 57 | * types, removing or reassigning enums, adding/removing/rearranging |
| 58 | * fields to structures |
| 59 | * |
| 60 | * \note |
| 61 | * VPX_ENCODER_ABI_VERSION has a VPX_EXT_RATECTRL_ABI_VERSION component |
| 62 | * because the VP9E_SET_EXTERNAL_RATE_CONTROL codec control uses |
| 63 | * vpx_rc_funcs_t. |
| 64 | */ |
| 65 | #define VPX_ENCODER_ABI_VERSION \ |
| 66 | (18 + VPX_CODEC_ABI_VERSION + \ |
| 67 | VPX_EXT_RATECTRL_ABI_VERSION) /**<\hideinitializer*/ |
| 68 |
| 69 | /*! \brief Encoder capabilities bitfield |
| 70 | * |
| 71 | * Each encoder advertises the capabilities it supports as part of its |
| 72 | * ::vpx_codec_iface_t interface structure. Capabilities are extra |
| 73 | * interfaces or functionality, and are not required to be supported |
| 74 | * by an encoder. |
| 75 | * |
| 76 | * The available flags are specified by VPX_CODEC_CAP_* defines. |
| 77 | */ |
| 78 | #define VPX_CODEC_CAP_PSNR 0x10000 /**< Can issue PSNR packets */ |
| 79 |
| 80 | /*! Can output one partition at a time. Each partition is returned in its |
| 81 | * own VPX_CODEC_CX_FRAME_PKT, with the FRAME_IS_FRAGMENT flag set for |
| 82 | * every partition but the last. In this mode all frames are always |
| 83 | * returned partition by partition. |
| 84 | */ |
| 85 | #define VPX_CODEC_CAP_OUTPUT_PARTITION 0x20000 |
| 86 |
| 87 | /*! \brief Initialization-time Feature Enabling |
| 88 | * |
| 89 | * Certain codec features must be known at initialization time, to allow |
| 90 | * for proper memory allocation. |
| 91 | * |
| 92 | * The available flags are specified by VPX_CODEC_USE_* defines. |
| 93 | */ |
| 94 | #define VPX_CODEC_USE_PSNR 0x10000 /**< Calculate PSNR on each frame */ |
| 95 | /*!\brief Make the encoder output one partition at a time. */ |
| 96 | #define VPX_CODEC_USE_OUTPUT_PARTITION 0x20000 |
| 97 | #define VPX_CODEC_USE_HIGHBITDEPTH 0x40000 /**< Use high bitdepth */ |
| 98 |
| 99 | /*!\brief Generic fixed size buffer structure |
| 100 | * |
| 101 | * This structure is able to hold a reference to any fixed size buffer. |
| 102 | */ |
| 103 | typedef struct vpx_fixed_buf { |
| 104 | void *buf; /**< Pointer to the data */ |
| 105 | size_t sz; /**< Length of the buffer, in chars */ |
| 106 | } vpx_fixed_buf_t; /**< alias for struct vpx_fixed_buf */ |
| 107 |
| 108 | /*!\brief Time Stamp Type |
| 109 | * |
| 110 | * An integer, which when multiplied by the stream's time base, provides |
| 111 | * the absolute time of a sample. |
| 112 | */ |
| 113 | typedef int64_t vpx_codec_pts_t; |
| 114 |
| 115 | /*!\brief Compressed Frame Flags |
| 116 | * |
| 117 | * This type represents a bitfield containing information about a compressed |
| 118 | * frame that may be useful to an application. The most significant 16 bits |
| 119 | * can be used by an algorithm to provide additional detail, for example to |
| 120 | * support frame types that are codec specific (MPEG-1 D-frames for example) |
| 121 | */ |
| 122 | typedef uint32_t vpx_codec_frame_flags_t; |
| 123 | #define VPX_FRAME_IS_KEY 0x1u /**< frame is the start of a GOP */ |
| 124 | /*!\brief frame can be dropped without affecting the stream (no future frame |
| 125 | * depends on this one) */ |
| 126 | #define VPX_FRAME_IS_DROPPABLE 0x2u |
| 127 | /*!\brief frame should be decoded but will not be shown */ |
| 128 | #define VPX_FRAME_IS_INVISIBLE 0x4u |
| 129 | /*!\brief this is a fragment of the encoded frame */ |
| 130 | #define VPX_FRAME_IS_FRAGMENT 0x8u |
| 131 |
| 132 | /*!\brief Error Resilient flags |
| 133 | * |
| 134 | * These flags define which error resilient features to enable in the |
| 135 | * encoder. The flags are specified through the |
| 136 | * vpx_codec_enc_cfg::g_error_resilient variable. |
| 137 | */ |
| 138 | typedef uint32_t vpx_codec_er_flags_t; |
| 139 | /*!\brief Improve resiliency against losses of whole frames */ |
| 140 | #define VPX_ERROR_RESILIENT_DEFAULT 0x1u |
| 141 | /*!\brief The frame partitions are independently decodable by the bool decoder, |
| 142 | * meaning that partitions can be decoded even though earlier partitions have |
| 143 | * been lost. Note that intra prediction is still done over the partition |
| 144 | * boundary. |
| 145 | * \note This is only supported by VP8.*/ |
| 146 | #define VPX_ERROR_RESILIENT_PARTITIONS 0x2u |
| 147 |
| 148 | /*!\brief Encoder output packet variants |
| 149 | * |
| 150 | * This enumeration lists the different kinds of data packets that can be |
| 151 | * returned by calls to vpx_codec_get_cx_data(). Algorithms \ref MAY |
| 152 | * extend this list to provide additional functionality. |
| 153 | */ |
| 154 | enum vpx_codec_cx_pkt_kind { |
| 155 | VPX_CODEC_CX_FRAME_PKT, /**< Compressed video frame */ |
| 156 | VPX_CODEC_STATS_PKT, /**< Two-pass statistics for this frame */ |
| 157 | VPX_CODEC_FPMB_STATS_PKT, /**< first pass mb statistics for this frame */ |
| 158 | VPX_CODEC_PSNR_PKT, /**< PSNR statistics for this frame */ |
| 159 | VPX_CODEC_CUSTOM_PKT = 256 /**< Algorithm extensions */ |
| 160 | }; |
| 161 |
| 162 | /*!\brief Encoder output packet |
| 163 | * |
| 164 | * This structure contains the different kinds of output data the encoder |
| 165 | * may produce while compressing a frame. |
| 166 | */ |
| 167 | typedef struct vpx_codec_cx_pkt { |
| 168 | enum vpx_codec_cx_pkt_kind kind; /**< packet variant */ |
| 169 | union { |
| 170 | struct { |
| 171 | void *buf; /**< compressed data buffer */ |
| 172 | size_t sz; /**< length of compressed data */ |
| 173 | /*!\brief time stamp to show frame (in timebase units) */ |
| 174 | vpx_codec_pts_t pts; |
| 175 | /*!\brief duration to show frame (in timebase units) */ |
| 176 | unsigned long duration; |
| 177 | vpx_codec_frame_flags_t flags; /**< flags for this frame */ |
| 178 | /*!\brief the partition id defines the decoding order of the partitions. |
| 179 | * Only applicable when "output partition" mode is enabled. First |
| 180 | * partition has id 0.*/ |
| 181 | int partition_id; |
| 182 | /*!\brief Width and height of frames in this packet. VP8 will only use the |
| 183 | * first one.*/ |
| 184 | unsigned int width[VPX_SS_MAX_LAYERS]; /**< frame width */ |
| 185 | unsigned int height[VPX_SS_MAX_LAYERS]; /**< frame height */ |
| 186 | /*!\brief Flag to indicate if spatial layer frame in this packet is |
| 187 | * encoded or dropped. VP8 will always be set to 1.*/ |
| 188 | uint8_t spatial_layer_encoded[VPX_SS_MAX_LAYERS]; |
| 189 | } frame; /**< data for compressed frame packet */ |
| 190 | vpx_fixed_buf_t twopass_stats; /**< data for two-pass packet */ |
| 191 | vpx_fixed_buf_t firstpass_mb_stats; /**< first pass mb packet */ |
| 192 | struct vpx_psnr_pkt { |
| 193 | unsigned int samples[4]; /**< Number of samples, total/y/u/v */ |
| 194 | uint64_t sse[4]; /**< sum squared error, total/y/u/v */ |
| 195 | double psnr[4]; /**< PSNR, total/y/u/v */ |
| 196 | int spatial_layer_id; /**< Spatial layer id */ |
| 197 | } psnr; /**< data for PSNR packet */ |
| 198 | vpx_fixed_buf_t raw; /**< data for arbitrary packets */ |
| 199 |
| 200 | /* This packet size is fixed to allow codecs to extend this |
| 201 | * interface without having to manage storage for raw packets, |
| 202 | * i.e., if it's smaller than 128 bytes, you can store in the |
| 203 | * packet list directly. |
| 204 | */ |
| 205 | char pad[128 - sizeof(enum vpx_codec_cx_pkt_kind)]; /**< fixed sz */ |
| 206 | } data; /**< packet data */ |
| 207 | } vpx_codec_cx_pkt_t; /**< alias for struct vpx_codec_cx_pkt */ |
| 208 |
| 209 | /*!\brief Encoder return output buffer callback |
| 210 | * |
| 211 | * This callback function, when registered, returns with packets when each |
| 212 | * spatial layer is encoded. |
| 213 | */ |
| 214 | typedef void (*vpx_codec_enc_output_cx_pkt_cb_fn_t)(vpx_codec_cx_pkt_t *pkt, |
| 215 | void *user_data); |
| 216 |
| 217 | /*!\brief Callback function pointer / user data pair storage */ |
| 218 | typedef struct vpx_codec_enc_output_cx_cb_pair { |
| 219 | vpx_codec_enc_output_cx_pkt_cb_fn_t output_cx_pkt; /**< Callback function */ |
| 220 | void *user_priv; /**< Pointer to private data */ |
| 221 | } vpx_codec_priv_output_cx_pkt_cb_pair_t; |
| 222 |
| 223 | /*!\brief Rational Number |
| 224 | * |
| 225 | * This structure holds a fractional value. |
| 226 | */ |
| 227 | typedef struct vpx_rational { |
| 228 | int num; /**< fraction numerator */ |
| 229 | int den; /**< fraction denominator */ |
| 230 | } vpx_rational_t; /**< alias for struct vpx_rational */ |
| 231 |
| 232 | /*!\brief Multi-pass Encoding Pass */ |
| 233 | typedef enum vpx_enc_pass { |
| 234 | VPX_RC_ONE_PASS, /**< Single pass mode */ |
| 235 | VPX_RC_FIRST_PASS, /**< First pass of multi-pass mode */ |
| 236 | VPX_RC_LAST_PASS /**< Final pass of multi-pass mode */ |
| 237 | } vpx_enc_pass; |
| 238 |
| 239 | /*!\brief Rate control mode */ |
| 240 | enum vpx_rc_mode { |
| 241 | VPX_VBR, /**< Variable Bit Rate (VBR) mode */ |
| 242 | VPX_CBR, /**< Constant Bit Rate (CBR) mode */ |
| 243 | VPX_CQ, /**< Constrained Quality (CQ) mode */ |
| 244 | VPX_Q, /**< Constant Quality (Q) mode */ |
| 245 | }; |
| 246 |
| 247 | /*!\brief Keyframe placement mode. |
| 248 | * |
| 249 | * This enumeration determines whether keyframes are placed automatically by |
| 250 | * the encoder or whether this behavior is disabled. Older releases of this |
| 251 | * SDK were implemented such that VPX_KF_FIXED meant keyframes were disabled. |
| 252 | * This name is confusing for this behavior, so the new symbols to be used |
| 253 | * are VPX_KF_AUTO and VPX_KF_DISABLED. |
| 254 | */ |
| 255 | enum vpx_kf_mode { |
| 256 | VPX_KF_FIXED, /**< deprecated, implies VPX_KF_DISABLED */ |
| 257 | VPX_KF_AUTO, /**< Encoder determines optimal placement automatically */ |
| 258 | VPX_KF_DISABLED = 0 /**< Encoder does not place keyframes. */ |
| 259 | }; |
| 260 |
| 261 | /*!\brief Encoded Frame Flags |
| 262 | * |
| 263 | * This type indicates a bitfield to be passed to vpx_codec_encode(), defining |
| 264 | * per-frame boolean values. By convention, bits common to all codecs will be |
| 265 | * named VPX_EFLAG_*, and bits specific to an algorithm will be named |
| 266 | * /algo/_eflag_*. The lower order 16 bits are reserved for common use. |
| 267 | */ |
| 268 | typedef long vpx_enc_frame_flags_t; |
| 269 | #define VPX_EFLAG_FORCE_KF (1 << 0) /**< Force this frame to be a keyframe */ |
| 270 | /** Calculate PSNR on this frame, requires g_lag_in_frames to be 0 */ |
| 271 | #define VPX_EFLAG_CALCULATE_PSNR (1 << 1) |
| 272 |
| 273 | /*!\brief Encoder configuration structure |
| 274 | * |
| 275 | * This structure contains the encoder settings that have common representations |
| 276 | * across all codecs. This doesn't imply that all codecs support all features, |
| 277 | * however. |
| 278 | */ |
| 279 | typedef struct vpx_codec_enc_cfg { |
| 280 | /* |
| 281 | * generic settings (g) |
| 282 | */ |
| 283 |
| 284 | /*!\brief Deprecated: Algorithm specific "usage" value |
| 285 | * |
| 286 | * This value must be zero. |
| 287 | */ |
| 288 | unsigned int g_usage; |
| 289 |
| 290 | /*!\brief Maximum number of threads to use |
| 291 | * |
| 292 | * For multi-threaded implementations, use no more than this number of |
| 293 | * threads. The codec may use fewer threads than allowed. The value |
| 294 | * 0 is equivalent to the value 1. |
| 295 | */ |
| 296 | unsigned int g_threads; |
| 297 |
| 298 | /*!\brief Bitstream profile to use |
| 299 | * |
| 300 | * Some codecs support a notion of multiple bitstream profiles. Typically |
| 301 | * this maps to a set of features that are turned on or off. Often the |
| 302 | * profile to use is determined by the features of the intended decoder. |
| 303 | * Consult the documentation for the codec to determine the valid values |
| 304 | * for this parameter, or set to zero for a sane default. |
| 305 | */ |
| 306 | unsigned int g_profile; /**< profile of bitstream to use */ |
| 307 |
| 308 | /*!\brief Width of the frame |
| 309 | * |
| 310 | * This value identifies the presentation resolution of the frame, |
| 311 | * in pixels. Note that the frames passed as input to the encoder must |
| 312 | * have this resolution. Frames will be presented by the decoder in this |
| 313 | * resolution, independent of any spatial resampling the encoder may do. |
| 314 | */ |
| 315 | unsigned int g_w; |
| 316 |
| 317 | /*!\brief Height of the frame |
| 318 | * |
| 319 | * This value identifies the presentation resolution of the frame, |
| 320 | * in pixels. Note that the frames passed as input to the encoder must |
| 321 | * have this resolution. Frames will be presented by the decoder in this |
| 322 | * resolution, independent of any spatial resampling the encoder may do. |
| 323 | */ |
| 324 | unsigned int g_h; |
| 325 |
| 326 | /*!\brief Bit-depth of the codec |
| 327 | * |
| 328 | * This value identifies the bit_depth of the codec, |
| 329 | * Only certain bit-depths are supported as identified in the |
| 330 | * vpx_bit_depth_t enum. |
| 331 | */ |
| 332 | vpx_bit_depth_t g_bit_depth; |
| 333 |
| 334 | /*!\brief Bit-depth of the input frames |
| 335 | * |
| 336 | * This value identifies the bit_depth of the input frames in bits. |
| 337 | * Note that the frames passed as input to the encoder must have |
| 338 | * this bit-depth. |
| 339 | */ |
| 340 | unsigned int g_input_bit_depth; |
| 341 |
| 342 | /*!\brief Stream timebase units |
| 343 | * |
| 344 | * Indicates the smallest interval of time, in seconds, used by the stream. |
| 345 | * For fixed frame rate material, or variable frame rate material where |
| 346 | * frames are timed at a multiple of a given clock (ex: video capture), |
| 347 | * the \ref RECOMMENDED method is to set the timebase to the reciprocal |
| 348 | * of the frame rate (ex: 1001/30000 for 29.970 Hz NTSC). This allows the |
| 349 | * pts to correspond to the frame number, which can be handy. For |
| 350 | * re-encoding video from containers with absolute time timestamps, the |
| 351 | * \ref RECOMMENDED method is to set the timebase to that of the parent |
| 352 | * container or multimedia framework (ex: 1/1000 for ms, as in FLV). |
| 353 | */ |
| 354 | struct vpx_rational g_timebase; |
| 355 |
| 356 | /*!\brief Enable error resilient modes. |
| 357 | * |
| 358 | * The error resilient bitfield indicates to the encoder which features |
| 359 | * it should enable to take measures for streaming over lossy or noisy |
| 360 | * links. |
| 361 | */ |
| 362 | vpx_codec_er_flags_t g_error_resilient; |
| 363 |
| 364 | /*!\brief Multi-pass Encoding Mode |
| 365 | * |
| 366 | * This value should be set to the current phase for multi-pass encoding. |
| 367 | * For single pass, set to #VPX_RC_ONE_PASS. |
| 368 | */ |
| 369 | enum vpx_enc_pass g_pass; |
| 370 |
| 371 | /*!\brief Allow lagged encoding |
| 372 | * |
| 373 | * If set, this value allows the encoder to consume a number of input |
| 374 | * frames before producing output frames. This allows the encoder to |
| 375 | * base decisions for the current frame on future frames. This does |
| 376 | * increase the latency of the encoding pipeline, so it is not appropriate |
| 377 | * in all situations (ex: realtime encoding). |
| 378 | * |
| 379 | * Note that this is a maximum value -- the encoder may produce frames |
| 380 | * sooner than the given limit. Set this value to 0 to disable this |
| 381 | * feature. |
| 382 | */ |
| 383 | unsigned int g_lag_in_frames; |
| 384 |
| 385 | /* |
| 386 | * rate control settings (rc) |
| 387 | */ |
| 388 |
| 389 | /*!\brief Temporal resampling configuration, if supported by the codec. |
| 390 | * |
| 391 | * Temporal resampling allows the codec to "drop" frames as a strategy to |
| 392 | * meet its target data rate. This can cause temporal discontinuities in |
| 393 | * the encoded video, which may appear as stuttering during playback. This |
| 394 | * trade-off is often acceptable, but for many applications is not. It can |
| 395 | * be disabled in these cases. |
| 396 | * |
| 397 | * This threshold is described as a percentage of the target data buffer. |
| 398 | * When the data buffer falls below this percentage of fullness, a |
| 399 | * dropped frame is indicated. Set the threshold to zero (0) to disable |
| 400 | * this feature. |
| 401 | */ |
| 402 | unsigned int rc_dropframe_thresh; |
| 403 |
| 404 | /*!\brief Enable/disable spatial resampling, if supported by the codec. |
| 405 | * |
| 406 | * Spatial resampling allows the codec to compress a lower resolution |
| 407 | * version of the frame, which is then upscaled by the encoder to the |
| 408 | * correct presentation resolution. This increases visual quality at |
| 409 | * low data rates, at the expense of CPU time on the encoder/decoder. |
| 410 | */ |
| 411 | unsigned int rc_resize_allowed; |
| 412 |
| 413 | /*!\brief Internal coded frame width. |
| 414 | * |
| 415 | * If spatial resampling is enabled this specifies the width of the |
| 416 | * encoded frame. |
| 417 | */ |
| 418 | unsigned int rc_scaled_width; |
| 419 |
| 420 | /*!\brief Internal coded frame height. |
| 421 | * |
| 422 | * If spatial resampling is enabled this specifies the height of the |
| 423 | * encoded frame. |
| 424 | */ |
| 425 | unsigned int rc_scaled_height; |
| 426 |
| 427 | /*!\brief Spatial resampling up watermark. |
| 428 | * |
| 429 | * This threshold is described as a percentage of the target data buffer. |
| 430 | * When the data buffer rises above this percentage of fullness, the |
| 431 | * encoder will step up to a higher resolution version of the frame. |
| 432 | */ |
| 433 | unsigned int rc_resize_up_thresh; |
| 434 |
| 435 | /*!\brief Spatial resampling down watermark. |
| 436 | * |
| 437 | * This threshold is described as a percentage of the target data buffer. |
| 438 | * When the data buffer falls below this percentage of fullness, the |
| 439 | * encoder will step down to a lower resolution version of the frame. |
| 440 | */ |
| 441 | unsigned int rc_resize_down_thresh; |
| 442 |
| 443 | /*!\brief Rate control algorithm to use. |
| 444 | * |
| 445 | * Indicates whether the end usage of this stream is to be streamed over |
| 446 | * a bandwidth constrained link, indicating that Constant Bit Rate (CBR) |
| 447 | * mode should be used, or whether it will be played back on a high |
| 448 | * bandwidth link, as from a local disk, where higher variations in |
| 449 | * bitrate are acceptable. |
| 450 | */ |
| 451 | enum vpx_rc_mode rc_end_usage; |
| 452 |
| 453 | /*!\brief Two-pass stats buffer. |
| 454 | * |
| 455 | * A buffer containing all of the stats packets produced in the first |
| 456 | * pass, concatenated. |
| 457 | */ |
| 458 | vpx_fixed_buf_t rc_twopass_stats_in; |
| 459 |
| 460 | /*!\brief first pass mb stats buffer. |
| 461 | * |
| 462 | * A buffer containing all of the first pass mb stats packets produced |
| 463 | * in the first pass, concatenated. |
| 464 | */ |
| 465 | vpx_fixed_buf_t rc_firstpass_mb_stats_in; |
| 466 |
| 467 | /*!\brief Target data rate |
| 468 | * |
| 469 | * Target bitrate to use for this stream, in kilobits per second. |
| 470 | * Internally capped to the smaller of the uncompressed bitrate and |
| 471 | * 1000000 kilobits per second. |
| 472 | */ |
| 473 | unsigned int rc_target_bitrate; |
| 474 |
| 475 | /* |
| 476 | * quantizer settings |
| 477 | */ |
| 478 |
| 479 | /*!\brief Minimum (Best Quality) Quantizer |
| 480 | * |
| 481 | * The quantizer is the most direct control over the quality of the |
| 482 | * encoded image. The range of valid values for the quantizer is codec |
| 483 | * specific. Consult the documentation for the codec to determine the |
| 484 | * values to use. |
| 485 | */ |
| 486 | unsigned int rc_min_quantizer; |
| 487 |
| 488 | /*!\brief Maximum (Worst Quality) Quantizer |
| 489 | * |
| 490 | * The quantizer is the most direct control over the quality of the |
| 491 | * encoded image. The range of valid values for the quantizer is codec |
| 492 | * specific. Consult the documentation for the codec to determine the |
| 493 | * values to use. |
| 494 | */ |
| 495 | unsigned int rc_max_quantizer; |
| 496 |
| 497 | /* |
| 498 | * bitrate tolerance |
| 499 | */ |
| 500 |
| 501 | /*!\brief Rate control adaptation undershoot control |
| 502 | * |
| 503 | * VP8: Expressed as a percentage of the target bitrate, |
| 504 | * controls the maximum allowed adaptation speed of the codec. |
| 505 | * This factor controls the maximum amount of bits that can |
| 506 | * be subtracted from the target bitrate in order to compensate |
| 507 | * for prior overshoot. |
| 508 | * VP9: Expressed as a percentage of the target bitrate, a threshold |
| 509 | * undershoot level (current rate vs target) beyond which more aggressive |
| 510 | * corrective measures are taken. |
| 511 | * * |
| 512 | * Valid values in the range VP8:0-100 VP9: 0-100. |
| 513 | */ |
| 514 | unsigned int rc_undershoot_pct; |
| 515 |
| 516 | /*!\brief Rate control adaptation overshoot control |
| 517 | * |
| 518 | * VP8: Expressed as a percentage of the target bitrate, |
| 519 | * controls the maximum allowed adaptation speed of the codec. |
| 520 | * This factor controls the maximum amount of bits that can |
| 521 | * be added to the target bitrate in order to compensate for |
| 522 | * prior undershoot. |
| 523 | * VP9: Expressed as a percentage of the target bitrate, a threshold |
| 524 | * overshoot level (current rate vs target) beyond which more aggressive |
| 525 | * corrective measures are taken. |
| 526 | * |
| 527 | * Valid values in the range VP8:0-100 VP9: 0-100. |
| 528 | */ |
| 529 | unsigned int rc_overshoot_pct; |
| 530 |
| 531 | /* |
| 532 | * decoder buffer model parameters |
| 533 | */ |
| 534 |
| 535 | /*!\brief Decoder Buffer Size |
| 536 | * |
| 537 | * This value indicates the amount of data that may be buffered by the |
| 538 | * decoding application. Note that this value is expressed in units of |
| 539 | * time (milliseconds). For example, a value of 5000 indicates that the |
| 540 | * client will buffer (at least) 5000ms worth of encoded data. Use the |
| 541 | * target bitrate (#rc_target_bitrate) to convert to bits/bytes, if |
| 542 | * necessary. |
| 543 | */ |
| 544 | unsigned int rc_buf_sz; |
| 545 |
| 546 | /*!\brief Decoder Buffer Initial Size |
| 547 | * |
| 548 | * This value indicates the amount of data that will be buffered by the |
| 549 | * decoding application prior to beginning playback. This value is |
| 550 | * expressed in units of time (milliseconds). Use the target bitrate |
| 551 | * (#rc_target_bitrate) to convert to bits/bytes, if necessary. |
| 552 | */ |
| 553 | unsigned int rc_buf_initial_sz; |
| 554 |
| 555 | /*!\brief Decoder Buffer Optimal Size |
| 556 | * |
| 557 | * This value indicates the amount of data that the encoder should try |
| 558 | * to maintain in the decoder's buffer. This value is expressed in units |
| 559 | * of time (milliseconds). Use the target bitrate (#rc_target_bitrate) |
| 560 | * to convert to bits/bytes, if necessary. |
| 561 | */ |
| 562 | unsigned int rc_buf_optimal_sz; |
| 563 |
| 564 | /* |
| 565 | * 2 pass rate control parameters |
| 566 | */ |
| 567 |
| 568 | /*!\brief Two-pass mode CBR/VBR bias |
| 569 | * |
| 570 | * Bias, expressed on a scale of 0 to 100, for determining target size |
| 571 | * for the current frame. The value 0 indicates the optimal CBR mode |
| 572 | * value should be used. The value 100 indicates the optimal VBR mode |
| 573 | * value should be used. Values in between indicate which way the |
| 574 | * encoder should "lean." |
| 575 | */ |
| 576 | unsigned int rc_2pass_vbr_bias_pct; |
| 577 |
| 578 | /*!\brief Two-pass mode per-GOP minimum bitrate |
| 579 | * |
| 580 | * This value, expressed as a percentage of the target bitrate, indicates |
| 581 | * the minimum bitrate to be used for a single GOP (aka "section") |
| 582 | */ |
| 583 | unsigned int rc_2pass_vbr_minsection_pct; |
| 584 |
| 585 | /*!\brief Two-pass mode per-GOP maximum bitrate |
| 586 | * |
| 587 | * This value, expressed as a percentage of the target bitrate, indicates |
| 588 | * the maximum bitrate to be used for a single GOP (aka "section") |
| 589 | */ |
| 590 | unsigned int rc_2pass_vbr_maxsection_pct; |
| 591 |
| 592 | /*!\brief Two-pass corpus vbr mode complexity control |
| 593 | * Used only in VP9: A value representing the corpus midpoint complexity |
| 594 | * for corpus vbr mode. This value defaults to 0 which disables corpus vbr |
| 595 | * mode in favour of normal vbr mode. |
| 596 | */ |
| 597 | unsigned int rc_2pass_vbr_corpus_complexity; |
| 598 |
| 599 | /* |
| 600 | * keyframing settings (kf) |
| 601 | */ |
| 602 |
| 603 | /*!\brief Keyframe placement mode |
| 604 | * |
| 605 | * This value indicates whether the encoder should place keyframes at a |
| 606 | * fixed interval, or determine the optimal placement automatically |
| 607 | * (as governed by the #kf_min_dist and #kf_max_dist parameters) |
| 608 | */ |
| 609 | enum vpx_kf_mode kf_mode; |
| 610 |
| 611 | /*!\brief Keyframe minimum interval |
| 612 | * |
| 613 | * This value, expressed as a number of frames, prevents the encoder from |
| 614 | * placing a keyframe nearer than kf_min_dist to the previous keyframe. At |
| 615 | * least kf_min_dist frames non-keyframes will be coded before the next |
| 616 | * keyframe. Set kf_min_dist equal to kf_max_dist for a fixed interval. |
| 617 | */ |
| 618 | unsigned int kf_min_dist; |
| 619 |
| 620 | /*!\brief Keyframe maximum interval |
| 621 | * |
| 622 | * This value, expressed as a number of frames, forces the encoder to code |
| 623 | * a keyframe if one has not been coded in the last kf_max_dist frames. |
| 624 | * A value of 0 implies all frames will be keyframes. Set kf_min_dist |
| 625 | * equal to kf_max_dist for a fixed interval. |
| 626 | */ |
| 627 | unsigned int kf_max_dist; |
| 628 |
| 629 | /* |
| 630 | * Spatial scalability settings (ss) |
| 631 | */ |
| 632 |
| 633 | /*!\brief Number of spatial coding layers. |
| 634 | * |
| 635 | * This value specifies the number of spatial coding layers to be used. |
| 636 | */ |
| 637 | unsigned int ss_number_layers; |
| 638 |
| 639 | /*!\brief Enable auto alt reference flags for each spatial layer. |
| 640 | * |
| 641 | * These values specify if auto alt reference frame is enabled for each |
| 642 | * spatial layer. |
| 643 | */ |
| 644 | int ss_enable_auto_alt_ref[VPX_SS_MAX_LAYERS]; |
| 645 |
| 646 | /*!\brief Target bitrate for each spatial layer. |
| 647 | * |
| 648 | * These values specify the target coding bitrate to be used for each |
| 649 | * spatial layer. (in kbps) |
| 650 | */ |
| 651 | unsigned int ss_target_bitrate[VPX_SS_MAX_LAYERS]; |
| 652 |
| 653 | /*!\brief Number of temporal coding layers. |
| 654 | * |
| 655 | * This value specifies the number of temporal layers to be used. |
| 656 | */ |
| 657 | unsigned int ts_number_layers; |
| 658 |
| 659 | /*!\brief Target bitrate for each temporal layer. |
| 660 | * |
| 661 | * These values specify the target coding bitrate to be used for each |
| 662 | * temporal layer. (in kbps) |
| 663 | */ |
| 664 | unsigned int ts_target_bitrate[VPX_TS_MAX_LAYERS]; |
| 665 |
| 666 | /*!\brief Frame rate decimation factor for each temporal layer. |
| 667 | * |
| 668 | * These values specify the frame rate decimation factors to apply |
| 669 | * to each temporal layer. |
| 670 | */ |
| 671 | unsigned int ts_rate_decimator[VPX_TS_MAX_LAYERS]; |
| 672 |
| 673 | /*!\brief Length of the sequence defining frame temporal layer membership. |
| 674 | * |
| 675 | * This value specifies the length of the sequence that defines the |
| 676 | * membership of frames to temporal layers. For example, if the |
| 677 | * ts_periodicity = 8, then the frames are assigned to coding layers with a |
| 678 | * repeated sequence of length 8. |
| 679 | */ |
| 680 | unsigned int ts_periodicity; |
| 681 |
| 682 | /*!\brief Template defining the membership of frames to temporal layers. |
| 683 | * |
| 684 | * This array defines the membership of frames to temporal coding layers. |
| 685 | * For a 2-layer encoding that assigns even numbered frames to one temporal |
| 686 | * layer (0) and odd numbered frames to a second temporal layer (1) with |
| 687 | * ts_periodicity=8, then ts_layer_id = (0,1,0,1,0,1,0,1). |
| 688 | */ |
| 689 | unsigned int ts_layer_id[VPX_TS_MAX_PERIODICITY]; |
| 690 |
| 691 | /*!\brief Target bitrate for each spatial/temporal layer. |
| 692 | * |
| 693 | * These values specify the target coding bitrate to be used for each |
| 694 | * spatial/temporal layer. (in kbps) |
| 695 | * |
| 696 | */ |
| 697 | unsigned int layer_target_bitrate[VPX_MAX_LAYERS]; |
| 698 |
| 699 | /*!\brief Temporal layering mode indicating which temporal layering scheme to |
| 700 | * use. |
| 701 | * |
| 702 | * The value (refer to VP9E_TEMPORAL_LAYERING_MODE) specifies the |
| 703 | * temporal layering mode to use. |
| 704 | * |
| 705 | */ |
| 706 | int temporal_layering_mode; |
| 707 |
| 708 | /*!\brief A flag indicating whether to use external rate control parameters. |
| 709 | * By default is 0. If set to 1, the following parameters will be used in the |
| 710 | * rate control system. |
| 711 | */ |
| 712 | int use_vizier_rc_params; |
| 713 |
| 714 | /*!\brief Active worst quality factor. |
| 715 | * |
| 716 | * Rate control parameters, set from external experiment results. |
| 717 | * Only when |use_vizier_rc_params| is set to 1, the pass in value will be |
| 718 | * used. Otherwise, the default value is used. |
| 719 | * |
| 720 | */ |
| 721 | vpx_rational_t active_wq_factor; |
| 722 |
| 723 | /*!\brief Error per macroblock adjustment factor. |
| 724 | * |
| 725 | * Rate control parameters, set from external experiment results. |
| 726 | * Only when |use_vizier_rc_params| is set to 1, the pass in value will be |
| 727 | * used. Otherwise, the default value is used. |
| 728 | * |
| 729 | */ |
| 730 | vpx_rational_t err_per_mb_factor; |
| 731 |
| 732 | /*!\brief Second reference default decay limit. |
| 733 | * |
| 734 | * Rate control parameters, set from external experiment results. |
| 735 | * Only when |use_vizier_rc_params| is set to 1, the pass in value will be |
| 736 | * used. Otherwise, the default value is used. |
| 737 | * |
| 738 | */ |
| 739 | vpx_rational_t sr_default_decay_limit; |
| 740 |
| 741 | /*!\brief Second reference difference factor. |
| 742 | * |
| 743 | * Rate control parameters, set from external experiment results. |
| 744 | * Only when |use_vizier_rc_params| is set to 1, the pass in value will be |
| 745 | * used. Otherwise, the default value is used. |
| 746 | * |
| 747 | */ |
| 748 | vpx_rational_t sr_diff_factor; |
| 749 |
| 750 | /*!\brief Keyframe error per macroblock adjustment factor. |
| 751 | * |
| 752 | * Rate control parameters, set from external experiment results. |
| 753 | * Only when |use_vizier_rc_params| is set to 1, the pass in value will be |
| 754 | * used. Otherwise, the default value is used. |
| 755 | * |
| 756 | */ |
| 757 | vpx_rational_t kf_err_per_mb_factor; |
| 758 |
| 759 | /*!\brief Keyframe minimum boost adjustment factor. |
| 760 | * |
| 761 | * Rate control parameters, set from external experiment results. |
| 762 | * Only when |use_vizier_rc_params| is set to 1, the pass in value will be |
| 763 | * used. Otherwise, the default value is used. |
| 764 | * |
| 765 | */ |
| 766 | vpx_rational_t kf_frame_min_boost_factor; |
| 767 |
| 768 | /*!\brief Keyframe maximum boost adjustment factor, for the first keyframe |
| 769 | * in a chunk. |
| 770 | * |
| 771 | * Rate control parameters, set from external experiment results. |
| 772 | * Only when |use_vizier_rc_params| is set to 1, the pass in value will be |
| 773 | * used. Otherwise, the default value is used. |
| 774 | * |
| 775 | */ |
| 776 | vpx_rational_t kf_frame_max_boost_first_factor; |
| 777 |
| 778 | /*!\brief Keyframe maximum boost adjustment factor, for subsequent keyframes. |
| 779 | * |
| 780 | * Rate control parameters, set from external experiment results. |
| 781 | * Only when |use_vizier_rc_params| is set to 1, the pass in value will be |
| 782 | * used. Otherwise, the default value is used. |
| 783 | * |
| 784 | */ |
| 785 | vpx_rational_t kf_frame_max_boost_subs_factor; |
| 786 |
| 787 | /*!\brief Keyframe maximum total boost adjustment factor. |
| 788 | * |
| 789 | * Rate control parameters, set from external experiment results. |
| 790 | * Only when |use_vizier_rc_params| is set to 1, the pass in value will be |
| 791 | * used. Otherwise, the default value is used. |
| 792 | * |
| 793 | */ |
| 794 | vpx_rational_t kf_max_total_boost_factor; |
| 795 |
| 796 | /*!\brief Golden frame maximum total boost adjustment factor. |
| 797 | * |
| 798 | * Rate control parameters, set from external experiment results. |
| 799 | * Only when |use_vizier_rc_params| is set to 1, the pass in value will be |
| 800 | * used. Otherwise, the default value is used. |
| 801 | * |
| 802 | */ |
| 803 | vpx_rational_t gf_max_total_boost_factor; |
| 804 |
| 805 | /*!\brief Golden frame maximum boost adjustment factor. |
| 806 | * |
| 807 | * Rate control parameters, set from external experiment results. |
| 808 | * Only when |use_vizier_rc_params| is set to 1, the pass in value will be |
| 809 | * used. Otherwise, the default value is used. |
| 810 | * |
| 811 | */ |
| 812 | vpx_rational_t gf_frame_max_boost_factor; |
| 813 |
| 814 | /*!\brief Zero motion power factor. |
| 815 | * |
| 816 | * Rate control parameters, set from external experiment results. |
| 817 | * Only when |use_vizier_rc_params| is set to 1, the pass in value will be |
| 818 | * used. Otherwise, the default value is used. |
| 819 | * |
| 820 | */ |
| 821 | vpx_rational_t zm_factor; |
| 822 |
| 823 | /*!\brief Rate-distortion multiplier for inter frames. |
| 824 | * The multiplier is a crucial parameter in the calculation of rate distortion |
| 825 | * cost. It is often related to the qp (qindex) value. |
| 826 | * Rate control parameters, could be set from external experiment results. |
| 827 | * Only when |use_vizier_rc_params| is set to 1, the pass in value will be |
| 828 | * used. Otherwise, the default value is used. |
| 829 | * |
| 830 | */ |
| 831 | vpx_rational_t rd_mult_inter_qp_fac; |
| 832 |
| 833 | /*!\brief Rate-distortion multiplier for alt-ref frames. |
| 834 | * The multiplier is a crucial parameter in the calculation of rate distortion |
| 835 | * cost. It is often related to the qp (qindex) value. |
| 836 | * Rate control parameters, could be set from external experiment results. |
| 837 | * Only when |use_vizier_rc_params| is set to 1, the pass in value will be |
| 838 | * used. Otherwise, the default value is used. |
| 839 | * |
| 840 | */ |
| 841 | vpx_rational_t rd_mult_arf_qp_fac; |
| 842 |
| 843 | /*!\brief Rate-distortion multiplier for key frames. |
| 844 | * The multiplier is a crucial parameter in the calculation of rate distortion |
| 845 | * cost. It is often related to the qp (qindex) value. |
| 846 | * Rate control parameters, could be set from external experiment results. |
| 847 | * Only when |use_vizier_rc_params| is set to 1, the pass in value will be |
| 848 | * used. Otherwise, the default value is used. |
| 849 | * |
| 850 | */ |
| 851 | vpx_rational_t rd_mult_key_qp_fac; |
| 852 | } vpx_codec_enc_cfg_t; /**< alias for struct vpx_codec_enc_cfg */ |
| 853 |
| 854 | /*!\brief vp9 svc extra configure parameters |
| 855 | * |
| 856 | * This defines max/min quantizers and scale factors for each layer |
| 857 | * |
| 858 | */ |
| 859 | typedef struct vpx_svc_parameters { |
| 860 | int max_quantizers[VPX_MAX_LAYERS]; /**< Max Q for each layer */ |
| 861 | int min_quantizers[VPX_MAX_LAYERS]; /**< Min Q for each layer */ |
| 862 | int scaling_factor_num[VPX_MAX_LAYERS]; /**< Scaling factor-numerator */ |
| 863 | int scaling_factor_den[VPX_MAX_LAYERS]; /**< Scaling factor-denominator */ |
| 864 | int speed_per_layer[VPX_MAX_LAYERS]; /**< Speed setting for each sl */ |
| 865 | int temporal_layering_mode; /**< Temporal layering mode */ |
| 866 | int loopfilter_ctrl[VPX_MAX_LAYERS]; /**< Loopfilter ctrl for each sl */ |
| 867 | } vpx_svc_extra_cfg_t; |
| 868 |
| 869 | /*!\brief Initialize an encoder instance |
| 870 | * |
| 871 | * Initializes an encoder context using the given interface. Applications |
| 872 | * should call the vpx_codec_enc_init convenience macro instead of this |
| 873 | * function directly, to ensure that the ABI version number parameter |
| 874 | * is properly initialized. |
| 875 | * |
| 876 | * If the library was configured with --disable-multithread, this call |
| 877 | * is not thread safe and should be guarded with a lock if being used |
| 878 | * in a multithreaded context. |
| 879 | * |
| 880 | * If vpx_codec_enc_init_ver() fails, it is not necessary to call |
| 881 | * vpx_codec_destroy() on the encoder context. |
| 882 | * |
| 883 | * \param[in] ctx Pointer to this instance's context. |
| 884 | * \param[in] iface Pointer to the algorithm interface to use. |
| 885 | * \param[in] cfg Configuration to use. |
| 886 | * \param[in] flags Bitfield of VPX_CODEC_USE_* flags |
| 887 | * \param[in] ver ABI version number. Must be set to |
| 888 | * VPX_ENCODER_ABI_VERSION |
| 889 | * \retval #VPX_CODEC_OK |
| 890 | * The decoder algorithm initialized. |
| 891 | * \retval #VPX_CODEC_MEM_ERROR |
| 892 | * Memory allocation failed. |
| 893 | */ |
| 894 | vpx_codec_err_t vpx_codec_enc_init_ver(vpx_codec_ctx_t *ctx, |
| 895 | vpx_codec_iface_t *iface, |
| 896 | const vpx_codec_enc_cfg_t *cfg, |
| 897 | vpx_codec_flags_t flags, int ver); |
| 898 |
| 899 | /*!\brief Convenience macro for vpx_codec_enc_init_ver() |
| 900 | * |
| 901 | * Ensures the ABI version parameter is properly set. |
| 902 | */ |
| 903 | #define vpx_codec_enc_init(ctx, iface, cfg, flags) \ |
| 904 | vpx_codec_enc_init_ver(ctx, iface, cfg, flags, VPX_ENCODER_ABI_VERSION) |
| 905 |
| 906 | /*!\brief Initialize multi-encoder instance |
| 907 | * |
| 908 | * Initializes multiple encoder contexts using the given interface. |
| 909 | * Applications should call the vpx_codec_enc_init_multi convenience macro |
| 910 | * instead of this function directly, to ensure that the ABI version number |
| 911 | * parameter is properly initialized. |
| 912 | * |
| 913 | * \param[in] ctx Pointer to an array of num_enc instances' contexts. |
| 914 | * \param[in] iface Pointer to the algorithm interface to use. |
| 915 | * \param[in] cfg An array of num_enc configurations to use. |
| 916 | * \param[in] num_enc Total number of encoders. |
| 917 | * \param[in] flags Bitfield of VPX_CODEC_USE_* flags |
| 918 | * \param[in] dsf Pointer to an array of num_enc down-sampling factors. |
| 919 | * \param[in] ver ABI version number. Must be set to |
| 920 | * VPX_ENCODER_ABI_VERSION |
| 921 | * \retval #VPX_CODEC_OK |
| 922 | * The encoder algorithm has been initialized. |
| 923 | * \retval #VPX_CODEC_MEM_ERROR |
| 924 | * Memory allocation failed. |
| 925 | * |
| 926 | * \note |
| 927 | * This is only supported by VP8. iface must point to the interface to the VP8 |
| 928 | * encoder. |
| 929 | */ |
| 930 | vpx_codec_err_t vpx_codec_enc_init_multi_ver( |
| 931 | vpx_codec_ctx_t *ctx, vpx_codec_iface_t *iface, |
| 932 | const vpx_codec_enc_cfg_t *cfg, int num_enc, vpx_codec_flags_t flags, |
| 933 | const vpx_rational_t *dsf, int ver); |
| 934 |
| 935 | /*!\brief Convenience macro for vpx_codec_enc_init_multi_ver() |
| 936 | * |
| 937 | * Ensures the ABI version parameter is properly set. |
| 938 | */ |
| 939 | #define vpx_codec_enc_init_multi(ctx, iface, cfg, num_enc, flags, dsf) \ |
| 940 | vpx_codec_enc_init_multi_ver(ctx, iface, cfg, num_enc, flags, dsf, \ |
| 941 | VPX_ENCODER_ABI_VERSION) |
| 942 |
| 943 | /*!\brief Get a default configuration |
| 944 | * |
| 945 | * Initializes a 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. |
| 950 | * |
| 951 | * \param[in] iface Pointer to the algorithm interface to use. |
| 952 | * \param[out] cfg Configuration buffer to populate. |
| 953 | * \param[in] usage Must be set to 0. |
| 954 | * |
| 955 | * \retval #VPX_CODEC_OK |
| 956 | * The configuration was populated. |
| 957 | * \retval #VPX_CODEC_INCAPABLE |
| 958 | * Interface is not an encoder interface. |
| 959 | * \retval #VPX_CODEC_INVALID_PARAM |
| 960 | * A parameter was NULL, or the usage value was not recognized. |
| 961 | */ |
| 962 | vpx_codec_err_t vpx_codec_enc_config_default(vpx_codec_iface_t *iface, |
| 963 | vpx_codec_enc_cfg_t *cfg, |
| 964 | unsigned int usage); |
| 965 |
| 966 | /*!\brief Set or change configuration |
| 967 | * |
| 968 | * Reconfigures an encoder instance according to the given configuration. |
| 969 | * |
| 970 | * \param[in] ctx Pointer to this instance's context |
| 971 | * \param[in] cfg Configuration buffer to use |
| 972 | * |
| 973 | * \retval #VPX_CODEC_OK |
| 974 | * The configuration was populated. |
| 975 | * \retval #VPX_CODEC_INCAPABLE |
| 976 | * Interface is not an encoder interface. |
| 977 | * \retval #VPX_CODEC_INVALID_PARAM |
| 978 | * A parameter was NULL, or the usage value was not recognized. |
| 979 | */ |
| 980 | vpx_codec_err_t vpx_codec_enc_config_set(vpx_codec_ctx_t *ctx, |
| 981 | const vpx_codec_enc_cfg_t *cfg); |
| 982 |
| 983 | /*!\brief Get global stream headers |
| 984 | * |
| 985 | * Retrieves a stream level global header packet, if supported by the codec. |
| 986 | * |
| 987 | * \li VP8: Unsupported |
| 988 | * \li VP9: Returns a buffer of <tt>ID (1 byte)|Length (1 byte)|Length |
| 989 | * bytes</tt> values. The function should be called after encoding to retrieve |
| 990 | * the most accurate information. |
| 991 | * |
| 992 | * \param[in] ctx Pointer to this instance's context |
| 993 | * |
| 994 | * \retval NULL |
| 995 | * Encoder does not support global header |
| 996 | * \retval Non-NULL |
| 997 | * Pointer to buffer containing global header packet. The buffer pointer |
| 998 | * and its contents are only valid for the lifetime of \a ctx. The contents |
| 999 | * may change in subsequent calls to the function. |
| 1000 | * \sa |
| 1001 | * https://www.webmproject.org/docs/container/#vp9-codec-feature-metadata-codecprivate |
| 1002 | */ |
| 1003 | vpx_fixed_buf_t *vpx_codec_get_global_headers(vpx_codec_ctx_t *ctx); |
| 1004 |
| 1005 | /*!\brief Encode Deadline |
| 1006 | * |
| 1007 | * This type indicates a deadline, in microseconds, to be passed to |
| 1008 | * vpx_codec_encode(). |
| 1009 | */ |
| 1010 | typedef unsigned long vpx_enc_deadline_t; |
| 1011 | /*!\brief deadline parameter analogous to VPx REALTIME mode. */ |
| 1012 | #define VPX_DL_REALTIME 1ul |
| 1013 | /*!\brief deadline parameter analogous to VPx GOOD QUALITY mode. */ |
| 1014 | #define VPX_DL_GOOD_QUALITY 1000000ul |
| 1015 | /*!\brief deadline parameter analogous to VPx BEST QUALITY mode. */ |
| 1016 | #define VPX_DL_BEST_QUALITY 0ul |
| 1017 | /*!\brief Encode a frame |
| 1018 | * |
| 1019 | * Encodes a video frame at the given "presentation time." The presentation |
| 1020 | * time stamp (PTS) \ref MUST be strictly increasing. |
| 1021 | * |
| 1022 | * The encoder supports the notion of a soft real-time deadline. Given a |
| 1023 | * non-zero value to the deadline parameter, the encoder will make a "best |
| 1024 | * effort" guarantee to return before the given time slice expires. It is |
| 1025 | * implicit that limiting the available time to encode will degrade the |
| 1026 | * output quality. The encoder can be given an unlimited time to produce the |
| 1027 | * best possible frame by specifying a deadline of '0'. This deadline |
| 1028 | * supersedes the VPx notion of "best quality, good quality, realtime". |
| 1029 | * Applications that wish to map these former settings to the new deadline |
| 1030 | * based system can use the symbols #VPX_DL_REALTIME, #VPX_DL_GOOD_QUALITY, |
| 1031 | * and #VPX_DL_BEST_QUALITY. |
| 1032 | * |
| 1033 | * When the last frame has been passed to the encoder, this function should |
| 1034 | * continue to be called, with the img parameter set to NULL. This will |
| 1035 | * signal the end-of-stream condition to the encoder and allow it to encode |
| 1036 | * any held buffers. Encoding is complete when vpx_codec_encode() is called |
| 1037 | * and vpx_codec_get_cx_data() returns no data. |
| 1038 | * |
| 1039 | * \param[in] ctx Pointer to this instance's context |
| 1040 | * \param[in] img Image data to encode, NULL to flush. |
| 1041 | * Encoding sample values outside the range |
| 1042 | * [0..(1<<img->bit_depth)-1] is undefined behavior. |
| 1043 | * \param[in] pts Presentation time stamp, in timebase units. |
| 1044 | * \param[in] duration Duration to show frame, in timebase units. |
| 1045 | * \param[in] flags Flags to use for encoding this frame. |
| 1046 | * \param[in] deadline Time to spend encoding, in microseconds. (0=infinite) |
| 1047 | * |
| 1048 | * \retval #VPX_CODEC_OK |
| 1049 | * The configuration was populated. |
| 1050 | * \retval #VPX_CODEC_INCAPABLE |
| 1051 | * Interface is not an encoder interface. |
| 1052 | * \retval #VPX_CODEC_INVALID_PARAM |
| 1053 | * A parameter was NULL, the image format is unsupported, etc. |
| 1054 | */ |
| 1055 | vpx_codec_err_t vpx_codec_encode(vpx_codec_ctx_t *ctx, const vpx_image_t *img, |
| 1056 | vpx_codec_pts_t pts, unsigned long duration, |
| 1057 | vpx_enc_frame_flags_t flags, |
| 1058 | vpx_enc_deadline_t deadline); |
| 1059 |
| 1060 | /*!\brief Set compressed data output buffer |
| 1061 | * |
| 1062 | * Sets the buffer that the codec should output the compressed data |
| 1063 | * into. This call effectively sets the buffer pointer returned in the |
| 1064 | * next VPX_CODEC_CX_FRAME_PKT packet. Subsequent packets will be |
| 1065 | * appended into this buffer. The buffer is preserved across frames, |
| 1066 | * so applications must periodically call this function after flushing |
| 1067 | * the accumulated compressed data to disk or to the network to reset |
| 1068 | * the pointer to the buffer's head. |
| 1069 | * |
| 1070 | * `pad_before` bytes will be skipped before writing the compressed |
| 1071 | * data, and `pad_after` bytes will be appended to the packet. The size |
| 1072 | * of the packet will be the sum of the size of the actual compressed |
| 1073 | * data, pad_before, and pad_after. The padding bytes will be preserved |
| 1074 | * (not overwritten). |
| 1075 | * |
| 1076 | * Note that calling this function does not guarantee that the returned |
| 1077 | * compressed data will be placed into the specified buffer. In the |
| 1078 | * event that the encoded data will not fit into the buffer provided, |
| 1079 | * the returned packet \ref MAY point to an internal buffer, as it would |
| 1080 | * if this call were never used. In this event, the output packet will |
| 1081 | * NOT have any padding, and the application must free space and copy it |
| 1082 | * to the proper place. This is of particular note in configurations |
| 1083 | * that may output multiple packets for a single encoded frame (e.g., lagged |
| 1084 | * encoding) or if the application does not reset the buffer periodically. |
| 1085 | * |
| 1086 | * Applications may restore the default behavior of the codec providing |
| 1087 | * the compressed data buffer by calling this function with a NULL |
| 1088 | * buffer. |
| 1089 | * |
| 1090 | * Applications \ref MUSTNOT call this function during iteration of |
| 1091 | * vpx_codec_get_cx_data(). |
| 1092 | * |
| 1093 | * \param[in] ctx Pointer to this instance's context |
| 1094 | * \param[in] buf Buffer to store compressed data into |
| 1095 | * \param[in] pad_before Bytes to skip before writing compressed data |
| 1096 | * \param[in] pad_after Bytes to skip after writing compressed data |
| 1097 | * |
| 1098 | * \retval #VPX_CODEC_OK |
| 1099 | * The buffer was set successfully. |
| 1100 | * \retval #VPX_CODEC_INVALID_PARAM |
| 1101 | * A parameter was NULL, the image format is unsupported, etc. |
| 1102 | * |
| 1103 | * \note |
| 1104 | * `duration` and `deadline` are of the unsigned long type, which can be 32 |
| 1105 | * or 64 bits. `duration` and `deadline` must be less than or equal to |
| 1106 | * UINT32_MAX so that their ranges are independent of the size of unsigned |
| 1107 | * long. |
| 1108 | */ |
| 1109 | vpx_codec_err_t vpx_codec_set_cx_data_buf(vpx_codec_ctx_t *ctx, |
| 1110 | const vpx_fixed_buf_t *buf, |
| 1111 | unsigned int pad_before, |
| 1112 | unsigned int pad_after); |
| 1113 |
| 1114 | /*!\brief Encoded data iterator |
| 1115 | * |
| 1116 | * Iterates over a list of data packets to be passed from the encoder to the |
| 1117 | * application. The different kinds of packets available are enumerated in |
| 1118 | * #vpx_codec_cx_pkt_kind. |
| 1119 | * |
| 1120 | * #VPX_CODEC_CX_FRAME_PKT packets should be passed to the application's |
| 1121 | * muxer. Multiple compressed frames may be in the list. |
| 1122 | * #VPX_CODEC_STATS_PKT packets should be appended to a global buffer. |
| 1123 | * |
| 1124 | * The application \ref MUST silently ignore any packet kinds that it does |
| 1125 | * not recognize or support. |
| 1126 | * |
| 1127 | * The data buffers returned from this function are only guaranteed to be |
| 1128 | * valid until the application makes another call to any vpx_codec_* function. |
| 1129 | * |
| 1130 | * \param[in] ctx Pointer to this instance's context |
| 1131 | * \param[in,out] iter Iterator storage, initialized to NULL |
| 1132 | * |
| 1133 | * \return Returns a pointer to an output data packet (compressed frame data, |
| 1134 | * two-pass statistics, etc.) or NULL to signal end-of-list. |
| 1135 | * |
| 1136 | */ |
| 1137 | const vpx_codec_cx_pkt_t *vpx_codec_get_cx_data(vpx_codec_ctx_t *ctx, |
| 1138 | vpx_codec_iter_t *iter); |
| 1139 |
| 1140 | /*!\brief Get Preview Frame |
| 1141 | * |
| 1142 | * Returns an image that can be used as a preview. Shows the image as it would |
| 1143 | * exist at the decompressor. The application \ref MUST NOT write into this |
| 1144 | * image buffer. |
| 1145 | * |
| 1146 | * \param[in] ctx Pointer to this instance's context |
| 1147 | * |
| 1148 | * \return Returns a pointer to a preview image, or NULL if no image is |
| 1149 | * available. |
| 1150 | * |
| 1151 | */ |
| 1152 | const vpx_image_t *vpx_codec_get_preview_frame(vpx_codec_ctx_t *ctx); |
| 1153 |
| 1154 | /*!@} - end defgroup encoder*/ |
| 1155 | #ifdef __cplusplus |
| 1156 | } |
| 1157 | #endif |
| 1158 | #endif // VPX_VPX_VPX_ENCODER_H_ |
| 1159 |