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_ENCODER_H_
11 #define VPX_VPX_ENCODER_H_
12 
28 #ifdef __cplusplus
29 extern "C" {
30 #endif
31 
32 #include "./vpx_codec.h"
33 
37 #define VPX_TS_MAX_PERIODICITY 16
38 
40 #define VPX_TS_MAX_LAYERS 5
41 
43 #define MAX_PERIODICITY VPX_TS_MAX_PERIODICITY
44 
46 #define VPX_MAX_LAYERS 12 // 3 temporal + 4 spatial layers are allowed.
47 
49 #define MAX_LAYERS VPX_MAX_LAYERS // 3 temporal + 4 spatial layers allowed.
50 
52 #define VPX_SS_MAX_LAYERS 5
53 
55 #define VPX_SS_DEFAULT_LAYERS 1
56 
65 #define VPX_ENCODER_ABI_VERSION \
66  (6 + VPX_CODEC_ABI_VERSION)
77 #define VPX_CODEC_CAP_PSNR 0x10000
84 #define VPX_CODEC_CAP_OUTPUT_PARTITION 0x20000
85 
93 #define VPX_CODEC_USE_PSNR 0x10000
95 #define VPX_CODEC_USE_OUTPUT_PARTITION 0x20000
96 #define VPX_CODEC_USE_HIGHBITDEPTH 0x40000
102 typedef struct vpx_fixed_buf {
103  void *buf;
104  size_t sz;
105 } vpx_fixed_buf_t;
112 typedef int64_t vpx_codec_pts_t;
113 
121 typedef uint32_t vpx_codec_frame_flags_t;
122 #define VPX_FRAME_IS_KEY 0x1
125 #define VPX_FRAME_IS_DROPPABLE 0x2
126 
127 #define VPX_FRAME_IS_INVISIBLE 0x4
128 
129 #define VPX_FRAME_IS_FRAGMENT 0x8
130 
137 typedef uint32_t vpx_codec_er_flags_t;
139 #define VPX_ERROR_RESILIENT_DEFAULT 0x1
140 
144 #define VPX_ERROR_RESILIENT_PARTITIONS 0x2
145 
157 // Spatial SVC is still experimental and may be removed.
158 #if defined(VPX_TEST_SPATIAL_SVC)
159  VPX_CODEC_SPATIAL_SVC_LAYER_SIZES,
160  VPX_CODEC_SPATIAL_SVC_LAYER_PSNR,
161 #endif
163 };
164 
170 typedef struct vpx_codec_cx_pkt {
172  union {
173  struct {
174  void *buf;
175  size_t sz;
179  unsigned long duration;
185  } frame;
188  struct vpx_psnr_pkt {
189  unsigned int samples[4];
190  uint64_t sse[4];
191  double psnr[4];
192  } psnr;
194 // Spatial SVC is still experimental and may be removed.
195 #if defined(VPX_TEST_SPATIAL_SVC)
196  size_t layer_sizes[VPX_SS_MAX_LAYERS];
197  struct vpx_psnr_pkt layer_psnr[VPX_SS_MAX_LAYERS];
198 #endif
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)];
206  } data;
214 // putting the definitions here for now. (agrange: find if there
215 // is a better place for this)
217  void *user_data);
218 
222  void *user_priv;
224 
229 typedef struct vpx_rational {
230  int num;
231  int den;
232 } vpx_rational_t;
239 };
240 
247 };
248 
261 };
262 
271 #define VPX_EFLAG_FORCE_KF (1 << 0)
279 typedef struct vpx_codec_enc_cfg {
280  /*
281  * generic settings (g)
282  */
283 
291  unsigned int g_usage;
292 
299  unsigned int g_threads;
300 
309  unsigned int g_profile;
318  unsigned int g_w;
319 
327  unsigned int g_h;
328 
336 
343  unsigned int g_input_bit_depth;
344 
357  struct vpx_rational g_timebase;
358 
366 
372  enum vpx_enc_pass g_pass;
373 
386  unsigned int g_lag_in_frames;
387 
388  /*
389  * rate control settings (rc)
390  */
391 
408  unsigned int rc_dropframe_thresh;
409 
417  unsigned int rc_resize_allowed;
418 
424  unsigned int rc_scaled_width;
425 
431  unsigned int rc_scaled_height;
432 
439  unsigned int rc_resize_up_thresh;
440 
447  unsigned int rc_resize_down_thresh;
448 
457  enum vpx_rc_mode rc_end_usage;
458 
465 
472 
477  unsigned int rc_target_bitrate;
478 
479  /*
480  * quantizer settings
481  */
482 
491  unsigned int rc_min_quantizer;
492 
501  unsigned int rc_max_quantizer;
502 
503  /*
504  * bitrate tolerance
505  */
506 
520  unsigned int rc_undershoot_pct;
521 
535  unsigned int rc_overshoot_pct;
536 
537  /*
538  * decoder buffer model parameters
539  */
540 
550  unsigned int rc_buf_sz;
551 
559  unsigned int rc_buf_initial_sz;
560 
568  unsigned int rc_buf_optimal_sz;
569 
570  /*
571  * 2 pass rate control parameters
572  */
573 
582  unsigned int rc_2pass_vbr_bias_pct;
583 
590 
597 
604 
605  /*
606  * keyframing settings (kf)
607  */
608 
615  enum vpx_kf_mode kf_mode;
616 
624  unsigned int kf_min_dist;
625 
633  unsigned int kf_max_dist;
634 
635  /*
636  * Spatial scalability settings (ss)
637  */
638 
643  unsigned int ss_number_layers;
644 
650  int ss_enable_auto_alt_ref[VPX_SS_MAX_LAYERS];
651 
657  unsigned int ss_target_bitrate[VPX_SS_MAX_LAYERS];
658 
663  unsigned int ts_number_layers;
664 
670  unsigned int ts_target_bitrate[VPX_TS_MAX_LAYERS];
671 
677  unsigned int ts_rate_decimator[VPX_TS_MAX_LAYERS];
678 
686  unsigned int ts_periodicity;
687 
695  unsigned int ts_layer_id[VPX_TS_MAX_PERIODICITY];
696 
703  unsigned int layer_target_bitrate[VPX_MAX_LAYERS];
704 
720 typedef struct vpx_svc_parameters {
728 
752  vpx_codec_iface_t *iface,
753  const vpx_codec_enc_cfg_t *cfg,
754  vpx_codec_flags_t flags, int ver);
755 
760 #define vpx_codec_enc_init(ctx, iface, cfg, flags) \
761  vpx_codec_enc_init_ver(ctx, iface, cfg, flags, VPX_ENCODER_ABI_VERSION)
762 
785  int num_enc, vpx_codec_flags_t flags, vpx_rational_t *dsf, int ver);
786 
791 #define vpx_codec_enc_init_multi(ctx, iface, cfg, num_enc, flags, dsf) \
792  vpx_codec_enc_init_multi_ver(ctx, iface, cfg, num_enc, flags, dsf, \
793  VPX_ENCODER_ABI_VERSION)
794 
815  vpx_codec_enc_cfg_t *cfg,
816  unsigned int reserved);
817 
833  const vpx_codec_enc_cfg_t *cfg);
834 
847 
849 #define VPX_DL_REALTIME (1)
850 
851 #define VPX_DL_GOOD_QUALITY (1000000)
852 
853 #define VPX_DL_BEST_QUALITY (0)
854 
891  vpx_codec_pts_t pts, unsigned long duration,
892  vpx_enc_frame_flags_t flags,
893  unsigned long deadline);
894 
939  const vpx_fixed_buf_t *buf,
940  unsigned int pad_before,
941  unsigned int pad_after);
942 
967  vpx_codec_iter_t *iter);
968 
982 
984 #ifdef __cplusplus
985 }
986 #endif
987 #endif // VPX_VPX_ENCODER_H_
Rational Number.
Definition: vpx_encoder.h:229
unsigned int rc_buf_initial_sz
Decoder Buffer Initial Size.
Definition: vpx_encoder.h:559
vpx_fixed_buf_t twopass_stats
Definition: vpx_encoder.h:186
int min_quantizers[12]
Definition: vpx_encoder.h:722
unsigned int ts_number_layers
Number of temporal coding layers.
Definition: vpx_encoder.h:663
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:46
Definition: vpx_encoder.h:246
Image Descriptor.
Definition: vpx_image.h:88
int temporal_layering_mode
Definition: vpx_encoder.h:726
vpx_codec_pts_t pts
time stamp to show frame (in timebase units)
Definition: vpx_encoder.h:177
vpx_kf_mode
Keyframe placement mode.
Definition: vpx_encoder.h:257
unsigned int rc_scaled_width
Internal coded frame width.
Definition: vpx_encoder.h:424
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:216
#define VPX_TS_MAX_LAYERS
Definition: vpx_encoder.h:40
Definition: vpx_encoder.h:244
unsigned int g_usage
Algorithm specific "usage" value.
Definition: vpx_encoder.h:291
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:550
unsigned int g_input_bit_depth
Bit-depth of the input frames.
Definition: vpx_encoder.h:343
vpx_codec_enc_output_cx_pkt_cb_fn_t output_cx_pkt
Definition: vpx_encoder.h:221
int den
Definition: vpx_encoder.h:231
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:501
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:491
Definition: vpx_encoder.h:154
char pad[128 - sizeof(enum vpx_codec_cx_pkt_kind)]
Definition: vpx_encoder.h:205
unsigned int kf_max_dist
Keyframe maximum interval.
Definition: vpx_encoder.h:633
int partition_id
the partition id defines the decoding order of the partitions. Only applicable when "output partition...
Definition: vpx_encoder.h:184
unsigned int g_lag_in_frames
Allow lagged encoding.
Definition: vpx_encoder.h:386
vpx_enc_pass
Multi-pass Encoding Pass.
Definition: vpx_encoder.h:235
Encoder configuration structure.
Definition: vpx_encoder.h:279
Definition: vpx_encoder.h:162
Definition: vpx_encoder.h:156
Definition: vpx_encoder.h:259
void * user_priv
Definition: vpx_encoder.h:222
Encoder output packet.
Definition: vpx_encoder.h:170
unsigned int rc_overshoot_pct
Rate control adaptation overshoot control.
Definition: vpx_encoder.h:535
void * buf
Definition: vpx_encoder.h:103
unsigned int rc_2pass_vbr_bias_pct
Two-pass mode CBR/VBR bias.
Definition: vpx_encoder.h:582
unsigned int rc_buf_optimal_sz
Decoder Buffer Optimal Size.
Definition: vpx_encoder.h:568
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:102
uint32_t vpx_codec_frame_flags_t
Compressed Frame Flags.
Definition: vpx_encoder.h:121
unsigned int kf_min_dist
Keyframe minimum interval.
Definition: vpx_encoder.h:624
Definition: vpx_encoder.h:237
unsigned int g_profile
Bitstream profile to use.
Definition: vpx_encoder.h:309
Definition: vpx_encoder.h:238
struct vpx_codec_cx_pkt::@1::@2 frame
#define VPX_SS_MAX_LAYERS
Definition: vpx_encoder.h:52
int scaling_factor_num[12]
Definition: vpx_encoder.h:723
unsigned int g_w
Width of the frame.
Definition: vpx_encoder.h:318
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:520
uint64_t sse[4]
Definition: vpx_encoder.h:190
unsigned int g_h
Height of the frame.
Definition: vpx_encoder.h:327
size_t sz
Definition: vpx_encoder.h:175
enum vpx_codec_cx_pkt_kind kind
Definition: vpx_encoder.h:171
unsigned int rc_dropframe_thresh
Temporal resampling configuration, if supported by the codec.
Definition: vpx_encoder.h:408
vpx_fixed_buf_t raw
Definition: vpx_encoder.h:193
Callback function pointer / user data pair storage.
Definition: vpx_encoder.h:220
long vpx_enc_frame_flags_t
Encoded Frame Flags.
Definition: vpx_encoder.h:270
unsigned int rc_target_bitrate
Target data rate.
Definition: vpx_encoder.h:477
int num
Definition: vpx_encoder.h:230
const struct vpx_codec_iface vpx_codec_iface_t
Codec interface structure.
Definition: vpx_codec.h:174
long vpx_codec_flags_t
Initialization-time Feature Enabling.
Definition: vpx_codec.h:167
vpx_codec_cx_pkt_kind
Encoder output packet variants.
Definition: vpx_encoder.h:152
Definition: vpx_encoder.h:243
double psnr[4]
Definition: vpx_encoder.h:191
Definition: vpx_encoder.h:258
unsigned int g_threads
Maximum number of threads to use.
Definition: vpx_encoder.h:299
unsigned int samples[4]
Definition: vpx_encoder.h:189
vpx_fixed_buf_t firstpass_mb_stats
Definition: vpx_encoder.h:187
vpx_rc_mode
Rate control mode.
Definition: vpx_encoder.h:242
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:643
unsigned long duration
duration to show frame (in timebase units)
Definition: vpx_encoder.h:179
vpx_bit_depth_t g_bit_depth
Bit-depth of the codec.
Definition: vpx_encoder.h:335
uint32_t vpx_codec_er_flags_t
Error Resilient flags.
Definition: vpx_encoder.h:137
unsigned int rc_resize_allowed
Enable/disable spatial resampling, if supported by the codec.
Definition: vpx_encoder.h:417
vpx_codec_err_t
Algorithm return codes.
Definition: vpx_codec.h:90
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:712
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:464
Definition: vpx_encoder.h:260
int speed_per_layer[12]
Definition: vpx_encoder.h:725
unsigned int rc_scaled_height
Internal coded frame height.
Definition: vpx_encoder.h:431
Definition: vpx_encoder.h:155
vpx_fixed_buf_t rc_firstpass_mb_stats_in
first pass mb stats buffer.
Definition: vpx_encoder.h:471
int64_t vpx_codec_pts_t
Time Stamp Type.
Definition: vpx_encoder.h:112
vpx_codec_err_t vpx_codec_enc_config_default(vpx_codec_iface_t *iface, vpx_codec_enc_cfg_t *cfg, unsigned int reserved)
Get a default configuration.
#define VPX_TS_MAX_PERIODICITY
Definition: vpx_encoder.h:37
vpx_fixed_buf_t * vpx_codec_get_global_headers(vpx_codec_ctx_t *ctx)
Get global stream headers.
Definition: vpx_encoder.h:245
Describes the codec algorithm interface to applications.
unsigned int ts_periodicity
Length of the sequence defining frame temporal layer membership.
Definition: vpx_encoder.h:686
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:104
unsigned int rc_resize_down_thresh
Spatial resampling down watermark.
Definition: vpx_encoder.h:447
int scaling_factor_den[12]
Definition: vpx_encoder.h:724
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:187
Definition: vpx_encoder.h:153
int max_quantizers[12]
Definition: vpx_encoder.h:721
vpx_codec_frame_flags_t flags
Definition: vpx_encoder.h:180
void * buf
Definition: vpx_encoder.h:174
unsigned int rc_2pass_vbr_maxsection_pct
Two-pass mode per-GOP maximum bitrate.
Definition: vpx_encoder.h:596
vp9 svc extra configure parameters
Definition: vpx_encoder.h:720
vpx_codec_er_flags_t g_error_resilient
Enable error resilient modes.
Definition: vpx_encoder.h:365
unsigned int rc_2pass_vbr_minsection_pct
Two-pass mode per-GOP minimum bitrate.
Definition: vpx_encoder.h:589
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:603
unsigned int rc_resize_up_thresh
Spatial resampling up watermark.
Definition: vpx_encoder.h:439
Definition: vpx_encoder.h:236
Codec context structure.
Definition: vpx_codec.h:197