WebM Codec SDK
vpx_encoder.h
Go to the documentation of this file.
1 /*
2  * Copyright (c) 2010 The WebM project authors. All Rights Reserved.
3  *
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.
9  */
10 #ifndef VPX_VPX_VPX_ENCODER_H_
11 #define VPX_VPX_VPX_ENCODER_H_
12 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include "./vpx_codec.h"
33 #include "./vpx_ext_ratectrl.h"
34 
38 #define VPX_TS_MAX_PERIODICITY 16
39 
41 #define VPX_TS_MAX_LAYERS 5
42 
44 #define VPX_MAX_LAYERS 12 // 3 temporal + 4 spatial layers are allowed.
45 
47 #define VPX_SS_MAX_LAYERS 5
48 
50 #define VPX_SS_DEFAULT_LAYERS 1
51 
60 #define VPX_ENCODER_ABI_VERSION \
61  (14 + VPX_CODEC_ABI_VERSION + \
62  VPX_EXT_RATECTRL_ABI_VERSION)
73 #define VPX_CODEC_CAP_PSNR 0x10000
80 #define VPX_CODEC_CAP_OUTPUT_PARTITION 0x20000
81 
89 #define VPX_CODEC_USE_PSNR 0x10000
91 #define VPX_CODEC_USE_OUTPUT_PARTITION 0x20000
92 #define VPX_CODEC_USE_HIGHBITDEPTH 0x40000
98 typedef struct vpx_fixed_buf {
99  void *buf;
100  size_t sz;
101 } vpx_fixed_buf_t;
108 typedef int64_t vpx_codec_pts_t;
109 
117 typedef uint32_t vpx_codec_frame_flags_t;
118 #define VPX_FRAME_IS_KEY 0x1
121 #define VPX_FRAME_IS_DROPPABLE 0x2
122 
123 #define VPX_FRAME_IS_INVISIBLE 0x4
124 
125 #define VPX_FRAME_IS_FRAGMENT 0x8
126 
133 typedef uint32_t vpx_codec_er_flags_t;
135 #define VPX_ERROR_RESILIENT_DEFAULT 0x1
136 
140 #define VPX_ERROR_RESILIENT_PARTITIONS 0x2
141 
154 };
155 
161 typedef struct vpx_codec_cx_pkt {
163  union {
164  struct {
165  void *buf;
166  size_t sz;
170  unsigned long duration;
178  unsigned int width[VPX_SS_MAX_LAYERS];
179  unsigned int height[VPX_SS_MAX_LAYERS];
183  } frame;
186  struct vpx_psnr_pkt {
187  unsigned int samples[4];
188  uint64_t sse[4];
189  double psnr[4];
190  } psnr;
193  /* This packet size is fixed to allow codecs to extend this
194  * interface without having to manage storage for raw packets,
195  * i.e., if it's smaller than 128 bytes, you can store in the
196  * packet list directly.
197  */
198  char pad[128 - sizeof(enum vpx_codec_cx_pkt_kind)];
199  } data;
208  void *user_data);
209 
213  void *user_priv;
215 
220 typedef struct vpx_rational {
221  int num;
222  int den;
223 } vpx_rational_t;
226 typedef enum vpx_enc_pass {
230 } vpx_enc_pass;
231 
238 };
239 
252 };
253 
262 #define VPX_EFLAG_FORCE_KF (1 << 0)
270 typedef struct vpx_codec_enc_cfg {
271  /*
272  * generic settings (g)
273  */
274 
279  unsigned int g_usage;
280 
287  unsigned int g_threads;
288 
297  unsigned int g_profile;
306  unsigned int g_w;
307 
315  unsigned int g_h;
316 
324 
331  unsigned int g_input_bit_depth;
332 
345  struct vpx_rational g_timebase;
346 
354 
360  enum vpx_enc_pass g_pass;
361 
374  unsigned int g_lag_in_frames;
375 
376  /*
377  * rate control settings (rc)
378  */
379 
393  unsigned int rc_dropframe_thresh;
394 
402  unsigned int rc_resize_allowed;
403 
409  unsigned int rc_scaled_width;
410 
416  unsigned int rc_scaled_height;
417 
424  unsigned int rc_resize_up_thresh;
425 
432  unsigned int rc_resize_down_thresh;
433 
442  enum vpx_rc_mode rc_end_usage;
443 
450 
457 
462  unsigned int rc_target_bitrate;
463 
464  /*
465  * quantizer settings
466  */
467 
475  unsigned int rc_min_quantizer;
476 
484  unsigned int rc_max_quantizer;
485 
486  /*
487  * bitrate tolerance
488  */
489 
503  unsigned int rc_undershoot_pct;
504 
518  unsigned int rc_overshoot_pct;
519 
520  /*
521  * decoder buffer model parameters
522  */
523 
533  unsigned int rc_buf_sz;
534 
542  unsigned int rc_buf_initial_sz;
543 
551  unsigned int rc_buf_optimal_sz;
552 
553  /*
554  * 2 pass rate control parameters
555  */
556 
565  unsigned int rc_2pass_vbr_bias_pct;
566 
573 
580 
587 
588  /*
589  * keyframing settings (kf)
590  */
591 
598  enum vpx_kf_mode kf_mode;
599 
607  unsigned int kf_min_dist;
608 
616  unsigned int kf_max_dist;
617 
618  /*
619  * Spatial scalability settings (ss)
620  */
621 
626  unsigned int ss_number_layers;
627 
633  int ss_enable_auto_alt_ref[VPX_SS_MAX_LAYERS];
634 
640  unsigned int ss_target_bitrate[VPX_SS_MAX_LAYERS];
641 
646  unsigned int ts_number_layers;
647 
653  unsigned int ts_target_bitrate[VPX_TS_MAX_LAYERS];
654 
660  unsigned int ts_rate_decimator[VPX_TS_MAX_LAYERS];
661 
669  unsigned int ts_periodicity;
670 
678  unsigned int ts_layer_id[VPX_TS_MAX_PERIODICITY];
679 
686  unsigned int layer_target_bitrate[VPX_MAX_LAYERS];
687 
703 typedef struct vpx_svc_parameters {
704  int max_quantizers[VPX_MAX_LAYERS];
705  int min_quantizers[VPX_MAX_LAYERS];
706  int scaling_factor_num[VPX_MAX_LAYERS];
707  int scaling_factor_den[VPX_MAX_LAYERS];
708  int speed_per_layer[VPX_MAX_LAYERS];
710  int loopfilter_ctrl[VPX_MAX_LAYERS];
712 
736  vpx_codec_iface_t *iface,
737  const vpx_codec_enc_cfg_t *cfg,
738  vpx_codec_flags_t flags, int ver);
739 
744 #define vpx_codec_enc_init(ctx, iface, cfg, flags) \
745  vpx_codec_enc_init_ver(ctx, iface, cfg, flags, VPX_ENCODER_ABI_VERSION)
746 
769  int num_enc, vpx_codec_flags_t flags, vpx_rational_t *dsf, int ver);
770 
775 #define vpx_codec_enc_init_multi(ctx, iface, cfg, num_enc, flags, dsf) \
776  vpx_codec_enc_init_multi_ver(ctx, iface, cfg, num_enc, flags, dsf, \
777  VPX_ENCODER_ABI_VERSION)
778 
799  vpx_codec_enc_cfg_t *cfg,
800  unsigned int usage);
801 
817  const vpx_codec_enc_cfg_t *cfg);
818 
831 
833 #define VPX_DL_REALTIME (1)
834 
835 #define VPX_DL_GOOD_QUALITY (1000000)
836 
837 #define VPX_DL_BEST_QUALITY (0)
838 
875  vpx_codec_pts_t pts, unsigned long duration,
877  unsigned long deadline);
878 
923  const vpx_fixed_buf_t *buf,
924  unsigned int pad_before,
925  unsigned int pad_after);
926 
951  vpx_codec_iter_t *iter);
952 
966 
968 #ifdef __cplusplus
969 }
970 #endif
971 #endif // VPX_VPX_VPX_ENCODER_H_
Rational Number.
Definition: vpx_encoder.h:220
unsigned int rc_buf_initial_sz
Decoder Buffer Initial Size.
Definition: vpx_encoder.h:542
vpx_fixed_buf_t twopass_stats
Definition: vpx_encoder.h:184
unsigned int width[5]
Width and height of frames in this packet. VP8 will only use the first one.
Definition: vpx_encoder.h:178
unsigned int ts_number_layers
Number of temporal coding layers.
Definition: vpx_encoder.h:646
vpx_codec_err_t vpx_codec_set_cx_data_buf(vpx_codec_ctx_t *ctx, const vpx_fixed_buf_t *buf, unsigned int pad_before, unsigned int pad_after)
Set compressed data output buffer.
#define VPX_MAX_LAYERS
Definition: vpx_encoder.h:44
Definition: vpx_encoder.h:237
Image Descriptor.
Definition: vpx_image.h:72
int temporal_layering_mode
Definition: vpx_encoder.h:709
vpx_codec_pts_t pts
time stamp to show frame (in timebase units)
Definition: vpx_encoder.h:168
vpx_kf_mode
Keyframe placement mode.
Definition: vpx_encoder.h:248
unsigned int rc_scaled_width
Internal coded frame width.
Definition: vpx_encoder.h:409
void(* vpx_codec_enc_output_cx_pkt_cb_fn_t)(vpx_codec_cx_pkt_t *pkt, void *user_data)
Encoder return output buffer callback.
Definition: vpx_encoder.h:207
#define VPX_TS_MAX_LAYERS
Definition: vpx_encoder.h:41
Definition: vpx_encoder.h:235
unsigned int g_usage
Deprecated: Algorithm specific "usage" value.
Definition: vpx_encoder.h:279
struct vpx_codec_enc_cfg vpx_codec_enc_cfg_t
Encoder configuration structure.
struct vpx_fixed_buf vpx_fixed_buf_t
Generic fixed size buffer structure.
unsigned int rc_buf_sz
Decoder Buffer Size.
Definition: vpx_encoder.h:533
unsigned int g_input_bit_depth
Bit-depth of the input frames.
Definition: vpx_encoder.h:331
vpx_codec_enc_output_cx_pkt_cb_fn_t output_cx_pkt
Definition: vpx_encoder.h:212
int den
Definition: vpx_encoder.h:222
vpx_codec_err_t vpx_codec_encode(vpx_codec_ctx_t *ctx, const vpx_image_t *img, vpx_codec_pts_t pts, unsigned long duration, vpx_enc_frame_flags_t flags, unsigned long deadline)
Encode a frame.
unsigned int rc_max_quantizer
Maximum (Worst Quality) Quantizer.
Definition: vpx_encoder.h:484
struct vpx_svc_parameters vpx_svc_extra_cfg_t
vp9 svc extra configure parameters
unsigned int rc_min_quantizer
Minimum (Best Quality) Quantizer.
Definition: vpx_encoder.h:475
Definition: vpx_encoder.h:150
unsigned int kf_max_dist
Keyframe maximum interval.
Definition: vpx_encoder.h:616
int partition_id
the partition id defines the decoding order of the partitions. Only applicable when "output partition...
Definition: vpx_encoder.h:175
unsigned int g_lag_in_frames
Allow lagged encoding.
Definition: vpx_encoder.h:374
vpx_enc_pass
Multi-pass Encoding Pass.
Definition: vpx_encoder.h:226
Encoder configuration structure.
Definition: vpx_encoder.h:270
Definition: vpx_encoder.h:153
Definition: vpx_encoder.h:152
Definition: vpx_encoder.h:250
void * user_priv
Definition: vpx_encoder.h:213
Encoder output packet.
Definition: vpx_encoder.h:161
unsigned int rc_overshoot_pct
Rate control adaptation overshoot control.
Definition: vpx_encoder.h:518
void * buf
Definition: vpx_encoder.h:99
unsigned int rc_2pass_vbr_bias_pct
Two-pass mode CBR/VBR bias.
Definition: vpx_encoder.h:565
unsigned int rc_buf_optimal_sz
Decoder Buffer Optimal Size.
Definition: vpx_encoder.h:551
vpx_codec_err_t vpx_codec_enc_config_set(vpx_codec_ctx_t *ctx, const vpx_codec_enc_cfg_t *cfg)
Set or change configuration.
Generic fixed size buffer structure.
Definition: vpx_encoder.h:98
uint32_t vpx_codec_frame_flags_t
Compressed Frame Flags.
Definition: vpx_encoder.h:117
unsigned int kf_min_dist
Keyframe minimum interval.
Definition: vpx_encoder.h:607
Definition: vpx_encoder.h:228
unsigned int g_profile
Bitstream profile to use.
Definition: vpx_encoder.h:297
Definition: vpx_encoder.h:229
struct vpx_codec_cx_pkt::@1::@2 frame
#define VPX_SS_MAX_LAYERS
Definition: vpx_encoder.h:47
unsigned int g_w
Width of the frame.
Definition: vpx_encoder.h:306
enum vpx_bit_depth vpx_bit_depth_t
Bit depth for codecThis enumeration determines the bit depth of the codec.
unsigned int rc_undershoot_pct
Rate control adaptation undershoot control.
Definition: vpx_encoder.h:503
uint64_t sse[4]
Definition: vpx_encoder.h:188
unsigned int g_h
Height of the frame.
Definition: vpx_encoder.h:315
size_t sz
Definition: vpx_encoder.h:166
enum vpx_codec_cx_pkt_kind kind
Definition: vpx_encoder.h:162
uint8_t spatial_layer_encoded[5]
Flag to indicate if spatial layer frame in this packet is encoded or dropped. VP8 will always be set ...
Definition: vpx_encoder.h:182
unsigned int rc_dropframe_thresh
Temporal resampling configuration, if supported by the codec.
Definition: vpx_encoder.h:393
vpx_fixed_buf_t raw
Definition: vpx_encoder.h:191
Callback function pointer / user data pair storage.
Definition: vpx_encoder.h:211
long vpx_enc_frame_flags_t
Encoded Frame Flags.
Definition: vpx_encoder.h:261
unsigned int rc_target_bitrate
Target data rate.
Definition: vpx_encoder.h:462
int num
Definition: vpx_encoder.h:221
const struct vpx_codec_iface vpx_codec_iface_t
Codec interface structure.
Definition: vpx_codec.h:177
char pad[128-sizeof(enum vpx_codec_cx_pkt_kind)]
Definition: vpx_encoder.h:198
vpx_codec_err_t vpx_codec_enc_config_default(vpx_codec_iface_t *iface, vpx_codec_enc_cfg_t *cfg, unsigned int usage)
Get a default configuration.
long vpx_codec_flags_t
Initialization-time Feature Enabling.
Definition: vpx_codec.h:170
vpx_codec_cx_pkt_kind
Encoder output packet variants.
Definition: vpx_encoder.h:148
Definition: vpx_encoder.h:234
double psnr[4]
Definition: vpx_encoder.h:189
Definition: vpx_encoder.h:249
unsigned int g_threads
Maximum number of threads to use.
Definition: vpx_encoder.h:287
unsigned int samples[4]
Definition: vpx_encoder.h:187
vpx_fixed_buf_t firstpass_mb_stats
Definition: vpx_encoder.h:185
vpx_rc_mode
Rate control mode.
Definition: vpx_encoder.h:233
const vpx_image_t * vpx_codec_get_preview_frame(vpx_codec_ctx_t *ctx)
Get Preview Frame.
unsigned int ss_number_layers
Number of spatial coding layers.
Definition: vpx_encoder.h:626
unsigned int height[5]
Definition: vpx_encoder.h:179
unsigned long duration
duration to show frame (in timebase units)
Definition: vpx_encoder.h:170
vpx_bit_depth_t g_bit_depth
Bit-depth of the codec.
Definition: vpx_encoder.h:323
uint32_t vpx_codec_er_flags_t
Error Resilient flags.
Definition: vpx_encoder.h:133
unsigned int rc_resize_allowed
Enable/disable spatial resampling, if supported by the codec.
Definition: vpx_encoder.h:402
vpx_codec_err_t
Algorithm return codes.
Definition: vpx_codec.h:93
const vpx_codec_cx_pkt_t * vpx_codec_get_cx_data(vpx_codec_ctx_t *ctx, vpx_codec_iter_t *iter)
Encoded data iterator.
union vpx_codec_cx_pkt::@1 data
struct vpx_codec_cx_pkt vpx_codec_cx_pkt_t
Encoder output packet.
struct vpx_rational vpx_rational_t
Rational Number.
int temporal_layering_mode
Temporal layering mode indicating which temporal layering scheme to use.
Definition: vpx_encoder.h:695
struct vpx_codec_enc_output_cx_cb_pair vpx_codec_priv_output_cx_pkt_cb_pair_t
Callback function pointer / user data pair storage.
vpx_fixed_buf_t rc_twopass_stats_in
Two-pass stats buffer.
Definition: vpx_encoder.h:449
Definition: vpx_encoder.h:251
unsigned int rc_scaled_height
Internal coded frame height.
Definition: vpx_encoder.h:416
Definition: vpx_encoder.h:151
vpx_fixed_buf_t rc_firstpass_mb_stats_in
first pass mb stats buffer.
Definition: vpx_encoder.h:456
int64_t vpx_codec_pts_t
Time Stamp Type.
Definition: vpx_encoder.h:108
#define VPX_TS_MAX_PERIODICITY
Definition: vpx_encoder.h:38
vpx_fixed_buf_t * vpx_codec_get_global_headers(vpx_codec_ctx_t *ctx)
Get global stream headers.
Definition: vpx_encoder.h:236
Describes the codec algorithm interface to applications.
unsigned int ts_periodicity
Length of the sequence defining frame temporal layer membership.
Definition: vpx_encoder.h:669
vpx_codec_err_t vpx_codec_enc_init_multi_ver(vpx_codec_ctx_t *ctx, vpx_codec_iface_t *iface, vpx_codec_enc_cfg_t *cfg, int num_enc, vpx_codec_flags_t flags, vpx_rational_t *dsf, int ver)
Initialize multi-encoder instance.
size_t sz
Definition: vpx_encoder.h:100
unsigned int rc_resize_down_thresh
Spatial resampling down watermark.
Definition: vpx_encoder.h:432
vpx_codec_err_t vpx_codec_enc_init_ver(vpx_codec_ctx_t *ctx, vpx_codec_iface_t *iface, const vpx_codec_enc_cfg_t *cfg, vpx_codec_flags_t flags, int ver)
Initialize an encoder instance.
const void * vpx_codec_iter_t
Iterator.
Definition: vpx_codec.h:190
Definition: vpx_encoder.h:149
vpx_codec_frame_flags_t flags
Definition: vpx_encoder.h:171
void * buf
Definition: vpx_encoder.h:165
unsigned int rc_2pass_vbr_maxsection_pct
Two-pass mode per-GOP maximum bitrate.
Definition: vpx_encoder.h:579
vp9 svc extra configure parameters
Definition: vpx_encoder.h:703
vpx_codec_er_flags_t g_error_resilient
Enable error resilient modes.
Definition: vpx_encoder.h:353
unsigned int rc_2pass_vbr_minsection_pct
Two-pass mode per-GOP minimum bitrate.
Definition: vpx_encoder.h:572
unsigned int rc_2pass_vbr_corpus_complexity
Two-pass corpus vbr mode complexity control Used only in VP9: A value representing the corpus midpoin...
Definition: vpx_encoder.h:586
unsigned int rc_resize_up_thresh
Spatial resampling up watermark.
Definition: vpx_encoder.h:424
Definition: vpx_encoder.h:227
Codec context structure.
Definition: vpx_codec.h:200