2 * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
4 * Use of this source code is governed by a BSD-style license
5 * that can be found in the LICENSE file in the root of the source
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.
10 #ifndef VPX_VPX_ENCODER_H_
11 #define VPX_VPX_ENCODER_H_
13 /*!\defgroup encoder Encoder Algorithm Interface
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.
22 * \brief Describes the encoder algorithm interface to applications.
24 * This file describes the interface between an application and a
25 * video encoder algorithm.
32 #include "./vpx_codec.h"
34 /*! Temporal Scalability: Maximum length of the sequence defining frame
37 #define VPX_TS_MAX_PERIODICITY 16
39 /*! Temporal Scalability: Maximum number of coding layers */
40 #define VPX_TS_MAX_LAYERS 5
42 /*!\deprecated Use #VPX_TS_MAX_PERIODICITY instead. */
43 #define MAX_PERIODICITY VPX_TS_MAX_PERIODICITY
45 /*! Temporal+Spatial Scalability: Maximum number of coding layers */
46 #define VPX_MAX_LAYERS 12 // 3 temporal + 4 spatial layers are allowed.
48 /*!\deprecated Use #VPX_MAX_LAYERS instead. */
49 #define MAX_LAYERS VPX_MAX_LAYERS // 3 temporal + 4 spatial layers allowed.
51 /*! Spatial Scalability: Maximum number of coding layers */
52 #define VPX_SS_MAX_LAYERS 5
54 /*! Spatial Scalability: Default number of coding layers */
55 #define VPX_SS_DEFAULT_LAYERS 1
57 /*!\brief Current ABI version number
60 * If this file is altered in any way that changes the ABI, this value
61 * must be bumped. Examples include, but are not limited to, changing
62 * types, removing or reassigning enums, adding/removing/rearranging
63 * fields to structures
65 #define VPX_ENCODER_ABI_VERSION \
66 (7 + VPX_CODEC_ABI_VERSION) /**<\hideinitializer*/
68 /*! \brief Encoder capabilities bitfield
70 * Each encoder advertises the capabilities it supports as part of its
71 * ::vpx_codec_iface_t interface structure. Capabilities are extra
72 * interfaces or functionality, and are not required to be supported
75 * The available flags are specified by VPX_CODEC_CAP_* defines.
77 #define VPX_CODEC_CAP_PSNR 0x10000 /**< Can issue PSNR packets */
79 /*! Can output one partition at a time. Each partition is returned in its
80 * own VPX_CODEC_CX_FRAME_PKT, with the FRAME_IS_FRAGMENT flag set for
81 * every partition but the last. In this mode all frames are always
82 * returned partition by partition.
84 #define VPX_CODEC_CAP_OUTPUT_PARTITION 0x20000
86 /*! \brief Initialization-time Feature Enabling
88 * Certain codec features must be known at initialization time, to allow
89 * for proper memory allocation.
91 * The available flags are specified by VPX_CODEC_USE_* defines.
93 #define VPX_CODEC_USE_PSNR 0x10000 /**< Calculate PSNR on each frame */
94 /*!\brief Make the encoder output one partition at a time. */
95 #define VPX_CODEC_USE_OUTPUT_PARTITION 0x20000
96 #define VPX_CODEC_USE_HIGHBITDEPTH 0x40000 /**< Use high bitdepth */
98 /*!\brief Generic fixed size buffer structure
100 * This structure is able to hold a reference to any fixed size buffer.
102 typedef struct vpx_fixed_buf {
103 void *buf; /**< Pointer to the data */
104 size_t sz; /**< Length of the buffer, in chars */
105 } vpx_fixed_buf_t; /**< alias for struct vpx_fixed_buf */
107 /*!\brief Time Stamp Type
109 * An integer, which when multiplied by the stream's time base, provides
110 * the absolute time of a sample.
112 typedef int64_t vpx_codec_pts_t;
114 /*!\brief Compressed Frame Flags
116 * This type represents a bitfield containing information about a compressed
117 * frame that may be useful to an application. The most significant 16 bits
118 * can be used by an algorithm to provide additional detail, for example to
119 * support frame types that are codec specific (MPEG-1 D-frames for example)
121 typedef uint32_t vpx_codec_frame_flags_t;
122 #define VPX_FRAME_IS_KEY 0x1 /**< frame is the start of a GOP */
123 /*!\brief frame can be dropped without affecting the stream (no future frame
124 * depends on this one) */
125 #define VPX_FRAME_IS_DROPPABLE 0x2
126 /*!\brief frame should be decoded but will not be shown */
127 #define VPX_FRAME_IS_INVISIBLE 0x4
128 /*!\brief this is a fragment of the encoded frame */
129 #define VPX_FRAME_IS_FRAGMENT 0x8
131 /*!\brief Error Resilient flags
133 * These flags define which error resilient features to enable in the
134 * encoder. The flags are specified through the
135 * vpx_codec_enc_cfg::g_error_resilient variable.
137 typedef uint32_t vpx_codec_er_flags_t;
138 /*!\brief Improve resiliency against losses of whole frames */
139 #define VPX_ERROR_RESILIENT_DEFAULT 0x1
140 /*!\brief The frame partitions are independently decodable by the bool decoder,
141 * meaning that partitions can be decoded even though earlier partitions have
142 * been lost. Note that intra prediction is still done over the partition
144 #define VPX_ERROR_RESILIENT_PARTITIONS 0x2
146 /*!\brief Encoder output packet variants
148 * This enumeration lists the different kinds of data packets that can be
149 * returned by calls to vpx_codec_get_cx_data(). Algorithms \ref MAY
150 * extend this list to provide additional functionality.
152 enum vpx_codec_cx_pkt_kind {
153 VPX_CODEC_CX_FRAME_PKT, /**< Compressed video frame */
154 VPX_CODEC_STATS_PKT, /**< Two-pass statistics for this frame */
155 VPX_CODEC_FPMB_STATS_PKT, /**< first pass mb statistics for this frame */
156 VPX_CODEC_PSNR_PKT, /**< PSNR statistics for this frame */
157 // Spatial SVC is still experimental and may be removed.
158 #if defined(VPX_TEST_SPATIAL_SVC)
159 VPX_CODEC_SPATIAL_SVC_LAYER_SIZES, /**< Sizes for each layer in this frame*/
160 VPX_CODEC_SPATIAL_SVC_LAYER_PSNR, /**< PSNR for each layer in this frame*/
162 VPX_CODEC_CUSTOM_PKT = 256 /**< Algorithm extensions */
165 /*!\brief Encoder output packet
167 * This structure contains the different kinds of output data the encoder
168 * may produce while compressing a frame.
170 typedef struct vpx_codec_cx_pkt {
171 enum vpx_codec_cx_pkt_kind kind; /**< packet variant */
174 void *buf; /**< compressed data buffer */
175 size_t sz; /**< length of compressed data */
176 /*!\brief time stamp to show frame (in timebase units) */
178 /*!\brief duration to show frame (in timebase units) */
179 unsigned long duration;
180 vpx_codec_frame_flags_t flags; /**< flags for this frame */
181 /*!\brief the partition id defines the decoding order of the partitions.
182 * Only applicable when "output partition" mode is enabled. First
183 * partition has id 0.*/
185 unsigned int width; /**< frame width */
186 unsigned int height; /**< frame height */
187 } frame; /**< data for compressed frame packet */
188 vpx_fixed_buf_t twopass_stats; /**< data for two-pass packet */
189 vpx_fixed_buf_t firstpass_mb_stats; /**< first pass mb packet */
190 struct vpx_psnr_pkt {
191 unsigned int samples[4]; /**< Number of samples, total/y/u/v */
192 uint64_t sse[4]; /**< sum squared error, total/y/u/v */
193 double psnr[4]; /**< PSNR, total/y/u/v */
194 } psnr; /**< data for PSNR packet */
195 vpx_fixed_buf_t raw; /**< data for arbitrary packets */
196 // Spatial SVC is still experimental and may be removed.
197 #if defined(VPX_TEST_SPATIAL_SVC)
198 size_t layer_sizes[VPX_SS_MAX_LAYERS];
199 struct vpx_psnr_pkt layer_psnr[VPX_SS_MAX_LAYERS];
202 /* This packet size is fixed to allow codecs to extend this
203 * interface without having to manage storage for raw packets,
204 * i.e., if it's smaller than 128 bytes, you can store in the
205 * packet list directly.
207 char pad[128 - sizeof(enum vpx_codec_cx_pkt_kind)]; /**< fixed sz */
208 } data; /**< packet data */
209 } vpx_codec_cx_pkt_t; /**< alias for struct vpx_codec_cx_pkt */
211 /*!\brief Encoder return output buffer callback
213 * This callback function, when registered, returns with packets when each
214 * spatial layer is encoded.
216 // putting the definitions here for now. (agrange: find if there
217 // is a better place for this)
218 typedef void (*vpx_codec_enc_output_cx_pkt_cb_fn_t)(vpx_codec_cx_pkt_t *pkt,
221 /*!\brief Callback function pointer / user data pair storage */
222 typedef struct vpx_codec_enc_output_cx_cb_pair {
223 vpx_codec_enc_output_cx_pkt_cb_fn_t output_cx_pkt; /**< Callback function */
224 void *user_priv; /**< Pointer to private data */
225 } vpx_codec_priv_output_cx_pkt_cb_pair_t;
227 /*!\brief Rational Number
229 * This structure holds a fractional value.
231 typedef struct vpx_rational {
232 int num; /**< fraction numerator */
233 int den; /**< fraction denominator */
234 } vpx_rational_t; /**< alias for struct vpx_rational */
236 /*!\brief Multi-pass Encoding Pass */
238 VPX_RC_ONE_PASS, /**< Single pass mode */
239 VPX_RC_FIRST_PASS, /**< First pass of multi-pass mode */
240 VPX_RC_LAST_PASS /**< Final pass of multi-pass mode */
243 /*!\brief Rate control mode */
245 VPX_VBR, /**< Variable Bit Rate (VBR) mode */
246 VPX_CBR, /**< Constant Bit Rate (CBR) mode */
247 VPX_CQ, /**< Constrained Quality (CQ) mode */
248 VPX_Q, /**< Constant Quality (Q) mode */
251 /*!\brief Keyframe placement mode.
253 * This enumeration determines whether keyframes are placed automatically by
254 * the encoder or whether this behavior is disabled. Older releases of this
255 * SDK were implemented such that VPX_KF_FIXED meant keyframes were disabled.
256 * This name is confusing for this behavior, so the new symbols to be used
257 * are VPX_KF_AUTO and VPX_KF_DISABLED.
260 VPX_KF_FIXED, /**< deprecated, implies VPX_KF_DISABLED */
261 VPX_KF_AUTO, /**< Encoder determines optimal placement automatically */
262 VPX_KF_DISABLED = 0 /**< Encoder does not place keyframes. */
265 /*!\brief Encoded Frame Flags
267 * This type indicates a bitfield to be passed to vpx_codec_encode(), defining
268 * per-frame boolean values. By convention, bits common to all codecs will be
269 * named VPX_EFLAG_*, and bits specific to an algorithm will be named
270 * /algo/_eflag_*. The lower order 16 bits are reserved for common use.
272 typedef long vpx_enc_frame_flags_t;
273 #define VPX_EFLAG_FORCE_KF (1 << 0) /**< Force this frame to be a keyframe */
275 /*!\brief Encoder configuration structure
277 * This structure contains the encoder settings that have common representations
278 * across all codecs. This doesn't imply that all codecs support all features,
281 typedef struct vpx_codec_enc_cfg {
283 * generic settings (g)
286 /*!\brief Algorithm specific "usage" value
288 * Algorithms may define multiple values for usage, which may convey the
289 * intent of how the application intends to use the stream. If this value
290 * is non-zero, consult the documentation for the codec to determine its
293 unsigned int g_usage;
295 /*!\brief Maximum number of threads to use
297 * For multi-threaded implementations, use no more than this number of
298 * threads. The codec may use fewer threads than allowed. The value
299 * 0 is equivalent to the value 1.
301 unsigned int g_threads;
303 /*!\brief Bitstream profile to use
305 * Some codecs support a notion of multiple bitstream profiles. Typically
306 * this maps to a set of features that are turned on or off. Often the
307 * profile to use is determined by the features of the intended decoder.
308 * Consult the documentation for the codec to determine the valid values
309 * for this parameter, or set to zero for a sane default.
311 unsigned int g_profile; /**< profile of bitstream to use */
313 /*!\brief Width of the frame
315 * This value identifies the presentation resolution of the frame,
316 * in pixels. Note that the frames passed as input to the encoder must
317 * have this resolution. Frames will be presented by the decoder in this
318 * resolution, independent of any spatial resampling the encoder may do.
322 /*!\brief Height of the frame
324 * This value identifies the presentation resolution of the frame,
325 * in pixels. Note that the frames passed as input to the encoder must
326 * have this resolution. Frames will be presented by the decoder in this
327 * resolution, independent of any spatial resampling the encoder may do.
331 /*!\brief Bit-depth of the codec
333 * This value identifies the bit_depth of the codec,
334 * Only certain bit-depths are supported as identified in the
335 * vpx_bit_depth_t enum.
337 vpx_bit_depth_t g_bit_depth;
339 /*!\brief Bit-depth of the input frames
341 * This value identifies the bit_depth of the input frames in bits.
342 * Note that the frames passed as input to the encoder must have
345 unsigned int g_input_bit_depth;
347 /*!\brief Stream timebase units
349 * Indicates the smallest interval of time, in seconds, used by the stream.
350 * For fixed frame rate material, or variable frame rate material where
351 * frames are timed at a multiple of a given clock (ex: video capture),
352 * the \ref RECOMMENDED method is to set the timebase to the reciprocal
353 * of the frame rate (ex: 1001/30000 for 29.970 Hz NTSC). This allows the
354 * pts to correspond to the frame number, which can be handy. For
355 * re-encoding video from containers with absolute time timestamps, the
356 * \ref RECOMMENDED method is to set the timebase to that of the parent
357 * container or multimedia framework (ex: 1/1000 for ms, as in FLV).
359 struct vpx_rational g_timebase;
361 /*!\brief Enable error resilient modes.
363 * The error resilient bitfield indicates to the encoder which features
364 * it should enable to take measures for streaming over lossy or noisy
367 vpx_codec_er_flags_t g_error_resilient;
369 /*!\brief Multi-pass Encoding Mode
371 * This value should be set to the current phase for multi-pass encoding.
372 * For single pass, set to #VPX_RC_ONE_PASS.
374 enum vpx_enc_pass g_pass;
376 /*!\brief Allow lagged encoding
378 * If set, this value allows the encoder to consume a number of input
379 * frames before producing output frames. This allows the encoder to
380 * base decisions for the current frame on future frames. This does
381 * increase the latency of the encoding pipeline, so it is not appropriate
382 * in all situations (ex: realtime encoding).
384 * Note that this is a maximum value -- the encoder may produce frames
385 * sooner than the given limit. Set this value to 0 to disable this
388 unsigned int g_lag_in_frames;
391 * rate control settings (rc)
394 /*!\brief Temporal resampling configuration, if supported by the codec.
396 * Temporal resampling allows the codec to "drop" frames as a strategy to
397 * meet its target data rate. This can cause temporal discontinuities in
398 * the encoded video, which may appear as stuttering during playback. This
399 * trade-off is often acceptable, but for many applications is not. It can
400 * be disabled in these cases.
402 * Note that not all codecs support this feature. All vpx VPx codecs do.
403 * For other codecs, consult the documentation for that algorithm.
405 * This threshold is described as a percentage of the target data buffer.
406 * When the data buffer falls below this percentage of fullness, a
407 * dropped frame is indicated. Set the threshold to zero (0) to disable
410 unsigned int rc_dropframe_thresh;
412 /*!\brief Enable/disable spatial resampling, if supported by the codec.
414 * Spatial resampling allows the codec to compress a lower resolution
415 * version of the frame, which is then upscaled by the encoder to the
416 * correct presentation resolution. This increases visual quality at
417 * low data rates, at the expense of CPU time on the encoder/decoder.
419 unsigned int rc_resize_allowed;
421 /*!\brief Internal coded frame width.
423 * If spatial resampling is enabled this specifies the width of the
426 unsigned int rc_scaled_width;
428 /*!\brief Internal coded frame height.
430 * If spatial resampling is enabled this specifies the height of the
433 unsigned int rc_scaled_height;
435 /*!\brief Spatial resampling up watermark.
437 * This threshold is described as a percentage of the target data buffer.
438 * When the data buffer rises above this percentage of fullness, the
439 * encoder will step up to a higher resolution version of the frame.
441 unsigned int rc_resize_up_thresh;
443 /*!\brief Spatial resampling down watermark.
445 * This threshold is described as a percentage of the target data buffer.
446 * When the data buffer falls below this percentage of fullness, the
447 * encoder will step down to a lower resolution version of the frame.
449 unsigned int rc_resize_down_thresh;
451 /*!\brief Rate control algorithm to use.
453 * Indicates whether the end usage of this stream is to be streamed over
454 * a bandwidth constrained link, indicating that Constant Bit Rate (CBR)
455 * mode should be used, or whether it will be played back on a high
456 * bandwidth link, as from a local disk, where higher variations in
457 * bitrate are acceptable.
459 enum vpx_rc_mode rc_end_usage;
461 /*!\brief Two-pass stats buffer.
463 * A buffer containing all of the stats packets produced in the first
464 * pass, concatenated.
466 vpx_fixed_buf_t rc_twopass_stats_in;
468 /*!\brief first pass mb stats buffer.
470 * A buffer containing all of the first pass mb stats packets produced
471 * in the first pass, concatenated.
473 vpx_fixed_buf_t rc_firstpass_mb_stats_in;
475 /*!\brief Target data rate
477 * Target bandwidth to use for this stream, in kilobits per second.
479 unsigned int rc_target_bitrate;
485 /*!\brief Minimum (Best Quality) Quantizer
487 * The quantizer is the most direct control over the quality of the
488 * encoded image. The range of valid values for the quantizer is codec
489 * specific. Consult the documentation for the codec to determine the
490 * values to use. To determine the range programmatically, call
491 * vpx_codec_enc_config_default() with a usage value of 0.
493 unsigned int rc_min_quantizer;
495 /*!\brief Maximum (Worst Quality) Quantizer
497 * The quantizer is the most direct control over the quality of the
498 * encoded image. The range of valid values for the quantizer is codec
499 * specific. Consult the documentation for the codec to determine the
500 * values to use. To determine the range programmatically, call
501 * vpx_codec_enc_config_default() with a usage value of 0.
503 unsigned int rc_max_quantizer;
509 /*!\brief Rate control adaptation undershoot control
511 * VP8: Expressed as a percentage of the target bitrate,
512 * controls the maximum allowed adaptation speed of the codec.
513 * This factor controls the maximum amount of bits that can
514 * be subtracted from the target bitrate in order to compensate
515 * for prior overshoot.
516 * VP9: Expressed as a percentage of the target bitrate, a threshold
517 * undershoot level (current rate vs target) beyond which more agressive
518 * corrective measures are taken.
520 * Valid values in the range VP8:0-1000 VP9: 0-100.
522 unsigned int rc_undershoot_pct;
524 /*!\brief Rate control adaptation overshoot control
526 * VP8: Expressed as a percentage of the target bitrate,
527 * controls the maximum allowed adaptation speed of the codec.
528 * This factor controls the maximum amount of bits that can
529 * be added to the target bitrate in order to compensate for
531 * VP9: Expressed as a percentage of the target bitrate, a threshold
532 * overshoot level (current rate vs target) beyond which more agressive
533 * corrective measures are taken.
535 * Valid values in the range VP8:0-1000 VP9: 0-100.
537 unsigned int rc_overshoot_pct;
540 * decoder buffer model parameters
543 /*!\brief Decoder Buffer Size
545 * This value indicates the amount of data that may be buffered by the
546 * decoding application. Note that this value is expressed in units of
547 * time (milliseconds). For example, a value of 5000 indicates that the
548 * client will buffer (at least) 5000ms worth of encoded data. Use the
549 * target bitrate (#rc_target_bitrate) to convert to bits/bytes, if
552 unsigned int rc_buf_sz;
554 /*!\brief Decoder Buffer Initial Size
556 * This value indicates the amount of data that will be buffered by the
557 * decoding application prior to beginning playback. This value is
558 * expressed in units of time (milliseconds). Use the target bitrate
559 * (#rc_target_bitrate) to convert to bits/bytes, if necessary.
561 unsigned int rc_buf_initial_sz;
563 /*!\brief Decoder Buffer Optimal Size
565 * This value indicates the amount of data that the encoder should try
566 * to maintain in the decoder's buffer. This value is expressed in units
567 * of time (milliseconds). Use the target bitrate (#rc_target_bitrate)
568 * to convert to bits/bytes, if necessary.
570 unsigned int rc_buf_optimal_sz;
573 * 2 pass rate control parameters
576 /*!\brief Two-pass mode CBR/VBR bias
578 * Bias, expressed on a scale of 0 to 100, for determining target size
579 * for the current frame. The value 0 indicates the optimal CBR mode
580 * value should be used. The value 100 indicates the optimal VBR mode
581 * value should be used. Values in between indicate which way the
582 * encoder should "lean."
584 unsigned int rc_2pass_vbr_bias_pct;
586 /*!\brief Two-pass mode per-GOP minimum bitrate
588 * This value, expressed as a percentage of the target bitrate, indicates
589 * the minimum bitrate to be used for a single GOP (aka "section")
591 unsigned int rc_2pass_vbr_minsection_pct;
593 /*!\brief Two-pass mode per-GOP maximum bitrate
595 * This value, expressed as a percentage of the target bitrate, indicates
596 * the maximum bitrate to be used for a single GOP (aka "section")
598 unsigned int rc_2pass_vbr_maxsection_pct;
600 /*!\brief Two-pass corpus vbr mode complexity control
601 * Used only in VP9: A value representing the corpus midpoint complexity
602 * for corpus vbr mode. This value defaults to 0 which disables corpus vbr
603 * mode in favour of normal vbr mode.
605 unsigned int rc_2pass_vbr_corpus_complexity;
608 * keyframing settings (kf)
611 /*!\brief Keyframe placement mode
613 * This value indicates whether the encoder should place keyframes at a
614 * fixed interval, or determine the optimal placement automatically
615 * (as governed by the #kf_min_dist and #kf_max_dist parameters)
617 enum vpx_kf_mode kf_mode;
619 /*!\brief Keyframe minimum interval
621 * This value, expressed as a number of frames, prevents the encoder from
622 * placing a keyframe nearer than kf_min_dist to the previous keyframe. At
623 * least kf_min_dist frames non-keyframes will be coded before the next
624 * keyframe. Set kf_min_dist equal to kf_max_dist for a fixed interval.
626 unsigned int kf_min_dist;
628 /*!\brief Keyframe maximum interval
630 * This value, expressed as a number of frames, forces the encoder to code
631 * a keyframe if one has not been coded in the last kf_max_dist frames.
632 * A value of 0 implies all frames will be keyframes. Set kf_min_dist
633 * equal to kf_max_dist for a fixed interval.
635 unsigned int kf_max_dist;
638 * Spatial scalability settings (ss)
641 /*!\brief Number of spatial coding layers.
643 * This value specifies the number of spatial coding layers to be used.
645 unsigned int ss_number_layers;
647 /*!\brief Enable auto alt reference flags for each spatial layer.
649 * These values specify if auto alt reference frame is enabled for each
652 int ss_enable_auto_alt_ref[VPX_SS_MAX_LAYERS];
654 /*!\brief Target bitrate for each spatial layer.
656 * These values specify the target coding bitrate to be used for each
659 unsigned int ss_target_bitrate[VPX_SS_MAX_LAYERS];
661 /*!\brief Number of temporal coding layers.
663 * This value specifies the number of temporal layers to be used.
665 unsigned int ts_number_layers;
667 /*!\brief Target bitrate for each temporal layer.
669 * These values specify the target coding bitrate to be used for each
672 unsigned int ts_target_bitrate[VPX_TS_MAX_LAYERS];
674 /*!\brief Frame rate decimation factor for each temporal layer.
676 * These values specify the frame rate decimation factors to apply
677 * to each temporal layer.
679 unsigned int ts_rate_decimator[VPX_TS_MAX_LAYERS];
681 /*!\brief Length of the sequence defining frame temporal layer membership.
683 * This value specifies the length of the sequence that defines the
684 * membership of frames to temporal layers. For example, if the
685 * ts_periodicity = 8, then the frames are assigned to coding layers with a
686 * repeated sequence of length 8.
688 unsigned int ts_periodicity;
690 /*!\brief Template defining the membership of frames to temporal layers.
692 * This array defines the membership of frames to temporal coding layers.
693 * For a 2-layer encoding that assigns even numbered frames to one temporal
694 * layer (0) and odd numbered frames to a second temporal layer (1) with
695 * ts_periodicity=8, then ts_layer_id = (0,1,0,1,0,1,0,1).
697 unsigned int ts_layer_id[VPX_TS_MAX_PERIODICITY];
699 /*!\brief Target bitrate for each spatial/temporal layer.
701 * These values specify the target coding bitrate to be used for each
702 * spatial/temporal layer.
705 unsigned int layer_target_bitrate[VPX_MAX_LAYERS];
707 /*!\brief Temporal layering mode indicating which temporal layering scheme to
710 * The value (refer to VP9E_TEMPORAL_LAYERING_MODE) specifies the
711 * temporal layering mode to use.
714 int temporal_layering_mode;
715 } vpx_codec_enc_cfg_t; /**< alias for struct vpx_codec_enc_cfg */
717 /*!\brief vp9 svc extra configure parameters
719 * This defines max/min quantizers and scale factors for each layer
722 typedef struct vpx_svc_parameters {
723 int max_quantizers[VPX_MAX_LAYERS]; /**< Max Q for each layer */
724 int min_quantizers[VPX_MAX_LAYERS]; /**< Min Q for each layer */
725 int scaling_factor_num[VPX_MAX_LAYERS]; /**< Scaling factor-numerator */
726 int scaling_factor_den[VPX_MAX_LAYERS]; /**< Scaling factor-denominator */
727 int speed_per_layer[VPX_MAX_LAYERS]; /**< Speed setting for each sl */
728 int temporal_layering_mode; /**< Temporal layering mode */
729 } vpx_svc_extra_cfg_t;
731 /*!\brief Initialize an encoder instance
733 * Initializes a encoder context using the given interface. Applications
734 * should call the vpx_codec_enc_init convenience macro instead of this
735 * function directly, to ensure that the ABI version number parameter
736 * is properly initialized.
738 * If the library was configured with --disable-multithread, this call
739 * is not thread safe and should be guarded with a lock if being used
740 * in a multithreaded context.
742 * \param[in] ctx Pointer to this instance's context.
743 * \param[in] iface Pointer to the algorithm interface to use.
744 * \param[in] cfg Configuration to use, if known. May be NULL.
745 * \param[in] flags Bitfield of VPX_CODEC_USE_* flags
746 * \param[in] ver ABI version number. Must be set to
747 * VPX_ENCODER_ABI_VERSION
748 * \retval #VPX_CODEC_OK
749 * The decoder algorithm initialized.
750 * \retval #VPX_CODEC_MEM_ERROR
751 * Memory allocation failed.
753 vpx_codec_err_t vpx_codec_enc_init_ver(vpx_codec_ctx_t *ctx,
754 vpx_codec_iface_t *iface,
755 const vpx_codec_enc_cfg_t *cfg,
756 vpx_codec_flags_t flags, int ver);
758 /*!\brief Convenience macro for vpx_codec_enc_init_ver()
760 * Ensures the ABI version parameter is properly set.
762 #define vpx_codec_enc_init(ctx, iface, cfg, flags) \
763 vpx_codec_enc_init_ver(ctx, iface, cfg, flags, VPX_ENCODER_ABI_VERSION)
765 /*!\brief Initialize multi-encoder instance
767 * Initializes multi-encoder context using the given interface.
768 * Applications should call the vpx_codec_enc_init_multi convenience macro
769 * instead of this function directly, to ensure that the ABI version number
770 * parameter is properly initialized.
772 * \param[in] ctx Pointer to this instance's context.
773 * \param[in] iface Pointer to the algorithm interface to use.
774 * \param[in] cfg Configuration to use, if known. May be NULL.
775 * \param[in] num_enc Total number of encoders.
776 * \param[in] flags Bitfield of VPX_CODEC_USE_* flags
777 * \param[in] dsf Pointer to down-sampling factors.
778 * \param[in] ver ABI version number. Must be set to
779 * VPX_ENCODER_ABI_VERSION
780 * \retval #VPX_CODEC_OK
781 * The decoder algorithm initialized.
782 * \retval #VPX_CODEC_MEM_ERROR
783 * Memory allocation failed.
785 vpx_codec_err_t vpx_codec_enc_init_multi_ver(
786 vpx_codec_ctx_t *ctx, vpx_codec_iface_t *iface, vpx_codec_enc_cfg_t *cfg,
787 int num_enc, vpx_codec_flags_t flags, vpx_rational_t *dsf, int ver);
789 /*!\brief Convenience macro for vpx_codec_enc_init_multi_ver()
791 * Ensures the ABI version parameter is properly set.
793 #define vpx_codec_enc_init_multi(ctx, iface, cfg, num_enc, flags, dsf) \
794 vpx_codec_enc_init_multi_ver(ctx, iface, cfg, num_enc, flags, dsf, \
795 VPX_ENCODER_ABI_VERSION)
797 /*!\brief Get a default configuration
799 * Initializes a encoder configuration structure with default values. Supports
800 * the notion of "usages" so that an algorithm may offer different default
801 * settings depending on the user's intended goal. This function \ref SHOULD
802 * be called by all applications to initialize the configuration structure
803 * before specializing the configuration with application specific values.
805 * \param[in] iface Pointer to the algorithm interface to use.
806 * \param[out] cfg Configuration buffer to populate.
807 * \param[in] reserved Must set to 0 for VP8 and VP9.
809 * \retval #VPX_CODEC_OK
810 * The configuration was populated.
811 * \retval #VPX_CODEC_INCAPABLE
812 * Interface is not an encoder interface.
813 * \retval #VPX_CODEC_INVALID_PARAM
814 * A parameter was NULL, or the usage value was not recognized.
816 vpx_codec_err_t vpx_codec_enc_config_default(vpx_codec_iface_t *iface,
817 vpx_codec_enc_cfg_t *cfg,
818 unsigned int reserved);
820 /*!\brief Set or change configuration
822 * Reconfigures an encoder instance according to the given configuration.
824 * \param[in] ctx Pointer to this instance's context
825 * \param[in] cfg Configuration buffer to use
827 * \retval #VPX_CODEC_OK
828 * The configuration was populated.
829 * \retval #VPX_CODEC_INCAPABLE
830 * Interface is not an encoder interface.
831 * \retval #VPX_CODEC_INVALID_PARAM
832 * A parameter was NULL, or the usage value was not recognized.
834 vpx_codec_err_t vpx_codec_enc_config_set(vpx_codec_ctx_t *ctx,
835 const vpx_codec_enc_cfg_t *cfg);
837 /*!\brief Get global stream headers
839 * Retrieves a stream level global header packet, if supported by the codec.
841 * \param[in] ctx Pointer to this instance's context
844 * Encoder does not support global header
846 * Pointer to buffer containing global header packet
848 vpx_fixed_buf_t *vpx_codec_get_global_headers(vpx_codec_ctx_t *ctx);
850 /*!\brief deadline parameter analogous to VPx REALTIME mode. */
851 #define VPX_DL_REALTIME (1)
852 /*!\brief deadline parameter analogous to VPx GOOD QUALITY mode. */
853 #define VPX_DL_GOOD_QUALITY (1000000)
854 /*!\brief deadline parameter analogous to VPx BEST QUALITY mode. */
855 #define VPX_DL_BEST_QUALITY (0)
856 /*!\brief Encode a frame
858 * Encodes a video frame at the given "presentation time." The presentation
859 * time stamp (PTS) \ref MUST be strictly increasing.
861 * The encoder supports the notion of a soft real-time deadline. Given a
862 * non-zero value to the deadline parameter, the encoder will make a "best
863 * effort" guarantee to return before the given time slice expires. It is
864 * implicit that limiting the available time to encode will degrade the
865 * output quality. The encoder can be given an unlimited time to produce the
866 * best possible frame by specifying a deadline of '0'. This deadline
867 * supercedes the VPx notion of "best quality, good quality, realtime".
868 * Applications that wish to map these former settings to the new deadline
869 * based system can use the symbols #VPX_DL_REALTIME, #VPX_DL_GOOD_QUALITY,
870 * and #VPX_DL_BEST_QUALITY.
872 * When the last frame has been passed to the encoder, this function should
873 * continue to be called, with the img parameter set to NULL. This will
874 * signal the end-of-stream condition to the encoder and allow it to encode
875 * any held buffers. Encoding is complete when vpx_codec_encode() is called
876 * and vpx_codec_get_cx_data() returns no data.
878 * \param[in] ctx Pointer to this instance's context
879 * \param[in] img Image data to encode, NULL to flush.
880 * \param[in] pts Presentation time stamp, in timebase units.
881 * \param[in] duration Duration to show frame, in timebase units.
882 * \param[in] flags Flags to use for encoding this frame.
883 * \param[in] deadline Time to spend encoding, in microseconds. (0=infinite)
885 * \retval #VPX_CODEC_OK
886 * The configuration was populated.
887 * \retval #VPX_CODEC_INCAPABLE
888 * Interface is not an encoder interface.
889 * \retval #VPX_CODEC_INVALID_PARAM
890 * A parameter was NULL, the image format is unsupported, etc.
892 vpx_codec_err_t vpx_codec_encode(vpx_codec_ctx_t *ctx, const vpx_image_t *img,
893 vpx_codec_pts_t pts, unsigned long duration,
894 vpx_enc_frame_flags_t flags,
895 unsigned long deadline);
897 /*!\brief Set compressed data output buffer
899 * Sets the buffer that the codec should output the compressed data
900 * into. This call effectively sets the buffer pointer returned in the
901 * next VPX_CODEC_CX_FRAME_PKT packet. Subsequent packets will be
902 * appended into this buffer. The buffer is preserved across frames,
903 * so applications must periodically call this function after flushing
904 * the accumulated compressed data to disk or to the network to reset
905 * the pointer to the buffer's head.
907 * `pad_before` bytes will be skipped before writing the compressed
908 * data, and `pad_after` bytes will be appended to the packet. The size
909 * of the packet will be the sum of the size of the actual compressed
910 * data, pad_before, and pad_after. The padding bytes will be preserved
913 * Note that calling this function does not guarantee that the returned
914 * compressed data will be placed into the specified buffer. In the
915 * event that the encoded data will not fit into the buffer provided,
916 * the returned packet \ref MAY point to an internal buffer, as it would
917 * if this call were never used. In this event, the output packet will
918 * NOT have any padding, and the application must free space and copy it
919 * to the proper place. This is of particular note in configurations
920 * that may output multiple packets for a single encoded frame (e.g., lagged
921 * encoding) or if the application does not reset the buffer periodically.
923 * Applications may restore the default behavior of the codec providing
924 * the compressed data buffer by calling this function with a NULL
927 * Applications \ref MUSTNOT call this function during iteration of
928 * vpx_codec_get_cx_data().
930 * \param[in] ctx Pointer to this instance's context
931 * \param[in] buf Buffer to store compressed data into
932 * \param[in] pad_before Bytes to skip before writing compressed data
933 * \param[in] pad_after Bytes to skip after writing compressed data
935 * \retval #VPX_CODEC_OK
936 * The buffer was set successfully.
937 * \retval #VPX_CODEC_INVALID_PARAM
938 * A parameter was NULL, the image format is unsupported, etc.
940 vpx_codec_err_t vpx_codec_set_cx_data_buf(vpx_codec_ctx_t *ctx,
941 const vpx_fixed_buf_t *buf,
942 unsigned int pad_before,
943 unsigned int pad_after);
945 /*!\brief Encoded data iterator
947 * Iterates over a list of data packets to be passed from the encoder to the
948 * application. The different kinds of packets available are enumerated in
949 * #vpx_codec_cx_pkt_kind.
951 * #VPX_CODEC_CX_FRAME_PKT packets should be passed to the application's
952 * muxer. Multiple compressed frames may be in the list.
953 * #VPX_CODEC_STATS_PKT packets should be appended to a global buffer.
955 * The application \ref MUST silently ignore any packet kinds that it does
956 * not recognize or support.
958 * The data buffers returned from this function are only guaranteed to be
959 * valid until the application makes another call to any vpx_codec_* function.
961 * \param[in] ctx Pointer to this instance's context
962 * \param[in,out] iter Iterator storage, initialized to NULL
964 * \return Returns a pointer to an output data packet (compressed frame data,
965 * two-pass statistics, etc.) or NULL to signal end-of-list.
968 const vpx_codec_cx_pkt_t *vpx_codec_get_cx_data(vpx_codec_ctx_t *ctx,
969 vpx_codec_iter_t *iter);
971 /*!\brief Get Preview Frame
973 * Returns an image that can be used as a preview. Shows the image as it would
974 * exist at the decompressor. The application \ref MUST NOT write into this
977 * \param[in] ctx Pointer to this instance's context
979 * \return Returns a pointer to a preview image, or NULL if no image is
983 const vpx_image_t *vpx_codec_get_preview_frame(vpx_codec_ctx_t *ctx);
985 /*!@} - end defgroup encoder*/
989 #endif // VPX_VPX_ENCODER_H_