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 MAX_LAYERS VPX_TS_MAX_LAYERS
47 
49 #define VPX_SS_MAX_LAYERS 5
50 
52 #define VPX_SS_DEFAULT_LAYERS 1
53 
62 #define VPX_ENCODER_ABI_VERSION (4 + VPX_CODEC_ABI_VERSION)
74 #define VPX_CODEC_CAP_PSNR 0x10000
81 #define VPX_CODEC_CAP_OUTPUT_PARTITION 0x20000
82 
85 #define VPX_CODEC_CAP_HIGHBITDEPTH 0x40000
86 
94 #define VPX_CODEC_USE_PSNR 0x10000
95 #define VPX_CODEC_USE_OUTPUT_PARTITION 0x20000
97 #define VPX_CODEC_USE_HIGHBITDEPTH 0x40000
104  typedef struct vpx_fixed_buf {
105  void *buf;
106  size_t sz;
115  typedef int64_t vpx_codec_pts_t;
117 
125  typedef uint32_t vpx_codec_frame_flags_t;
126 #define VPX_FRAME_IS_KEY 0x1
127 #define VPX_FRAME_IS_DROPPABLE 0x2
130 #define VPX_FRAME_IS_INVISIBLE 0x4
132 #define VPX_FRAME_IS_FRAGMENT 0x8
141  typedef uint32_t vpx_codec_er_flags_t;
142 #define VPX_ERROR_RESILIENT_DEFAULT 0x1
144 #define VPX_ERROR_RESILIENT_PARTITIONS 0x2
159  enum vpx_codec_cx_pkt_kind {
164  // Spatial SVC is still experimental and may be removed before the next ABI
165  // bump.
166 #if VPX_ENCODER_ABI_VERSION > (4 + VPX_CODEC_ABI_VERSION)
167  VPX_CODEC_SPATIAL_SVC_LAYER_SIZES,
168  VPX_CODEC_SPATIAL_SVC_LAYER_PSNR,
169 #endif
170  VPX_CODEC_CUSTOM_PKT = 256
171  };
179  typedef struct vpx_codec_cx_pkt {
181  union {
182  struct {
183  void *buf;
184  size_t sz;
187  unsigned long duration;
190  int partition_id;
197  } frame;
200  struct vpx_psnr_pkt {
201  unsigned int samples[4];
202  uint64_t sse[4];
203  double psnr[4];
204  } psnr;
206  // Spatial SVC is still experimental and may be removed before the next
207  // ABI bump.
208 #if VPX_ENCODER_ABI_VERSION > (4 + VPX_CODEC_ABI_VERSION)
209  size_t layer_sizes[VPX_SS_MAX_LAYERS];
210  struct vpx_psnr_pkt layer_psnr[VPX_SS_MAX_LAYERS];
211 #endif
213  /* This packet size is fixed to allow codecs to extend this
214  * interface without having to manage storage for raw packets,
215  * i.e., if it's smaller than 128 bytes, you can store in the
216  * packet list directly.
217  */
218  char pad[128 - sizeof(enum vpx_codec_cx_pkt_kind)];
219  } data;
228  // putting the definitions here for now. (agrange: find if there
229  // is a better place for this)
231  void *user_data);
232 
234  typedef struct vpx_codec_enc_output_cx_cb_pair {
236  void *user_priv;
238 
243  typedef struct vpx_rational {
244  int num;
245  int den;
246  } vpx_rational_t;
250  enum vpx_enc_pass {
254  };
255 
258  enum vpx_rc_mode {
259  VPX_VBR,
260  VPX_CBR,
261  VPX_CQ,
262  VPX_Q,
263  };
274  enum vpx_kf_mode {
276  VPX_KF_AUTO,
277  VPX_KF_DISABLED = 0
278  };
279 
280 
288  typedef long vpx_enc_frame_flags_t;
289 #define VPX_EFLAG_FORCE_KF (1<<0)
298  typedef struct vpx_codec_enc_cfg {
299  /*
300  * generic settings (g)
301  */
310  unsigned int g_usage;
312 
319  unsigned int g_threads;
320 
321 
330  unsigned int g_profile;
341  unsigned int g_w;
342 
351  unsigned int g_h;
352 
359  vpx_bit_depth_t g_bit_depth;
360 
367  unsigned int g_input_bit_depth;
368 
381  struct vpx_rational g_timebase;
382 
383 
390  vpx_codec_er_flags_t g_error_resilient;
391 
392 
398  enum vpx_enc_pass g_pass;
399 
400 
413  unsigned int g_lag_in_frames;
414 
415 
416  /*
417  * rate control settings (rc)
418  */
419 
436  unsigned int rc_dropframe_thresh;
437 
438 
446  unsigned int rc_resize_allowed;
447 
453  unsigned int rc_scaled_width;
454 
460  unsigned int rc_scaled_height;
461 
468  unsigned int rc_resize_up_thresh;
469 
470 
477  unsigned int rc_resize_down_thresh;
478 
479 
488  enum vpx_rc_mode rc_end_usage;
489 
496  vpx_fixed_buf_t rc_twopass_stats_in;
497 
503  vpx_fixed_buf_t rc_firstpass_mb_stats_in;
504 
509  unsigned int rc_target_bitrate;
510 
511 
512  /*
513  * quantizer settings
514  */
515 
525  unsigned int rc_min_quantizer;
526 
527 
536  unsigned int rc_max_quantizer;
537 
539  /*
540  * bitrate tolerance
541  */
542 
543 
554  unsigned int rc_undershoot_pct;
555 
556 
567  unsigned int rc_overshoot_pct;
568 
569 
570  /*
571  * decoder buffer model parameters
572  */
573 
574 
584  unsigned int rc_buf_sz;
585 
586 
594  unsigned int rc_buf_initial_sz;
595 
596 
604  unsigned int rc_buf_optimal_sz;
605 
606 
607  /*
608  * 2 pass rate control parameters
609  */
610 
611 
620  unsigned int rc_2pass_vbr_bias_pct;
628  unsigned int rc_2pass_vbr_minsection_pct;
629 
630 
636  unsigned int rc_2pass_vbr_maxsection_pct;
637 
638 
639  /*
640  * keyframing settings (kf)
641  */
642 
649  enum vpx_kf_mode kf_mode;
650 
651 
659  unsigned int kf_min_dist;
660 
661 
669  unsigned int kf_max_dist;
670 
671  /*
672  * Spatial scalability settings (ss)
673  */
674 
679  unsigned int ss_number_layers;
680 
686  int ss_enable_auto_alt_ref[VPX_SS_MAX_LAYERS];
687 
693  unsigned int ss_target_bitrate[VPX_SS_MAX_LAYERS];
694 
699  unsigned int ts_number_layers;
700 
706  unsigned int ts_target_bitrate[VPX_TS_MAX_LAYERS];
707 
713  unsigned int ts_rate_decimator[VPX_TS_MAX_LAYERS];
714 
722  unsigned int ts_periodicity;
723 
731  unsigned int ts_layer_id[VPX_TS_MAX_PERIODICITY];
739  typedef struct vpx_svc_parameters {
745 
746 
770  vpx_codec_iface_t *iface,
771  const vpx_codec_enc_cfg_t *cfg,
772  vpx_codec_flags_t flags,
773  int ver);
774 
775 
780 #define vpx_codec_enc_init(ctx, iface, cfg, flags) \
781  vpx_codec_enc_init_ver(ctx, iface, cfg, flags, VPX_ENCODER_ABI_VERSION)
782 
783 
805  vpx_codec_iface_t *iface,
806  vpx_codec_enc_cfg_t *cfg,
807  int num_enc,
808  vpx_codec_flags_t flags,
809  vpx_rational_t *dsf,
810  int ver);
811 
812 
817 #define vpx_codec_enc_init_multi(ctx, iface, cfg, num_enc, flags, dsf) \
818  vpx_codec_enc_init_multi_ver(ctx, iface, cfg, num_enc, flags, dsf, \
819  VPX_ENCODER_ABI_VERSION)
820 
821 
842  vpx_codec_enc_cfg_t *cfg,
843  unsigned int reserved);
844 
845 
861  const vpx_codec_enc_cfg_t *cfg);
862 
863 
876 
877 
878 #define VPX_DL_REALTIME (1)
880 #define VPX_DL_GOOD_QUALITY (1000000)
882 #define VPX_DL_BEST_QUALITY (0)
920  vpx_codec_err_t vpx_codec_encode(vpx_codec_ctx_t *ctx,
921  const vpx_image_t *img,
922  vpx_codec_pts_t pts,
923  unsigned long duration,
924  vpx_enc_frame_flags_t flags,
925  unsigned long deadline);
926 
971  const vpx_fixed_buf_t *buf,
972  unsigned int pad_before,
973  unsigned int pad_after);
974 
975 
1000  vpx_codec_iter_t *iter);
1001 
1002 
1016 
1017 
1019 #ifdef __cplusplus
1020 }
1021 #endif
1022 #endif // VPX_VPX_ENCODER_H_
1023 
Rational Number.
Definition: vpx_encoder.h:256
vpx_fixed_buf_t twopass_stats
Definition: vpx_encoder.h:211
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.
Definition: vpx_encoder.h:275
Image Descriptor.
Definition: vpx_image.h:82
vpx_codec_pts_t pts
Definition: vpx_encoder.h:198
vpx_kf_mode
Keyframe placement mode.
Definition: vpx_encoder.h:287
#define VPX_TS_MAX_LAYERS
Definition: vpx_encoder.h:40
Definition: vpx_encoder.h:273
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.
int min_quantizers[5]
Definition: vpx_encoder.h:754
vpx_codec_enc_output_cx_pkt_cb_fn_t output_cx_pkt
Definition: vpx_encoder.h:248
int den
Definition: vpx_encoder.h:258
struct vpx_svc_parameters vpx_svc_extra_cfg_t
vp9 svc extra configure parameters
Definition: vpx_encoder.h:174
int partition_id
Definition: vpx_encoder.h:203
vpx_enc_pass
Multi-pass Encoding Pass.
Definition: vpx_encoder.h:263
Encoder configuration structure.
Definition: vpx_encoder.h:311
Definition: vpx_encoder.h:183
Definition: vpx_encoder.h:176
Definition: vpx_encoder.h:289
void * user_priv
Definition: vpx_encoder.h:249
Encoder output packet.
Definition: vpx_encoder.h:192
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:105
uint32_t vpx_codec_frame_flags_t
Compressed Frame Flags.
Definition: vpx_encoder.h:126
Definition: vpx_encoder.h:265
Definition: vpx_encoder.h:266
struct vpx_codec_cx_pkt::@1::@2 frame
#define VPX_SS_MAX_LAYERS
Definition: vpx_encoder.h:49
int max_quantizers[5]
Definition: vpx_encoder.h:753
enum vpx_bit_depth vpx_bit_depth_t
Bit depth for codecThis enumeration determines the bit depth of the codec.
uint64_t sse[4]
Definition: vpx_encoder.h:215
int scaling_factor_den[5]
Definition: vpx_encoder.h:756
size_t sz
Definition: vpx_encoder.h:197
enum vpx_codec_cx_pkt_kind kind
Definition: vpx_encoder.h:193
vpx_fixed_buf_t raw
Definition: vpx_encoder.h:218
Callback function pointer / user data pair storage.
Definition: vpx_encoder.h:247
long vpx_enc_frame_flags_t
Encoded Frame Flags.
Definition: vpx_encoder.h:301
int num
Definition: vpx_encoder.h:257
const struct vpx_codec_iface vpx_codec_iface_t
Codec interface structure.
Definition: vpx_codec.h:173
char pad[128-sizeof(enum vpx_codec_cx_pkt_kind)]
Definition: vpx_encoder.h:231
int scaling_factor_num[5]
Definition: vpx_encoder.h:755
long vpx_codec_flags_t
Initialization-time Feature Enabling.
Definition: vpx_codec.h:165
vpx_codec_cx_pkt_kind
Encoder output packet variants.
Definition: vpx_encoder.h:172
Definition: vpx_encoder.h:272
double psnr[4]
Definition: vpx_encoder.h:216
Definition: vpx_encoder.h:288
unsigned int samples[4]
Definition: vpx_encoder.h:214
vpx_fixed_buf_t firstpass_mb_stats
Definition: vpx_encoder.h:212
vpx_rc_mode
Rate control mode.
Definition: vpx_encoder.h:271
const vpx_image_t * vpx_codec_get_preview_frame(vpx_codec_ctx_t *ctx)
Get Preview Frame.
unsigned long duration
Definition: vpx_encoder.h:200
uint32_t vpx_codec_er_flags_t
Error Resilient flags.
Definition: vpx_encoder.h:146
vpx_codec_err_t
Algorithm return codes.
Definition: vpx_codec.h:89
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
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:243
struct vpx_codec_cx_pkt vpx_codec_cx_pkt_t
Encoder output packet.
struct vpx_rational vpx_rational_t
Rational Number.
struct vpx_codec_enc_output_cx_cb_pair vpx_codec_priv_output_cx_pkt_cb_pair_t
Callback function pointer / user data pair storage.
Definition: vpx_encoder.h:290
Definition: vpx_encoder.h:175
int64_t vpx_codec_pts_t
Time Stamp Type.
Definition: vpx_encoder.h:116
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:274
Describes the codec algorithm interface to applications.
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.
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:188
Definition: vpx_encoder.h:173
vpx_codec_frame_flags_t flags
Definition: vpx_encoder.h:202
void * buf
Definition: vpx_encoder.h:196
vp9 svc extra configure parameters
Definition: vpx_encoder.h:752
Definition: vpx_encoder.h:264
Codec context structure.
Definition: vpx_codec.h:199